Skip to content

Commit

Permalink
Add blockValue to EngineGetPayloadResultV2
Browse files Browse the repository at this point in the history
Ported code over from #4833

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
  • Loading branch information
siladu committed Dec 20, 2022
1 parent 37b72d6 commit 46f4390
Show file tree
Hide file tree
Showing 4 changed files with 300 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ public EngineGetPayloadResultV2 enginePayloadTransactionCompleteV2(final Block b
w.stream()
.map(WithdrawalParameter::fromWithdrawal)
.collect(Collectors.toList()));
return new EngineGetPayloadResultV2(block.getHeader(), txs, withdrawals);
return new EngineGetPayloadResultV2(
new PayloadResultV2(block.getHeader(), txs, withdrawals), Quantity.create(0));
}

public BlockResult transactionHash(final BlockWithMetadata<Hash, Hash> blockWithMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,145 +14,29 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.results;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.core.BlockHeader;

import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.apache.tuweni.bytes.Bytes32;

@JsonPropertyOrder({
"parentHash",
"feeRecipient",
"stateRoot",
"receiptsRoot",
"logsBloom",
"prevRandao",
"blockNumber",
"gasLimit",
"gasUsed",
"timestamp",
"extraData",
"baseFeePerGas",
"blockHash",
"transactions",
"withdrawals"
"executionPayload",
"blockValue",
})
public class EngineGetPayloadResultV2 {
protected final String blockHash;
private final String parentHash;
private final String feeRecipient;
private final String stateRoot;
private final String receiptsRoot;
private final String logsBloom;
private final String prevRandao;
private final String blockNumber;
private final String gasLimit;
private final String gasUsed;
private final String timestamp;
private final String extraData;
private final String baseFeePerGas;
protected final List<String> transactions;
protected final Optional<List<WithdrawalParameter>> withdrawals;

public EngineGetPayloadResultV2(
final BlockHeader header,
final List<String> transactions,
final Optional<List<WithdrawalParameter>> withdrawals) {
this.blockNumber = Quantity.create(header.getNumber());
this.blockHash = header.getHash().toString();
this.parentHash = header.getParentHash().toString();
this.logsBloom = header.getLogsBloom().toString();
this.stateRoot = header.getStateRoot().toString();
this.receiptsRoot = header.getReceiptsRoot().toString();
this.extraData = header.getExtraData().toString();
this.baseFeePerGas = header.getBaseFee().map(Quantity::create).orElse(null);
this.gasLimit = Quantity.create(header.getGasLimit());
this.gasUsed = Quantity.create(header.getGasUsed());
this.timestamp = Quantity.create(header.getTimestamp());
this.transactions = transactions;
this.feeRecipient = header.getCoinbase().toString();
this.prevRandao = header.getPrevRandao().map(Bytes32::toHexString).orElse(null);
this.withdrawals = withdrawals;
}

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

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

@JsonGetter(value = "parentHash")
public String getParentHash() {
return parentHash;
}

@JsonGetter(value = "logsBloom")
public String getLogsBloom() {
return logsBloom;
}

@JsonGetter(value = "prevRandao")
public String getPrevRandao() {
return prevRandao;
}

@JsonGetter(value = "stateRoot")
public String getStateRoot() {
return stateRoot;
}

@JsonGetter(value = "receiptsRoot")
public String getReceiptRoot() {
return receiptsRoot;
}

@JsonGetter(value = "extraData")
public String getExtraData() {
return extraData;
}

@JsonGetter(value = "baseFeePerGas")
public String getBaseFeePerGas() {
return baseFeePerGas;
}

@JsonGetter(value = "gasLimit")
public String getGasLimit() {
return gasLimit;
}

@JsonGetter(value = "gasUsed")
public String getGasUsed() {
return gasUsed;
}

@JsonGetter(value = "timestamp")
public String getTimestamp() {
return timestamp;
}
protected final PayloadResultV2 executionPayload;
private final String blockValue;

@JsonGetter(value = "transactions")
public List<String> getTransactions() {
return transactions;
public EngineGetPayloadResultV2(final PayloadResultV2 executionPayload, final String blockValue) {
this.executionPayload = executionPayload;
this.blockValue = blockValue;
}

@JsonGetter(value = "feeRecipient")
@JsonInclude(JsonInclude.Include.NON_NULL)
public String getFeeRecipient() {
return feeRecipient;
@JsonGetter(value = "executionPayload")
public PayloadResultV2 getExecutionPayload() {
return executionPayload;
}

@JsonGetter(value = "withdrawals")
public List<WithdrawalParameter> getWithdrawals() {
return withdrawals.orElse(null);
@JsonGetter(value = "blockValue")
public String getBlockValue() {
return blockValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* 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.results;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.core.BlockHeader;

import java.util.List;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.apache.tuweni.bytes.Bytes32;

@JsonPropertyOrder({
"parentHash",
"feeRecipient",
"stateRoot",
"receiptsRoot",
"logsBloom",
"prevRandao",
"blockNumber",
"gasLimit",
"gasUsed",
"timestamp",
"extraData",
"baseFeePerGas",
"blockHash",
"transactions",
"withdrawals"
})
public class PayloadResultV2 {
protected final String blockHash;
private final String parentHash;
private final String feeRecipient;
private final String stateRoot;
private final String receiptsRoot;
private final String logsBloom;
private final String prevRandao;
private final String blockNumber;
private final String gasLimit;
private final String gasUsed;
private final String timestamp;
private final String extraData;
private final String baseFeePerGas;
protected final List<String> transactions;
protected final Optional<List<WithdrawalParameter>> withdrawals;

public PayloadResultV2(
final BlockHeader header,
final List<String> transactions,
final Optional<List<WithdrawalParameter>> withdrawals) {
this.blockNumber = Quantity.create(header.getNumber());
this.blockHash = header.getHash().toString();
this.parentHash = header.getParentHash().toString();
this.logsBloom = header.getLogsBloom().toString();
this.stateRoot = header.getStateRoot().toString();
this.receiptsRoot = header.getReceiptsRoot().toString();
this.extraData = header.getExtraData().toString();
this.baseFeePerGas = header.getBaseFee().map(Quantity::create).orElse(null);
this.gasLimit = Quantity.create(header.getGasLimit());
this.gasUsed = Quantity.create(header.getGasUsed());
this.timestamp = Quantity.create(header.getTimestamp());
this.transactions = transactions;
this.feeRecipient = header.getCoinbase().toString();
this.prevRandao = header.getPrevRandao().map(Bytes32::toHexString).orElse(null);
this.withdrawals = withdrawals;
}

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

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

@JsonGetter(value = "parentHash")
public String getParentHash() {
return parentHash;
}

@JsonGetter(value = "logsBloom")
public String getLogsBloom() {
return logsBloom;
}

@JsonGetter(value = "prevRandao")
public String getPrevRandao() {
return prevRandao;
}

@JsonGetter(value = "stateRoot")
public String getStateRoot() {
return stateRoot;
}

@JsonGetter(value = "receiptsRoot")
public String getReceiptRoot() {
return receiptsRoot;
}

@JsonGetter(value = "extraData")
public String getExtraData() {
return extraData;
}

@JsonGetter(value = "baseFeePerGas")
public String getBaseFeePerGas() {
return baseFeePerGas;
}

@JsonGetter(value = "gasLimit")
public String getGasLimit() {
return gasLimit;
}

@JsonGetter(value = "gasUsed")
public String getGasUsed() {
return gasUsed;
}

@JsonGetter(value = "timestamp")
public String getTimestamp() {
return timestamp;
}

@JsonGetter(value = "transactions")
public List<String> getTransactions() {
return transactions;
}

@JsonGetter(value = "feeRecipient")
@JsonInclude(JsonInclude.Include.NON_NULL)
public String getFeeRecipient() {
return feeRecipient;
}

@JsonGetter(value = "withdrawals")
public List<WithdrawalParameter> getWithdrawals() {
return withdrawals.orElse(null);
}
}

0 comments on commit 46f4390

Please sign in to comment.