Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Navie Chan <naviechan@gmail.com>
  • Loading branch information
ensi321 committed Feb 19, 2023
1 parent f8a0f87 commit d57d70b
Show file tree
Hide file tree
Showing 28 changed files with 971 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ default boolean isConsensusMigration() {
*/
OptionalLong getCancunTime();

/**
* Gets EIP-6110 time.
*
* @return the EIP-6110 time
*/
OptionalLong getEIP6110Time();

/**
* Gets future eips time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public OptionalLong getCancunTime() {
return getOptionalLong("cancuntime");
}

@Override
public OptionalLong getEIP6110Time() {
return getOptionalLong("eip6110time");
}

@Override
public OptionalLong getFutureEipsTime() {
return getOptionalLong("futureeipstime");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong mergeNetSplitBlockNumber = OptionalLong.empty();
private OptionalLong shanghaiTime = OptionalLong.empty();
private OptionalLong cancunTime = OptionalLong.empty();
private OptionalLong eip6110Time = OptionalLong.empty();
private OptionalLong futureEipsTime = OptionalLong.empty();
private OptionalLong experimentalEipsTime = OptionalLong.empty();
private OptionalLong terminalBlockNumber = OptionalLong.empty();
Expand Down Expand Up @@ -231,6 +232,11 @@ public OptionalLong getCancunTime() {
return cancunTime;
}

@Override
public OptionalLong getEIP6110Time() {
return eip6110Time;
}

@Override
public OptionalLong getFutureEipsTime() {
return futureEipsTime;
Expand Down Expand Up @@ -619,6 +625,17 @@ public StubGenesisConfigOptions cancunTime(final long timestamp) {
return this;
}

/**
* Cancun time.
*
* @param timestamp the timestamp
* @return the stub genesis config options
*/
public StubGenesisConfigOptions eip6110Time(final long timestamp) {
eip6110Time = OptionalLong.of(timestamp);
return this;
}

/**
* Future EIPs Time block.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* 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.parameters;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.vertx.core.json.JsonObject;
import org.apache.tuweni.units.bigints.UInt64;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.GWei;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.core.Deposit;

import java.util.Objects;

public class DepositParameter {

private final String pubKey;

private final String withdrawalCredentials;
private final String amount;

private final String signature;
private final String index;

@JsonCreator
public DepositParameter(
@JsonProperty("pubKey") final String pubKey,
@JsonProperty("withdrawalCredentials") final String withdrawalCredentials,
@JsonProperty("amount") final String amount,
@JsonProperty("signature") final String signature,
@JsonProperty("index") final String index) {
this.pubKey = pubKey;
this.withdrawalCredentials = withdrawalCredentials;
this.amount = amount;
this.signature = signature;
this.index = index;
}

public static DepositParameter fromDeposit(final Deposit deposit) {
return new DepositParameter(
deposit.getPubKey().toString(), //TODO
deposit.getWithdrawalCredentials().toString(),
deposit.getAmount().toShortHexString(),
deposit.getSignature().toString(),
deposit.getIndex().toBytes().toQuantityHexString()
);
}

//TODO
public Deposit toDeposit() {
return new Deposit(
pubKey,
withdrawalCredentials,
GWei.fromHexString(amount),
signature,
UInt64.fromHexString(index));
}

public JsonObject asJsonObject() {
return new JsonObject()
.put("pubKey", pubKey)
.put("withdrawalCredentials", withdrawalCredentials)
.put("amount", amount)
.put("signature", signature)
.put("index", index);
}

@JsonGetter
public String getPubKey() {
return pubKey;
}

@JsonGetter
public String getWithdrawalCredentials() {
return withdrawalCredentials;
}

@JsonGetter
public String getAmount() {
return amount;
}

@JsonGetter
public String getSignature() {
return signature;
}

@JsonGetter
public String getIndex() {
return index;
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final DepositParameter that = (DepositParameter) o;
return Objects.equals(pubKey, that.pubKey)
&& Objects.equals(withdrawalCredentials, that.withdrawalCredentials)
&& Objects.equals(amount, that.amount)
&& Objects.equals(signature, that.signature)
&& Objects.equals(index, that.index);
}

@Override
public int hashCode() {
return Objects.hash(pubKey, withdrawalCredentials, amount, signature, index);
}

@Override
public String toString() {
return "DepositParameter{" +
"pubKey='" + pubKey + '\'' +
", withdrawalCredentials='" + withdrawalCredentials + '\'' +
", amount='" + amount + '\'' +
", signature='" + signature + '\'' +
", index='" + index + '\'' +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* 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 com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.DepositParameter;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.WithdrawalParameter;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Deposit;
import org.hyperledger.besu.ethereum.core.Withdrawal;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@JsonPropertyOrder({
"executionPayload",
"blockValue",
})
public class EngineGetPayloadResultV6110 {
protected final PayloadResult executionPayload;
private final String blockValue;

public EngineGetPayloadResultV6110(
final BlockHeader header,
final List<String> transactions,
final Optional<List<Withdrawal>> withdrawals,
final Optional<List<Deposit>> deposits,
final String blockValue) {
this.executionPayload = new PayloadResult(header, transactions, withdrawals, deposits);
this.blockValue = blockValue;
}

@JsonGetter(value = "executionPayload")
public PayloadResult getExecutionPayload() {
return executionPayload;
}

@JsonGetter(value = "blockValue")
public String getBlockValue() {
return blockValue;
}

public static class PayloadResult {

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;
private final List<WithdrawalParameter> withdrawals;

private final List<DepositParameter> deposits;

public PayloadResult(
final BlockHeader header,
final List<String> transactions,
final Optional<List<Withdrawal>> withdrawals,
final Optional<List<Deposit>> deposits) {
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
.map(
ws ->
ws.stream()
.map(WithdrawalParameter::fromWithdrawal)
.collect(Collectors.toList()))
.orElse(null);
this.deposits =
deposits
.map(
ws ->
ws.stream()
.map(DepositParameter::fromDeposit)
.collect(Collectors.toList()))
.orElse(null);
}

@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 = "withdrawals")
public List<WithdrawalParameter> getWithdrawals() {
return withdrawals;
}

@JsonGetter(value = "withdrawals")
public List<DepositParameter> getDeposits() {
return deposits;
}

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

0 comments on commit d57d70b

Please sign in to comment.