diff --git a/package-lock.json b/package-lock.json index 75e0a14c..07b1ac03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "caver-js", - "version": "1.9.1", + "version": "1.10.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "caver-js", - "version": "1.9.1", + "version": "1.10.1", "license": "LGPL-3.0", "dependencies": { "@babel/runtime": "7.3.1", diff --git a/package.json b/package.json index 600a1b59..0c1d60fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "caver-js", - "version": "1.10.1", + "version": "1.10.2", "description": "caver-js is a JavaScript API library that allows developers to interact with a Klaytn node", "main": "index.js", "types": "types/index.d.ts", @@ -82,7 +82,7 @@ "eventemitter3": "4.0.0", "http": "0.0.1-security", "https": "^1.0.0", - "ipfs-http-client": "^57.0.3", + "ipfs-http-client": "^49.0.4", "lodash": "4.17.21", "multiformats": "^9.7.1", "number-to-bn": "1.7.0", diff --git a/packages/caver-ipfs/src/index.js b/packages/caver-ipfs/src/index.js index bac52ed4..926de224 100644 --- a/packages/caver-ipfs/src/index.js +++ b/packages/caver-ipfs/src/index.js @@ -19,6 +19,7 @@ const lodash = require('lodash') const fs = require('fs') +const ipfsClient = require('ipfs-http-client') const { CID } = require('multiformats/cid') const _ = require('lodash') @@ -56,17 +57,14 @@ class IPFS { * @param {object} [options] An object contains configuration variables. * @return {void} */ - async setIPFSNode(host, port, ssl, options = {}) { + setIPFSNode(host, port, ssl, options = {}) { const protocol = ssl ? 'https' : 'http' - // Use the dynamic import function to load ipfs at runtime - // refer to https://github.com/ipfs/js-ipfs/blob/master/docs/upgrading/v0.62-v0.63.md#esm - const { create } = await import('ipfs-http-client') const createObject = { host, port, protocol } if (options.headers) { // Copy the headers object createObject.headers = JSON.parse(JSON.stringify(options.headers)) } - this.ipfs = await create(createObject) + this.ipfs = ipfsClient(createObject) } /** diff --git a/packages/caver-rpc/src/governance.js b/packages/caver-rpc/src/governance.js index fd27072e..6f7cb943 100644 --- a/packages/caver-rpc/src/governance.js +++ b/packages/caver-rpc/src/governance.js @@ -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} The latest chain configuration + * @return {Promise} 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, }), /** * Returns the chain configuration at a specific block. @@ -229,6 +232,28 @@ const Governance = function Governance(...args) { params: 1, inputFormatter: [formatters.inputDefaultBlockNumberFormatter], }), + /** + * Returns governance items at a specific block. + * It is the result of previous voting of the block and used as configuration for chain at the given block number. + * + * @memberof Governance + * @method getParams + * @instance + * + * @example + * const result = await caver.rpc.governance.getParams() + * + * @param {string|number} [blockNumberOrTag] A block number, or the string `latest` or `earliest`. If omitted, `latest` will be used. + * @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second. + * @return {Promise} The governance items. + */ + new Method({ + name: 'getParams', + call: 'governance_getParams', + params: 1, + inputFormatter: [formatters.inputDefaultBlockNumberFormatter], + }), + /** * Returns the list of items that have received enough number of votes but not yet finalized. * At the end of the current epoch, these changes will be finalized and the result will be in effect from the epoch after next epoch. diff --git a/packages/caver-rpc/src/klay.js b/packages/caver-rpc/src/klay.js index a5d7887b..046a3697 100644 --- a/packages/caver-rpc/src/klay.js +++ b/packages/caver-rpc/src/klay.js @@ -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} The latest chain configuration + * @return {Promise} 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. @@ -2280,6 +2283,27 @@ class Klay { call: 'klay_chainConfigAt', params: 1, }), + /** + * Returns governance items at a specific block. + * It is the result of previous voting of the block and used as configuration for chain at the given block number. + * + * @memberof klay + * @method getParams + * @instance + * + * @example + * const result = await caver.rpc.klay.getParams() + * + * @param {string|number} [blockNumberOrTag] A block number, or the string `latest` or `earliest`. If omitted, `latest` will be used. + * @param {function} [callback] Optional callback, returns an error object as the first parameter and the result as the second. + * @return {Promise} The governance items. + */ + new Method({ + name: 'getParams', + call: 'klay_getParams', + params: 1, + inputFormatter: [formatters.inputDefaultBlockNumberFormatter], + }), /** * Provides an address of the operating node. * It is derived from the nodekey and used to sign consensus messages. diff --git a/test/ipfsTest.js b/test/ipfsTest.js index 1f844589..b3addea3 100644 --- a/test/ipfsTest.js +++ b/test/ipfsTest.js @@ -45,7 +45,8 @@ describe('Connect IPFS with Klaytn', () => { it('CAVERJS-UNIT-IPFS-001: should add file to IPFS and return hash (test with infura ipfs node)', async () => { // Set IPFS Node const options = caver.ipfs.createOptions({ projectId, projectSecret }) - await caver.ipfs.setIPFSNode('ipfs.infura.io', 5001, true, options) + // await caver.ipfs.setIPFSNode('ipfs.infura.io', 5001, true, options) + caver.ipfs.setIPFSNode('ipfs.infura.io', 5001, true, options) // Create test txt file for IPFS const testFileName = './ipfsTestFile.txt' diff --git a/test/packages/caver.rpc.js b/test/packages/caver.rpc.js index c17b056c..e3a4e5c4 100644 --- a/test/packages/caver.rpc.js +++ b/test/packages/caver.rpc.js @@ -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, @@ -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, @@ -1212,13 +1212,13 @@ describe('caver.rpc.governance', () => { }).timeout(100000) }) - context('caver.rpc.governance.getItemsAt', () => { + context('caver.rpc.governance.getParams', () => { it('CAVERJS-UNIT-RPC-017: should return governance items at specific block', async () => { const govRPCStub = sandbox - .stub(caver.rpc.governance.getItemsAt.method.requestManager, 'send') + .stub(caver.rpc.governance.getParams.method.requestManager, 'send') .callsFake((payload, sendTxCallback) => { expect(payload.method).to.equal('governance_itemsAt') - expect(payload.params.length).to.equal(caver.rpc.governance.getItemsAt.method.params) + expect(payload.params.length).to.equal(caver.rpc.governance.getParams.method.params) const ret = { 'governance.governancemode': 'single', 'governance.governingnode': '0xa80de139de3fb29fba7e2d20bda593c5ffe63ce9', @@ -1237,7 +1237,7 @@ describe('caver.rpc.governance', () => { sendTxCallback(null, ret) }) - await caver.rpc.governance.getItemsAt(0) + await caver.rpc.governance.getParams(0) expect(govRPCStub.callCount).to.equal(1) }).timeout(100000) }) diff --git a/types/packages/caver-klay/src/index.d.ts b/types/packages/caver-klay/src/index.d.ts index 4b5043e6..53879686 100644 --- a/types/packages/caver-klay/src/index.d.ts +++ b/types/packages/caver-klay/src/index.d.ts @@ -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'] diff --git a/types/packages/caver-rpc/src/governance.d.ts b/types/packages/caver-rpc/src/governance.d.ts index 1e851ea6..79346878 100644 --- a/types/packages/caver-rpc/src/governance.d.ts +++ b/types/packages/caver-rpc/src/governance.d.ts @@ -76,11 +76,14 @@ export class Governance { getMyVotingPower(callback?: (error: Error, result: number) => void): Promise getMyVotes(callback?: (error: Error, result: MyVote[]) => void): Promise getChainConfig(callback?: (error: Error, result: ChainConfig) => void): Promise + getChainConfig(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise getChainConfigAt(callback?: (error: Error, result: ChainConfig) => void): Promise getChainConfigAt(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise getNodeAddress(callback?: (error: Error, result: string) => void): Promise getItemsAt(callback?: (error: Error, result: GovernanceItems) => void): Promise getItemsAt(blockNumber: BlockNumber, callback?: (error: Error, result: GovernanceItems) => void): Promise + getParams(callback?: (error: Error, result: GovernanceItems) => void): Promise + getParams(blockNumber: BlockNumber, callback?: (error: Error, result: GovernanceItems) => void): Promise getStakingInfo(callback?: (error: Error, result: StakingInformation) => void): Promise getStakingInfo(blockNumber: BlockNumber, callback?: (error: Error, result: StakingInformation) => void): Promise getPendingChanges(callback?: (error: Error, result: VoteItems) => void): Promise diff --git a/types/packages/caver-rpc/src/klay.d.ts b/types/packages/caver-rpc/src/klay.d.ts index c83a98c8..037d027f 100644 --- a/types/packages/caver-rpc/src/klay.d.ts +++ b/types/packages/caver-rpc/src/klay.d.ts @@ -139,7 +139,10 @@ export class Klay { getHeaderByHash(blockHash: string, callback?: (error: Error, result: Header) => void): Promise
getRewards(blockNumber: BlockNumber, callback?: (error: Error, result: Header) => void): Promise + getParams(callback?: (error: Error, result: GovernanceItems) => void): Promise + getParams(blockNumber: BlockNumber, callback?: (error: Error, result: GovernanceItems) => void): Promise getChainConfig(callback?: (error: Error, result: ChainConfig) => void): Promise + getChainConfig(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise getChainConfigAt(callback?: (error: Error, result: ChainConfig) => void): Promise getChainConfigAt(blockNumber: BlockNumber, callback?: (error: Error, result: ChainConfig) => void): Promise getNodeAddress(callback?: (error: Error, result: string) => void): Promise diff --git a/types/packages/caver-rtm/src/index.d.ts b/types/packages/caver-rtm/src/index.d.ts index 6f6faa90..56fa5a57 100644 --- a/types/packages/caver-rtm/src/index.d.ts +++ b/types/packages/caver-rtm/src/index.d.ts @@ -136,6 +136,10 @@ export default class RpcCallToMethod { klay_chainConfig( callback?: (error: Error, result: ChainConfig) => void ): Promise + klay_getChainConfig( + blockNumberOrHash?: BlockNumber | string, + callback?: (error: Error, result: ChainConfig) => void + ): Promise klay_chainConfigAt( blockNumberOrHash: BlockNumber | string, callback?: (error: Error, result: ChainConfig) => void diff --git a/types/test/rpc-test.ts b/types/test/rpc-test.ts index 0beb131e..7ff2406b 100644 --- a/types/test/rpc-test.ts +++ b/types/test/rpc-test.ts @@ -1191,6 +1191,11 @@ rpc.klay.getRewardbase() // $ExpectType Promise rpc.klay.getRewardbase((err: Error, ret: string) => {}) +// $ExpectType Promise +rpc.klay.getChainConfig() +// $ExpectType Promise +rpc.klay.getChainConfig((err: Error, ret: ChainConfig) => {}) + // $ExpectType Promise rpc.klay.getFilterChanges('filterId') // $ExpectType Promise @@ -1325,29 +1330,29 @@ rpc.governance.getNodeAddress() rpc.governance.getNodeAddress((err: Error, ret: string) => {}) // $ExpectType Promise -rpc.governance.getItemsAt(0) +rpc.governance.getParams(0) // $ExpectType Promise -rpc.governance.getItemsAt(new BigNumber(0)) +rpc.governance.getParams(new BigNumber(0)) // $ExpectType Promise -rpc.governance.getItemsAt(new BN(0)) +rpc.governance.getParams(new BN(0)) // $ExpectType Promise -rpc.governance.getItemsAt('genesis') +rpc.governance.getParams('genesis') // $ExpectType Promise -rpc.governance.getItemsAt('latest') +rpc.governance.getParams('latest') // $ExpectType Promise -rpc.governance.getItemsAt('hash') +rpc.governance.getParams('hash') // $ExpectType Promise -rpc.governance.getItemsAt(0, (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams(0, (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise -rpc.governance.getItemsAt(new BigNumber(0), (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams(new BigNumber(0), (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise -rpc.governance.getItemsAt(new BN(0), (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams(new BN(0), (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise -rpc.governance.getItemsAt('genesis', (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams('genesis', (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise -rpc.governance.getItemsAt('latest', (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams('latest', (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise -rpc.governance.getItemsAt('hash', (err: Error, ret: GovernanceItems) => {}) +rpc.governance.getParams('hash', (err: Error, ret: GovernanceItems) => {}) // $ExpectType Promise rpc.governance.getPendingChanges()