@@ -10,6 +10,7 @@ import io.iohk.ethereum.network.p2p.Message
10
10
import io .iohk .ethereum .network .p2p .MessageSerializableImplicit
11
11
import io .iohk .ethereum .rlp .RLPCodec .Ops
12
12
import io .iohk .ethereum .rlp .RLPImplicitConversions ._
13
+ import io .iohk .ethereum .rlp .RLPImplicitDerivations .RLPListDecoder
13
14
import io .iohk .ethereum .rlp .RLPImplicits ._
14
15
import io .iohk .ethereum .rlp ._
15
16
import io .iohk .ethereum .utils .ByteStringUtils .ByteStringOps
@@ -157,32 +158,29 @@ object BaseETH6XMessages {
157
158
158
159
implicit class SignedTransactionEnc (val signedTx : SignedTransaction ) extends RLPSerializable {
159
160
160
- override def toBytes : Array [Byte ] =
161
- signedTx.tx match {
162
- // transaction with access list encoding is defined in eip2930
163
- case _ : TransactionWithAccessList => Transaction .Type01 +: (super .toBytes: Array [Byte ])
164
- case _ : LegacyTransaction => super .toBytes
165
- }
166
-
167
161
override def toRLPEncodable : RLPEncodeable = {
168
162
val receivingAddressBytes = signedTx.tx.receivingAddress
169
163
.map(_.toArray)
170
164
.getOrElse(Array .emptyByteArray)
171
165
signedTx.tx match {
172
166
case TransactionWithAccessList (chainId, nonce, gasPrice, gasLimit, _, value, payload, accessList) =>
173
- RLPList (
174
- chainId,
175
- nonce,
176
- gasPrice,
177
- gasLimit,
178
- receivingAddressBytes,
179
- value,
180
- payload,
181
- toRlpList(accessList),
182
- signedTx.signature.v,
183
- signedTx.signature.r,
184
- signedTx.signature.s
167
+ PrefixedRLPEncodable (
168
+ Transaction .Type01 ,
169
+ RLPList (
170
+ chainId,
171
+ nonce,
172
+ gasPrice,
173
+ gasLimit,
174
+ receivingAddressBytes,
175
+ value,
176
+ payload,
177
+ toRlpList(accessList),
178
+ signedTx.signature.v,
179
+ signedTx.signature.r,
180
+ signedTx.signature.s
181
+ )
185
182
)
183
+
186
184
case LegacyTransaction (nonce, gasPrice, gasLimit, _, value, payload) =>
187
185
RLPList (
188
186
nonce,
@@ -208,27 +206,40 @@ object BaseETH6XMessages {
208
206
}
209
207
210
208
implicit class SignedTransactionsDec (val bytes : Array [Byte ]) extends AnyVal {
211
- def toSignedTransactions : SignedTransactions = rawDecode(bytes) match {
212
- case rlpList : RLPList => SignedTransactions (rlpList.items.map(_.toSignedTransaction))
213
- case _ => throw new RuntimeException (" Cannot decode SignedTransactions" )
214
- }
209
+
210
+ def mergeTransactionType (encodables : Seq [RLPEncodeable ]): Seq [RLPEncodeable ] =
211
+ encodables match {
212
+ case Seq () => Seq ()
213
+ case Seq (RLPValue (v), rlpList : RLPList , tail @ _* ) if v.length == 1 =>
214
+ PrefixedRLPEncodable (v.head, rlpList) +: mergeTransactionType(tail)
215
+ case Seq (head, tail @ _* ) => head +: mergeTransactionType(tail)
216
+ }
217
+ def toSignedTransactions : SignedTransactions =
218
+ rawDecode(bytes) match {
219
+ case rlpList : RLPList => SignedTransactions (mergeTransactionType(rlpList.items).map(_.toSignedTransaction))
220
+ case _ => throw new RuntimeException (" Cannot decode SignedTransactions" )
221
+ }
215
222
}
216
223
217
224
implicit class SignedTransactionRlpEncodableDec (val rlpEncodeable : RLPEncodeable ) extends AnyVal {
218
225
226
+ // scalastyle:off method.length
219
227
def toSignedTransaction : SignedTransaction = rlpEncodeable match {
220
- case RLPList (
221
- chainId,
222
- nonce,
223
- gasPrice,
224
- gasLimit,
225
- (receivingAddress : RLPValue ),
226
- value,
227
- payload,
228
- (accessList : RLPList ),
229
- pointSign,
230
- signatureRandom,
231
- signature
228
+ case PrefixedRLPEncodable (
229
+ Transaction .Type01 ,
230
+ RLPList (
231
+ chainId,
232
+ nonce,
233
+ gasPrice,
234
+ gasLimit,
235
+ (receivingAddress : RLPValue ),
236
+ value,
237
+ payload,
238
+ (accessList : RLPList ),
239
+ pointSign,
240
+ signatureRandom,
241
+ signature
242
+ )
232
243
) =>
233
244
val receivingAddressOpt = if (receivingAddress.bytes.isEmpty) None else Some (Address (receivingAddress.bytes))
234
245
SignedTransaction (
@@ -246,6 +257,7 @@ object BaseETH6XMessages {
246
257
signatureRandom,
247
258
signature
248
259
)
260
+
249
261
case RLPList (
250
262
nonce,
251
263
gasPrice,
@@ -273,7 +285,7 @@ object BaseETH6XMessages {
273
285
def toSignedTransaction : SignedTransaction = {
274
286
val first = bytes(0 )
275
287
(first match {
276
- case Transaction .Type01 => rawDecode(bytes.tail)
288
+ case Transaction .Type01 => PrefixedRLPEncodable ( Transaction . Type01 , rawDecode(bytes.tail) )
277
289
// TODO enforce legacy boundaries
278
290
case _ => rawDecode(bytes)
279
291
}).toSignedTransaction
0 commit comments