示例#1
0
        private static int TransactionCount(Nethereum.RPC.Eth.DTOs.Block block)
        {
            if (block is BlockWithTransactions b)
            {
                return(b.Transactions?.Length ?? 0);
            }

            if (block is BlockWithTransactionHashes bh)
            {
                return(bh.TransactionHashes?.Length ?? 0);
            }

            return(0);
        }
示例#2
0
 public static void Map(this Block block, Nethereum.RPC.Eth.DTOs.Block source)
 {
     block.BlockNumber      = source.Number.Value.ToString();
     block.Difficulty       = source.Difficulty?.Value.ToString();
     block.GasLimit         = source.GasLimit?.Value.ToString();
     block.GasUsed          = source.GasUsed?.Value.ToString();
     block.Size             = source.Size?.Value.ToString();
     block.Timestamp        = source.Timestamp?.Value.ToString();
     block.TotalDifficulty  = source.TotalDifficulty?.Value.ToString();
     block.ExtraData        = source.ExtraData ?? string.Empty;
     block.Hash             = source.BlockHash ?? string.Empty;
     block.ParentHash       = source.ParentHash ?? string.Empty;
     block.Miner            = source.Miner ?? string.Empty;
     block.Nonce            = source.Nonce;
     block.TransactionCount = source.TransactionCount();
 }
 public static void Map(this Block block, Nethereum.RPC.Eth.DTOs.Block source)
 {
     block.BlockNumber      = source.Number.Value.ToString();
     block.Difficulty       = source.Difficulty.ToLong();
     block.GasLimit         = source.GasLimit.ToLong();
     block.GasUsed          = source.GasUsed.ToLong();
     block.Size             = source.Size.ToLong();
     block.Timestamp        = source.Timestamp.ToLong();
     block.TotalDifficulty  = source.TotalDifficulty.ToLong();
     block.ExtraData        = source.ExtraData ?? string.Empty;
     block.Hash             = source.BlockHash ?? string.Empty;
     block.ParentHash       = source.ParentHash ?? string.Empty;
     block.Miner            = source.Miner ?? string.Empty;
     block.Nonce            = string.IsNullOrEmpty(source.Nonce) ? 0 : new HexBigInteger(source.Nonce).ToLong();
     block.TransactionCount = source.TransactionCount();
 }
示例#4
0
        public static IndexedBlock MapBlock(
            Block block,
            IReadOnlyCollection <Transaction> transactions,
            IReadOnlyCollection <TransactionReceipt> receipts)
        {
            var transactionHashes = transactions.Select(x => x.TransactionHash).OrderBy(x => x);
            var receiptHashes     = receipts.Select(x => x.TransactionHash).OrderBy(x => x);

            if (!transactionHashes.SequenceEqual(receiptHashes))
            {
                throw new ArgumentException("Transactions and receipts should contain corresponding data.");
            }

            if (transactions.Any(x => x.BlockHash != block.BlockHash))
            {
                throw new ArgumentException("All transactions should belong to the specified block.");
            }

            if (receipts.Any(x => x.BlockHash != block.BlockHash))
            {
                throw new ArgumentException("All receipts should belong to the specified block.");
            }

            var transactionsWithReceipts = transactions.Join
                                           (
                receipts,
                x => x.TransactionHash,
                y => y.TransactionHash,
                (x, y) => (Transaction: x, Receipt: y)
                                           );

            return(new IndexedBlock
            {
                BlockHash = block.BlockHash,
                Number = (long)block.Number.Value,
                ParentHash = block.ParentHash,
                Timestamp = (long)block.Timestamp.Value,
                Transactions = MapTransactions(transactionsWithReceipts).ToList()
            });
        }
示例#5
0
 public static Block MapToStorageEntityForUpsert(this Nethereum.RPC.Eth.DTOs.Block source)
 {
     return(new Block().MapToStorageEntityForUpsert(source));
 }
示例#6
0
 public static TEntity MapToStorageEntityForUpsert <TEntity>(this TEntity block, Nethereum.RPC.Eth.DTOs.Block source) where TEntity : Block
 {
     block.Map(source);
     block.UpdateRowDates();
     return(block);
 }
示例#7
0
 public static TEntity MapToStorageEntityForUpsert <TEntity>(this Nethereum.RPC.Eth.DTOs.Block source) where TEntity : Block, new()
 {
     return(new TEntity().MapToStorageEntityForUpsert(source));
 }