fix: update from getEpochVoteAccounts to getVoteAccounts rpc
This commit is contained in:
committed by
Michael Vines
parent
38ffe85737
commit
a3bf378d0d
@ -92,7 +92,7 @@ declare module '@solana/web3.js' {
|
|||||||
): Promise<Array<[PublicKey, AccountInfo]>>;
|
): Promise<Array<[PublicKey, AccountInfo]>>;
|
||||||
getBalance(publicKey: PublicKey): Promise<number>;
|
getBalance(publicKey: PublicKey): Promise<number>;
|
||||||
getClusterNodes(): Promise<Array<ContactInfo>>;
|
getClusterNodes(): Promise<Array<ContactInfo>>;
|
||||||
getEpochVoteAccounts(): Promise<Array<VoteAccountInfo>>;
|
getVoteAccounts(): Promise<VoteAccountStatus>;
|
||||||
confirmTransaction(signature: TransactionSignature): Promise<boolean>;
|
confirmTransaction(signature: TransactionSignature): Promise<boolean>;
|
||||||
getSlot(): Promise<number>;
|
getSlot(): Promise<number>;
|
||||||
getSlotLeader(): Promise<string>;
|
getSlotLeader(): Promise<string>;
|
||||||
|
8
web3.js/package-lock.json
generated
8
web3.js/package-lock.json
generated
@ -7092,7 +7092,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"marked": {
|
"marked": {
|
||||||
"version": "0.3.19",
|
"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==",
|
"integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
@ -7356,7 +7356,7 @@
|
|||||||
},
|
},
|
||||||
"marked": {
|
"marked": {
|
||||||
"version": "0.3.19",
|
"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==",
|
"integrity": "sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
@ -13628,7 +13628,7 @@
|
|||||||
},
|
},
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.0",
|
"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=",
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
@ -18610,7 +18610,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"minimist": {
|
"minimist": {
|
||||||
"version": "1.2.0",
|
"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=",
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||||
"dev": true
|
"dev": true
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,30 @@ type ContactInfo = {
|
|||||||
* @typedef {Object} VoteAccountInfo
|
* @typedef {Object} VoteAccountInfo
|
||||||
* @property {string} votePubkey Public key of the vote account
|
* @property {string} votePubkey Public key of the vote account
|
||||||
* @property {string} nodePubkey Identity public key of the node voting with this 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 {number} activatedStake The stake, in lamports, delegated to this vote account and activated
|
||||||
* @property {string} commission A 8-bit unsigned integer used as a fraction (commission/0xFF) for rewards payout
|
* @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 = {
|
type VoteAccountInfo = {
|
||||||
votePubkey: string,
|
votePubkey: string,
|
||||||
nodePubkey: string,
|
nodePubkey: string,
|
||||||
stake: number,
|
activatedStake: number,
|
||||||
|
epochVoteAccount: boolean,
|
||||||
commission: number,
|
commission: number,
|
||||||
|
lastVote: number,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A collection of cluster vote accounts
|
||||||
|
*
|
||||||
|
* @typedef {Object} VoteAccountStatus
|
||||||
|
* @property {Array<VoteAccountInfo>} current Active vote accounts
|
||||||
|
* @property {Array<VoteAccountInfo>} delinquent Inactive vote accounts
|
||||||
|
*/
|
||||||
|
type VoteAccountStatus = {
|
||||||
|
current: Array<VoteAccountInfo>,
|
||||||
|
delinquent: Array<VoteAccountInfo>,
|
||||||
};
|
};
|
||||||
|
|
||||||
function createRpcRequest(url): RpcRequest {
|
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(
|
const GetVoteAccounts = jsonRpcResult(
|
||||||
struct.list([
|
struct({
|
||||||
struct({
|
current: struct.list([
|
||||||
votePubkey: 'string',
|
struct({
|
||||||
nodePubkey: 'string',
|
votePubkey: 'string',
|
||||||
stake: 'number',
|
nodePubkey: 'string',
|
||||||
commission: 'number',
|
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
|
* Return the list of nodes that are currently participating in the cluster
|
||||||
*/
|
*/
|
||||||
async getEpochVoteAccounts(): Promise<Array<VoteAccountInfo>> {
|
async getVoteAccounts(): Promise<VoteAccountStatus> {
|
||||||
const unsafeRes = await this._rpcRequest('getEpochVoteAccounts', []);
|
const unsafeRes = await this._rpcRequest('getVoteAccounts', []);
|
||||||
const res = GetEpochVoteAccounts(unsafeRes);
|
const res = GetVoteAccounts(unsafeRes);
|
||||||
//const res = unsafeRes;
|
//const res = unsafeRes;
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
throw new Error(res.error.message);
|
throw new Error(res.error.message);
|
||||||
|
@ -210,15 +210,15 @@ test('get cluster nodes', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getEpochVoteAccounts', async () => {
|
test('getVoteAccounts', async () => {
|
||||||
if (mockRpcEnabled) {
|
if (mockRpcEnabled) {
|
||||||
console.log('non-live test skipped');
|
console.log('non-live test skipped');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const connection = new Connection(url);
|
const connection = new Connection(url);
|
||||||
const voteAccounts = await connection.getEpochVoteAccounts();
|
const voteAccounts = await connection.getVoteAccounts();
|
||||||
expect(voteAccounts.length).toBeGreaterThan(0);
|
expect(voteAccounts.current.length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('confirm transaction - error', async () => {
|
test('confirm transaction - error', async () => {
|
||||||
|
Reference in New Issue
Block a user