diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/BesuPrivateTransaction.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/BesuPrivateTransaction.java index 8d0963a9d..cffded33a 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/BesuPrivateTransaction.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/BesuPrivateTransaction.java @@ -51,14 +51,29 @@ private BesuPrivateTransaction( @Override protected RawPrivateTransaction createTransaction() { - return RawPrivateTransaction.createTransaction( - nonce, - transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE), - transactionJsonParameters.gas().orElse(DEFAULT_GAS), - transactionJsonParameters.receiver().orElse(DEFAULT_TO), - transactionJsonParameters.data().orElse(DEFAULT_DATA), - transactionJsonParameters.privateFrom(), - privacyGroupId, - Restriction.fromString(transactionJsonParameters.restriction())); + if (transactionJsonParameters.maxPriorityFeePerGas().isPresent() + && transactionJsonParameters.maxFeePerGas().isPresent()) { + return RawPrivateTransaction.createTransaction( + chainId, + nonce, + transactionJsonParameters.maxPriorityFeePerGas().orElseThrow(), + transactionJsonParameters.maxFeePerGas().orElseThrow(), + transactionJsonParameters.gas().orElse(DEFAULT_GAS), + transactionJsonParameters.receiver().orElse(DEFAULT_TO), + transactionJsonParameters.data().orElse(DEFAULT_DATA), + transactionJsonParameters.privateFrom(), + privacyGroupId, + Restriction.fromString(transactionJsonParameters.restriction())); + } else { + return RawPrivateTransaction.createTransaction( + nonce, + transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE), + transactionJsonParameters.gas().orElse(DEFAULT_GAS), + transactionJsonParameters.receiver().orElse(DEFAULT_TO), + transactionJsonParameters.data().orElse(DEFAULT_DATA), + transactionJsonParameters.privateFrom(), + privacyGroupId, + Restriction.fromString(transactionJsonParameters.restriction())); + } } } diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/EeaPrivateTransaction.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/EeaPrivateTransaction.java index 27239c658..1abec01af 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/EeaPrivateTransaction.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/EeaPrivateTransaction.java @@ -67,14 +67,28 @@ public String toString() { @Override protected RawPrivateTransaction createTransaction() { - return RawPrivateTransaction.createTransaction( - nonce, - transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE), - transactionJsonParameters.gas().orElse(DEFAULT_GAS), - transactionJsonParameters.receiver().orElse(DEFAULT_TO), - transactionJsonParameters.data().orElse(DEFAULT_DATA), - transactionJsonParameters.privateFrom(), - privateFor, - Restriction.fromString(transactionJsonParameters.restriction())); + if (isEip1559()) { + return RawPrivateTransaction.createTransaction( + chainId, + nonce, + transactionJsonParameters.maxPriorityFeePerGas().orElseThrow(), + transactionJsonParameters.maxFeePerGas().orElseThrow(), + transactionJsonParameters.gas().orElse(DEFAULT_GAS), + transactionJsonParameters.receiver().orElse(DEFAULT_TO), + transactionJsonParameters.data().orElse(DEFAULT_DATA), + transactionJsonParameters.privateFrom(), + privateFor, + Restriction.fromString(transactionJsonParameters.restriction())); + } else { + return RawPrivateTransaction.createTransaction( + nonce, + transactionJsonParameters.gasPrice().orElse(DEFAULT_GAS_PRICE), + transactionJsonParameters.gas().orElse(DEFAULT_GAS), + transactionJsonParameters.receiver().orElse(DEFAULT_TO), + transactionJsonParameters.data().orElse(DEFAULT_DATA), + transactionJsonParameters.privateFrom(), + privateFor, + Restriction.fromString(transactionJsonParameters.restriction())); + } } } diff --git a/core/src/test/java/tech/pegasys/web3signer/core/service/jsonrpc/sendtransaction/transaction/EeaPrivateTransactionTest.java b/core/src/test/java/tech/pegasys/web3signer/core/service/jsonrpc/sendtransaction/transaction/EeaPrivateTransactionTest.java index 342078b42..5edf3018c 100644 --- a/core/src/test/java/tech/pegasys/web3signer/core/service/jsonrpc/sendtransaction/transaction/EeaPrivateTransactionTest.java +++ b/core/src/test/java/tech/pegasys/web3signer/core/service/jsonrpc/sendtransaction/transaction/EeaPrivateTransactionTest.java @@ -24,12 +24,17 @@ import tech.pegasys.web3signer.core.service.jsonrpc.handlers.sendtransaction.transaction.PrivateTransaction; import java.math.BigInteger; +import java.nio.ByteBuffer; import java.util.List; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.web3j.crypto.Sign.SignatureData; +import org.web3j.crypto.transaction.type.Transaction1559; +import org.web3j.crypto.transaction.type.TransactionType; import org.web3j.protocol.eea.crypto.PrivateTransactionDecoder; +import org.web3j.protocol.eea.crypto.RawPrivateTransaction; import org.web3j.protocol.eea.crypto.SignedRawPrivateTransaction; import org.web3j.utils.Base64String; import org.web3j.utils.Numeric; @@ -92,6 +97,62 @@ public void rlpEncodesTransaction() { assertThat(trimLeadingZeroes(decodedSignatureData.getS())).isEqualTo(new byte[] {3}); } + @Disabled("TODO SLD") + @Test + public void rlpEncodesEip1559Transaction() { + final EeaSendTransactionJsonParameters params = + new EeaSendTransactionJsonParameters( + "0x7577919ae5df4941180eac211965f275cdce314d", + "ZlapEsl9qDLPy/e88+/6yvCUEVIvH83y0N4A6wHuKXI=", + "restricted"); + params.receiver("0xd46e8dd67c5d32be8058bb8eb970870f07244567"); + params.gas("0x76c0"); + params.maxPriorityFeePerGas("0x9184e72a000"); + params.maxFeePerGas("0x9184e72a001"); + params.value("0x0"); + params.nonce("0x1"); + params.data( + "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"); + params.privateFor(new String[] {"GV8m0VZAccYGAAYMBuYQtKEj0XtpXeaw2APcoBmtA2w="}); + + privateTransaction = + EeaPrivateTransaction.from(1337L, params, () -> BigInteger.ZERO, new JsonRpcRequestId(1)); + + final SignatureData signatureData = null; + final byte[] rlpEncodedBytes = privateTransaction.rlpEncode(signatureData); + final String rlpString = Numeric.toHexString(prependEip1559TransactionType(rlpEncodedBytes)); + + final RawPrivateTransaction decodedTransaction = PrivateTransactionDecoder.decode(rlpString); + final Transaction1559 decoded1559Transaction = + (Transaction1559) decodedTransaction.getTransaction(); + assertThat(decoded1559Transaction.getTo()) + .isEqualTo("0xd46e8dd67c5d32be8058bb8eb970870f07244567"); + assertThat(decoded1559Transaction.getGasLimit()).isEqualTo(decodeQuantity("0x76c0")); + assertThat(decoded1559Transaction.getMaxPriorityFeePerGas()) + .isEqualTo(decodeQuantity("0x9184e72a000")); + assertThat(decoded1559Transaction.getMaxFeePerGas()).isEqualTo(decodeQuantity("0x9184e72a001")); + assertThat(decoded1559Transaction.getNonce()).isEqualTo(decodeQuantity("0x1")); + assertThat(decoded1559Transaction.getValue()).isEqualTo(decodeQuantity("0x0")); + assertThat(decoded1559Transaction.getData()) + .isEqualTo( + "d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"); + assertThat(decodedTransaction.getRestriction()).isEqualTo(Restriction.RESTRICTED); + + final Base64String expectedDecodedPrivateFrom = params.privateFrom(); + final Base64String expectedDecodedPrivateFor = params.privateFor().get().get(0); + + assertThat(decodedTransaction.getPrivateFrom()).isEqualTo(expectedDecodedPrivateFrom); + assertThat(decodedTransaction.getPrivateFor().get().get(0)) + .isEqualTo(expectedDecodedPrivateFor); + } + + private static byte[] prependEip1559TransactionType(byte[] bytesToSign) { + return ByteBuffer.allocate(bytesToSign.length + 1) + .put(TransactionType.EIP1559.getRlpType()) + .put(bytesToSign) + .array(); + } + @Test @SuppressWarnings("unchecked") public void createsJsonEeaRequest() {