Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
feat: add api 20230810
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-HauTran3 committed Oct 18, 2023
1 parent fc66b2c commit cbdc6b1
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 138 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/com/klaytn/caver/Caver.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class Caver {

public static String DEFAULT_URL = "http://localhost:8551";
public static String DEFAULT_URL = "http://localhost:8545";

/**
* @deprecated Please use <code>caver.rpc.klay</code> instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2022 The caver-java Authors
*
* 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.
*/

package com.klaytn.caver.methods.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import org.web3j.protocol.core.Response;

public class ForkStatusResult
extends Response<ForkStatusResult.ForkStatusData> {

public static class ForkStatusData {

@JsonProperty("EthTxType")
private Boolean EthTxType;

@JsonProperty("Istanbul")
private Boolean Istanbul;

@JsonProperty("KIP103")
private Boolean KIP103;

@JsonProperty("Kore")
private Boolean Kore;

@JsonProperty("London")
private Boolean London;

@JsonProperty("Magma")
private Boolean Magma;

@JsonProperty("Mantle")
private Boolean Mantle;

public ForkStatusData (
Boolean EthTxType,
Boolean Istanbul,
Boolean KIP103,
Boolean Kore,
Boolean London,
Boolean Magma,
Boolean Mantle
) {
this.EthTxType = EthTxType;
this.Istanbul = Istanbul;
this.KIP103 = KIP103;
this.Kore = Kore;
this.London = London;
this.Magma = Magma;
this.Mantle = Mantle;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2020 The caver-java Authors
*
* 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.
*/

package com.klaytn.caver.methods.response;

import java.util.Map;

import org.web3j.protocol.core.Response;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

public class RewardsAccumulated extends Response<RewardsAccumulated.RewardsAccumulatedData> {
public static class RewardsAccumulatedData {

@JsonProperty("firstBlockTime")
private String firstBlockTime;

@JsonProperty("lastBlockTime")
private String lastBlockTime;

@JsonProperty("firstBlock")
private String firstBlock;

@JsonProperty("lastBlock")
private String lastBlock;

@JsonProperty("totalMinted")
private String totalMinted;

@JsonProperty("totalTxFee")
private String totalTxFee;

@JsonProperty("totalBurntTxFee")
private String totalBurntTxFee;

@JsonProperty("totalProposerRewards")
private String totalProposerRewards;

@JsonProperty("totalStakingRewards")
private String totalStakingRewards;

@JsonProperty("totalKFFRewards")
private String totalKFFRewards;

@JsonProperty("totalKCFRewards")
private String totalKCFRewards;

/**
* mapping from reward recipient to amounts
*/
@JsonProperty("rewards")
private Map<String, String> rewards;

public RewardsAccumulatedData(
String firstBlockTime,
String lastBlockTime,
String firstBlock,
String lastBlock,
String totalMinted,
String totalTxFee,
String totalBurntTxFee,
String totalProposerRewards,
String totalStakingRewards,
String totalKFFRewards,
String totalKCFRewards,
Map<String, String> Rewards
) {
this.firstBlockTime = firstBlockTime;
this.lastBlockTime = lastBlockTime;
this.firstBlock = firstBlock;
this.lastBlock = lastBlock;
this.totalMinted = totalMinted;
this.totalTxFee = totalTxFee;
this.totalBurntTxFee = totalBurntTxFee;
this.totalProposerRewards = totalProposerRewards;
this.totalStakingRewards = totalStakingRewards;
this.totalKFFRewards = totalKFFRewards;
this.totalKCFRewards = totalKCFRewards;
this.rewards = rewards;
}
}
}
141 changes: 37 additions & 104 deletions core/src/main/java/com/klaytn/caver/rpc/Governance.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Request<?, GovernanceMyVotes> getMyVotes() {
* @return Request&lt;?, GovernanceChainConfig&gt;
*/
public Request<?, GovernanceChainConfig> getChainConfig() {
return getChainConfigAt(DefaultBlockParameterName.LATEST);
return getChainConfig(DefaultBlockParameterName.LATEST);
}

/**
Expand Down Expand Up @@ -330,44 +330,6 @@ public Request<?, GovernanceChainConfig> getChainConfig(DefaultBlockParameter bl
);
}

/**
* Provides the chain configuration at the specified block number
* <pre>Example :
* {@code
* GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.ZERO).send();
* }
* </pre>
* @return Request&lt;?, GovernanceChainConfig&gt;
*/
public Request<?, GovernanceChainConfig> getChainConfigAt(BigInteger blockNumber) {
return getChainConfigAt(DefaultBlockParameter.valueOf(blockNumber));
}

/**
* Provides the chain configuration by block tag (latest, earliest, pending)
* <pre>Example :
* {@code
* GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send();
* }
* </pre>
* @return Request&lt;?, GovernanceChainConfig&gt;
*/
public Request<?, GovernanceChainConfig> getChainConfigAt(String blockTag) {
return getChainConfigAt(DefaultBlockParameterName.fromString(blockTag));
}

/**
* return chain configuration
*/
public Request<?, GovernanceChainConfig> getChainConfigAt(DefaultBlockParameter blockNumberOrTag) {
return new Request<>(
"governance_chainConfigAt",
Arrays.asList(blockNumberOrTag),
provider,
GovernanceChainConfig.class
);
}

/**
* Provides the address of the node that a user is using.<p>
* It is derived from the nodekey and used to sign consensus messages. And the value of "governingnode" has to be one of validator's node address.
Expand Down Expand Up @@ -467,59 +429,6 @@ Request<?, GovernanceItems> getParams(DefaultBlockParameter blockParameter) {
);
}

/**
* Returns governance items at specific block.<p>
* It is the result of previous voting of the block and used as configuration for chain at the given block number.<p>
* It pass the latest block tag as a parameter.
* <pre>Example :
* {@code
* GovernanceItems response = caver.rpc.governance.getItemsAt().send();
* Map<String, Object> governanceItem = response.getResult();
*
* String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
* }</pre>
* @return Request&lt;?, Bytes20&gt;
*/
public Request<?, GovernanceItems> getItemsAt() {
return getItemsAt(DefaultBlockParameterName.LATEST);
}

/**
* Returns governance items at specific block.<p>
* It is the result of previous voting of the block and used as configuration for chain at the given block number.
* <pre>Example :
* {@code
* GovernanceItems response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send();
* Map<String, Object> governanceItem = response.getResult();
*
* String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
* }</pre>
* @param blockNumber The block number to query.
* @return Request&lt;?, GovernanceItems&gt;
*/
public Request<?, GovernanceItems> getItemsAt(BigInteger blockNumber) {
return getItemsAt(DefaultBlockParameter.valueOf(blockNumber));
}

/**
* Returns governance items at specific block.<p>
* It is the result of previous voting of the block and used as configuration for chain at the given block number.
* <pre>Example :
* {@code
* GovernanceItems response = caver.rpc.governance.getItemsAt("latest").send();
* Map<String, Object> governanceItem = response.getResult();
*
* String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
* }
* </pre>
* @param blockTag The block tag to query
* @return Request&lt;?, GovernanceItems&gt;
*/
public Request<?, GovernanceItems> getItemsAt(String blockTag) {
DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag);
return getItemsAt(blockTagName);
}

/**
* Returns governance items at specific block.<p>
* It is the result of previous voting of the block and used as configuration for chain at the given block number.
Expand All @@ -534,18 +443,18 @@ public Request<?, GovernanceItems> getItemsAt(String blockTag) {
* @param blockTag The block tag to query
* @return Request&lt;?, GovernanceItems&gt;
*/
public Request<?, GovernanceItems> getItemsAt(DefaultBlockParameterName blockTag) {
return getItemsAt((DefaultBlockParameter)blockTag);
}
// public Request<?, GovernanceItems> getItemsAt(DefaultBlockParameterName blockTag) {
// return getItemsAt((DefaultBlockParameter)blockTag);
// }

Request<?, GovernanceItems> getItemsAt(DefaultBlockParameter blockParameter) {
return new Request<>(
"governance_itemsAt",
Arrays.asList(blockParameter.getValue()),
provider,
GovernanceItems.class
);
}
// Request<?, GovernanceItems> getItemsAt(DefaultBlockParameter blockParameter) {
// return new Request<>(
// "governance_itemsAt",
// Arrays.asList(blockParameter.getValue()),
// provider,
// GovernanceItems.class
// );
// }

/**
* Returns the list of items that have received enough number of votes but not yet finalized.<p>
Expand Down Expand Up @@ -713,4 +622,28 @@ Request<?, GovernanceStakingInfo> getStakingInfo(DefaultBlockParameter blockPara
GovernanceStakingInfo.class
);
}
}

public Request<?, RewardsAccumulated> getRewardsAccumulated(String fromBlock, String toBlock) {
DefaultBlockParameterName fromBlockTagName = DefaultBlockParameterName.fromString(fromBlock);
DefaultBlockParameterName toBlockTagName = DefaultBlockParameterName.fromString(toBlock);

return getRewardsAccumulated(fromBlockTagName, toBlockTagName);
}

public Request<?, RewardsAccumulated> getRewardsAccumulated(BigInteger fromBlock, BigInteger toBlock) {
return getRewardsAccumulated(fromBlock, toBlock);
}

public Request<?, RewardsAccumulated> getRewardsAccumulated(DefaultBlockParameterName fromBlock, DefaultBlockParameterName toBlock) {
return getRewardsAccumulated((DefaultBlockParameter)fromBlock, (DefaultBlockParameter)toBlock);
}

Request<?, RewardsAccumulated> getRewardsAccumulated(DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock) {
return new Request<>(
"governance_getRewardsAccumulated",
Arrays.asList(fromBlock, toBlock),
provider,
RewardsAccumulated.class
);
}
}
Loading

0 comments on commit cbdc6b1

Please sign in to comment.