/* * GetBlock * blockHash, UInt256 */ public string?GetBlock(string[] arguments) { if (arguments.Length != 2) { return("Wrong number of arguments"); } var value = EraseHexPrefix(arguments[1]); return(ulong.TryParse(value, out var blockHeight) ? ProtoUtils.ParsedObject(_blockManager.GetByHeight(blockHeight) ?? throw new InvalidOperationException()) : ProtoUtils.ParsedObject(_blockManager.GetByHash(arguments[1].HexToUInt256()) ?? throw new InvalidOperationException())); }
private JObject?GetBlockByHash(string blockHash) { var block = _blockManager.GetByHash(blockHash.HexToBytes().ToUInt256()); return(block?.ToJson()); }
public JObject?GetBlockByHash(string blockHash, bool fullTx = true) { var block = _blockManager.GetByHash(blockHash.HexToBytes().ToUInt256()); if (block == null) { return(null); } List <TransactionReceipt> txs = new List <TransactionReceipt>(); try { foreach (var txHash in block.TransactionHashes) { Logger.LogInformation($"Transaction hash {txHash.ToHex()} in block {block.Header.Index}"); TransactionReceipt?tx = _transactionManager.GetByHash(txHash); if (tx is null) { Logger.LogWarning($"Transaction not found in DB {txHash.ToHex()}"); } else { txs.Add(tx); } } } catch (Exception e) { Logger.LogWarning($"Exception {e}"); Logger.LogWarning($"block {block!.Hash}, {block.Header.Index}, {block.TransactionHashes.Count}"); foreach (var txhash in block.TransactionHashes) { Logger.LogWarning($"txhash {txhash.ToHex()}"); } } ulong gasUsed = 0; try { gasUsed = txs.Aggregate(gasUsed, (current, tx) => current + tx.GasUsed); } catch (Exception e) { Logger.LogWarning($"Exception {e}"); Logger.LogWarning($"txs {txs}"); foreach (var tx in txs) { if (tx is null) { continue; } Logger.LogWarning($"tx {tx.Hash.ToHex()} {tx.GasUsed} {tx.Status} {tx.IndexInBlock}"); } } var txArray = fullTx ? Web3DataFormatUtils.Web3BlockTransactionArray(txs, block !.Hash, block !.Header.Index) : new JArray(); if (!fullTx) { foreach (var tx in txs) { txArray.Add(Web3DataFormatUtils.Web3Data(tx.Hash)); } } return(Web3DataFormatUtils.Web3Block(block !, gasUsed, txArray)); }