@@ -137,7 +137,7 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error {
137137 buf := encodeBufferPool .Get ().(* bytes.Buffer )
138138 defer encodeBufferPool .Put (buf )
139139 buf .Reset ()
140- if err := tx .encodeTyped (buf ); err != nil {
140+ if err := tx .encodeTypedMinimal (buf ); err != nil {
141141 return err
142142 }
143143 return rlp .Encode (w , buf .Bytes ())
@@ -156,7 +156,12 @@ func (tx *Transaction) encodeTypedMinimal(w io.Writer) error {
156156 if _ , err := w .Write ([]byte {tx .Type ()}); err != nil {
157157 return err
158158 }
159- return rlp .Encode (w , tx .inner )
159+ // TODO(inphi): clean
160+ if tx .Type () == BlobTxType {
161+ return EncodeSSZ (w , tx .inner .(* SignedBlobTx ))
162+ } else {
163+ return rlp .Encode (w , tx .inner )
164+ }
160165}
161166
162167// MarshalBinary returns the canonical encoding of the transaction.
@@ -201,10 +206,9 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
201206 if b , err = s .Bytes (); err != nil {
202207 return err
203208 }
204- inner , wrapData , err := tx .decodeTyped (b )
209+ inner , err := tx .decodeTypedMinimal (b )
205210 if err == nil {
206211 tx .setDecoded (inner , len (b ))
207- tx .wrapData = wrapData
208212 }
209213 return err
210214 }
@@ -568,7 +572,7 @@ func (s Transactions) EncodeIndex(i int, w *bytes.Buffer) {
568572 if tx .Type () == LegacyTxType {
569573 rlp .Encode (w , tx .inner )
570574 } else {
571- tx .encodeTyped (w )
575+ tx .encodeTypedMinimal (w )
572576 }
573577}
574578
@@ -812,3 +816,63 @@ func copyAddressPtr(a *common.Address) *common.Address {
812816 cpy := * a
813817 return & cpy
814818}
819+
820+ // NetworkTransaction is a Transaction wrapper that encodes its maximal representation
821+ type NetworkTransaction struct {
822+ Tx * Transaction
823+ }
824+
825+ func NewNetworkTransaction (tx * Transaction ) * NetworkTransaction {
826+ return & NetworkTransaction {Tx : tx }
827+ }
828+
829+ // EncodeRLP implements rlp.Encoder
830+ func (tx * NetworkTransaction ) EncodeRLP (w io.Writer ) error {
831+ if tx .Tx .Type () == LegacyTxType {
832+ return rlp .Encode (w , tx .Tx )
833+ }
834+ // It's an EIP-2718 typed TX envelope.
835+ buf := encodeBufferPool .Get ().(* bytes.Buffer )
836+ defer encodeBufferPool .Put (buf )
837+ buf .Reset ()
838+ if err := tx .Tx .encodeTyped (buf ); err != nil {
839+ return err
840+ }
841+ return rlp .Encode (w , buf .Bytes ())
842+ }
843+
844+ // DecodeRLP implements rlp.Decoder
845+ func (tx * NetworkTransaction ) DecodeRLP (s * rlp.Stream ) error {
846+ kind , size , err := s .Kind ()
847+ switch {
848+ case err != nil :
849+ return err
850+ case kind == rlp .List :
851+ // It's a legacy transaction.
852+ var inner LegacyTx
853+ err := s .Decode (& inner )
854+ if err == nil {
855+ tx .Tx .setDecoded (& inner , int (rlp .ListSize (size )))
856+ }
857+ return err
858+ default :
859+ // It's an EIP-2718 typed TX envelope.
860+ var b []byte
861+ if b , err = s .Bytes (); err != nil {
862+ return err
863+ }
864+ inner , wrapData , err := tx .Tx .decodeTyped (b )
865+ if err == nil {
866+ tx .Tx .setDecoded (inner , len (b ))
867+ tx .Tx .wrapData = wrapData
868+ }
869+ return err
870+ }
871+ }
872+
873+ // Hash returns the transaction hash.
874+ func (tx * NetworkTransaction ) Hash () common.Hash {
875+ return tx .Tx .Hash ()
876+ }
877+
878+ type NetworkTransactions []* NetworkTransaction
0 commit comments