File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
rlp/src/main/scala/io/iohk/ethereum/rlp
src/main/scala/io/iohk/ethereum Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ package object rlp {
58
58
* @param prefixedRLPEncodeable the RLPEncodable to prefix with
59
59
*/
60
60
case class PrefixedRLPEncodable (prefix : Byte , prefixedRLPEncodeable : RLPEncodeable ) extends RLPEncodeable {
61
- require(prefix <= 0x07f , " prefix should be lower than 0x7f" )
61
+ require(prefix >= 0 , " prefix should be in the range [0; 0x7f] " )
62
62
}
63
63
64
64
trait RLPEncoder [T ] {
Original file line number Diff line number Diff line change @@ -23,13 +23,25 @@ sealed trait Transaction extends Product with Serializable {
23
23
24
24
object Transaction {
25
25
val Type01 : Byte = 1 .toByte
26
+
27
+ val MinAllowedType : Byte = 0
28
+ val MaxAllowedType : Byte = 0x7f
29
+
26
30
val LegacyThresholdLowerBound : Int = 0xc0
27
31
val LegacyThresholdUpperBound : Int = 0xfe
28
32
29
33
def withGasLimit (gl : BigInt ): Transaction => Transaction = {
30
34
case tx : LegacyTransaction => tx.copy(gasLimit = gl)
31
35
case tx : TransactionWithAccessList => tx.copy(gasLimit = gl)
32
36
}
37
+
38
+ implicit class TransactionTypeValidator (val transactionType : Byte ) extends AnyVal {
39
+ def isValidTransactionType : Boolean = transactionType >= MinAllowedType && transactionType <= MaxAllowedType
40
+ }
41
+
42
+ implicit class ByteArrayTransactionTypeValidator (val binaryData : Array [Byte ]) extends AnyVal {
43
+ def isValidTransactionType : Boolean = binaryData.length == 1 && binaryData.head.isValidTransactionType
44
+ }
33
45
}
34
46
35
47
sealed trait TypedTransaction extends Transaction
Original file line number Diff line number Diff line change @@ -161,6 +161,8 @@ object BaseETH6XMessages {
161
161
object TypedTransaction {
162
162
implicit class TypedTransactionsRLPAggregator (val encodables : Seq [RLPEncodeable ]) extends AnyVal {
163
163
164
+ import Transaction .ByteArrayTransactionTypeValidator
165
+
164
166
/** Convert a Seq of RLPEncodable containing TypedTransaction informations into a Seq of
165
167
* Prefixed RLPEncodable.
166
168
*
@@ -181,7 +183,7 @@ object BaseETH6XMessages {
181
183
def toTypedRLPEncodables : Seq [RLPEncodeable ] =
182
184
encodables match {
183
185
case Seq () => Seq ()
184
- case Seq (RLPValue (v), rlpList : RLPList , tail @ _* ) if v.length == 1 && v.head < 0x7f =>
186
+ case Seq (RLPValue (v), rlpList : RLPList , tail @ _* ) if v.isValidTransactionType =>
185
187
PrefixedRLPEncodable (v.head, rlpList) +: tail.toTypedRLPEncodables
186
188
case Seq (head, tail @ _* ) => head +: tail.toTypedRLPEncodables
187
189
}
You can’t perform that action at this time.
0 commit comments