Skip to content

Commit 0e7371b

Browse files
committed
solution: some shortcuts to access / write tx type as in EIP-2718
1 parent 264aca1 commit 0e7371b

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

etherjar-tx/src/main/java/io/emeraldpay/etherjar/tx/TransactionType.java

+22-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum TransactionType {
2323
/**
2424
* A standard transaction available in Ethereum from the beginning
2525
*/
26-
STANDARD((byte)-1),
26+
STANDARD(null),
2727

2828
/**
2929
* Transaction with Access List introduced by EIP-2930 and available since Berlin Fork of Ethereum Mainnet.
@@ -42,9 +42,9 @@ public enum TransactionType {
4242
*/
4343
BLOB((byte)3);
4444

45-
private final byte flag;
45+
private final Byte flag;
4646

47-
TransactionType(byte flag) {
47+
TransactionType(Byte flag) {
4848
this.flag = flag;
4949
}
5050

@@ -83,11 +83,27 @@ public static TransactionType fromPrefix(byte prefix) {
8383
throw new IllegalArgumentException("Unsupported type: 0x" + Integer.toHexString(u));
8484
}
8585

86-
public byte getFlag() {
86+
public static TransactionType fromTransaction(Transaction tx) {
87+
return tx.getType();
88+
}
89+
90+
/**
91+
* A byte to prepend to the transaction when encode in Raw
92+
*
93+
* @return the byte for EIP-2718 type, or null for other transactions
94+
*/
95+
public Byte getFlag() {
8796
return flag;
8897
}
8998

90-
public boolean isFlagPrefixed() {
91-
return this == STANDARD;
99+
/**
100+
* Check if this type is actually an EIP-2718 type (which also means it's a part of the Raw Transaction, etc.).
101+
* I.e. the Legacy / Standard transaction is not an EIP-2718 type, but all other types are.
102+
*
103+
* @see <a href="https://eips.ethereum.org/EIPS/eip-2718">EIP-2718</a>
104+
* @return true if this type is an EIP-2718 type
105+
*/
106+
public boolean is2718() {
107+
return this != STANDARD;
92108
}
93109
}

0 commit comments

Comments
 (0)