예제 #1
0
        private BlockResult FillBlock(Block block, Chain chain)
        {
            var result = new BlockResult
            {
                hash                                                  = block.Hash.ToString(),
                previousHash                                          = block.PreviousHash.ToString(),
                timestamp                                             = block.Timestamp.Value,
                height                                                = block.Height,
                chainAddress                                          = chain.Address.ToString(),
                payload                                               = block.Payload != null?block.Payload.Encode() : new byte[0].Encode(),
                                                     reward           = chain.GetBlockReward(block).ToString(),
                                                     validatorAddress = Nexus.FindValidatorForBlock(block).ToString(),
            };

            var txs = new List <TransactionResult>();

            if (block.TransactionHashes != null && block.TransactionHashes.Any())
            {
                foreach (var transactionHash in block.TransactionHashes)
                {
                    var tx      = Nexus.FindTransactionByHash(transactionHash);
                    var txEntry = FillTransaction(tx);
                    txs.Add(txEntry);
                }
            }
            result.txs = txs.ToArray();

            // todo add other block info, eg: size, gas, txs
            return(result);
        }