Ejemplo n.º 1
0
        public async Task HandleTransactions(WebWalletTransactionsAction action, IDispatcher dispatcher)
        {
            var result = await action.wallet.Sync(null);

            List <string> txs = new List <string>();

            if (result == Lyra.Core.Blocks.APIResultCodes.Success)
            {
                var accHeight = await client.GetAccountHeight(action.wallet.AccountId);

                Dictionary <string, long> oldBalance = null;
                var start = accHeight.Height - 100;
                if (start < 1)
                {
                    start = 1;                                          // only show the last 100 tx
                }
                for (long i = start; i <= accHeight.Height; i++)
                {
                    var blockResult = await client.GetBlockByIndex(action.wallet.AccountId, i);

                    var block = blockResult.GetBlock() as TransactionBlock;
                    if (block == null)
                    {
                        txs.Add("Null");
                    }
                    else
                    {
                        var str = $"No. {block.Height} {block.TimeStamp}, ";
                        if (block is SendTransferBlock sb)
                        {
                            str += $"Send to {sb.DestinationAccountId}";
                        }
                        else if (block is ReceiveTransferBlock rb)
                        {
                            if (rb.SourceHash == null)
                            {
                                str += $"Genesis";
                            }
                            else
                            {
                                var srcBlockResult = await client.GetBlock(rb.SourceHash);

                                var srcBlock = srcBlockResult.GetBlock() as TransactionBlock;
                                str += $"Receive from {srcBlock.AccountID}";
                            }
                        }
                        str += BalanceDifference(oldBalance, block.Balances);
                        str += $" Balance: {string.Join(", ", block.Balances.Select(m => $"{m.Key}: {m.Value.ToBalanceDecimal()}"))}";

                        txs.Add(str);

                        oldBalance = block.Balances;
                    }
                }
            }
            txs.Reverse();
            dispatcher.Dispatch(new WebWalletTransactionsResultAction {
                wallet = action.wallet, transactions = txs
            });
        }
Ejemplo n.º 2
0
 public static WebWalletState GetTransactionActionHandler(WebWalletState state, WebWalletTransactionsAction action) => state.With(new { IsLoading = true });