Add debug_getRawTransaction (#5635)

* Add debug_getRawTransaction

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

* Add changelog entry

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>

---------

Signed-off-by: Gabriel Fukushima <gabrielfukushima@gmail.com>
pull/5637/head
Gabriel Fukushima 1 year ago committed by GitHub
parent a0e5dd6fe0
commit 2beb15a601
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 1
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/RpcMethod.java
  3. 57
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugGetRawTransaction.java
  4. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/DebugJsonRpcMethods.java

@ -28,6 +28,7 @@ and in case a rollback is needed, before installing a previous version, the migr
- Remove PoW validation if merge is enabled as it is not needed any more [#5538](https://github.com/hyperledger/besu/pull/5538)
- Use BlobDB for blockchain storage to reduce initial sync time and write amplification [#5475](https://github.com/hyperledger/besu/pull/5475)
- Add healing flat db mechanism with early access CLI options `--Xsnapsync-synchronizer-flat-db-healing-enabled=true` [#5319](https://github.com/hyperledger/besu/pull/5319)
- Add debug_getRawTransaction method to the DEBUG suite [#5635](https://github.com/hyperledger/besu/pull/5635)
### Bug Fixes
- Fix backwards sync bug where chain is rolled back too far, especially when restarting Nimbus [#5497](https://github.com/hyperledger/besu/pull/5497)

@ -49,6 +49,7 @@ public enum RpcMethod {
DEBUG_GET_RAW_HEADER("debug_getRawHeader"),
DEBUG_GET_RAW_BLOCK("debug_getRawBlock"),
DEBUG_GET_RAW_RECEIPTS("debug_getRawReceipts"),
DEBUG_GET_RAW_TRANSACTION("debug_getRawTransaction"),
ENGINE_GET_PAYLOAD_V1("engine_getPayloadV1"),
ENGINE_GET_PAYLOAD_V2("engine_getPayloadV2"),
ENGINE_NEW_PAYLOAD_V1("engine_newPayloadV1"),

@ -0,0 +1,57 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
public class DebugGetRawTransaction implements JsonRpcMethod {
protected final BlockchainQueries blockchainQueries;
public DebugGetRawTransaction(final BlockchainQueries blockchainQueries) {
this.blockchainQueries = blockchainQueries;
}
@Override
public String getName() {
return RpcMethod.DEBUG_GET_RAW_TRANSACTION.getMethodName();
}
@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Hash txHash = requestContext.getRequiredParameter(0, Hash.class);
return blockchainQueries
.transactionByHash(txHash)
.map(
tx ->
new JsonRpcSuccessResponse(
requestContext.getRequest().getId(), toRawString(tx.getTransaction())))
.orElse(new JsonRpcSuccessResponse(requestContext.getRequest().getId(), null));
}
private String toRawString(final Transaction transaction) {
final BytesValueRLPOutput out = new BytesValueRLPOutput();
transaction.writeTo(out);
return out.encoded().toHexString();
}
}

@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetBadBlo
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawBlock;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawHeader;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawReceipts;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugGetRawTransaction;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugMetrics;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugResyncWorldstate;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.DebugSetHead;
@ -111,6 +112,7 @@ public class DebugJsonRpcMethods extends ApiGroupJsonRpcMethods {
new DebugAccountAt(blockchainQueries, () -> new BlockTracer(blockReplay)),
new DebugGetRawHeader(blockchainQueries),
new DebugGetRawBlock(blockchainQueries),
new DebugGetRawReceipts(blockchainQueries));
new DebugGetRawReceipts(blockchainQueries),
new DebugGetRawTransaction(blockchainQueries));
}
}

Loading…
Cancel
Save