Skip to content

Commit

Permalink
Add fields to eth_getTransaction series of RPCs (#1835)
Browse files Browse the repository at this point in the history
Add fields for `chainId`, `publicKey`, and `raw` to RPCs where detailed
transaction data is returned (`eth_getTransactionByBlockHash`,
`eth_getTransactionByBlockNumber`, `eth_getTransactionByHash`, and
`eth_getBlock` with certain parameters).

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Jan 27, 2021
1 parent e7a5b1c commit 27521c5
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 15 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
* `--skip-pow-validation-enabled` is now an error with `block import --format JSON`. This is because the JSON format doesn't include the nonce so the proof of work must be calculated. [\#1815](https://github.com/hyperledger/besu/pull/1815)
* Added a new CLI option `--Xlauncher` to start a mainnet launcher. It will help to configure Besu easily.
* Return the revert reason from `eth_call` JSON-RPC api calls when the contract causes a revert. [\#1829](https://github.com/hyperledger/besu/pull/1829)
* Added `chainId`, `publicKey`, and `raw` to JSON-RPC api calls returning detailed transaction results. [\#1835](https://github.com/hyperledger/besu/pull/1835)

### Bug Fixes
* Ethereum classic heights will no longer be reported in mainnet metrics. Issue [\#1751]((https://github.com/hyperledger/besu/pull/1751) Fix [\#1820](https://github.com/hyperledger/besu/pull/1820)
* Don't enforce balance checks in `eth_call` unless explicitly requested. Issue [\#502]((https://github.com/hyperledger/besu/pull/502) Fix [\#1834](https://github.com/hyperledger/besu/pull/1834)
* Ethereum classic heights will no longer be reported in mainnet metrics. Issue [\#1751](https://github.com/hyperledger/besu/pull/1751) Fix [\#1820](https://github.com/hyperledger/besu/pull/1820)
* Don't enforce balance checks in `eth_call` unless explicitly requested. Issue [\#502](https://github.com/hyperledger/besu/pull/502) Fix [\#1834](https://github.com/hyperledger/besu/pull/1834)

### Early Access Features

Expand Down Expand Up @@ -2203,16 +2204,16 @@ The [documentation](https://docs.pantheon.pegasys.tech/en/latest/) has been upda
| `--datadir` | [`--data-path`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#data-path) | Renamed |
| `--dev-mode` | [`--network=dev`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--genesis` | [`--genesis-file`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#genesis-file) | Renamed |
| `--goerli` | [`--network=goerli`]((https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--goerli` | [`--network=goerli`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--metrics-listen=<HOST:PORT>` | [`--metrics-host=<HOST>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#metrics-host) and [`--metrics-port=<PORT>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#metrics-port) | Split into host and port options |
| `--miner-extraData` | [`--miner-extra-data`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#miner-extra-data) | Renamed |
| `--miner-minTransactionGasPriceWei` | [`--min-gas-price`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#min-gas-price) | Renamed |
| `--no-discovery` | [`--discovery-enabled`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#discovery-enabled) | Replaced |
| `--node-private-key` | [`--node-private-key-file`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#node-private-key-file) | Renamed |
| `--ottoman` | N/A | Removed |
| `--p2p-listen=<HOST:PORT>` | [`--p2p-host=<HOST>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#p2p-hostt) and [`--p2p-port=<PORT>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#p2p-port) | Split into host and port options |
| `--rinkeby` | [`--network=rinkeby`]((https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--ropsten` | [`--network=ropsten`]((https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--rinkeby` | [`--network=rinkeby`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--ropsten` | [`--network=ropsten`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#network) | Replaced by `--network` option |
| `--rpc-enabled` | [` --rpc-http-enabled`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-enabled)| Renamed|
| `--rpc-listen=<HOST:PORT>` | [`--rpc-http-host=<HOST>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-host) and [`--rpc-http-port=<PORT>`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-port) | Split into host and port options |
| `--rpc-api` | [`--rpc-http-api`](https://besu.hyperledger.org/en/latest/Reference/CLI/CLI-Syntax/#rpc-http-api)| Renamed |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.api.jsonrpc;

public enum JsonRpcResponseKey {
CHAIN_ID,
COINBASE,
DIFFICULTY,
EXTRA_DATA,
Expand All @@ -26,6 +27,8 @@ public enum JsonRpcResponseKey {
NUMBER,
OMMERS_HASH,
PARENT_HASH,
PUBLIC_KEY,
RAW,
RECEIPTS_ROOT,
SIZE,
STATE_ROOT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TIMESTAMP;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TOTAL_DIFFICULTY;
import static org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcResponseKey.TRANSACTION_ROOT;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -51,6 +53,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.rlp.RLPOutput;

import java.math.BigInteger;
import java.util.ArrayList;
Expand Down Expand Up @@ -145,12 +148,15 @@ public List<TransactionResult> transactions(final TransactionResult... transacti
public TransactionResult transaction(
final String blockHash,
final String blockNumber,
final String chainId,
final String fromAddress,
final String gas,
final String gasPrice,
final String hash,
final String input,
final String nonce,
final String publicKey,
final String raw,
final String toAddress,
final String transactionIndex,
final String value,
Expand All @@ -170,6 +176,15 @@ public TransactionResult transaction(
when(transaction.getPayload()).thenReturn(bytes(input));
when(transaction.getValue()).thenReturn(wei(value));
when(transaction.getGasLimit()).thenReturn(unsignedLong(gas));
when(transaction.getChainId()).thenReturn(Optional.ofNullable(bigInteger(chainId)));
when(transaction.getPublicKey()).thenReturn(Optional.ofNullable(publicKey));
doAnswer(
answer -> {
answer.getArgument(0, RLPOutput.class).writeRLPBytes(Bytes.fromHexString(raw));
return null;
})
.when(transaction)
.writeTo(any());

return new TransactionCompleteResult(
new TransactionWithMetadata(
Expand Down Expand Up @@ -198,7 +213,7 @@ private String removeHexPrefix(final String prefixedHex) {
}

private BigInteger bigInteger(final String hex) {
return new BigInteger(removeHexPrefix(hex), HEX_RADIX);
return hex == null ? null : new BigInteger(removeHexPrefix(hex), HEX_RADIX);
}

private Wei wei(final String hex) {
Expand Down
Loading

0 comments on commit 27521c5

Please sign in to comment.