public void RemoveLocalTimelineEntry(TransactionId transactionId) { this.RunDbOperation(litedbDal => { int dayId = 0; if (litedbDal.CollectionExists <NeuraliumWalletTimeline>()) { NeuraliumWalletTimeline entry = litedbDal.GetOne <NeuraliumWalletTimeline>(k => k.TransactionId == transactionId.ToString()); if (entry != null) { dayId = entry.DayId; } litedbDal.Remove <NeuraliumWalletTimeline>(k => k.TransactionId == transactionId.ToString()); } // if the day has no entries, we remove it. if (dayId != 0) { if (litedbDal.Any <NeuraliumWalletTimeline>(k => k.DayId == dayId) == false) { litedbDal.Remove <NeuraliumWalletTimelineDay>(k => k.Id == dayId); } } }); this.Save(); }
public void InsertTimelineEntry(NeuraliumWalletTimeline entry) { lock (this.locker) { this.RunDbOperation(litedbDal => { DateTime day = DateTime.SpecifyKind(new DateTime(entry.Timestamp.Year, entry.Timestamp.Month, entry.Timestamp.Day), DateTimeKind.Utc); NeuraliumWalletTimelineDay dayEntry = null; if (litedbDal.CollectionExists <NeuraliumWalletTimelineDay>() && (entry.Id != 0) && litedbDal.Exists <NeuraliumWalletTimeline>(k => k.Id == entry.Id)) { return; } // first, lets enter the day if required, otherwise update it if (!litedbDal.CollectionExists <NeuraliumWalletTimelineDay>() || !litedbDal.Exists <NeuraliumWalletTimelineDay>(k => k.Timestamp == day)) { dayEntry = new NeuraliumWalletTimelineDay(); int newId = 0; if (litedbDal.CollectionExists <NeuraliumWalletTimelineDay>() && litedbDal.Any <NeuraliumWalletTimelineDay>()) { newId = litedbDal.All <NeuraliumWalletTimelineDay>().Max(d => d.Id); } dayEntry.Id = newId + 1; dayEntry.Timestamp = day; dayEntry.Total = entry.Total; litedbDal.Insert(dayEntry, k => k.Id); } dayEntry = litedbDal.GetOne <NeuraliumWalletTimelineDay>(k => k.Timestamp == day); // update to the latest total dayEntry.Total = entry.Total; litedbDal.Update(dayEntry); entry.DayId = dayEntry.Id; litedbDal.Insert(entry, k => k.Id); }); this.Save(); } }
public void ConfirmLocalTimelineEntry(TransactionId transactionId) { this.RunDbOperation(litedbDal => { if (litedbDal.CollectionExists <NeuraliumWalletTimeline>()) { NeuraliumWalletTimeline entry = litedbDal.GetOne <NeuraliumWalletTimeline>(k => k.TransactionId == transactionId.ToString()); if (entry != null) { // update to the latest total entry.Confirmed = true; litedbDal.Update(entry); } } }); this.Save(); }
public override IWalletElectionsHistory InsertElectionsHistoryEntry(SynthesizedBlock.SynthesizedElectionResult electionResult, AccountId electedAccountId) { this.EnsureWalletLoaded(); IWalletElectionsHistory historyEntry = base.InsertElectionsHistoryEntry(electionResult, electedAccountId); // now let's add a neuralium timeline entry if (historyEntry is INeuraliumWalletElectionsHistory neuraliumWalletElectionsHistory && electionResult is NeuraliumSynthesizedBlock.NeuraliumSynthesizedElectionResult neuraliumSynthesizedElectionResult) { IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == electedAccountId); if (account == null) { throw new ApplicationException("Invalid account"); } if (this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { NeuraliumWalletTimeline neuraliumWalletTimeline = new NeuraliumWalletTimeline(); INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo; neuraliumWalletTimeline.Timestamp = neuraliumSynthesizedElectionResult.Timestamp; neuraliumWalletTimeline.Amount = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].bountyShare; neuraliumWalletTimeline.Tips = neuraliumSynthesizedElectionResult.ElectedGains[electedAccountId].tips; neuraliumWalletTimeline.RecipientAccountId = electedAccountId; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Election; neuraliumWalletTimeline.Total = this.GetAccountBalance(electedAccountId, false).Total + neuraliumWalletTimeline.Amount + neuraliumWalletTimeline.Tips; neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline); } } return(historyEntry); }
private void InsertNeuraliumTransactionTimelineEntry(ITransaction transaction, AccountId targetAccountId, INeuraliumWalletTransactionHistory neuraliumWalletTransactionHistory) { if ((neuraliumWalletTransactionHistory.Amount == 0) && (neuraliumWalletTransactionHistory.Tip == 0)) { // this transaction is most probably not a token influencing transaction. let's ignore 0 values return; } // this is an incomming transaction, now let's add a neuralium timeline entry IWalletAccount account = this.WalletFileInfo.WalletBase.Accounts.Values.SingleOrDefault(a => a.GetAccountId() == targetAccountId); if (account == null) { throw new ApplicationException("Invalid account"); } if (this.WalletFileInfo.Accounts[account.AccountUuid] is INeuraliumAccountFileInfo neuraliumAccountFileInfo) { NeuraliumWalletTimeline neuraliumWalletTimeline = new NeuraliumWalletTimeline(); INeuraliumWalletTimelineFileInfo neuraliumWalletTimelineFileInfo = neuraliumAccountFileInfo.WalletTimelineFileInfo; neuraliumWalletTimeline.Timestamp = this.serviceSet.TimeService.GetTimestampDateTime(transaction.TransactionId.Timestamp.Value, this.centralCoordinator.ChainComponentProvider.ChainStateProvider.ChainInception); neuraliumWalletTimeline.Amount = neuraliumWalletTransactionHistory.Amount; neuraliumWalletTimeline.Tips = 0; neuraliumWalletTimeline.TransactionId = transaction.TransactionId.ToString(); bool local = targetAccountId == transaction.TransactionId.Account; neuraliumWalletTimeline.SenderAccountId = transaction.TransactionId.Account; neuraliumWalletTimeline.RecipientAccountId = targetAccountId; decimal total = this.GetAccountBalance(targetAccountId, false).Total; if (local) { // in most cases, transactions we make wil be debits neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Debit; neuraliumWalletTimeline.Total = total - neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Tips = neuraliumWalletTransactionHistory.Tip; #if TESTNET || DEVNET if (transaction is INeuraliumRefillNeuraliumsTransaction) { neuraliumWalletTimeline.Total = total + neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction; } #endif neuraliumWalletTimeline.Total -= neuraliumWalletTimeline.Tips; neuraliumWalletTimeline.Confirmed = false; } else { neuraliumWalletTimeline.Total = total + neuraliumWalletTimeline.Amount; neuraliumWalletTimeline.Confirmed = true; neuraliumWalletTimeline.Direction = NeuraliumWalletTimeline.MoneratyTransactionTypes.Credit; neuraliumWalletTimeline.CreditType = NeuraliumWalletTimeline.CreditTypes.Tranasaction; } neuraliumWalletTimelineFileInfo.InsertTimelineEntry(neuraliumWalletTimeline); } }