Skip to content

Commit

Permalink
Fixes for PR-EIP1559 accessList
Browse files Browse the repository at this point in the history
Signed-off-by: Nischal Sharma <nischal@web3labs.com>
  • Loading branch information
NickSneo committed Jan 17, 2024
1 parent afbace5 commit 53c8ae2
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 8 deletions.
27 changes: 25 additions & 2 deletions crypto/src/main/java/org/web3j/crypto/RawTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,31 @@ public static RawTransaction createTransaction(
data,
maxPriorityFeePerGas,
maxFeePerGas,
Collections.emptyList()
));
Collections.emptyList()));

Check warning on line 120 in crypto/src/main/java/org/web3j/crypto/RawTransaction.java

View check run for this annotation

Codecov / codecov/patch

crypto/src/main/java/org/web3j/crypto/RawTransaction.java#L120

Added line #L120 was not covered by tests
}

public static RawTransaction createTransaction(
long chainId,
BigInteger nonce,
BigInteger gasLimit,
String to,
BigInteger value,
String data,
BigInteger maxPriorityFeePerGas,
BigInteger maxFeePerGas,
List<AccessListObject> accessList) {

return new RawTransaction(
Transaction1559.createTransaction(
chainId,
nonce,
gasLimit,
to,
value,
data,
maxPriorityFeePerGas,
maxFeePerGas,
accessList));
}

public static RawTransaction createTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private static RawTransaction decodeEIP1559Transaction(final byte[] transaction)

final BigInteger value = ((RlpString) values.getValues().get(6)).asPositiveBigInteger();
final String data = ((RlpString) values.getValues().get(7)).asString();
List<AccessListObject> accessList =
decodeAccessList(((RlpList) values.getValues().get(8)).getValues());

final RawTransaction rawTransaction =
RawTransaction.createTransaction(
Expand All @@ -74,7 +76,8 @@ private static RawTransaction decodeEIP1559Transaction(final byte[] transaction)
value,
data,
maxPriorityFeePerGas,
maxFeePerGas);
maxFeePerGas,
accessList);

if (values.getValues().size() == UNSIGNED_EIP1559TX_RLP_LIST_SIZE) {
return rawTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.web3j.utils.Bytes;
import org.web3j.utils.Numeric;

import static org.web3j.crypto.transaction.type.TransactionType.EIP1559;

/**
* Transaction class used for signing 1559 transactions locally.<br>
* For the specification, refer to p4 of the <a href="http://gavwood.com/paper.pdf">yellow
Expand All @@ -37,6 +35,20 @@ public class Transaction1559 extends Transaction2930 implements ITransaction {
private BigInteger maxPriorityFeePerGas;
private BigInteger maxFeePerGas;

public Transaction1559(
long chainId,
BigInteger nonce,
BigInteger gasLimit,
String to,
BigInteger value,
String data,
BigInteger maxPriorityFeePerGas,
BigInteger maxFeePerGas) {
super(chainId, nonce, null, gasLimit, to, value, data, Collections.emptyList());
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.maxFeePerGas = maxFeePerGas;
}

Check warning on line 50 in crypto/src/main/java/org/web3j/crypto/transaction/type/Transaction1559.java

View check run for this annotation

Codecov / codecov/patch

crypto/src/main/java/org/web3j/crypto/transaction/type/Transaction1559.java#L47-L50

Added lines #L47 - L50 were not covered by tests

public Transaction1559(
long chainId,
BigInteger nonce,
Expand All @@ -47,7 +59,7 @@ public Transaction1559(
BigInteger maxPriorityFeePerGas,
BigInteger maxFeePerGas,
List<AccessListObject> accessList) {
super(chainId, nonce, null, gasLimit, to, value, data,accessList);
super(chainId, nonce, null, gasLimit, to, value, data, accessList);
this.maxPriorityFeePerGas = maxPriorityFeePerGas;
this.maxFeePerGas = maxFeePerGas;
}
Expand Down Expand Up @@ -104,7 +116,15 @@ public static Transaction1559 createEtherTransaction(
BigInteger maxPriorityFeePerGas,
BigInteger maxFeePerGas) {
return new Transaction1559(
chainId, nonce, gasLimit, to, value, "", maxPriorityFeePerGas, maxFeePerGas, Collections.emptyList());
chainId,
nonce,
gasLimit,
to,
value,
"",
maxPriorityFeePerGas,
maxFeePerGas,
Collections.emptyList());
}

public static Transaction1559 createTransaction(
Expand All @@ -119,7 +139,34 @@ public static Transaction1559 createTransaction(
List<AccessListObject> accessList) {

return new Transaction1559(
chainId, nonce, gasLimit, to, value, data, maxPriorityFeePerGas, maxFeePerGas, accessList);
chainId,
nonce,
gasLimit,
to,
value,
data,
maxPriorityFeePerGas,
maxFeePerGas,
accessList);
}

public static Transaction1559 createTransaction(
long chainId,
BigInteger nonce,
BigInteger gasLimit,
String to,
BigInteger value,
String data,
BigInteger maxPriorityFeePerGas,
BigInteger maxFeePerGas) {

return new Transaction1559(
chainId, nonce, gasLimit, to, value, data, maxPriorityFeePerGas, maxFeePerGas);
}

@Override
public TransactionType getType() {
return TransactionType.EIP1559;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public List<RlpType> asRlpValues(Sign.SignatureData signatureData) {

return result;
}

protected List<RlpType> rlpAccessListRlp() {

List<AccessListObject> accessList = getAccessList();
Expand Down
51 changes: 51 additions & 0 deletions crypto/src/test/java/org/web3j/crypto/TransactionDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ public void testDecoding1559() {
assertEquals(transaction1559.getData(), resultTransaction1559.getData());
}

@Test
public void testDecoding1559AccessList() {
final RawTransaction rawTransaction = createEip1559RawTransactionAccessList();
final Transaction1559 transaction1559 = (Transaction1559) rawTransaction.getTransaction();

final byte[] encodedMessage = TransactionEncoder.encode(rawTransaction);
final String hexMessage = Numeric.toHexString(encodedMessage);

final RawTransaction result = TransactionDecoder.decode(hexMessage);
assertTrue(result.getTransaction() instanceof Transaction1559);
final Transaction1559 resultTransaction1559 = (Transaction1559) result.getTransaction();

assertNotNull(result);
assertEquals(transaction1559.getChainId(), resultTransaction1559.getChainId());
assertEquals(transaction1559.getNonce(), resultTransaction1559.getNonce());
assertEquals(transaction1559.getMaxFeePerGas(), resultTransaction1559.getMaxFeePerGas());
assertEquals(
transaction1559.getMaxPriorityFeePerGas(),
resultTransaction1559.getMaxPriorityFeePerGas());
assertEquals(transaction1559.getGasLimit(), resultTransaction1559.getGasLimit());
assertEquals(transaction1559.getTo(), resultTransaction1559.getTo());
assertEquals(transaction1559.getValue(), resultTransaction1559.getValue());
assertEquals(transaction1559.getData(), resultTransaction1559.getData());
assertEquals(transaction1559.getAccessList(), resultTransaction1559.getAccessList());
}

@Test
public void testDecodingSigned1559() throws SignatureException {
final RawTransaction rawTransaction = createEip1559RawTransaction();
Expand Down Expand Up @@ -202,6 +228,31 @@ private static RawTransaction createEip1559RawTransaction() {
BigInteger.valueOf(1100000));
}

private static RawTransaction createEip1559RawTransactionAccessList() {
List<AccessListObject> accessList =
Stream.of(
new AccessListObject(
"0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
Stream.of(
"0x0000000000000000000000000000000000000000000000000000000000000003",
"0x0000000000000000000000000000000000000000000000000000000000000007")
.collect(toList())),
new AccessListObject(
"0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
Collections.emptyList()))
.collect(toList());
return RawTransaction.createTransaction(
3L,
BigInteger.valueOf(0),
BigInteger.valueOf(30000),
"0x627306090abab3a6e1400e9345bc60c78a8bef57",
BigInteger.valueOf(123),
"0x1000001111100000",
BigInteger.valueOf(5678),
BigInteger.valueOf(1100000),
accessList);
}

@Test
public void testDecoding2930() {
final RawTransaction rawTransaction = createEip2930RawTransaction();
Expand Down

0 comments on commit 53c8ae2

Please sign in to comment.