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

Update ChainConfig API #741

Merged
merged 6 commits into from
Mar 16, 2023
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
9 changes: 6 additions & 3 deletions packages/caver-rpc/src/governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ const Governance = function Governance(...args) {
* @instance
*
* @example
* const result = await caver.rpc.governance.getChainConfig(0)
* // latest by default
* const result = await caver.rpc.governance.getChainConfig()
*
* @param {number|string} blockNumber A block number, or the hex number string to query chain configuration.
* @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second.
* @return {Promise<object>} The latest chain configuration
* @return {Promise<object>} The latest chain configuration, or chain configuration at the given block number.
*/
new Method({
name: 'getChainConfig',
call: 'governance_chainConfig',
params: 0,
call: 'governance_getChainConfig',
params: 1,
kjeom marked this conversation as resolved.
Show resolved Hide resolved
}),
/**
* Returns the chain configuration at a specific block.
Expand Down
9 changes: 6 additions & 3 deletions packages/caver-rpc/src/klay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2249,15 +2249,18 @@ class Klay {
* @instance
*
* @example
* const result = await caver.rpc.klay.getChainConfig(0)
* // latest by default
* const result = await caver.rpc.klay.getChainConfig()
*
* @param {number|string} blockNumber A block number, or the hex number string to query chain configuration.
* @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second.
* @return {Promise<object>} The latest chain configuration
* @return {Promise<object>} The latest chain configuration, or chain configuration at the given block number.
*/
new Method({
name: 'getChainConfig',
call: 'klay_chainConfig',
params: 0,
call: 'klay_getChainConfig',
params: 1,
}),
/**
* Returns the chain configuration at a specific block.
Expand Down
4 changes: 2 additions & 2 deletions test/packages/caver.rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ describe('caver.rpc.klay', () => {
const klayRPCStub = sandbox
.stub(caver.rpc.klay.getChainConfig.method.requestManager, 'send')
.callsFake((payload, sendTxCallback) => {
expect(payload.method).to.equal('klay_chainConfig')
expect(payload.method).to.equal('klay_getChainConfig')
expect(payload.params.length).to.equal(caver.rpc.klay.getChainConfig.method.params)
const ret = {
chainId: 1001,
Expand Down Expand Up @@ -1098,7 +1098,7 @@ describe('caver.rpc.governance', () => {
const govRPCStub = sandbox
.stub(caver.rpc.governance.getChainConfig.method.requestManager, 'send')
.callsFake((payload, sendTxCallback) => {
expect(payload.method).to.equal('governance_chainConfig')
expect(payload.method).to.equal('governance_getChainConfig')
expect(payload.params.length).to.equal(caver.rpc.governance.getChainConfig.method.params)
const ret = {
chainId: 1001,
Expand Down
2 changes: 0 additions & 2 deletions types/packages/caver-klay/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ export class DeprecatedKlayRPC {
getHeaderByHash: RpcCallToMethod['klay_getHeaderByHash']
getBlockReceipts: RpcCallToMethod['klay_getBlockReceipts']
getRewards: RpcCallToMethod['klay_getRewards']
getChainConfig: RpcCallToMethod['klay_chainConfig']
getChainConfigAt: RpcCallToMethod['klay_chainConfigAt']
getNodeAddress: RpcCallToMethod['klay_nodeAddress']
getGovParamsAt: RpcCallToMethod['klay_govParamsAt']
getStakingInfo: RpcCallToMethod['klay_getStakingInfo']
Expand Down
1 change: 1 addition & 0 deletions types/packages/caver-rpc/src/governance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class Governance {
getMyVotingPower(callback?: (error: Error, result: number) => void): Promise<number>
getMyVotes(callback?: (error: Error, result: MyVote[]) => void): Promise<MyVote[]>
getChainConfig(callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getChainConfig(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
ian0371 marked this conversation as resolved.
Show resolved Hide resolved
getChainConfigAt(callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getChainConfigAt(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getNodeAddress(callback?: (error: Error, result: string) => void): Promise<string>
Expand Down
1 change: 1 addition & 0 deletions types/packages/caver-rpc/src/klay.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export class Klay {

getRewards(blockNumber: BlockNumber, callback?: (error: Error, result: Header) => void): Promise<Rewards>
getChainConfig(callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getChainConfig(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getChainConfigAt(callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getChainConfigAt(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise<ChainConfig>
getNodeAddress(callback?: (error: Error, result: string) => void): Promise<string>
Expand Down
4 changes: 4 additions & 0 deletions types/packages/caver-rtm/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export default class RpcCallToMethod {
klay_chainConfig(
callback?: (error: Error, result: ChainConfig) => void
): Promise<ChainConfig>
klay_getChainConfig(
blockNumberOrHash?: BlockNumber | string,
callback?: (error: Error, result: ChainConfig) => void
): Promise<ChainConfig>
klay_chainConfigAt(
blockNumberOrHash: BlockNumber | string,
callback?: (error: Error, result: ChainConfig) => void
Expand Down
5 changes: 5 additions & 0 deletions types/test/rpc-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,11 @@ rpc.klay.getRewardbase()
// $ExpectType Promise<string>
rpc.klay.getRewardbase((err: Error, ret: string) => {})

// $ExpectType Promise<ChainConfig>
rpc.klay.getChainConfig()
// $ExpectType Promise<ChainConfig>
rpc.klay.getChainConfig((err: Error, ret: ChainConfig) => {})

// $ExpectType Promise<LogObject[]>
rpc.klay.getFilterChanges('filterId')
// $ExpectType Promise<LogObject[]>
Expand Down