From 8b537c6d901cc731d5318df0e2cbb2d9c15d737b Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Mon, 21 Nov 2022 20:02:59 +1100 Subject: [PATCH] Add type field to eth_getTransactionReceipt (#4713) Signed-off-by: garyschulte --- CHANGELOG.md | 1 + .../internal/results/TransactionReceiptResult.java | 14 +++++++++++++- .../methods/EthGetTransactionReceiptTest.java | 3 +++ .../eth_getTransactionReceipt_contractAddress.json | 3 ++- .../eth/eth_getTransactionReceipt_logs.json | 3 ++- ..._getTransactionReceipt_nullContractAddress.json | 3 ++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 135133f279c..42252c1e8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Shanghai implementation of EIP-3855 Push0 [#4660](https://github.com/hyperledger/besu/pull/4660) - Shanghai implementation of EIP-3540 and EIP-3670 Ethereum Object Format and Code Validation [#4644](https://github.com/hyperledger/besu/pull/4644) - Remove some log statements that are keeping some objects live in heap for a long time, to reduce the amount of memory required during initial sync [#4705](https://github.com/hyperledger/besu/pull/4705) +- Add field `type` to Transaction receipt object (eth_getTransactionReceipt) [#4505](https://github.com/hyperledger/besu/issues/4505) ### Bug Fixes diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionReceiptResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionReceiptResult.java index 9c2920b9caf..db032289bde 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionReceiptResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionReceiptResult.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.plugin.data.TransactionType; import java.util.ArrayList; import java.util.List; @@ -44,7 +45,8 @@ "to", "transactionHash", "transactionIndex", - "revertReason" + "revertReason", + "type" }) public abstract class TransactionReceiptResult { @@ -63,6 +65,7 @@ public abstract class TransactionReceiptResult { private final String revertReason; protected final TransactionReceipt receipt; + protected final String type; protected TransactionReceiptResult(final TransactionReceiptWithMetadata receiptWithMetadata) { final Transaction txn = receiptWithMetadata.getTransaction(); @@ -88,6 +91,10 @@ protected TransactionReceiptResult(final TransactionReceiptWithMetadata receiptW this.transactionHash = txn.getHash().toString(); this.transactionIndex = Quantity.create(receiptWithMetadata.getTransactionIndex()); this.revertReason = receipt.getRevertReason().map(Bytes::toString).orElse(null); + this.type = + txn.getType().equals(TransactionType.FRONTIER) + ? Quantity.create(0) + : Quantity.create(txn.getType().getSerializedType()); } @JsonGetter(value = "blockHash") @@ -150,6 +157,11 @@ public String getTransactionIndex() { return transactionIndex; } + @JsonGetter(value = "type") + public String getType() { + return type; + } + @JsonInclude(JsonInclude.Include.NON_NULL) @JsonGetter(value = "revertReason") public String getRevertReason() { diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index 9cb3c1326e4..ff3e1d54802 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -164,6 +164,7 @@ public void shouldCreateAStatusTransactionReceiptWhenStatusTypeProtocol() { final TransactionReceiptStatusResult result = (TransactionReceiptStatusResult) response.getResult(); + assertThat(result.getType()).isEqualTo("0x0"); assertThat(result.getStatus()).isEqualTo("0x1"); } @@ -178,6 +179,7 @@ public void shouldCreateARootTransactionReceiptWhenRootTypeProtocol() { (JsonRpcSuccessResponse) ethGetTransactionReceipt.response(request); final TransactionReceiptRootResult result = (TransactionReceiptRootResult) response.getResult(); + assertThat(result.getType()).isEqualTo("0x0"); assertThat(result.getRoot()).isEqualTo(stateRoot.toString()); } @@ -200,6 +202,7 @@ public void shouldWorkFor1559Txs() { (TransactionReceiptStatusResult) response.getResult(); assertThat(result.getStatus()).isEqualTo("0x1"); + assertThat(result.getType()).isEqualTo("0x2"); assertThat(Wei.fromHexString(result.getEffectiveGasPrice())) .isEqualTo( UInt256s.min( diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_contractAddress.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_contractAddress.json index 9d0bb80ba4e..63e8e5e6bea 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_contractAddress.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_contractAddress.json @@ -23,7 +23,8 @@ "root": "0x6a59608add7cee26032d1c5c3923b91d0b50e6103f61b2137b68229bcdc87395", "to": null, "transactionHash": "0x812742182a79a8e67733edc58cfa3767aa2d7ad06439d156ddbbb33e3403b4ed", - "transactionIndex": "0x0" + "transactionIndex": "0x0", + "type" : "0x0" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_logs.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_logs.json index 8e4f8e95ef9..d056272effa 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_logs.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_logs.json @@ -40,7 +40,8 @@ "root": "0xb55d027526b3f56953584db678b5c3d1a418812c0106b0cfbc3c912c7898dfe5", "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", "transactionHash": "0x185a9154a0acc4e0ffc84029aee0f3dbf57ff0b84ec7624cb80e7373a03e8aeb", - "transactionIndex": "0x0" + "transactionIndex": "0x0", + "type" : "0x0" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_nullContractAddress.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_nullContractAddress.json index 8f78ec03183..b084bb285b8 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_nullContractAddress.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/jsonrpc/eth/eth_getTransactionReceipt_nullContractAddress.json @@ -23,7 +23,8 @@ "root": "0x947228066df6272aac99931a1a639621d4ac7dc461ce9fd93dfcaad933e299ee", "to": "0x6295ee1b4f6dd65047762f924ecd367c17eabf8f", "transactionHash": "0xb1a62356d1433202cdef0ef9030f8abdfbb3aef549fab0867cf0eaee70b09d81", - "transactionIndex": "0x0" + "transactionIndex": "0x0", + "type" : "0x0" } }, "statusCode": 200