@@ -37,12 +37,12 @@ public byte[] encode(Transaction tx, boolean includeSignature) {
37
37
}
38
38
if (tx .getType () == TransactionType .STANDARD ) {
39
39
if (includeSignature ) {
40
- return encodeStandard (tx , true , null );
40
+ return encodeLegacy (tx , true , null );
41
41
} else {
42
42
Signature signature = tx .getSignature ();
43
43
if (signature .getType () == SignatureType .EIP155 ) {
44
44
int chainId = ((SignatureEIP155 )signature ).getChainId ();
45
- return encodeStandard (tx , false , chainId );
45
+ return encodeLegacy (tx , false , chainId );
46
46
} else {
47
47
throw new IllegalStateException ("Neither signature nor chainId specified" );
48
48
}
@@ -51,7 +51,16 @@ public byte[] encode(Transaction tx, boolean includeSignature) {
51
51
throw new IllegalStateException ("Unsupported transaction type: " + tx .getType ());
52
52
}
53
53
54
- protected byte [] encodeStandard (Transaction tx , boolean includeSignature , Integer chainId ) {
54
+ /**
55
+ * Encode a Legacy transaction (pre EIP-2718 which introduces a new RLP format).
56
+ * For legacy transaction you have to encode either the signature or the chainId for unsigned transaction.
57
+ *
58
+ * @param tx legacy transaction
59
+ * @param includeSignature if true, include signature, if false include chainId
60
+ * @param chainId chain id to include in the transaction if signature is not specified
61
+ * @return RLP encoded transaction
62
+ */
63
+ public byte [] encodeLegacy (Transaction tx , boolean includeSignature , Integer chainId ) {
55
64
RlpWriter wrt = new RlpWriter ();
56
65
wrt .startList ()
57
66
.write (tx .getNonce ())
0 commit comments