Exemplo n.º 1
0
        private async Task GetDataFromNxtServer()
        {
            _lastBalanceMatchBlock = await _nxtServer.GetBlockAsync(_walletRepository.LastBalanceMatchBlockId);

            _blockchainStatus = await _nxtServer.GetBlockchainStatusAsync();

            _nxtTransactions      = (await _nxtServer.GetTransactionsAsync(_lastBalanceMatchBlock.Timestamp)).ToList();
            UnconfirmedBalanceNqt = await _nxtServer.GetUnconfirmedNqtBalanceAsync();
        }
Exemplo n.º 2
0
        public async Task TryCheckAllLedgerEntries(CancellationToken cancellationToken)
        {
            var syncBlockInfo = await SyncToLastCommonBlock();

            var blockchainStatus = syncBlockInfo.Item1;
            var lastKnownBlock   = syncBlockInfo.Item2;

            var knownUnconfirmedEntries = await _accountLedgerRepository.GetUnconfirmedLedgerEntriesAsync();

            var nrsUnconfirmedLedgerEntries = await _nxtServer.GetUnconfirmedAccountLedgerEntriesAsync();

            var nrsConfirmedLedgerEntries = await _nxtServer.GetAccountLedgerEntriesAsync(lastKnownBlock.Timestamp);

            var nrsLedgerEntries      = nrsUnconfirmedLedgerEntries.Union(nrsConfirmedLedgerEntries).ToList();
            var nrsUnconfirmedBalance = await _nxtServer.GetUnconfirmedNqtBalanceAsync();

            var updatedLedgerEntries = GetConfirmedEntries(knownUnconfirmedEntries, nrsConfirmedLedgerEntries).ToList();
            var deletedLedgerEntries = GetLostUnconfirmedEntries(knownUnconfirmedEntries, nrsLedgerEntries).ToList();

            // If NRS.unconfirmedBalance != last ledger entry balance + sum(unconfirmed transaction amounts)
            //   Log error, throw exception!

            cancellationToken.ThrowIfCancellationRequested();

            await _walletRepository.UpdateLastLedgerEntryBlockIdAsync(blockchainStatus.LastBlockId);

            if (_walletRepository.NqtBalance != nrsUnconfirmedBalance)
            {
                await _walletRepository.UpdateBalanceAsync(nrsUnconfirmedBalance);
            }
            await _accountLedgerRepository.AddLedgerEntriesAsync(nrsConfirmedLedgerEntries);

            await _accountLedgerRepository.UpdateLedgerEntriesAsync(updatedLedgerEntries);

            await _accountLedgerRepository.RemoveLedgerEntriesAsync(deletedLedgerEntries);

            Messenger.Default.Send(new BalanceUpdatedMessage(nrsUnconfirmedBalance));
            deletedLedgerEntries.ForEach(e => Messenger.Default.Send(new LedgerEntryMessage(e, LedgerEntryMessageAction.Removed)));
            nrsConfirmedLedgerEntries.ForEach(e => Messenger.Default.Send(new LedgerEntryMessage(e, LedgerEntryMessageAction.Added)));
            updatedLedgerEntries.ForEach(e => Messenger.Default.Send(new LedgerEntryMessage(e, LedgerEntryMessageAction.ConfirmationUpdated)));
        }