From ae3f84ff084cd9c1d30c34079dba16afca3b6a62 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 09:26:50 +0100 Subject: [PATCH 01/34] Masternode RPC (createmasternode, listmasternodes, getmasternode) --- .../masternode/createMasternode.test.ts | 64 +++++++++++ .../category/masternode/getMasternode.test.ts | 58 ++++++++++ .../masternode/listMasternodes.test.ts | 51 +++++++++ .../src/category/masternode.ts | 99 +++++++++++++++++ packages/jellyfish-api-core/src/index.ts | 3 + website/docs/jellyfish/api/masternode.md | 103 ++++++++++++++++++ 6 files changed, 378 insertions(+) create mode 100644 packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts create mode 100644 packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts create mode 100644 packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts create mode 100644 packages/jellyfish-api-core/src/category/masternode.ts create mode 100644 website/docs/jellyfish/api/masternode.md diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts new file mode 100644 index 0000000000..106fbf3cda --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -0,0 +1,64 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' +import { MasternodeState } from '../../../src/category/masternode' + +describe('Masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + await container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should create a masternode transaction', async () => { + const masternodesBefore = await client.masternode.listMasternodes() + const masternodesLengthBefore = Object.keys(masternodesBefore).length + + const address = await client.wallet.getNewAddress() + const masternode = await client.masternode.createMasternode(address) + + await container.generate(1) + + const masternodesAfter = await client.masternode.listMasternodes() + const masternodesLengthAfter = Object.keys(masternodesAfter).length + + expect(masternodesLengthAfter).toStrictEqual(masternodesLengthBefore + 1) + expect(typeof masternode).toStrictEqual('string') + + for (const masternode in masternodesAfter) { + const createdMasternode = masternodesAfter[masternode] + if (createdMasternode.ownerAuthAddress === address) { + expect(typeof createdMasternode.ownerAuthAddress).toStrictEqual('string') + expect(typeof createdMasternode.operatorAuthAddress).toStrictEqual('string') + expect(typeof createdMasternode.creationHeight).toStrictEqual('number') + expect(typeof createdMasternode.resignHeight).toStrictEqual('number') + expect(typeof createdMasternode.resignTx).toStrictEqual('string') + expect(typeof createdMasternode.banHeight).toStrictEqual('number') + expect(typeof createdMasternode.banTx).toStrictEqual('string') + expect(createdMasternode.state).toStrictEqual(MasternodeState.PRE_ENABLED) + expect(typeof createdMasternode.state).toStrictEqual('string') + expect(typeof createdMasternode.mintedBlocks).toStrictEqual('number') + expect(typeof createdMasternode.targetMultiplier).toStrictEqual('number') + } + } + }) + + it('should create masternode transaction with specified UTXOS to spend', async () => { + const utxos = await client.wallet.listUnspent() + const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) + const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { inputs }) + + expect(typeof masternodeTransaction).toStrictEqual('string') + }) + + it('should throw an error with invalid owner address', async () => { + const invalidAddress = 'invalidAddress' + await expect(client.masternode.createMasternode(invalidAddress)).rejects.toThrow('operatorAddress (invalidAddress) does not refer to a P2PKH or P2WPKH address') + }) +}) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts new file mode 100644 index 0000000000..e1544bac54 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -0,0 +1,58 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' +import { MasternodeState } from '../../../src/category/masternode' + +describe('Masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + await container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should get a masternode', async () => { + let id: string = '' + + const address = await client.wallet.getNewAddress() + await client.masternode.createMasternode(address) + + await container.generate(1) + + const masterNodes = await client.masternode.listMasternodes() + for (const mnId in masterNodes) { + if (masterNodes[mnId].ownerAuthAddress === address) { + id = mnId + } + } + + const masternode = await client.masternode.getMasternode(id) + + for (const masternodeKey in masternode) { + const data = masternode[masternodeKey] + expect(typeof data.operatorAuthAddress).toStrictEqual('string') + expect(typeof data.ownerAuthAddress).toStrictEqual('string') + expect(typeof data.creationHeight).toStrictEqual('number') + expect(typeof data.resignHeight).toStrictEqual('number') + expect(typeof data.resignTx).toStrictEqual('string') + expect(typeof data.banHeight).toStrictEqual('number') + expect(typeof data.banTx).toStrictEqual('string') + expect(data.state).toStrictEqual(MasternodeState.PRE_ENABLED) + expect(typeof data.state).toStrictEqual('string') + expect(typeof data.mintedBlocks).toStrictEqual('number') + expect(typeof data.targetMultiplier).toStrictEqual('number') + } + }) + + it('should fail and throw an error with invalid masternode id', async () => { + const invalidId = '8d4d987dee688e400a0cdc899386f243250d3656d802231755ab4d28178c9816' + const promise = client.masternode.getMasternode(invalidId) + + await expect(promise).rejects.toThrow('Masternode not found') + }) +}) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts new file mode 100644 index 0000000000..d1e54cb338 --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts @@ -0,0 +1,51 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' +import { MasternodePagination } from '../../../src/category/masternode' + +describe('Masternode', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + await container.waitForWalletCoinbaseMaturity() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should list masternodes', async () => { + const masternodes = await client.masternode.listMasternodes() + + for (const masternode in masternodes) { + const createdMasternode = masternodes[masternode] + expect(typeof createdMasternode.ownerAuthAddress).toStrictEqual('string') + expect(typeof createdMasternode.operatorAuthAddress).toStrictEqual('string') + expect(typeof createdMasternode.creationHeight).toStrictEqual('number') + expect(typeof createdMasternode.resignHeight).toStrictEqual('number') + expect(typeof createdMasternode.resignTx).toStrictEqual('string') + expect(typeof createdMasternode.banHeight).toStrictEqual('number') + expect(typeof createdMasternode.banTx).toStrictEqual('string') + expect(typeof createdMasternode.state).toStrictEqual('string') + expect(typeof createdMasternode.mintedBlocks).toStrictEqual('number') + expect(typeof createdMasternode.targetMultiplier).toStrictEqual('number') + } + }) + + it('should list masternodes with verbose set to false to get just the ids', async () => { + const masternodes = await client.masternode.listMasternodes({}, false) + + for (const value of Object.values(masternodes)) { + expect(typeof value).toStrictEqual('string') + } + }) + + it('should list masternodes with limit. Limited to 3 and should return 3', async () => { + const options: MasternodePagination = { limit: 3 } + const masternodes = await client.masternode.listMasternodes(options) + + expect(Object.keys(masternodes).length).toStrictEqual(3) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts new file mode 100644 index 0000000000..35f4549b97 --- /dev/null +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -0,0 +1,99 @@ +import { ApiClient } from '../.' + +export enum MasternodeState { + PRE_ENABLED = 'PRE_ENABLED', + ENABLED = 'ENABLED', + PRE_RESIGNED = 'PRE_RESIGNED', + RESIGNED = 'RESIGNED', + PRE_BANNED = 'PRE_BANNED', + BANNED = 'BANNED' +} + +export class Masternode { + private readonly client: ApiClient + + constructor (client: ApiClient) { + this.client = client + } + + /** + * Creates a masternode creation transaction with given owner and operator addresses. + * + * @param {string} ownerAddress Any valid address for keeping collateral amount + * @param {string} operatorAddress Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. + * @param {CreateMasternodeOptions} options + * @param {UTXO[]} [options.inputs = []] + * @param {string} [options.inputs.txid] The transaction id + * @param {string} [options.inputs.vout] The output number + * @return {Promise} + */ + async createMasternode ( + ownerAddress: string, + operatorAddress?: string, + options: CreateMasternodeOptions = { inputs: [] } + ): Promise { + operatorAddress = operatorAddress ?? ownerAddress + return await this.client.call('createmasternode', [ownerAddress, operatorAddress, options.inputs], 'number') + } + + /** + * Returns information about multiple masternodes. + * + * @param {MasternodePagination} pagination + * @param {string} [pagination.start] + * @param {boolean} [pagination.including_star = true] Include starting position. + * @param {string} [pagination.limit = 10000] Maximum number of orders to return. + * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. + */ + async listMasternodes ( + pagination: MasternodePagination = { + including_start: true, + limit: 10000 + }, + verbose: boolean = true + ): Promise { + return await this.client.call('listmasternodes', [pagination, verbose], 'number') + } + + /** + * Returns information about a single masternode + * + * @param {string} masternodeId The masternode's id. + * @return {Promise} + */ + async getMasternode (masternodeId: string): Promise { + return await this.client.call('getmasternode', [masternodeId], 'number') + } +} + +export interface UTXO { + txid?: string + vout?: number +} + +export interface CreateMasternodeOptions { + inputs?: UTXO[] +} + +export interface MasternodePagination { + start?: string + including_start?: boolean + limit?: number +} + +export interface MasternodeInfo { + ownerAuthAddress: string + operatorAuthAddress: string + creationHeight: number + resignHeight: number + resignTx: string + banHeight: number + banTx: string + state: MasternodeState + mintedBlocks: number + targetMultiplier: number +} + +export interface MasternodeResult { + [id: string]: MasternodeInfo +} diff --git a/packages/jellyfish-api-core/src/index.ts b/packages/jellyfish-api-core/src/index.ts index 7819be4983..feaa41d2d1 100644 --- a/packages/jellyfish-api-core/src/index.ts +++ b/packages/jellyfish-api-core/src/index.ts @@ -9,6 +9,7 @@ import { PoolPair } from './category/poolpair' import { Token } from './category/token' import { Oracle } from './category/oracle' import { Server } from './category/server' +import { Masternode } from './category/masternode' export * from '@defichain/jellyfish-json' @@ -22,6 +23,7 @@ export * as token from './category/token' export * as account from './category/account' export * as oracle from './category/oracle' export * as server from './category/server' +export * as masternode from './category/masternode' /** * A protocol agnostic DeFiChain node client, RPC calls are separated into their category. @@ -37,6 +39,7 @@ export abstract class ApiClient { public readonly token = new Token(this) public readonly oracle = new Oracle(this) public readonly server = new Server(this) + public readonly masternode = new Masternode(this) /** * A promise based procedure call handling diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md new file mode 100644 index 0000000000..0c0bce8b37 --- /dev/null +++ b/website/docs/jellyfish/api/masternode.md @@ -0,0 +1,103 @@ +--- +id: masternode +title: Masternode API +API sidebar_label: Masternode API +API slug: /jellyfish/api/masternode +--- + +```js +import {Client} from '@defichain/jellyfish' + +const client = new Client() +// Using client.account. +const something = await client.account.method() +``` + +## createMasternode + +Creates a masternode creation transaction with given owner and operator addresses. + +```ts title="client.masternode.createMasternode()" +interface masternode { + createMasternode ( + ownerAddress: string, + operatorAddress?: string, + options: CreateMasternodeOptions = {inputs: []} + ): Promise +} + +interface UTXO { + txid?: string + vout?: number +} + +interface CreateMasternodeOptions { + inputs?: UTXO[] +} +``` + +## listMasternodes + +Returns information about multiple masternodes. + +```ts title="client.masternode.listMasternodes()" +interface masternode { + listMasternodes ( + pagination: MasternodePagination = { + including_start: true, + limit: 10000 + }, + verbose: boolean = true + ): Promise +} + +interface MasternodePagination { + start?: string + including_start?: boolean + limit?: number +} + +interface MasternodeInfo { + ownerAuthAddress: string, + operatorAuthAddress: string, + creationHeight: number, + resignHeight: number, + resignTx: string, + banHeight: number, + banTx: string, + state: MasternodeState, + mintedBlocks: number, + targetMultiplier: number +} + +interface MasternodeResult { + [id: string]: MasternodeInfo +} +``` + +## getMasternode + +Returns information about a single masternode + +```ts title="client.masternode.getMasternode()" +interface masternode { + getMasternode (masternodeId: string): Promise +} + +interface MasternodeInfo { + ownerAuthAddress: string, + operatorAuthAddress: string, + creationHeight: number, + resignHeight: number, + resignTx: string, + banHeight: number, + banTx: string, + state: MasternodeState, + mintedBlocks: number, + targetMultiplier: number +} + +interface MasternodeResult { + [id: string]: MasternodeInfo +} +``` From 459bfee503c70ea88de6a7da0961eb9fa779e88b Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 09:51:32 +0100 Subject: [PATCH 02/34] updated sidebar.js --- website/sidebars.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/sidebars.js b/website/sidebars.js index 966bb0a750..5eaaf7773d 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -17,7 +17,8 @@ module.exports = { 'jellyfish/api/token', 'jellyfish/api/account', 'jellyfish/api/oracle', - 'jellyfish/api/server' + 'jellyfish/api/server', + 'jellyfish/api/masternode' ] } ], From df6fd4b6f6b6921eb9000836cd69051aff3a8c83 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 10:48:24 +0100 Subject: [PATCH 03/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: canonbrother --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 35f4549b97..e22425d425 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -22,7 +22,7 @@ export class Masternode { * @param {string} ownerAddress Any valid address for keeping collateral amount * @param {string} operatorAddress Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. * @param {CreateMasternodeOptions} options - * @param {UTXO[]} [options.inputs = []] + * @param {UTXO[]} [options.utxos = []] * @param {string} [options.inputs.txid] The transaction id * @param {string} [options.inputs.vout] The output number * @return {Promise} From 13abb5dc5e66a2a4b69fea2c8c482add032e9b54 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 10:48:55 +0100 Subject: [PATCH 04/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: canonbrother --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index e22425d425..c048356cd4 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -20,7 +20,7 @@ export class Masternode { * Creates a masternode creation transaction with given owner and operator addresses. * * @param {string} ownerAddress Any valid address for keeping collateral amount - * @param {string} operatorAddress Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. + * @param {string} [operatorAddress] Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. * @param {CreateMasternodeOptions} options * @param {UTXO[]} [options.utxos = []] * @param {string} [options.inputs.txid] The transaction id From cbc97602e735c6637176ee9ce6c0ae5a7e7bac79 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 10:49:14 +0100 Subject: [PATCH 05/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: canonbrother --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index c048356cd4..d701fc3d2e 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -21,7 +21,7 @@ export class Masternode { * * @param {string} ownerAddress Any valid address for keeping collateral amount * @param {string} [operatorAddress] Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. - * @param {CreateMasternodeOptions} options + * @param {CreateMasternodeOptions} [options] * @param {UTXO[]} [options.utxos = []] * @param {string} [options.inputs.txid] The transaction id * @param {string} [options.inputs.vout] The output number From bc5c327494cbc45e15e8bc2853a3529d2f8ed9a8 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 11:31:54 +0100 Subject: [PATCH 06/34] Minor fixes --- .../masternode/createMasternode.test.ts | 6 ++++- .../masternode/listMasternodes.test.ts | 26 ++++++++++--------- .../src/category/masternode.ts | 9 ++++--- website/docs/jellyfish/api/masternode.md | 14 ++++++---- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index 106fbf3cda..64f122dbd2 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -44,7 +44,11 @@ describe('Masternode', () => { expect(createdMasternode.state).toStrictEqual(MasternodeState.PRE_ENABLED) expect(typeof createdMasternode.state).toStrictEqual('string') expect(typeof createdMasternode.mintedBlocks).toStrictEqual('number') - expect(typeof createdMasternode.targetMultiplier).toStrictEqual('number') + expect(typeof createdMasternode.ownerIsMine).toStrictEqual('boolean') + expect(createdMasternode.ownerIsMine).toStrictEqual(true) + expect(typeof createdMasternode.localMasternode).toStrictEqual('boolean') + expect(typeof createdMasternode.operatorIsMine).toStrictEqual('boolean') + expect(createdMasternode.operatorIsMine).toStrictEqual(true) } } }) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts index d1e54cb338..4603eac0c7 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts @@ -1,6 +1,6 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' -import { MasternodePagination } from '../../../src/category/masternode' +import { MasternodePagination, MasternodeState } from '../../../src/category/masternode' describe('Masternode', () => { const container = new MasterNodeRegTestContainer() @@ -20,17 +20,19 @@ describe('Masternode', () => { const masternodes = await client.masternode.listMasternodes() for (const masternode in masternodes) { - const createdMasternode = masternodes[masternode] - expect(typeof createdMasternode.ownerAuthAddress).toStrictEqual('string') - expect(typeof createdMasternode.operatorAuthAddress).toStrictEqual('string') - expect(typeof createdMasternode.creationHeight).toStrictEqual('number') - expect(typeof createdMasternode.resignHeight).toStrictEqual('number') - expect(typeof createdMasternode.resignTx).toStrictEqual('string') - expect(typeof createdMasternode.banHeight).toStrictEqual('number') - expect(typeof createdMasternode.banTx).toStrictEqual('string') - expect(typeof createdMasternode.state).toStrictEqual('string') - expect(typeof createdMasternode.mintedBlocks).toStrictEqual('number') - expect(typeof createdMasternode.targetMultiplier).toStrictEqual('number') + const currentMasternode = masternodes[masternode] + expect(typeof currentMasternode.ownerAuthAddress).toStrictEqual('string') + expect(typeof currentMasternode.operatorAuthAddress).toStrictEqual('string') + expect(typeof currentMasternode.creationHeight).toStrictEqual('number') + expect(typeof currentMasternode.resignHeight).toStrictEqual('number') + expect(typeof currentMasternode.resignTx).toStrictEqual('string') + expect(typeof currentMasternode.banHeight).toStrictEqual('number') + expect(typeof currentMasternode.banTx).toStrictEqual('string') + expect(currentMasternode.state).toStrictEqual(MasternodeState.ENABLED) + expect(typeof currentMasternode.mintedBlocks).toStrictEqual('number') + expect(typeof currentMasternode.ownerIsMine).toStrictEqual('boolean') + expect(typeof currentMasternode.localMasternode).toStrictEqual('boolean') + expect(typeof currentMasternode.operatorIsMine).toStrictEqual('boolean') } }) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index d701fc3d2e..866cf9de9d 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -6,7 +6,8 @@ export enum MasternodeState { PRE_RESIGNED = 'PRE_RESIGNED', RESIGNED = 'RESIGNED', PRE_BANNED = 'PRE_BANNED', - BANNED = 'BANNED' + BANNED = 'BANNED', + UNKNOWN = 'UNKNOWN' } export class Masternode { @@ -41,7 +42,7 @@ export class Masternode { * * @param {MasternodePagination} pagination * @param {string} [pagination.start] - * @param {boolean} [pagination.including_star = true] Include starting position. + * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 10000] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. */ @@ -91,7 +92,9 @@ export interface MasternodeInfo { banTx: string state: MasternodeState mintedBlocks: number - targetMultiplier: number + ownerIsMine: boolean + operatorIsMine: boolean + localMasternode: boolean } export interface MasternodeResult { diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 0c0bce8b37..2e31a5477d 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -1,7 +1,7 @@ --- id: masternode -title: Masternode API -API sidebar_label: Masternode API +title: Masternode +sidebar_label: Masternode API API slug: /jellyfish/api/masternode --- @@ -10,7 +10,7 @@ import {Client} from '@defichain/jellyfish' const client = new Client() // Using client.account. -const something = await client.account.method() +const something = await client.masternode.method() ``` ## createMasternode @@ -67,7 +67,9 @@ interface MasternodeInfo { banTx: string, state: MasternodeState, mintedBlocks: number, - targetMultiplier: number + ownerIsMine: boolean, + operatorIsMine: boolean, + localMasternode: boolean } interface MasternodeResult { @@ -94,7 +96,9 @@ interface MasternodeInfo { banTx: string, state: MasternodeState, mintedBlocks: number, - targetMultiplier: number + ownerIsMine: boolean, + operatorIsMine: boolean, + localMasternode: boolean } interface MasternodeResult { From 6f908d1b4f1e3d28b9598b1fd68fec8c1f7055cc Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 11:51:55 +0100 Subject: [PATCH 07/34] Minor fixes --- .../__tests__/category/masternode/getMasternode.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index e1544bac54..4fa01783d6 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -45,7 +45,11 @@ describe('Masternode', () => { expect(data.state).toStrictEqual(MasternodeState.PRE_ENABLED) expect(typeof data.state).toStrictEqual('string') expect(typeof data.mintedBlocks).toStrictEqual('number') - expect(typeof data.targetMultiplier).toStrictEqual('number') + expect(typeof data.ownerIsMine).toStrictEqual('boolean') + expect(typeof data.localMasternode).toStrictEqual('boolean') + expect(typeof data.operatorIsMine).toStrictEqual('boolean') + expect(data.operatorIsMine).toStrictEqual(true) + expect(data.operatorIsMine).toStrictEqual(true) } }) From e751f6ccf5ddd31148c787cc6b1e90092fe4b5c2 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 12:45:06 +0100 Subject: [PATCH 08/34] Implementation of suggestion from code review. --- .../__tests__/category/masternode/createMasternode.test.ts | 6 ++++-- .../__tests__/category/masternode/getMasternode.test.ts | 7 ++++--- .../__tests__/category/masternode/listMasternodes.test.ts | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index 64f122dbd2..f56e4f7957 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -21,7 +21,7 @@ describe('Masternode', () => { const masternodesLengthBefore = Object.keys(masternodesBefore).length const address = await client.wallet.getNewAddress() - const masternode = await client.masternode.createMasternode(address) + const masternodeTransaction = await client.masternode.createMasternode(address) await container.generate(1) @@ -29,7 +29,8 @@ describe('Masternode', () => { const masternodesLengthAfter = Object.keys(masternodesAfter).length expect(masternodesLengthAfter).toStrictEqual(masternodesLengthBefore + 1) - expect(typeof masternode).toStrictEqual('string') + expect(typeof masternodeTransaction).toStrictEqual('string') + expect(masternodeTransaction.length).toStrictEqual(64) for (const masternode in masternodesAfter) { const createdMasternode = masternodesAfter[masternode] @@ -59,6 +60,7 @@ describe('Masternode', () => { const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { inputs }) expect(typeof masternodeTransaction).toStrictEqual('string') + expect(masternodeTransaction.length).toStrictEqual(64) }) it('should throw an error with invalid owner address', async () => { diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index 4fa01783d6..8f4d836c13 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -31,10 +31,11 @@ describe('Masternode', () => { } } - const masternode = await client.masternode.getMasternode(id) + const masternodeTransaction = await client.masternode.getMasternode(id) - for (const masternodeKey in masternode) { - const data = masternode[masternodeKey] + expect(Object.keys(masternodeTransaction).length).toStrictEqual(1) + for (const masternodeKey in masternodeTransaction) { + const data = masternodeTransaction[masternodeKey] expect(typeof data.operatorAuthAddress).toStrictEqual('string') expect(typeof data.ownerAuthAddress).toStrictEqual('string') expect(typeof data.creationHeight).toStrictEqual('number') diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts index 4603eac0c7..395008042d 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts @@ -17,10 +17,11 @@ describe('Masternode', () => { }) it('should list masternodes', async () => { - const masternodes = await client.masternode.listMasternodes() + const masternodeTransaction = await client.masternode.listMasternodes() - for (const masternode in masternodes) { - const currentMasternode = masternodes[masternode] + expect(Object.keys(masternodeTransaction).length).toBeGreaterThanOrEqual(1) + for (const masternode in masternodeTransaction) { + const currentMasternode = masternodeTransaction[masternode] expect(typeof currentMasternode.ownerAuthAddress).toStrictEqual('string') expect(typeof currentMasternode.operatorAuthAddress).toStrictEqual('string') expect(typeof currentMasternode.creationHeight).toStrictEqual('number') From 8306bc95ccd61932fdddf245c818398fc26c5cc9 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 11 Jun 2021 15:21:58 +0100 Subject: [PATCH 09/34] Additional testings for createMasternode --- .../category/masternode/createMasternode.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index f56e4f7957..d0a1065a28 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -55,10 +55,16 @@ describe('Masternode', () => { }) it('should create masternode transaction with specified UTXOS to spend', async () => { - const utxos = await client.wallet.listUnspent() - const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) + const utxosBefore = await client.wallet.listUnspent() + const utxosBeforeLength = utxosBefore.length + + const inputs = utxosBefore.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { inputs }) + const utxosAfter = await client.wallet.listUnspent() + const utxosAfterLength = utxosAfter.length + + expect(utxosAfterLength).toStrictEqual((utxosBeforeLength - 1)) expect(typeof masternodeTransaction).toStrictEqual('string') expect(masternodeTransaction.length).toStrictEqual(64) }) From 481fd48ca7bc62d5bf135c0a2c7752fa4a2a6c7f Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Mon, 14 Jun 2021 14:05:22 +0100 Subject: [PATCH 10/34] Suggesstions from code review --- .../category/masternode/createMasternode.test.ts | 2 +- .../jellyfish-api-core/src/category/masternode.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index d0a1065a28..3835bfb2d3 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -59,7 +59,7 @@ describe('Masternode', () => { const utxosBeforeLength = utxosBefore.length const inputs = utxosBefore.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) - const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { inputs }) + const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { utxos: inputs }) const utxosAfter = await client.wallet.listUnspent() const utxosAfterLength = utxosAfter.length diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 866cf9de9d..c2c216331a 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -24,17 +24,17 @@ export class Masternode { * @param {string} [operatorAddress] Masternode operator auth address (P2PKH only, unique). If empty, owner address will be used. * @param {CreateMasternodeOptions} [options] * @param {UTXO[]} [options.utxos = []] - * @param {string} [options.inputs.txid] The transaction id - * @param {string} [options.inputs.vout] The output number + * @param {string} [options.uxtos.txid] The transaction id + * @param {string} [options.utxos.vout] The output number * @return {Promise} */ async createMasternode ( ownerAddress: string, operatorAddress?: string, - options: CreateMasternodeOptions = { inputs: [] } + options: CreateMasternodeOptions = { utxos: [] } ): Promise { operatorAddress = operatorAddress ?? ownerAddress - return await this.client.call('createmasternode', [ownerAddress, operatorAddress, options.inputs], 'number') + return await this.client.call('createmasternode', [ownerAddress, operatorAddress, options.utxos], 'number') } /** @@ -68,12 +68,12 @@ export class Masternode { } export interface UTXO { - txid?: string - vout?: number + txid: string + vout: number } export interface CreateMasternodeOptions { - inputs?: UTXO[] + utxos?: UTXO[] } export interface MasternodePagination { From 700fcfc743b08e903b4361f49ffbeee46e48eccc Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Tue, 15 Jun 2021 12:27:31 +0100 Subject: [PATCH 11/34] Clean up --- .../masternode/createMasternode.test.ts | 73 +++++++++---------- .../category/masternode/getMasternode.test.ts | 16 ++-- .../masternode/listMasternodes.test.ts | 27 +++---- 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index 3835bfb2d3..ba3f3568cb 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -16,57 +16,56 @@ describe('Masternode', () => { await container.stop() }) - it('should create a masternode transaction', async () => { - const masternodesBefore = await client.masternode.listMasternodes() - const masternodesLengthBefore = Object.keys(masternodesBefore).length + it('should createMasternode ', async () => { + const masternodesLengthBefore = Object.keys(await client.masternode.listMasternodes()).length - const address = await client.wallet.getNewAddress() - const masternodeTransaction = await client.masternode.createMasternode(address) + const ownerAddress = await client.wallet.getNewAddress() + const hex = await client.masternode.createMasternode(ownerAddress) + + expect(typeof hex).toStrictEqual('string') + expect(hex.length).toStrictEqual(64) await container.generate(1) const masternodesAfter = await client.masternode.listMasternodes() const masternodesLengthAfter = Object.keys(masternodesAfter).length + const createdMasternode = Object.values(masternodesAfter).filter(mn => mn.ownerAuthAddress === ownerAddress) + expect(masternodesLengthAfter).toStrictEqual(masternodesLengthBefore + 1) - expect(typeof masternodeTransaction).toStrictEqual('string') - expect(masternodeTransaction.length).toStrictEqual(64) - - for (const masternode in masternodesAfter) { - const createdMasternode = masternodesAfter[masternode] - if (createdMasternode.ownerAuthAddress === address) { - expect(typeof createdMasternode.ownerAuthAddress).toStrictEqual('string') - expect(typeof createdMasternode.operatorAuthAddress).toStrictEqual('string') - expect(typeof createdMasternode.creationHeight).toStrictEqual('number') - expect(typeof createdMasternode.resignHeight).toStrictEqual('number') - expect(typeof createdMasternode.resignTx).toStrictEqual('string') - expect(typeof createdMasternode.banHeight).toStrictEqual('number') - expect(typeof createdMasternode.banTx).toStrictEqual('string') - expect(createdMasternode.state).toStrictEqual(MasternodeState.PRE_ENABLED) - expect(typeof createdMasternode.state).toStrictEqual('string') - expect(typeof createdMasternode.mintedBlocks).toStrictEqual('number') - expect(typeof createdMasternode.ownerIsMine).toStrictEqual('boolean') - expect(createdMasternode.ownerIsMine).toStrictEqual(true) - expect(typeof createdMasternode.localMasternode).toStrictEqual('boolean') - expect(typeof createdMasternode.operatorIsMine).toStrictEqual('boolean') - expect(createdMasternode.operatorIsMine).toStrictEqual(true) - } + + for (const mn of createdMasternode) { + expect(typeof mn.ownerAuthAddress).toStrictEqual('string') + expect(typeof mn.operatorAuthAddress).toStrictEqual('string') + expect(typeof mn.creationHeight).toStrictEqual('number') + expect(typeof mn.resignHeight).toStrictEqual('number') + expect(typeof mn.resignTx).toStrictEqual('string') + expect(typeof mn.banHeight).toStrictEqual('number') + expect(typeof mn.banTx).toStrictEqual('string') + expect(mn.state).toStrictEqual(MasternodeState.PRE_ENABLED) + expect(typeof mn.state).toStrictEqual('string') + expect(typeof mn.mintedBlocks).toStrictEqual('number') + expect(typeof mn.ownerIsMine).toStrictEqual('boolean') + expect(mn.ownerIsMine).toStrictEqual(true) + expect(typeof mn.localMasternode).toStrictEqual('boolean') + expect(typeof mn.operatorIsMine).toStrictEqual('boolean') + expect(mn.operatorIsMine).toStrictEqual(true) } }) - it('should create masternode transaction with specified UTXOS to spend', async () => { - const utxosBefore = await client.wallet.listUnspent() - const utxosBeforeLength = utxosBefore.length + it('should createMasternode with specified UTXOS', async () => { + const utxos = await client.wallet.listUnspent() + const utxosBeforeLength = utxos.length - const inputs = utxosBefore.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) - const masternodeTransaction = await client.masternode.createMasternode(await client.wallet.getNewAddress(), undefined, { utxos: inputs }) + const ownerAddress = await client.wallet.getNewAddress() + const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) + const hex = await client.masternode.createMasternode(ownerAddress, undefined, { utxos: inputs }) - const utxosAfter = await client.wallet.listUnspent() - const utxosAfterLength = utxosAfter.length + expect(typeof hex).toStrictEqual('string') + expect(hex.length).toStrictEqual(64) - expect(utxosAfterLength).toStrictEqual((utxosBeforeLength - 1)) - expect(typeof masternodeTransaction).toStrictEqual('string') - expect(masternodeTransaction.length).toStrictEqual(64) + const utxosAfterLength = (await client.wallet.listUnspent()).length + expect(utxosAfterLength).toBeLessThan((utxosBeforeLength)) }) it('should throw an error with invalid owner address', async () => { diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index 8f4d836c13..d1c9b00e86 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -16,26 +16,26 @@ describe('Masternode', () => { await container.stop() }) - it('should get a masternode', async () => { + it('should getMasternode', async () => { let id: string = '' - const address = await client.wallet.getNewAddress() - await client.masternode.createMasternode(address) + const ownerAddress = await client.wallet.getNewAddress() + await client.masternode.createMasternode(ownerAddress) await container.generate(1) const masterNodes = await client.masternode.listMasternodes() for (const mnId in masterNodes) { - if (masterNodes[mnId].ownerAuthAddress === address) { + if (masterNodes[mnId].ownerAuthAddress === ownerAddress) { id = mnId } } - const masternodeTransaction = await client.masternode.getMasternode(id) + const masternode = await client.masternode.getMasternode(id) - expect(Object.keys(masternodeTransaction).length).toStrictEqual(1) - for (const masternodeKey in masternodeTransaction) { - const data = masternodeTransaction[masternodeKey] + expect(Object.keys(masternode).length).toStrictEqual(1) + for (const masternodeKey in masternode) { + const data = masternode[masternodeKey] expect(typeof data.operatorAuthAddress).toStrictEqual('string') expect(typeof data.ownerAuthAddress).toStrictEqual('string') expect(typeof data.creationHeight).toStrictEqual('number') diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts index 395008042d..9b0f7ddc8e 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts @@ -1,6 +1,6 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' -import { MasternodePagination, MasternodeState } from '../../../src/category/masternode' +import { MasternodeState } from '../../../src/category/masternode' describe('Masternode', () => { const container = new MasterNodeRegTestContainer() @@ -16,12 +16,12 @@ describe('Masternode', () => { await container.stop() }) - it('should list masternodes', async () => { - const masternodeTransaction = await client.masternode.listMasternodes() + it('should listMasternodes', async () => { + const masternodeList = await client.masternode.listMasternodes() - expect(Object.keys(masternodeTransaction).length).toBeGreaterThanOrEqual(1) - for (const masternode in masternodeTransaction) { - const currentMasternode = masternodeTransaction[masternode] + expect(Object.keys(masternodeList).length).toBeGreaterThanOrEqual(1) + for (const masternode in masternodeList) { + const currentMasternode = masternodeList[masternode] expect(typeof currentMasternode.ownerAuthAddress).toStrictEqual('string') expect(typeof currentMasternode.operatorAuthAddress).toStrictEqual('string') expect(typeof currentMasternode.creationHeight).toStrictEqual('number') @@ -37,18 +37,15 @@ describe('Masternode', () => { } }) - it('should list masternodes with verbose set to false to get just the ids', async () => { - const masternodes = await client.masternode.listMasternodes({}, false) - - for (const value of Object.values(masternodes)) { + it('should listMasternodes with verbose false', async () => { + const masternodeList = await client.masternode.listMasternodes({}, false) + for (const value of Object.values(masternodeList)) { expect(typeof value).toStrictEqual('string') } }) - it('should list masternodes with limit. Limited to 3 and should return 3', async () => { - const options: MasternodePagination = { limit: 3 } - const masternodes = await client.masternode.listMasternodes(options) - - expect(Object.keys(masternodes).length).toStrictEqual(3) + it('should listMasternodes with limit', async () => { + const masternodeList = await client.masternode.listMasternodes({ limit: 3 }) + expect(Object.keys(masternodeList).length).toStrictEqual(3) }) }) From f3256d41aef54e91abac14a4b77d7558bba16eeb Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Tue, 15 Jun 2021 14:02:19 +0100 Subject: [PATCH 12/34] fixing CI --- .../__tests__/category/masternode/createMasternode.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index ba3f3568cb..e010e4d1ea 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -54,10 +54,12 @@ describe('Masternode', () => { }) it('should createMasternode with specified UTXOS', async () => { + const ownerAddress = await client.wallet.getNewAddress() + await client.account.utxosToAccount({ [ownerAddress]: '10@DFI' }) + const utxos = await client.wallet.listUnspent() const utxosBeforeLength = utxos.length - const ownerAddress = await client.wallet.getNewAddress() const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) const hex = await client.masternode.createMasternode(ownerAddress, undefined, { utxos: inputs }) From 421738648b8d8949e52e6e9966d1da1b11a6aada Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Tue, 15 Jun 2021 21:28:56 +0100 Subject: [PATCH 13/34] fixing issue with CI --- .../category/masternode/createMasternode.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index e010e4d1ea..70229e68ed 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -10,12 +10,22 @@ describe('Masternode', () => { await container.start() await container.waitForReady() await container.waitForWalletCoinbaseMaturity() + await setup() }) afterAll(async () => { await container.stop() }) + let tokenAddr: string + + async function setup (): Promise { + tokenAddr = await container.call('getnewaddress') + await container.waitForWalletBalanceGTE(101) + await container.call('utxostoaccount', [{ [tokenAddr]: '100@0' }]) + await container.generate(1) + } + it('should createMasternode ', async () => { const masternodesLengthBefore = Object.keys(await client.masternode.listMasternodes()).length @@ -29,7 +39,6 @@ describe('Masternode', () => { const masternodesAfter = await client.masternode.listMasternodes() const masternodesLengthAfter = Object.keys(masternodesAfter).length - const createdMasternode = Object.values(masternodesAfter).filter(mn => mn.ownerAuthAddress === ownerAddress) expect(masternodesLengthAfter).toStrictEqual(masternodesLengthBefore + 1) @@ -55,13 +64,13 @@ describe('Masternode', () => { it('should createMasternode with specified UTXOS', async () => { const ownerAddress = await client.wallet.getNewAddress() - await client.account.utxosToAccount({ [ownerAddress]: '10@DFI' }) + await client.account.accountToUtxos(tokenAddr, { [ownerAddress]: '5@DFI' }) const utxos = await client.wallet.listUnspent() const utxosBeforeLength = utxos.length const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) - const hex = await client.masternode.createMasternode(ownerAddress, undefined, { utxos: inputs }) + const hex = await client.masternode.createMasternode(ownerAddress, ownerAddress, { utxos: inputs }) expect(typeof hex).toStrictEqual('string') expect(hex.length).toStrictEqual(64) From 9845c20dd4307d7e4aab36ab47b4987984982597 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Tue, 15 Jun 2021 21:56:05 +0100 Subject: [PATCH 14/34] Fixed issue with CI --- .../__tests__/category/masternode/createMasternode.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index 70229e68ed..2a20dfbeb3 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -22,6 +22,8 @@ describe('Masternode', () => { async function setup (): Promise { tokenAddr = await container.call('getnewaddress') await container.waitForWalletBalanceGTE(101) + await container.generate(1) + await container.call('utxostoaccount', [{ [tokenAddr]: '100@0' }]) await container.generate(1) } From eea316c53de56c1cbcbb3a6ad7029767de926da1 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 16 Jun 2021 09:54:13 +0100 Subject: [PATCH 15/34] Fixed issue with CI --- .../masternode/createMasternode.test.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts index 2a20dfbeb3..03c4ad2546 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/createMasternode.test.ts @@ -10,24 +10,12 @@ describe('Masternode', () => { await container.start() await container.waitForReady() await container.waitForWalletCoinbaseMaturity() - await setup() }) afterAll(async () => { await container.stop() }) - let tokenAddr: string - - async function setup (): Promise { - tokenAddr = await container.call('getnewaddress') - await container.waitForWalletBalanceGTE(101) - await container.generate(1) - - await container.call('utxostoaccount', [{ [tokenAddr]: '100@0' }]) - await container.generate(1) - } - it('should createMasternode ', async () => { const masternodesLengthBefore = Object.keys(await client.masternode.listMasternodes()).length @@ -66,12 +54,13 @@ describe('Masternode', () => { it('should createMasternode with specified UTXOS', async () => { const ownerAddress = await client.wallet.getNewAddress() - await client.account.accountToUtxos(tokenAddr, { [ownerAddress]: '5@DFI' }) + const { txid } = await container.fundAddress(ownerAddress, 10) const utxos = await client.wallet.listUnspent() const utxosBeforeLength = utxos.length - const inputs = utxos.map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) + const inputs = utxos.filter((utxos) => utxos.txid === txid) + .map((utxo: { txid: string, vout: number }) => ({ txid: utxo.txid, vout: utxo.vout })) const hex = await client.masternode.createMasternode(ownerAddress, ownerAddress, { utxos: inputs }) expect(typeof hex).toStrictEqual('string') From a854ada5bf83ed6ae5a8ee48318e59392fc4bf73 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Thu, 17 Jun 2021 00:28:11 +0100 Subject: [PATCH 16/34] Minor fixes --- .../category/masternode/getMasternode.test.ts | 1 - website/docs/jellyfish/api/masternode.md | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index d1c9b00e86..a97418b169 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -50,7 +50,6 @@ describe('Masternode', () => { expect(typeof data.localMasternode).toStrictEqual('boolean') expect(typeof data.operatorIsMine).toStrictEqual('boolean') expect(data.operatorIsMine).toStrictEqual(true) - expect(data.operatorIsMine).toStrictEqual(true) } }) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 2e31a5477d..83442591a7 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -51,6 +51,16 @@ interface masternode { ): Promise } +enum MasternodeState { + PRE_ENABLED = 'PRE_ENABLED', + ENABLED = 'ENABLED', + PRE_RESIGNED = 'PRE_RESIGNED', + RESIGNED = 'RESIGNED', + PRE_BANNED = 'PRE_BANNED', + BANNED = 'BANNED', + UNKNOWN = 'UNKNOWN' +} + interface MasternodePagination { start?: string including_start?: boolean @@ -86,6 +96,16 @@ interface masternode { getMasternode (masternodeId: string): Promise } +enum MasternodeState { + PRE_ENABLED = 'PRE_ENABLED', + ENABLED = 'ENABLED', + PRE_RESIGNED = 'PRE_RESIGNED', + RESIGNED = 'RESIGNED', + PRE_BANNED = 'PRE_BANNED', + BANNED = 'BANNED', + UNKNOWN = 'UNKNOWN' +} + interface MasternodeInfo { ownerAuthAddress: string, operatorAuthAddress: string, From 056d7a0a418772180c679044d761a5d5d0747661 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Thu, 17 Jun 2021 09:28:53 +0100 Subject: [PATCH 17/34] Minor fixes --- .../__tests__/category/masternode/getMasternode.test.ts | 1 + packages/jellyfish-api-core/src/category/masternode.ts | 1 + website/docs/jellyfish/api/masternode.md | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index a97418b169..6333683c5e 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -25,6 +25,7 @@ describe('Masternode', () => { await container.generate(1) const masterNodes = await client.masternode.listMasternodes() + for (const mnId in masterNodes) { if (masterNodes[mnId].ownerAuthAddress === ownerAddress) { id = mnId diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index c2c216331a..59e5a8a561 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -45,6 +45,7 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 10000] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. + * @return {Promise} */ async listMasternodes ( pagination: MasternodePagination = { diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 83442591a7..4e43a4f9bf 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -22,7 +22,7 @@ interface masternode { createMasternode ( ownerAddress: string, operatorAddress?: string, - options: CreateMasternodeOptions = {inputs: []} + options: CreateMasternodeOptions = { utxos: [] } ): Promise } From 374ac999086cfea24ce7fb021aec38aa2b362f13 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Thu, 17 Jun 2021 10:55:51 +0100 Subject: [PATCH 18/34] Minor fixes --- .../masternode/listMasternodes.test.ts | 33 ++++++++++++++++++- website/docs/jellyfish/api/masternode.md | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts index 9b0f7ddc8e..6fd875fd69 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/listMasternodes.test.ts @@ -1,6 +1,6 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' -import { MasternodeState } from '../../../src/category/masternode' +import { MasternodePagination, MasternodeState } from '../../../src/category/masternode' describe('Masternode', () => { const container = new MasterNodeRegTestContainer() @@ -48,4 +48,35 @@ describe('Masternode', () => { const masternodeList = await client.masternode.listMasternodes({ limit: 3 }) expect(Object.keys(masternodeList).length).toStrictEqual(3) }) + + it('should listMasternodes with pagination start and including_start', async () => { + const prevMasternodes = await client.masternode.listMasternodes() + const startId = Object.keys(prevMasternodes)[2] + const masterNodeLengthBefore = Object.keys(prevMasternodes).length + + const pagination: MasternodePagination = { + start: startId, + including_start: true + } + const masternodeList = await client.masternode.listMasternodes(pagination) + + const masternodeLengthAfter = Object.keys(masternodeList).length + expect(masternodeLengthAfter).toStrictEqual(masterNodeLengthBefore - 2) + + for (const masternode in masternodeList) { + const currentMasternode = masternodeList[masternode] + expect(typeof currentMasternode.ownerAuthAddress).toStrictEqual('string') + expect(typeof currentMasternode.operatorAuthAddress).toStrictEqual('string') + expect(typeof currentMasternode.creationHeight).toStrictEqual('number') + expect(typeof currentMasternode.resignHeight).toStrictEqual('number') + expect(typeof currentMasternode.resignTx).toStrictEqual('string') + expect(typeof currentMasternode.banHeight).toStrictEqual('number') + expect(typeof currentMasternode.banTx).toStrictEqual('string') + expect(currentMasternode.state).toStrictEqual(MasternodeState.ENABLED) + expect(typeof currentMasternode.mintedBlocks).toStrictEqual('number') + expect(typeof currentMasternode.ownerIsMine).toStrictEqual('boolean') + expect(typeof currentMasternode.localMasternode).toStrictEqual('boolean') + expect(typeof currentMasternode.operatorIsMine).toStrictEqual('boolean') + } + }) }) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 4e43a4f9bf..c562ff1e25 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -1,6 +1,6 @@ --- id: masternode -title: Masternode +title: Masternode API sidebar_label: Masternode API API slug: /jellyfish/api/masternode --- From fceae2837185f030147df5fe49c11001ac46b1f3 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Fri, 18 Jun 2021 08:53:01 +0100 Subject: [PATCH 19/34] Minor fixes --- website/docs/jellyfish/api/masternode.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index c562ff1e25..b934dd6a61 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -2,7 +2,7 @@ id: masternode title: Masternode API sidebar_label: Masternode API -API slug: /jellyfish/api/masternode +slug: /jellyfish/api/masternode --- ```js @@ -107,17 +107,17 @@ enum MasternodeState { } interface MasternodeInfo { - ownerAuthAddress: string, - operatorAuthAddress: string, - creationHeight: number, - resignHeight: number, - resignTx: string, - banHeight: number, - banTx: string, - state: MasternodeState, - mintedBlocks: number, - ownerIsMine: boolean, - operatorIsMine: boolean, + ownerAuthAddress: string + operatorAuthAddress: string + creationHeight: number + resignHeight: number + resignTx: string + banHeight: number + banTx: string + state: MasternodeState + mintedBlocks: number + ownerIsMine: boolean + operatorIsMine: boolean localMasternode: boolean } From ce443ead57a5d99806165a6a41fd72580df2c599 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Sat, 19 Jun 2021 13:09:05 +0100 Subject: [PATCH 20/34] Minor fixes --- website/docs/jellyfish/api/masternode.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index b934dd6a61..377c3f97ad 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -68,17 +68,17 @@ interface MasternodePagination { } interface MasternodeInfo { - ownerAuthAddress: string, - operatorAuthAddress: string, - creationHeight: number, - resignHeight: number, - resignTx: string, - banHeight: number, - banTx: string, - state: MasternodeState, - mintedBlocks: number, - ownerIsMine: boolean, - operatorIsMine: boolean, + ownerAuthAddress: string + operatorAuthAddress: string + creationHeight: number + resignHeight: number + resignTx: string + banHeight: number + banTx: string + state: MasternodeState + mintedBlocks: number + ownerIsMine: boolean + operatorIsMine: boolean localMasternode: boolean } From a42c7635c899020312f700103a8b5f1d6df00569 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Sun, 20 Jun 2021 05:29:03 +0100 Subject: [PATCH 21/34] Minor fixes --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- website/docs/jellyfish/api/masternode.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 59e5a8a561..85aa8611a4 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -74,7 +74,7 @@ export interface UTXO { } export interface CreateMasternodeOptions { - utxos?: UTXO[] + utxos: UTXO[] } export interface MasternodePagination { diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 377c3f97ad..124ea1dcd4 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -27,12 +27,12 @@ interface masternode { } interface UTXO { - txid?: string - vout?: number + txid: string + vout: number } interface CreateMasternodeOptions { - inputs?: UTXO[] + utxos: UTXO[] } ``` From f05451e5135bf1f43452c5882f67f3282da163d8 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Mon, 21 Jun 2021 08:17:23 +0100 Subject: [PATCH 22/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 85aa8611a4..5ea5524ea8 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -10,6 +10,9 @@ export enum MasternodeState { UNKNOWN = 'UNKNOWN' } +/** + * Masternode RPCs for DeFi Blockchain + */ export class Masternode { private readonly client: ApiClient From 782c2d3b25d561fe0623777e989e91345ec6795a Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Mon, 21 Jun 2021 08:18:17 +0100 Subject: [PATCH 23/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 5ea5524ea8..d7250683b0 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -48,7 +48,7 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 10000] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. - * @return {Promise} + * @return {Promise} */ async listMasternodes ( pagination: MasternodePagination = { From 37844d9caf9f799e483cc83998c30aee7192cb47 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Mon, 21 Jun 2021 10:59:11 +0100 Subject: [PATCH 24/34] Minor fix --- .../src/category/masternode.ts | 40 ++++++++++++++++++- website/docs/jellyfish/api/masternode.md | 5 ++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index d7250683b0..d796d70508 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -46,14 +46,50 @@ export class Masternode { * @param {MasternodePagination} pagination * @param {string} [pagination.start] * @param {boolean} [pagination.including_start = true] Include starting position. - * @param {string} [pagination.limit = 10000] Maximum number of orders to return. + * @param {string} [pagination.limit = 100] Maximum number of orders to return. + * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. + * @return {Promise} + */ + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise + + /** + * Returns information about multiple masternodes. + * + * @param {MasternodePagination} pagination + * @param {string} [pagination.start] + * @param {boolean} [pagination.including_start = true] Include starting position. + * @param {string} [pagination.limit = 100] Maximum number of orders to return. + * @param {boolean} verbose true + * @return {Promise} + */ + listMasternodes (pagination: MasternodePagination, verbose: true): Promise + + /** + * Returns information about multiple masternodes. + * + * @param {MasternodePagination} pagination + * @param {string} [pagination.start] + * @param {boolean} [pagination.including_start = true] Include starting position. + * @param {string} [pagination.limit = 100] Maximum number of orders to return. + * @param {boolean} verbose false. + * @return {Promise} + */ + listMasternodes (pagination: MasternodePagination, verbose: false): Promise + + /** + * Returns information about multiple masternodes. + * + * @param {MasternodePagination} pagination + * @param {string} [pagination.start] + * @param {boolean} [pagination.including_start = true] Include starting position. + * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. * @return {Promise} */ async listMasternodes ( pagination: MasternodePagination = { including_start: true, - limit: 10000 + limit: 100 }, verbose: boolean = true ): Promise { diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 124ea1dcd4..6486be182a 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -42,10 +42,13 @@ Returns information about multiple masternodes. ```ts title="client.masternode.listMasternodes()" interface masternode { + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise + listMasternodes (pagination: MasternodePagination, verbose: true): Promise + listMasternodes (pagination: MasternodePagination, verbose: false): Promise listMasternodes ( pagination: MasternodePagination = { including_start: true, - limit: 10000 + limit: 100 }, verbose: boolean = true ): Promise From 29c08525f0963d8b29dce65a8706c7c96bca5ee6 Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Tue, 22 Jun 2021 12:44:11 +0800 Subject: [PATCH 25/34] Update website/docs/jellyfish/api/masternode.md --- website/docs/jellyfish/api/masternode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 6486be182a..cd9065fd8e 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -9,7 +9,7 @@ slug: /jellyfish/api/masternode import {Client} from '@defichain/jellyfish' const client = new Client() -// Using client.account. +// Using client.masternode. const something = await client.masternode.method() ``` From 53a0a231037a493a58a9322999642f3e1c211e60 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Tue, 22 Jun 2021 10:26:09 +0100 Subject: [PATCH 26/34] Minor fixes --- .../src/category/masternode.ts | 22 +++++++++++-------- website/docs/jellyfish/api/masternode.md | 14 ++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index d796d70508..a284749cd6 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -48,9 +48,9 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. - * @return {Promise} + * @return {Promise} */ - listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> /** * Returns information about multiple masternodes. @@ -60,9 +60,9 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} verbose true - * @return {Promise} + * @return {Promise} */ - listMasternodes (pagination: MasternodePagination, verbose: true): Promise + listMasternodes (pagination: MasternodePagination, verbose: true): Promise> /** * Returns information about multiple masternodes. @@ -72,9 +72,9 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} verbose false. - * @return {Promise} + * @return {Promise} */ - listMasternodes (pagination: MasternodePagination, verbose: false): Promise + listMasternodes (pagination: MasternodePagination, verbose: false): Promise> /** * Returns information about multiple masternodes. @@ -84,15 +84,15 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. - * @return {Promise} + * @return {Promise} */ - async listMasternodes ( + async listMasternodes ( pagination: MasternodePagination = { including_start: true, limit: 100 }, verbose: boolean = true - ): Promise { + ): Promise> { return await this.client.call('listmasternodes', [pagination, verbose], 'number') } @@ -137,6 +137,10 @@ export interface MasternodeInfo { localMasternode: boolean } +export interface MasternodesResult { + [id: string]: T +} + export interface MasternodeResult { [id: string]: MasternodeInfo } diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index cd9065fd8e..c44ede5d9e 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -42,16 +42,16 @@ Returns information about multiple masternodes. ```ts title="client.masternode.listMasternodes()" interface masternode { - listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise - listMasternodes (pagination: MasternodePagination, verbose: true): Promise - listMasternodes (pagination: MasternodePagination, verbose: false): Promise - listMasternodes ( + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> + listMasternodes (pagination: MasternodePagination, verbose: true): Promise> + listMasternodes (pagination: MasternodePagination, verbose: false): Promise> + listMasternodes ( pagination: MasternodePagination = { including_start: true, limit: 100 }, verbose: boolean = true - ): Promise + ): Promise> } enum MasternodeState { @@ -85,8 +85,8 @@ interface MasternodeInfo { localMasternode: boolean } -interface MasternodeResult { - [id: string]: MasternodeInfo +interface MasternodesResult { + [id: string]: T } ``` From b188f9133919e61132d17b9da7ee80c38ebe104b Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:57:07 +0100 Subject: [PATCH 27/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index a284749cd6..3f2dcdb0b5 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -137,10 +137,6 @@ export interface MasternodeInfo { localMasternode: boolean } -export interface MasternodesResult { +export interface MasternodeResult { [id: string]: T } - -export interface MasternodeResult { - [id: string]: MasternodeInfo -} From a89f236825b5830d3ff547feb6e4a812cfb62003 Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:57:15 +0100 Subject: [PATCH 28/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 3f2dcdb0b5..1cdd908af2 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -92,7 +92,7 @@ export class Masternode { limit: 100 }, verbose: boolean = true - ): Promise> { + ): Promise> { return await this.client.call('listmasternodes', [pagination, verbose], 'number') } From f08a735fc2b98fec7dd5db5f28399d47df6a22ac Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:57:29 +0100 Subject: [PATCH 29/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 1cdd908af2..c8caa155d4 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -62,7 +62,7 @@ export class Masternode { * @param {boolean} verbose true * @return {Promise} */ - listMasternodes (pagination: MasternodePagination, verbose: true): Promise> + listMasternodes (pagination: MasternodePagination, verbose: true): Promise> /** * Returns information about multiple masternodes. From 814c5678e9db27f30b300696c7dfed68f65d84cb Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:57:38 +0100 Subject: [PATCH 30/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index c8caa155d4..c8ac98ceee 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -50,7 +50,7 @@ export class Masternode { * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. * @return {Promise} */ - listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> /** * Returns information about multiple masternodes. From 1216088b841151f65f8e63611e260988600c57ce Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:57:50 +0100 Subject: [PATCH 31/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index c8ac98ceee..588861a90d 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -102,7 +102,7 @@ export class Masternode { * @param {string} masternodeId The masternode's id. * @return {Promise} */ - async getMasternode (masternodeId: string): Promise { + async getMasternode (masternodeId: string): Promise> { return await this.client.call('getmasternode', [masternodeId], 'number') } } From 6469a39619c7b89ff69cd6e80e1818e2d3bd4b8f Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 08:58:02 +0100 Subject: [PATCH 32/34] Update packages/jellyfish-api-core/src/category/masternode.ts Co-authored-by: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> --- packages/jellyfish-api-core/src/category/masternode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index 588861a90d..df77f680fe 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -74,7 +74,7 @@ export class Masternode { * @param {boolean} verbose false. * @return {Promise} */ - listMasternodes (pagination: MasternodePagination, verbose: false): Promise> + listMasternodes (pagination: MasternodePagination, verbose: false): Promise> /** * Returns information about multiple masternodes. From eceaa117954982b333ac4ca18a2403d551ee9afa Mon Sep 17 00:00:00 2001 From: Suraj Auwal Date: Wed, 23 Jun 2021 11:50:35 +0100 Subject: [PATCH 33/34] Minor fixes --- .../category/masternode/getMasternode.test.ts | 12 +----------- .../jellyfish-api-core/src/category/masternode.ts | 10 +++++----- website/docs/jellyfish/api/masternode.md | 14 +++++++------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts index 6333683c5e..d9d769bea8 100644 --- a/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/masternode/getMasternode.test.ts @@ -17,21 +17,11 @@ describe('Masternode', () => { }) it('should getMasternode', async () => { - let id: string = '' - const ownerAddress = await client.wallet.getNewAddress() - await client.masternode.createMasternode(ownerAddress) + const id = await client.masternode.createMasternode(ownerAddress) await container.generate(1) - const masterNodes = await client.masternode.listMasternodes() - - for (const mnId in masterNodes) { - if (masterNodes[mnId].ownerAuthAddress === ownerAddress) { - id = mnId - } - } - const masternode = await client.masternode.getMasternode(id) expect(Object.keys(masternode).length).toStrictEqual(1) diff --git a/packages/jellyfish-api-core/src/category/masternode.ts b/packages/jellyfish-api-core/src/category/masternode.ts index df77f680fe..38c72146b1 100644 --- a/packages/jellyfish-api-core/src/category/masternode.ts +++ b/packages/jellyfish-api-core/src/category/masternode.ts @@ -48,9 +48,9 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. - * @return {Promise} + * @return {Promise>} */ - listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> /** * Returns information about multiple masternodes. @@ -60,7 +60,7 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} verbose true - * @return {Promise} + * @return {Promise>} */ listMasternodes (pagination: MasternodePagination, verbose: true): Promise> @@ -72,7 +72,7 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} verbose false. - * @return {Promise} + * @return {Promise>} */ listMasternodes (pagination: MasternodePagination, verbose: false): Promise> @@ -84,7 +84,7 @@ export class Masternode { * @param {boolean} [pagination.including_start = true] Include starting position. * @param {string} [pagination.limit = 100] Maximum number of orders to return. * @param {boolean} [verbose = true] Flag for verbose list. Only ids are returned when false. - * @return {Promise} + * @return {Promise>} */ async listMasternodes ( pagination: MasternodePagination = { diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index c44ede5d9e..613a7cde76 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -42,9 +42,9 @@ Returns information about multiple masternodes. ```ts title="client.masternode.listMasternodes()" interface masternode { - listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> - listMasternodes (pagination: MasternodePagination, verbose: true): Promise> - listMasternodes (pagination: MasternodePagination, verbose: false): Promise> + listMasternodes (pagination?: MasternodePagination, verbose?: boolean): Promise> + listMasternodes (pagination: MasternodePagination, verbose: true): Promise> + listMasternodes (pagination: MasternodePagination, verbose: false): Promise> listMasternodes ( pagination: MasternodePagination = { including_start: true, @@ -85,7 +85,7 @@ interface MasternodeInfo { localMasternode: boolean } -interface MasternodesResult { +interface MasternodeResult { [id: string]: T } ``` @@ -96,7 +96,7 @@ Returns information about a single masternode ```ts title="client.masternode.getMasternode()" interface masternode { - getMasternode (masternodeId: string): Promise + getMasternode (masternodeId: string): Promise> } enum MasternodeState { @@ -124,7 +124,7 @@ interface MasternodeInfo { localMasternode: boolean } -interface MasternodeResult { - [id: string]: MasternodeInfo +interface MasternodeResult { + [id: string]: T } ``` From 03a93f875005f7b7894da48cdd3674caefb009fe Mon Sep 17 00:00:00 2001 From: Fuxing Loh <4266087+fuxingloh@users.noreply.github.com> Date: Wed, 23 Jun 2021 21:54:04 +0800 Subject: [PATCH 34/34] Update website/docs/jellyfish/api/masternode.md --- website/docs/jellyfish/api/masternode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/jellyfish/api/masternode.md b/website/docs/jellyfish/api/masternode.md index 613a7cde76..03afce47f9 100644 --- a/website/docs/jellyfish/api/masternode.md +++ b/website/docs/jellyfish/api/masternode.md @@ -51,7 +51,7 @@ interface masternode { limit: 100 }, verbose: boolean = true - ): Promise> + ): Promise> } enum MasternodeState {