Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
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.jsonrpc.internal.results.BlockResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionHashResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionWithMetadataResult;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions;
Expand Down Expand Up @@ -202,7 +202,7 @@ public TransactionResult transaction(
.sender(address(fromAddress))
.build();

return new TransactionCompleteResult(
return new TransactionWithMetadataResult(
new TransactionWithMetadata(
transaction,
unsignedLong(blockNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
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.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionWithMetadataResult;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;

Expand Down Expand Up @@ -66,7 +66,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
final Optional<TransactionWithMetadata> transactionWithMetadata =
blockchain.transactionByBlockHashAndIndex(hash, index);
final TransactionResult result =
transactionWithMetadata.map(TransactionCompleteResult::new).orElse(null);
transactionWithMetadata.map(TransactionWithMetadataResult::new).orElse(null);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.JsonRpcParameter.JsonRpcParameterException;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionWithMetadataResult;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;

Expand Down Expand Up @@ -62,6 +62,6 @@ protected Object resultByBlockNumber(
}
final Optional<TransactionWithMetadata> transactionWithMetadata =
getBlockchainQueries().transactionByBlockNumberAndIndex(blockNumber, index);
return transactionWithMetadata.map(TransactionCompleteResult::new).orElse(null);
return transactionWithMetadata.map(TransactionWithMetadataResult::new).orElse(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
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.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionCompleteResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionPendingResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionBaseResult;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionWithMetadataResult;
import org.hyperledger.besu.ethereum.api.query.BlockchainQueries;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;

Expand Down Expand Up @@ -67,9 +67,13 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
}

private Object getResult(final Hash hash) {
final Optional<Object> transactionPendingResult =
transactionPool.getTransactionByHash(hash).map(TransactionPendingResult::new);
return transactionPendingResult.orElseGet(
() -> blockchain.transactionByHash(hash).map(TransactionCompleteResult::new).orElse(null));
final Optional<TransactionBaseResult> transactionResult =
transactionPool.getTransactionByHash(hash).map(TransactionBaseResult::new);
return transactionResult.orElseGet(
() ->
blockchain
.transactionByHash(hash)
.map(TransactionWithMetadataResult::new)
.orElse(null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public BlockResult transactionComplete(
final boolean includeCoinbase) {
final List<TransactionResult> txs =
blockWithMetadata.getTransactions().stream()
.map(TransactionCompleteResult::new)
.map(TransactionWithMetadataResult::new)
.collect(Collectors.toList());
final List<JsonNode> ommers =
blockWithMetadata.getOmmers().stream()
Expand Down Expand Up @@ -83,7 +83,7 @@ public BlockResult transactionComplete(final Block block) {
}
final List<TransactionResult> txs =
transactionWithMetadata.stream()
.map(TransactionCompleteResult::new)
.map(TransactionWithMetadataResult::new)
.collect(Collectors.toList());

final List<JsonNode> ommers =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private static List<TransactionResult> createFullTransactionResults(final Block
block.getHash(),
i,
block.getHeader().getTimestamp()))
.map(TransactionCompleteResult::new)
.map(TransactionWithMetadataResult::new)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright ConsenSys AG.
* Copyright contributors to Besu.
*
* 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
Expand All @@ -16,10 +16,8 @@

import org.hyperledger.besu.datatypes.AccessListEntry;
import org.hyperledger.besu.datatypes.BytesHolder;
import org.hyperledger.besu.datatypes.CodeDelegation;
import org.hyperledger.besu.datatypes.TransactionType;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
import org.hyperledger.besu.ethereum.core.Transaction;

import java.util.List;
Expand Down Expand Up @@ -56,17 +54,11 @@
"s",
"blobVersionedHashes"
})
public class TransactionCompleteResult implements TransactionResult {
public class TransactionBaseResult implements TransactionResult {

@JsonInclude(JsonInclude.Include.NON_NULL)
private final List<AccessListEntry> accessList;

private final String blockHash;
private final String blockNumber;

@JsonInclude(JsonInclude.Include.NON_NULL)
private final String blockTimestamp;

@JsonInclude(JsonInclude.Include.NON_NULL)
private final String chainId;

Expand All @@ -87,7 +79,6 @@ public class TransactionCompleteResult implements TransactionResult {
private final String input;
private final String nonce;
private final String to;
private final String transactionIndex;
private final String type;
private final String value;
private final String yParity;
Expand All @@ -101,33 +92,35 @@ public class TransactionCompleteResult implements TransactionResult {
@JsonInclude(JsonInclude.Include.NON_NULL)
private final List<CodeDelegationResult> authorizationList;

public TransactionCompleteResult(final TransactionWithMetadata tx) {
final Transaction transaction = tx.getTransaction();
public TransactionBaseResult(final Transaction transaction) {
this(transaction, Optional.empty());
}

public TransactionBaseResult(final Transaction transaction, final Optional<Wei> maybeBaseFee) {
final TransactionType transactionType = transaction.getType();
this.accessList =
transaction.getAccessList().orElse(transactionType.supportsAccessList() ? List.of() : null);
this.blockHash = tx.getBlockHash().get().toString();
this.blockNumber = Quantity.create(tx.getBlockNumber().get());
this.blockTimestamp = tx.getBlockTimestamp().map(Quantity::create).orElse(null);
this.chainId = transaction.getChainId().map(Quantity::create).orElse(null);
this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit());
this.maxPriorityFeePerGas =
tx.getTransaction().getMaxPriorityFeePerGas().map(Wei::toShortHexString).orElse(null);
this.maxFeePerGas =
tx.getTransaction().getMaxFeePerGas().map(Wei::toShortHexString).orElse(null);
transaction.getMaxPriorityFeePerGas().map(Wei::toShortHexString).orElse(null);
this.maxFeePerGas = transaction.getMaxFeePerGas().map(Wei::toShortHexString).orElse(null);
this.maxFeePerBlobGas =
transaction.getMaxFeePerBlobGas().map(Wei::toShortHexString).orElse(null);
this.gasPrice =
Quantity.create(
transaction
.getGasPrice()
.orElseGet(() -> transaction.getEffectiveGasPrice(tx.getBaseFee())));
.orElseGet(
() ->
maybeBaseFee.isPresent()
? transaction.getEffectiveGasPrice(maybeBaseFee)
: transaction.getMaxFeePerGas().get()));
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
this.nonce = Quantity.create(transaction.getNonce());
this.to = transaction.getTo().map(a -> a.getBytes().toHexString()).orElse(null);
this.transactionIndex = Quantity.create(tx.getTransactionIndex().get());
if (transactionType == TransactionType.FRONTIER) {
this.type = Quantity.create(0);
this.yParity = null;
Expand All @@ -153,9 +146,9 @@ public TransactionCompleteResult(final TransactionWithMetadata tx) {
hashes ->
hashes.stream().map(BytesHolder::getBytes).map(Bytes::toHexString).toList())
.orElse(null);
final Optional<List<CodeDelegation>> codeDelegationList = transaction.getCodeDelegationList();
this.authorizationList =
codeDelegationList
transaction
.getCodeDelegationList()
.map(cds -> cds.stream().map(CodeDelegationResult::new).toList())
.orElse(null);
}
Expand All @@ -165,21 +158,6 @@ public List<AccessListEntry> getAccessList() {
return accessList;
}

@JsonGetter(value = "blockHash")
public String getBlockHash() {
return blockHash;
}

@JsonGetter(value = "blockNumber")
public String getBlockNumber() {
return blockNumber;
}

@JsonGetter(value = "blockTimestamp")
public String getBlockTimestamp() {
return blockTimestamp;
}

@JsonGetter(value = "chainId")
public String getChainId() {
return chainId;
Expand All @@ -195,6 +173,11 @@ public String getGas() {
return gas;
}

@JsonGetter(value = "gasPrice")
public String getGasPrice() {
return gasPrice;
}

@JsonGetter(value = "maxPriorityFeePerGas")
public String getMaxPriorityFeePerGas() {
return maxPriorityFeePerGas;
Expand All @@ -210,11 +193,6 @@ public String getMaxFeePerBlobGas() {
return maxFeePerBlobGas;
}

@JsonGetter(value = "gasPrice")
public String getGasPrice() {
return gasPrice;
}

@JsonGetter(value = "hash")
public String getHash() {
return hash;
Expand All @@ -235,11 +213,6 @@ public String getTo() {
return to;
}

@JsonGetter(value = "transactionIndex")
public String getTransactionIndex() {
return transactionIndex;
}

@JsonGetter(value = "type")
public String getType() {
return type;
Expand Down Expand Up @@ -281,4 +254,24 @@ public List<String> getVersionedHashes() {
public List<CodeDelegationResult> getAuthorizationList() {
return authorizationList;
}

@JsonGetter(value = "blockHash")
public String getBlockHash() {
return null;
}

@JsonGetter(value = "blockNumber")
public String getBlockNumber() {
return null;
}

@JsonGetter(value = "blockTimestamp")
public String getBlockTimestamp() {
return null;
}

@JsonGetter(value = "transactionIndex")
public String getTransactionIndex() {
return null;
}
}
Loading
Loading