improve documentation of the encoding methods
This commit is contained in:
parent
4336bf63eb
commit
b13ce2a6ba
@ -139,6 +139,9 @@ func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt {
|
|||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
|
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
|
||||||
// into an RLP stream. If no post state is present, byzantium fork is assumed.
|
// into an RLP stream. If no post state is present, byzantium fork is assumed.
|
||||||
|
// For a legacy Receipt this returns RLP([PostStateOrStatus, CumulativeGasUsed, Bloom, Logs])
|
||||||
|
// For a EIP-2718 Receipt this returns RLP(TxType || ReceiptPayload)
|
||||||
|
// For a EIP-2930 Receipt, TxType == 0x01 and ReceiptPayload == RLP([PostStateOrStatus, CumulativeGasUsed, Bloom, Logs])
|
||||||
func (r *Receipt) EncodeRLP(w io.Writer) error {
|
func (r *Receipt) EncodeRLP(w io.Writer) error {
|
||||||
data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
|
data := &receiptRLP{r.statusEncoding(), r.CumulativeGasUsed, r.Bloom, r.Logs}
|
||||||
if r.Type == LegacyTxType {
|
if r.Type == LegacyTxType {
|
||||||
@ -151,16 +154,22 @@ func (r *Receipt) EncodeRLP(w io.Writer) error {
|
|||||||
buf := encodeBufferPool.Get().(*bytes.Buffer)
|
buf := encodeBufferPool.Get().(*bytes.Buffer)
|
||||||
defer encodeBufferPool.Put(buf)
|
defer encodeBufferPool.Put(buf)
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
buf.WriteByte(r.Type)
|
if err := r.encodeTyped(data, buf); err != nil {
|
||||||
if err := rlp.Encode(buf, data); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return rlp.Encode(w, buf.Bytes())
|
return rlp.Encode(w, buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalBinary returns the canonical encoding of the receipt.
|
// encodeTyped writes the canonical encoding of a typed receipt to w.
|
||||||
// For legacy receipts, it returns the RLP encoding. For EIP-2718 typed
|
func (r *Receipt) encodeTyped(data *receiptRLP, w *bytes.Buffer) error {
|
||||||
// receipts, it returns the `type || RLP encoding`.
|
w.WriteByte(r.Type)
|
||||||
|
return rlp.Encode(w, data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalBinary returns the canonical consensus encoding of the receipt.
|
||||||
|
// For a legacy Receipt this returns RLP([PostStateOrStatus, CumulativeGasUsed, Bloom, Logs])
|
||||||
|
// For a EIP-2718 Receipt this returns TxType || ReceiptPayload
|
||||||
|
// For a EIP-2930, TxType == 0x01 and ReceiptPayload == RLP([PostStateOrStatus, CumulativeGasUsed, Bloom, Logs])
|
||||||
func (r *Receipt) MarshalBinary() ([]byte, error) {
|
func (r *Receipt) MarshalBinary() ([]byte, error) {
|
||||||
if r.Type == LegacyTxType {
|
if r.Type == LegacyTxType {
|
||||||
return rlp.EncodeToBytes(r)
|
return rlp.EncodeToBytes(r)
|
||||||
@ -169,11 +178,8 @@ func (r *Receipt) MarshalBinary() ([]byte, error) {
|
|||||||
buf := encodeBufferPool.Get().(*bytes.Buffer)
|
buf := encodeBufferPool.Get().(*bytes.Buffer)
|
||||||
defer encodeBufferPool.Put(buf)
|
defer encodeBufferPool.Put(buf)
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
buf.WriteByte(r.Type)
|
err := r.encodeTyped(data, buf)
|
||||||
if err := rlp.Encode(buf, data); err != nil {
|
return buf.Bytes(), err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt
|
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt
|
||||||
|
@ -83,6 +83,9 @@ type TxData interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EncodeRLP implements rlp.Encoder
|
// EncodeRLP implements rlp.Encoder
|
||||||
|
// For a legacy Transaction this returns RLP([AccountNonce, GasPrice, GasLimit, Recipient, Amount, Data, V, R, S])
|
||||||
|
// For a EIP-2718 Transaction this returns RLP(TxType || TxPayload)
|
||||||
|
// For a EIP-2930 Transaction, TxType == 0x01 and TxPayload == RLP([ChainID, AccountNonce, GasPrice, GasLimit, Recipient, Amount, Data, AccessList, V, R, S]
|
||||||
func (tx *Transaction) EncodeRLP(w io.Writer) error {
|
func (tx *Transaction) EncodeRLP(w io.Writer) error {
|
||||||
if tx.Type() == LegacyTxType {
|
if tx.Type() == LegacyTxType {
|
||||||
return rlp.Encode(w, tx.inner)
|
return rlp.Encode(w, tx.inner)
|
||||||
@ -103,9 +106,10 @@ func (tx *Transaction) encodeTyped(w *bytes.Buffer) error {
|
|||||||
return rlp.Encode(w, tx.inner)
|
return rlp.Encode(w, tx.inner)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalBinary returns the canonical encoding of the transaction.
|
// MarshalBinary returns the canonical consensus encoding of the transaction.
|
||||||
// For legacy transactions, it returns the RLP encoding. For EIP-2718 typed
|
// For a legacy Transaction this returns RLP([AccountNonce, GasPrice, GasLimit, Recipient, Amount, Data, V, R, S])
|
||||||
// transactions, it returns the type and payload.
|
// For a EIP-2718 Transaction this returns TxType || TxPayload
|
||||||
|
// For a EIP-2930 Transaction, TxType == 0x01 and TxPayload == RLP([ChainID, AccountNonce, GasPrice, GasLimit, Recipient, Amount, Data, AccessList, V, R, S]
|
||||||
func (tx *Transaction) MarshalBinary() ([]byte, error) {
|
func (tx *Transaction) MarshalBinary() ([]byte, error) {
|
||||||
if tx.Type() == LegacyTxType {
|
if tx.Type() == LegacyTxType {
|
||||||
return rlp.EncodeToBytes(tx.inner)
|
return rlp.EncodeToBytes(tx.inner)
|
||||||
|
Loading…
Reference in New Issue
Block a user