private (int Total, int Logs) GetContentLength(TxReceipt item, RlpBehaviors rlpBehaviors) { var contentLength = 0; var logsLength = 0; if (item == null) { return(contentLength, 0); } contentLength += Rlp.LengthOf(item.GasUsedTotal); contentLength += Rlp.LengthOf(item.Bloom); logsLength = GetLogsLength(item); contentLength += Rlp.GetSequenceRlpLength(logsLength); bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts; if (isEip658Receipts) { contentLength += Rlp.LengthOf(item.StatusCode); } else { contentLength += Rlp.LengthOf(item.PostTransactionState); } return(contentLength, logsLength); }
private (int Total, int Logs) GetContentLength(TxReceipt item, RlpBehaviors rlpBehaviors) { if (item == null) { return(0, 0); } int contentLength = 0; contentLength += Rlp.LengthOf(item.GasUsedTotal); contentLength += Rlp.LengthOf(item.Bloom); int logsLength = GetLogsLength(item); contentLength += Rlp.GetSequenceRlpLength(logsLength); bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts; if (!item.SkipStateAndStatusInRlp) { contentLength += isEip658Receipts ? Rlp.LengthOf(item.StatusCode) : Rlp.LengthOf(item.PostTransactionState); } return(contentLength, logsLength); }
private (int Total, int Txs, int Ommers) GetContentLength(Block item, RlpBehaviors rlpBehaviors) { int contentLength = _headerDecoder.GetLength(item.Header, rlpBehaviors); int txLength = GetTxLength(item, rlpBehaviors); contentLength += Rlp.GetSequenceRlpLength(txLength); int ommersLength = GetOmmersLength(item, rlpBehaviors); contentLength += Rlp.GetSequenceRlpLength(ommersLength); return(contentLength, txLength, ommersLength); }
/// <summary> /// https://eips.ethereum.org/EIPS/eip-2718 /// </summary> public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors) { (int Total, int Logs)length = GetContentLength(item, rlpBehaviors); int receiptPayloadLength = Rlp.GetSequenceRlpLength(length.Total); bool isForTxRoot = (rlpBehaviors & RlpBehaviors.SkipTypedWrapping) == RlpBehaviors.SkipTypedWrapping; int result = item.TxType != TxType.Legacy ? isForTxRoot ? (1 + receiptPayloadLength) : Rlp.GetSequenceRlpLength(1 + receiptPayloadLength) // Rlp(TransactionType || TransactionPayload) : receiptPayloadLength; return(result); }
public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None) { if (item == null) { rlpStream.EncodeNullObject(); return; } (int totalContentLength, int logsLength) = GetContentLength(item, rlpBehaviors); int sequenceLength = Rlp.GetSequenceRlpLength(totalContentLength); bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts; if (item.TxType != TxType.Legacy) { if ((rlpBehaviors & RlpBehaviors.SkipTypedWrapping) == RlpBehaviors.None) { rlpStream.StartByteArray(sequenceLength + 1, false); } rlpStream.WriteByte((byte)item.TxType); } rlpStream.StartSequence(totalContentLength); if (!item.SkipStateAndStatusInRlp) { if (isEip658Receipts) { rlpStream.Encode(item.StatusCode); } else { rlpStream.Encode(item.PostTransactionState); } } rlpStream.Encode(item.GasUsedTotal); rlpStream.Encode(item.Bloom); rlpStream.StartSequence(logsLength); for (var i = 0; i < item.Logs.Length; i++) { rlpStream.Encode(item.Logs[i]); } }
private static (int Total, int Topics) GetContentLength(LogEntry?item) { var contentLength = 0; if (item == null) { return(contentLength, 0); } contentLength += Rlp.LengthOf(item.LoggersAddress); int topicsLength = GetTopicsLength(item); contentLength += Rlp.GetSequenceRlpLength(topicsLength); contentLength += Rlp.LengthOf(item.Data); return(contentLength, topicsLength); }
private (int Total, int Logs) GetContentLength(TxReceipt item, RlpBehaviors rlpBehaviors) { var contentLength = 0; var logsLength = 0; if (item == null) { return(contentLength, 0); } bool isStorage = (rlpBehaviors & RlpBehaviors.Storage) != 0; if (isStorage) { contentLength += Rlp.LengthOf(item.BlockHash); contentLength += Rlp.LengthOf(item.BlockNumber); contentLength += Rlp.LengthOf(item.Index); contentLength += Rlp.LengthOf(item.Sender); contentLength += Rlp.LengthOf(item.Recipient); contentLength += Rlp.LengthOf(item.ContractAddress); contentLength += Rlp.LengthOf(item.GasUsed); contentLength += 1 + Rlp.LengthOf(item.TxHash); } contentLength += Rlp.LengthOf(item.GasUsedTotal); contentLength += Rlp.LengthOf(item.Bloom); logsLength = GetLogsLength(item); contentLength += Rlp.GetSequenceRlpLength(logsLength); bool isEip658Receipts = (rlpBehaviors & RlpBehaviors.Eip658Receipts) == RlpBehaviors.Eip658Receipts; if (isEip658Receipts) { contentLength += Rlp.LengthOf(item.StatusCode); } else { contentLength += Rlp.LengthOf(item.PostTransactionState); } contentLength += Rlp.LengthOf(item.Error); return(contentLength, logsLength); }
public int GetLength(Transaction item, RlpBehaviors rlpBehaviors) => Rlp.GetSequenceRlpLength(GetContentLength(item, false));