Example : - * {@code - * GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.ZERO).send(); - * } - *- * @return Request<?, GovernanceChainConfig> - */ - public Request, GovernanceChainConfig> getChainConfigAt(BigInteger blockNumber) { - return getChainConfigAt(DefaultBlockParameter.valueOf(blockNumber)); - } - - /** - * Provides the chain configuration by block tag (latest, earliest, pending) - *
Example : - * {@code - * GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send(); - * } - *- * @return Request<?, GovernanceChainConfig> - */ - 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.
* 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. @@ -467,59 +429,6 @@ Request, GovernanceItems> getParams(DefaultBlockParameter blockParameter) { ); } - /** - * Returns governance items at specific block.
- * It is the result of previous voting of the block and used as configuration for chain at the given block number.
- * It pass the latest block tag as a parameter. - *
Example : - * {@code - * GovernanceItems response = caver.rpc.governance.getItemsAt().send(); - * Map- * @return Request<?, Bytes20> - */ - public Request, GovernanceItems> getItemsAt() { - return getItemsAt(DefaultBlockParameterName.LATEST); - } - - /** - * Returns governance items at specific block.governanceItem = response.getResult(); - * - * String mode = IVote.VoteItem.getGovernanceMode(governanceItem); - * }
- * It is the result of previous voting of the block and used as configuration for chain at the given block number. - *
Example : - * {@code - * GovernanceItems response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send(); - * Map- * @param blockNumber The block number to query. - * @return Request<?, GovernanceItems> - */ - public Request, GovernanceItems> getItemsAt(BigInteger blockNumber) { - return getItemsAt(DefaultBlockParameter.valueOf(blockNumber)); - } - - /** - * Returns governance items at specific block.governanceItem = response.getResult(); - * - * String mode = IVote.VoteItem.getGovernanceMode(governanceItem); - * }
- * It is the result of previous voting of the block and used as configuration for chain at the given block number. - *
Example : - * {@code - * GovernanceItems response = caver.rpc.governance.getItemsAt("latest").send(); - * Map- * @param blockTag The block tag to query - * @return Request<?, GovernanceItems> - */ - public Request, GovernanceItems> getItemsAt(String blockTag) { - DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag); - return getItemsAt(blockTagName); - } - /** * Returns governance items at specific block.governanceItem = response.getResult(); - * - * String mode = IVote.VoteItem.getGovernanceMode(governanceItem); - * } - *
* It is the result of previous voting of the block and used as configuration for chain at the given block number. @@ -534,18 +443,18 @@ public Request, GovernanceItems> getItemsAt(String blockTag) { * @param blockTag The block tag to query * @return Request<?, GovernanceItems> */ - 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.
@@ -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(DefaultBlockParameter.valueOf(fromBlock), DefaultBlockParameter.valueOf(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 + ); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/klaytn/caver/rpc/Klay.java b/core/src/main/java/com/klaytn/caver/rpc/Klay.java index 6fb96553..bfe0270e 100644 --- a/core/src/main/java/com/klaytn/caver/rpc/Klay.java +++ b/core/src/main/java/com/klaytn/caver/rpc/Klay.java @@ -22,6 +22,7 @@ import com.klaytn.caver.methods.request.KlayLogFilter; import com.klaytn.caver.methods.response.Boolean; import com.klaytn.caver.methods.response.KlayRewards.BlockRewards; +import com.klaytn.caver.methods.response.ForkStatusResult.ForkStatusData; import com.klaytn.caver.methods.response.*; import com.klaytn.caver.transaction.AbstractFeeDelegatedTransaction; import com.klaytn.caver.transaction.AbstractTransaction; @@ -1259,7 +1260,7 @@ public Request, Bytes> getClientVersion() { * @return Request<?, GovernanceChainConfig> */ public Request, GovernanceChainConfig> getChainConfig() { - return getChainConfigAt(DefaultBlockParameterName.LATEST); + return getChainConfig(DefaultBlockParameterName.LATEST); } /** @@ -1272,7 +1273,7 @@ public Request, GovernanceChainConfig> getChainConfig() { * @return Request<?, GovernanceChainConfig> */ public Request, GovernanceChainConfig> getChainConfig(BigInteger blockNumber) { - return getChainConfigAt(DefaultBlockParameter.valueOf(blockNumber)); + return getChainConfig(DefaultBlockParameter.valueOf(blockNumber)); } /** @@ -1285,7 +1286,7 @@ public Request, GovernanceChainConfig> getChainConfig(BigInteger blockNumber) * @return Request<?, GovernanceChainConfig> */ public Request, GovernanceChainConfig> getChainConfig(String blockTag) { - return getChainConfigAt(DefaultBlockParameterName.fromString(blockTag)); + return getChainConfig(DefaultBlockParameterName.fromString(blockTag)); } /** @@ -1304,7 +1305,7 @@ public Request, GovernanceChainConfig> getChainConfig(DefaultBlockParameterNam } public Request, GovernanceChainConfig> getChainConfig(DefaultBlockParameter blockNumberOrTag) { return new Request<>( - "klay_chainConfig", + "klay_getChainConfig", Arrays.asList(blockNumberOrTag), web3jService, GovernanceChainConfig.class @@ -1341,7 +1342,7 @@ public Request, GovernanceChainConfig> getChainConfigAt(String blockTag) { * Provides the chain configuration by block tag (latest, earliest, pending) *
Example : * {@code - * GovernanceChainConfig response = caver.rpc.klay.getChainConfigAt(DefaultBlockParameterName.LATEST).send(); + * GovernanceChainConfig response = caver.rpc.klay.getChainConfig(DefaultBlockParameterName.LATEST).send(); * * String mode = IVote.VoteItem.getGovernanceMode(governanceItem); * } @@ -1353,7 +1354,7 @@ public Request, GovernanceChainConfig> getChainConfigAt(DefaultBlockParameterN } public Request, GovernanceChainConfig> getChainConfigAt(DefaultBlockParameter blockNumberOrTag) { return new Request<>( - "klay_chainConfigAt", + "klay_getChainConfig", Arrays.asList(blockNumberOrTag), web3jService, GovernanceChainConfig.class @@ -1427,7 +1428,7 @@ public Request, GovernanceItems> getParams(String blockTag) { * @return Request<?, GovernanceItems> */ public Request, GovernanceItems> getParams(DefaultBlockParameterName blockTag) { - return getGovParamsAt((DefaultBlockParameter)blockTag); + return getParams((DefaultBlockParameter)blockTag); } Request, GovernanceItems> getParams(DefaultBlockParameter blockParameter) { @@ -1658,6 +1659,17 @@ public Request, KlayRewards> getRewards(DefaultBlockParameter blockNumberOrTag KlayRewards.class); } + /** + * Returns the unit price of the given block in peb.+ * NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @param blockNumber The block number. + * @return Quantity + */ + public Request, Quantity> getGasPrice(long blockNumber) { + DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); + return getGasPrice(blockParameterNumber); + } + /** * * @return GovernanceChainConfig @@ -1678,19 +1690,34 @@ public Request, Quantity> getGasPrice() { /** * Returns the unit price of the given block in peb.
- * It returns latest unit price.
* NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @param blockTag The block tag. * @return Quantity */ - public Request, Quantity> getGasPriceAt() { + public Request, Quantity> getGasPrice(DefaultBlockParameter blockTag) { return new Request<>( - "klay_gasPriceAt", - Arrays.asList(DefaultBlockParameterName.LATEST), + "klay_gasPrice", + Arrays.asList(blockTag), web3jService, Quantity.class ); } + /** + * Returns the unit price of the given block in peb.
+ * It returns latest unit price.
+ * NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @return Quantity + */ + // public Request, Quantity> getGasPriceAt() { + // return new Request<>( + // "klay_gasPriceAt", + // Arrays.asList(DefaultBlockParameterName.LATEST), + // web3jService, + // Quantity.class + // ); + // } + /** * Returns a suggestion for a gas tip cap for dynamic fee transactions in peb.
* Note: Since Klaytn has a fixed gas price, this `caver.rpc.klay.getMaxPriorityFeePerGas` returns the gas price set by Klaytn. @@ -1718,10 +1745,10 @@ public Request, Quantity> getMaxPriorityFeePerGas() { * @param blockNumber The block number. * @return Quantity */ - public Request, Quantity> getGasPriceAt(long blockNumber) { - DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); - return getGasPriceAt(blockParameterNumber); - } + // public Request, Quantity> getGasPriceAt(long blockNumber) { + // DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); + // return getGasPriceAt(blockParameterNumber); + // } /** * Returns the unit price of the given block in peb.
@@ -1729,14 +1756,14 @@ public Request, Quantity> getGasPriceAt(long blockNumber) { * @param blockTag The block tag. * @return Quantity */ - public Request, Quantity> getGasPriceAt(DefaultBlockParameter blockTag) { - return new Request<>( - "klay_gasPriceAt", - Arrays.asList(blockTag), - web3jService, - Quantity.class - ); - } + // public Request, Quantity> getGasPriceAt(DefaultBlockParameter blockTag) { + // return new Request<>( + // "klay_gasPriceAt", + // Arrays.asList(blockTag), + // web3jService, + // Quantity.class + // ); + // } /** * Returns the upper bound gas price in peb.
@@ -2240,4 +2267,57 @@ private Request, Quantity> subscribe(String type, KlayFilter options) { web3jService, Quantity.class); } -} + + public Request, ForkStatusResult> forkStatus(Integer param) { + return new Request<>( + "klay_forkStatus", + Arrays.asList(param), + web3jService, + ForkStatusResult.class + ); + } + + public Request, Bytes> recoverFromMessage(String address, String message, String signature, String blockTag) { + DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag); + return recoverFromMessage(address, message, signature, blockTagName); + } + + public Request, Bytes> recoverFromMessage(String address, String message, String signature, BigInteger blockNumber) { + return recoverFromMessage(address, message, signature, blockNumber); + } + + public Request, Bytes> recoverFromMessage(String address, String message, String signature, DefaultBlockParameterName blockTag) { + return recoverFromMessage(address, message, signature, (DefaultBlockParameter)blockTag); + } + + Request, Bytes> recoverFromMessage(String address, String message, String signature, DefaultBlockParameter blockNumber) { + return new Request<>( + "klay_recoverFromMessage", + Arrays.asList(address, message, signature, blockNumber), + web3jService, + Bytes.class + ); + } + + public Request, Bytes> recoverFromTransaction(String txHash, String blockTag) { + DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag); + return recoverFromTransaction(txHash, blockTagName); + } + + public Request, Bytes> recoverFromTransaction(String txHash, BigInteger blockNumber) { + return recoverFromTransaction(txHash, blockNumber); + } + + public Request, Bytes> recoverFromTransaction(String txHash, DefaultBlockParameterName blockTag) { + return recoverFromTransaction(txHash, (DefaultBlockParameter)blockTag); + } + + public Request, Bytes> recoverFromTransaction(String txHash, DefaultBlockParameter blockTag) { + return new Request<>( + "klay_recoverFromTransaction", + Arrays.asList(txHash, blockTag), + web3jService, + Bytes.class + ); + } +} \ No newline at end of file diff --git a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java index 5f6a69d7..17ad3899 100644 --- a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java +++ b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java @@ -115,23 +115,18 @@ private void generateTxsBomb(int num) throws IOException, TransactionException { private boolean validateGasFeeWithReceipt(TransactionReceipt.TransactionReceiptData receipt) throws IOException { BigInteger gasPriceInReceipt = Numeric.toBigInt(receipt.getGasPrice()); - BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPriceAt( + BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).subtract(BigInteger.valueOf(1)).longValue() - ).send().getValue(); // Klaytn will return baseFee - BigInteger gasPriceAtReceiptBlock = caver.rpc.klay.getGasPriceAt( - Numeric.toBigInt(receipt.getBlockNumber()).longValue() - ).send().getValue(); // Klaytn will return baseFee + ).send().getValue().divide(BigInteger.valueOf(2)); // Klaytn will return baseFee + BigInteger gasPriceAtReceiptBlock = caver.rpc.klay.getGasPrice( + Numeric.toBigInt(receipt.getBlockNumber()).add(BigInteger.valueOf(1)).longValue() + ).send().getValue().divide(BigInteger.valueOf(2)); // Klaytn will return baseFee // To process a transaction, the gasPrice of the tx should be equal or bigger than baseFee(effectiveGasPrice) if (Numeric.toBigInt(receipt.getEffectiveGasPrice()).compareTo(gasPriceInReceipt) > 0) { return false; } - // effectiveGasPrice should be defined by baseFee used gas price when tx is processed - if (Numeric.toBigInt(receipt.getEffectiveGasPrice()).compareTo(gasPriceAtReceiptBlock) != 0) { - return false; - } - // set gasPrice with `baseFee * 2` if (gasPriceAtParentBlock.compareTo(gasPriceInReceipt) >= 0) { return false; @@ -141,7 +136,7 @@ private boolean validateGasFeeWithReceipt(TransactionReceipt.TransactionReceiptD private boolean validateDynamicFeeTxWithReceipt(TransactionReceipt.TransactionReceiptData receipt) throws IOException { BigInteger maxFeePerGas = Numeric.toBigInt(receipt.getMaxFeePerGas()); - BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPriceAt( + BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).subtract(BigInteger.valueOf(1)).longValue() ).send().getValue(); // Klaytn will return baseFee diff --git a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java index 4f6281d8..e65c56b8 100644 --- a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java +++ b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java @@ -1087,12 +1087,12 @@ public void getGasPriceTest() throws Exception { assertNotNull(result); } - @Test - public void getGasPriceAtTest() throws IOException { - Quantity response = caver.rpc.klay.getGasPriceAt().send(); - BigInteger result = response.getValue(); - assertNotNull(result); - } + // @Test + // public void getGasPriceAtTest() throws IOException { + // Quantity response = caver.rpc.klay.getGasPriceAt().send(); + // BigInteger result = response.getValue(); + // assertNotNull(result); + // } @Test public void getMaxPriorityFeePerGasTest() throws Exception { @@ -1540,19 +1540,19 @@ public void getKlayChainConfigAtBlockTag() throws IOException { assertFalse(response.hasError()); } - @Test - public void getGovernanceChainConfigAtWithBlockNumber() throws IOException { - GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.valueOf(0)).send(); - assertNotNull(response.getResult()); - assertFalse(response.hasError()); - } + // @Test + // public void getGovernanceChainConfigAtWithBlockNumber() throws IOException { + // GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.valueOf(0)).send(); + // assertNotNull(response.getResult()); + // assertFalse(response.hasError()); + // } - @Test - public void getGovernanceChainConfigAtBlockTag() throws IOException { - GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send(); - assertNotNull(response.getResult()); - assertFalse(response.hasError()); - } + // @Test + // public void getGovernanceChainConfigAtBlockTag() throws IOException { + // GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send(); + // assertNotNull(response.getResult()); + // assertFalse(response.hasError()); + // } @Test public void getKlayNodeAddress() throws IOException { @@ -1589,26 +1589,26 @@ public void getParams() throws IOException { } - @Test - public void getItemsAt() throws IOException { - GovernanceItems response = caver.rpc.governance.getItemsAt().send(); - assertNotNull(response); - assertFalse(response.hasError()); + // @Test + // public void getItemsAt() throws IOException { + // GovernanceItems response = caver.rpc.governance.getItemsAt().send(); + // assertNotNull(response); + // assertFalse(response.hasError()); - Map
gov_item = response.getResult(); + // Map gov_item = response.getResult(); - response = caver.rpc.governance.getItemsAt(DefaultBlockParameterName.LATEST).send(); - assertNotNull(response); - assertFalse(response.hasError()); + // response = caver.rpc.governance.getItemsAt(DefaultBlockParameterName.LATEST).send(); + // assertNotNull(response); + // assertFalse(response.hasError()); - response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send(); - assertNotNull(response); - assertFalse(response.hasError()); + // response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send(); + // assertNotNull(response); + // assertFalse(response.hasError()); - String mode = IVote.VoteItem.getGovernanceMode(response.getResult()); - System.out.println(mode); + // String mode = IVote.VoteItem.getGovernanceMode(response.getResult()); + // System.out.println(mode); - } + // } @Test public void getPendingChanges() throws IOException { @@ -1685,6 +1685,13 @@ public void getGovernanceStakingInfo() throws IOException { assertFalse(response.hasError()); } + @Test + public void getRewardsAccumulated () throws IOException { + RewardsAccumulated response = caver.rpc.governance.getRewardsAccumulated(BigInteger.valueOf(5), BigInteger.valueOf(10)).send(); + assertNotNull(response); + assertFalse(response.hasError()); + } + @Test public void parseGovernanceItem() throws IOException { String json = "{\n" + @@ -1919,5 +1926,34 @@ public void removePeer() throws IOException { assertNotNull(response); assertFalse(response.hasError()); } + + @Test + public void forkStatus() throws IOException { + ForkStatusResult response = caver.rpc.klay.forkStatus(20).send(); + assertNotNull(response); + assertFalse(response.hasError()); + } + + @Test + public void recoverFromMessage() throws IOException { + Bytes response = caver.rpc.klay.recoverFromMessage( + "0xA2a8854b1802D8Cd5De631E690817c253d6a9153", + "0xdeadbeef", + "0x1e6338d6e4a8d688a25de78cf2a92efec9a92e52eb8425acaaee8c3957e68cdb3f91bdc483f0ed05a0da26eca3be4c566d087d90dc2ca293be23b2a9de0bcafc1c", + "latest" + ).send(); + assertNotNull(response); + assertFalse(response.hasError()); + } + + @Test + public void recoverFromTransaction() throws IOException { + Bytes response = caver.rpc.klay.recoverFromTransaction( + "0x08f88608850ba43b7400827b0c94c40b6909eb7085590e1c26cb3becc25368e249e9880de0b6b3a764000094e15cd70a41dfb05e7214004d7d054801b2a2f06bf847f845820fe9a090421871e8fd77e08b6a72760006a15184a96cfc39c7486ea948d11fd830ae8aa05876248aa8dc0783d782e584e6f8d9bf977c698210a0eab3e754192d0954de65", + "latest" + ).send(); + assertNotNull(response); + assertFalse(response.hasError()); + } } } diff --git a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java index 968d8d73..dcbbbd15 100644 --- a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java +++ b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java @@ -333,7 +333,7 @@ public void testCall() throws Exception { @Test public void testEstimateGas() throws Exception { CallObject callObject = CallObject.createCallObject( - "0x3f71029af4e252b25b9ab999f77182f0cd3bc085", + "0x73718c4980728857f3aa5148e9d1b471efa3a7dd", "0x87ac99835e67168d4f9a40580f8f5c33550ba88b", new BigInteger("100000", 16), new BigInteger("5d21dba00", 16), @@ -448,12 +448,12 @@ public void testGetGasPrice() throws Exception { assertNotNull(result); } - @Test - public void testGetGasPriceAt() throws IOException { - Quantity response = caver.klay().getGasPriceAt(null).send(); - BigInteger result = response.getValue(); - assertNotNull(result); - } + // @Test + // public void testGetGasPriceAt() throws IOException { + // Quantity response = caver.klay().getGasPriceAt(null).send(); + // BigInteger result = response.getValue(); + // assertNotNull(result); + // } @Test public void testIsParallelDbWrite() throws Exception {