@@ -45,6 +45,7 @@ const (
4545 LegacyTxType = iota
4646 AccessListTxType
4747 DynamicFeeTxType
48+ BlobTxType
4849
4950 L1MessageTxType = 0x7E
5051)
@@ -87,6 +88,9 @@ type TxData interface {
8788
8889 rawSignatureValues () (v , r , s * big.Int )
8990 setSignatureValues (chainID , v , r , s * big.Int )
91+
92+ encode (* bytes.Buffer ) error
93+ decode ([]byte ) error
9094}
9195
9296// EncodeRLP implements rlp.Encoder
@@ -107,7 +111,7 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error {
107111// encodeTyped writes the canonical encoding of a typed transaction to w.
108112func (tx * Transaction ) encodeTyped (w * bytes.Buffer ) error {
109113 w .WriteByte (tx .Type ())
110- return rlp . Encode ( w , tx .inner )
114+ return tx .inner . encode ( w )
111115}
112116
113117// MarshalBinary returns the canonical encoding of the transaction.
@@ -179,22 +183,21 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
179183 if len (b ) == 0 {
180184 return nil , errEmptyTypedTx
181185 }
186+ var inner TxData
182187 switch b [0 ] {
183188 case AccessListTxType :
184- var inner AccessListTx
185- err := rlp .DecodeBytes (b [1 :], & inner )
186- return & inner , err
189+ inner = new (AccessListTx )
187190 case DynamicFeeTxType :
188- var inner DynamicFeeTx
189- err := rlp . DecodeBytes ( b [ 1 :], & inner )
190- return & inner , err
191+ inner = new ( DynamicFeeTx )
192+ case BlobTxType :
193+ inner = new ( BlobTx )
191194 case L1MessageTxType :
192- var inner L1MessageTx
193- err := rlp .DecodeBytes (b [1 :], & inner )
194- return & inner , err
195+ inner = new (L1MessageTx )
195196 default :
196197 return nil , ErrTxTypeNotSupported
197198 }
199+ err := inner .decode (b [1 :])
200+ return inner , err
198201}
199202
200203// setDecoded sets the inner transaction and size after decoding.
@@ -389,6 +392,68 @@ func (tx *Transaction) EffectiveGasTipIntCmp(other *big.Int, baseFee *big.Int) i
389392 return tx .EffectiveGasTipValue (baseFee ).Cmp (other )
390393}
391394
395+ // BlobGas returns the blob gas limit of the transaction for blob transactions, 0 otherwise.
396+ func (tx * Transaction ) BlobGas () uint64 {
397+ if blobtx , ok := tx .inner .(* BlobTx ); ok {
398+ return blobtx .blobGas ()
399+ }
400+ return 0
401+ }
402+
403+ // BlobGasFeeCap returns the blob gas fee cap per blob gas of the transaction for blob transactions, nil otherwise.
404+ func (tx * Transaction ) BlobGasFeeCap () * big.Int {
405+ if blobtx , ok := tx .inner .(* BlobTx ); ok {
406+ return blobtx .BlobFeeCap .ToBig ()
407+ }
408+ return nil
409+ }
410+
411+ // BlobHashes returns the hashes of the blob commitments for blob transactions, nil otherwise.
412+ func (tx * Transaction ) BlobHashes () []common.Hash {
413+ if blobtx , ok := tx .inner .(* BlobTx ); ok {
414+ return blobtx .BlobHashes
415+ }
416+ return nil
417+ }
418+
419+ // BlobTxSidecar returns the sidecar of a blob transaction, nil otherwise.
420+ func (tx * Transaction ) BlobTxSidecar () * BlobTxSidecar {
421+ if blobtx , ok := tx .inner .(* BlobTx ); ok {
422+ return blobtx .Sidecar
423+ }
424+ return nil
425+ }
426+
427+ // BlobGasFeeCapCmp compares the blob fee cap of two transactions.
428+ func (tx * Transaction ) BlobGasFeeCapCmp (other * Transaction ) int {
429+ return tx .BlobGasFeeCap ().Cmp (other .BlobGasFeeCap ())
430+ }
431+
432+ // BlobGasFeeCapIntCmp compares the blob fee cap of the transaction against the given blob fee cap.
433+ func (tx * Transaction ) BlobGasFeeCapIntCmp (other * big.Int ) int {
434+ return tx .BlobGasFeeCap ().Cmp (other )
435+ }
436+
437+ // WithoutBlobTxSidecar returns a copy of tx with the blob sidecar removed.
438+ func (tx * Transaction ) WithoutBlobTxSidecar () * Transaction {
439+ blobtx , ok := tx .inner .(* BlobTx )
440+ if ! ok {
441+ return tx
442+ }
443+ cpy := & Transaction {
444+ inner : blobtx .withoutSidecar (),
445+ time : tx .time ,
446+ }
447+ // Note: tx.size cache not carried over because the sidecar is included in size!
448+ if h := tx .hash .Load (); h != nil {
449+ cpy .hash .Store (h )
450+ }
451+ if f := tx .from .Load (); f != nil {
452+ cpy .from .Store (f )
453+ }
454+ return cpy
455+ }
456+
392457// Hash returns the transaction hash.
393458func (tx * Transaction ) Hash () common.Hash {
394459 if hash := tx .hash .Load (); hash != nil {
0 commit comments