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]>>;
|
||||
getBalance(publicKey: PublicKey): Promise<number>;
|
||||
getClusterNodes(): Promise<Array<ContactInfo>>;
|
||||
getEpochVoteAccounts(): Promise<Array<VoteAccountInfo>>;
|
||||
getVoteAccounts(): Promise<VoteAccountStatus>;
|
||||
confirmTransaction(signature: TransactionSignature): Promise<boolean>;
|
||||
getSlot(): Promise<number>;
|
||||
getSlotLeader(): Promise<string>;
|
||||
|
8
web3.js/package-lock.json
generated
8
web3.js/package-lock.json
generated
@ -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
|
||||
}
|
||||
|
@ -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<VoteAccountInfo>} current Active vote accounts
|
||||
* @property {Array<VoteAccountInfo>} delinquent Inactive vote accounts
|
||||
*/
|
||||
type VoteAccountStatus = {
|
||||
current: Array<VoteAccountInfo>,
|
||||
delinquent: Array<VoteAccountInfo>,
|
||||
};
|
||||
|
||||
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<Array<VoteAccountInfo>> {
|
||||
const unsafeRes = await this._rpcRequest('getEpochVoteAccounts', []);
|
||||
const res = GetEpochVoteAccounts(unsafeRes);
|
||||
async getVoteAccounts(): Promise<VoteAccountStatus> {
|
||||
const unsafeRes = await this._rpcRequest('getVoteAccounts', []);
|
||||
const res = GetVoteAccounts(unsafeRes);
|
||||
//const res = unsafeRes;
|
||||
if (res.error) {
|
||||
throw new Error(res.error.message);
|
||||
|
@ -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 () => {
|
||||
|
Reference in New Issue
Block a user