From fdede8273486b96ec9b88be3d685208fc9276d8f Mon Sep 17 00:00:00 2001 From: Simon Dudley Date: Mon, 10 Jul 2023 15:17:39 +1000 Subject: [PATCH] Simplify Transaction interface Remove rlpEncode(final long chainId) method override This is to make the upcoming changes to the serialize method easier --- .../core/jsonrpcproxy/IllegalSignatureCreationTest.java | 4 +--- .../handlers/sendtransaction/transaction/Transaction.java | 6 ------ .../jsonrpc/handlers/signing/TransactionSerializer.java | 5 ++++- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/src/integrationTest/java/tech/pegasys/web3signer/core/jsonrpcproxy/IllegalSignatureCreationTest.java b/core/src/integrationTest/java/tech/pegasys/web3signer/core/jsonrpcproxy/IllegalSignatureCreationTest.java index 34a9cb96c..08560c2dd 100644 --- a/core/src/integrationTest/java/tech/pegasys/web3signer/core/jsonrpcproxy/IllegalSignatureCreationTest.java +++ b/core/src/integrationTest/java/tech/pegasys/web3signer/core/jsonrpcproxy/IllegalSignatureCreationTest.java @@ -30,8 +30,6 @@ void ensureSignaturesCreatedHavePositiveValues() { // transaction being signed with a given key, resulted in the transaction being rejected by // Besu due to "INVALID SIGNATURE" - ultimately, it was came down to byte[] --> BigInt resulting // in negative value. - final long chainId = 44844; - final EthSendTransactionJsonParameters txnParams = new EthSendTransactionJsonParameters("0xf17f52151ebef6c7334fad080c5704d77216b732"); txnParams.gasPrice("0x0"); @@ -42,7 +40,7 @@ void ensureSignaturesCreatedHavePositiveValues() { txnParams.receiver("0x627306090abaB3A6e1400e9345bC60c78a8BEf57"); final EthTransaction txn = new EthTransaction(1337L, txnParams, null, null); - final byte[] serialisedBytes = txn.rlpEncode(chainId); + final byte[] serialisedBytes = txn.rlpEncode(null); final CredentialSigner signer = new CredentialSigner( diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/Transaction.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/Transaction.java index 26e03e9b2..1b5e0e96e 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/Transaction.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/sendtransaction/transaction/Transaction.java @@ -34,12 +34,6 @@ public interface Transaction { byte[] rlpEncode(SignatureData signatureData); - default byte[] rlpEncode(final long chainId) { - final SignatureData signatureData = - new SignatureData(longToBytes(chainId), new byte[] {}, new byte[] {}); - return rlpEncode(signatureData); - } - boolean isNonceUserSpecified(); String sender(); diff --git a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java index 727ec41e4..ee65d4893 100644 --- a/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java +++ b/core/src/main/java/tech/pegasys/web3signer/core/service/jsonrpc/handlers/signing/TransactionSerializer.java @@ -12,6 +12,7 @@ */ package tech.pegasys.web3signer.core.service.jsonrpc.handlers.signing; +import static tech.pegasys.web3signer.core.service.jsonrpc.handlers.sendtransaction.transaction.Transaction.longToBytes; import static tech.pegasys.web3signer.core.service.jsonrpc.response.JsonRpcError.SIGNING_FROM_IS_NOT_AN_UNLOCKED_ACCOUNT; import static tech.pegasys.web3signer.core.util.Eth1AddressUtil.signerPublicKeyFromAddress; @@ -42,7 +43,9 @@ public TransactionSerializer(final ArtifactSignerProvider signer, final long cha } public String serialize(final Transaction transaction) { - final byte[] bytesToSign = transaction.rlpEncode(chainId); + final SignatureData signatureData = + new SignatureData(longToBytes(chainId), new byte[] {}, new byte[] {}); + final byte[] bytesToSign = transaction.rlpEncode(signatureData); Optional publicKey = signerPublicKeyFromAddress(signer, transaction.sender());