Esempio n. 1
0
        public Block MapBlock(Core.Block block, bool returnFullTransactionObjects)
        {
            var blockModel = new Block
            {
                Hash              = new Data(block.Hash.Bytes),
                Uncles            = block.Ommers?.Select(x => new Data(x.Hash.Bytes)).ToArray(),
                Transactions      = returnFullTransactionObjects ? block.Transactions?.Select(x => MapTransaction(x, block)).ToArray() : null,
                TransactionHashes = !returnFullTransactionObjects?block.Transactions?.Select(x => new Data(x.Hash.Bytes)).ToArray() : null
            };

            if (block.Header == null)
            {
                return(blockModel);
            }

            blockModel.Number           = new Quantity(block.Header.Number);
            blockModel.ParentHash       = new Data(block.Header.ParentHash.Bytes);
            blockModel.Nonce            = new Data(block.Header.Nonce.ToString());
            blockModel.Sha3Uncles       = new Data(block.Header.OmmersHash.Bytes);
            blockModel.LogsBloom        = new Data(block.Header.Bloom?.Bytes);
            blockModel.TransactionsRoot = new Data(block.Header.TransactionsRoot.Bytes);
            blockModel.StateRoot        = new Data(block.Header.StateRoot.Bytes);
            blockModel.ReceiptsRoot     = new Data(block.Header.ReceiptsRoot.Bytes);
            blockModel.Miner            = block.Header.Beneficiary != null ? new Data(block.Header.Beneficiary.Hex) : null;
            blockModel.Difficulty       = new Quantity(block.Header.Difficulty);
            //TotalDifficulty = new Quantity(block.Header.Difficulty),
            blockModel.ExtraData = new Data(block.Header.ExtraData);
            //Size = new Quantity(block.Header.)
            blockModel.GasLimit  = new Quantity(block.Header.GasLimit);
            blockModel.GasUsed   = new Quantity(block.Header.GasUsed);
            blockModel.Timestamp = new Quantity(block.Header.Timestamp);

            return(blockModel);
        }
        public Block MapBlock(Core.Block block, bool returnFullTransactionObjects)
        {
            Transaction[] transactions      = null;
            Data[]        transactionHashes = null;
            if (returnFullTransactionObjects)
            {
                transactions = new Transaction[block.Transactions.Length];
            }
            else
            {
                transactionHashes = new Data[block.Transactions.Length];
            }

            for (int i = 0; i < block.Transactions.Length; i++)
            {
                if (returnFullTransactionObjects)
                {
                    transactions[i] = MapTransaction(block.Hash, block.Number, i, block.Transactions[i]);
                }
                else
                {
                    transactionHashes[i] = new Data(block.Transactions[i].Hash);
                }
            }

            var blockModel = new Block
            {
                Hash              = new Data(block.Hash.Bytes),
                Uncles            = block.Ommers?.Select(x => new Data(x.Hash)).ToArray(),
                Transactions      = transactions,
                TransactionHashes = transactionHashes
            };

            if (block.Header == null)
            {
                return(blockModel);
            }

            blockModel.Number           = new Quantity(block.Header.Number);
            blockModel.ParentHash       = new Data(block.Header.ParentHash);
            blockModel.Nonce            = new Data(block.Header.Nonce.ToString());
            blockModel.MixHash          = new Data(block.Header.MixHash?.ToString());
            blockModel.Sha3Uncles       = new Data(block.Header.OmmersHash);
            blockModel.LogsBloom        = new Data(block.Header.Bloom?.Bytes);
            blockModel.TransactionsRoot = new Data(block.Header.TransactionsRoot);
            blockModel.StateRoot        = new Data(block.Header.StateRoot);
            blockModel.ReceiptsRoot     = new Data(block.Header.ReceiptsRoot);
            blockModel.Miner            = block.Header.Beneficiary != null ? new Data(block.Header.Beneficiary) : null;
            blockModel.Difficulty       = new Quantity(block.Header.Difficulty);
            blockModel.TotalDifficulty  = new Quantity(block.Header.TotalDifficulty ?? 0);
            blockModel.ExtraData        = new Data(block.Header.ExtraData);
            //Size = new Quantity(block.Header.)
            blockModel.GasLimit  = new Quantity(block.Header.GasLimit);
            blockModel.GasUsed   = new Quantity(block.Header.GasUsed);
            blockModel.Timestamp = new Quantity(block.Header.Timestamp);

            return(blockModel);
        }