Ejemplo n.º 1
0
        private Block GetBlock(
            RpcResponse response,
            bool includeTransactions)
        {
            if (response.Result.Type != JTokenType.Null)
            {
                var transactions = response.Result.Value <JArray>("transactions").ToList();

                IEnumerable <Transaction> GetTransactions()
                {
                    return(includeTransactions
                        ? transactions.Select(GetTransaction)
                        : null);
                }

                // ReSharper disable once ImplicitlyCapturedClosure
                IEnumerable <string> GetTransactionHashes()
                {
                    return(includeTransactions
                        ? transactions.Select(x => x.Value <string>("hash"))
                        : transactions.Select(x => x.Value <string>()));
                }

                return(new Block
                       (
                           blockHash: response.ResultValue <string>("hash"),
                           number: response.ResultValue <BigInteger?>("number"),
                           parentHash: response.ResultValue <string>("parentHash"),
                           timestamp: response.ResultValue <BigInteger>("timestamp"),
                           transactionHashes: GetTransactionHashes(),
                           transactions: GetTransactions()
                       ));
            }
            else
            {
                return(null);
            }
        }