From a3bf378d0d9b79a8b4619f10191a285a2a894c86 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Mon, 19 Aug 2019 11:39:08 -0600 Subject: [PATCH] fix: update from getEpochVoteAccounts to getVoteAccounts rpc --- web3.js/module.flow.js | 2 +- web3.js/package-lock.json | 8 ++--- web3.js/src/connection.js | 62 ++++++++++++++++++++++++--------- web3.js/test/connection.test.js | 6 ++-- 4 files changed, 54 insertions(+), 24 deletions(-) diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 558fd5a410..27dd0f667a 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -92,7 +92,7 @@ declare module '@solana/web3.js' { ): Promise>; getBalance(publicKey: PublicKey): Promise; getClusterNodes(): Promise>; - getEpochVoteAccounts(): Promise>; + getVoteAccounts(): Promise; confirmTransaction(signature: TransactionSignature): Promise; getSlot(): Promise; getSlotLeader(): Promise; diff --git a/web3.js/package-lock.json b/web3.js/package-lock.json index 798b7e2c18..9051f314d8 100644 --- a/web3.js/package-lock.json +++ b/web3.js/package-lock.json @@ -7092,7 +7092,7 @@ "dependencies": { "marked": { "version": "0.3.19", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.19.tgz", + "resolved": "http://registry.npmjs.org/marked/-/marked-0.3.19.tgz", "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==", "dev": true }, @@ -7356,7 +7356,7 @@ }, "marked": { "version": "0.3.19", - "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.19.tgz", + "resolved": "http://registry.npmjs.org/marked/-/marked-0.3.19.tgz", "integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==", "dev": true }, @@ -13628,7 +13628,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, @@ -18610,7 +18610,7 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true } diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index fa811e252e..2c21b2e22e 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -40,14 +40,30 @@ type ContactInfo = { * @typedef {Object} VoteAccountInfo * @property {string} votePubkey Public key of the vote account * @property {string} nodePubkey Identity public key of the node voting with this account - * @property {string} stake The stake, in lamports, delegated to this vote account - * @property {string} commission A 8-bit unsigned integer used as a fraction (commission/0xFF) for rewards payout + * @property {number} activatedStake The stake, in lamports, delegated to this vote account and activated + * @property {boolean} epochVoteAccount Whether the vote account is staked for this epoch + * @property {number} commission A 8-bit unsigned integer used as a fraction (commission/0xFF) for rewards payout + * @property {number} lastVote Most recent slot voted on by this vote account */ type VoteAccountInfo = { votePubkey: string, nodePubkey: string, - stake: number, + activatedStake: number, + epochVoteAccount: boolean, commission: number, + lastVote: number, +}; + +/** + * A collection of cluster vote accounts + * + * @typedef {Object} VoteAccountStatus + * @property {Array} current Active vote accounts + * @property {Array} delinquent Inactive vote accounts + */ +type VoteAccountStatus = { + current: Array, + delinquent: Array, }; function createRpcRequest(url): RpcRequest { @@ -198,17 +214,31 @@ const GetClusterNodes_015 = jsonRpcResult( ); /** - * Expected JSON RPC response for the "getEpochVoteAccounts" message + * Expected JSON RPC response for the "getVoteAccounts" message */ -const GetEpochVoteAccounts = jsonRpcResult( - struct.list([ - struct({ - votePubkey: 'string', - nodePubkey: 'string', - stake: 'number', - commission: 'number', - }), - ]), +const GetVoteAccounts = jsonRpcResult( + struct({ + current: struct.list([ + struct({ + votePubkey: 'string', + nodePubkey: 'string', + activatedStake: 'number', + epochVoteAccount: 'boolean', + commission: 'number', + lastVote: 'number', + }), + ]), + delinquent: struct.list([ + struct({ + votePubkey: 'string', + nodePubkey: 'string', + activatedStake: 'number', + epochVoteAccount: 'boolean', + commission: 'number', + lastVote: 'number', + }), + ]), + }), ); /** @@ -529,9 +559,9 @@ export class Connection { /** * Return the list of nodes that are currently participating in the cluster */ - async getEpochVoteAccounts(): Promise> { - const unsafeRes = await this._rpcRequest('getEpochVoteAccounts', []); - const res = GetEpochVoteAccounts(unsafeRes); + async getVoteAccounts(): Promise { + const unsafeRes = await this._rpcRequest('getVoteAccounts', []); + const res = GetVoteAccounts(unsafeRes); //const res = unsafeRes; if (res.error) { throw new Error(res.error.message); diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index e4e810871b..6ef7a8e63a 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -210,15 +210,15 @@ test('get cluster nodes', async () => { } }); -test('getEpochVoteAccounts', async () => { +test('getVoteAccounts', async () => { if (mockRpcEnabled) { console.log('non-live test skipped'); return; } const connection = new Connection(url); - const voteAccounts = await connection.getEpochVoteAccounts(); - expect(voteAccounts.length).toBeGreaterThan(0); + const voteAccounts = await connection.getVoteAccounts(); + expect(voteAccounts.current.length).toBeGreaterThan(0); }); test('confirm transaction - error', async () => {