@solana/web3.js 1.30.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/index.browser.esm.js +1063 -1067
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +960 -965
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +45 -12
- package/lib/index.esm.js +955 -963
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +28829 -28847
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +31 -31
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +57 -13
- package/package.json +8 -13
- package/src/account.ts +1 -1
- package/src/connection.ts +64 -13
- package/src/keypair.ts +1 -1
- package/src/publickey.ts +7 -3
- package/src/secp256k1-program.ts +5 -5
- package/src/sysvar.ts +16 -4
- package/src/transaction.ts +4 -1
- package/src/vote-account.ts +104 -31
package/src/vote-account.ts
CHANGED
|
@@ -23,6 +23,22 @@ export type EpochCredits = {
|
|
|
23
23
|
prevCredits: number;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
export type AuthorizedVoter = {
|
|
27
|
+
epoch: number;
|
|
28
|
+
authorizedVoter: PublicKey;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PriorVoter = {
|
|
32
|
+
authorizedPubkey: PublicKey;
|
|
33
|
+
epochOfLastAuthorizedSwitch: number;
|
|
34
|
+
targetEpoch: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type BlockTimestamp = {
|
|
38
|
+
slot: number;
|
|
39
|
+
timetamp: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
26
42
|
/**
|
|
27
43
|
* See https://github.com/solana-labs/solana/blob/8a12ed029cfa38d4a45400916c2463fb82bbec8c/programs/vote_api/src/vote_state.rs#L68-L88
|
|
28
44
|
*
|
|
@@ -30,8 +46,7 @@ export type EpochCredits = {
|
|
|
30
46
|
*/
|
|
31
47
|
const VoteAccountLayout = BufferLayout.struct([
|
|
32
48
|
Layout.publicKey('nodePubkey'),
|
|
33
|
-
Layout.publicKey('
|
|
34
|
-
Layout.publicKey('authorizedWithdrawerPubkey'),
|
|
49
|
+
Layout.publicKey('authorizedWithdrawer'),
|
|
35
50
|
BufferLayout.u8('commission'),
|
|
36
51
|
BufferLayout.nu64(), // votes.length
|
|
37
52
|
BufferLayout.seq(
|
|
@@ -44,9 +59,31 @@ const VoteAccountLayout = BufferLayout.struct([
|
|
|
44
59
|
),
|
|
45
60
|
BufferLayout.u8('rootSlotValid'),
|
|
46
61
|
BufferLayout.nu64('rootSlot'),
|
|
47
|
-
BufferLayout.nu64(
|
|
48
|
-
BufferLayout.
|
|
49
|
-
|
|
62
|
+
BufferLayout.nu64(), // authorizedVoters.length
|
|
63
|
+
BufferLayout.seq(
|
|
64
|
+
BufferLayout.struct([
|
|
65
|
+
BufferLayout.nu64('epoch'),
|
|
66
|
+
Layout.publicKey('authorizedVoter'),
|
|
67
|
+
]),
|
|
68
|
+
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
69
|
+
'authorizedVoters',
|
|
70
|
+
),
|
|
71
|
+
BufferLayout.struct(
|
|
72
|
+
[
|
|
73
|
+
BufferLayout.seq(
|
|
74
|
+
BufferLayout.struct([
|
|
75
|
+
Layout.publicKey('authorizedPubkey'),
|
|
76
|
+
BufferLayout.nu64('epochOfLastAuthorizedSwitch'),
|
|
77
|
+
BufferLayout.nu64('targetEpoch'),
|
|
78
|
+
]),
|
|
79
|
+
32,
|
|
80
|
+
'buf',
|
|
81
|
+
),
|
|
82
|
+
BufferLayout.nu64('idx'),
|
|
83
|
+
BufferLayout.u8('isEmpty'),
|
|
84
|
+
],
|
|
85
|
+
'priorVoters',
|
|
86
|
+
),
|
|
50
87
|
BufferLayout.nu64(), // epochCredits.length
|
|
51
88
|
BufferLayout.seq(
|
|
52
89
|
BufferLayout.struct([
|
|
@@ -57,19 +94,22 @@ const VoteAccountLayout = BufferLayout.struct([
|
|
|
57
94
|
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
58
95
|
'epochCredits',
|
|
59
96
|
),
|
|
97
|
+
BufferLayout.struct(
|
|
98
|
+
[BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')],
|
|
99
|
+
'lastTimestamp',
|
|
100
|
+
),
|
|
60
101
|
]);
|
|
61
102
|
|
|
62
103
|
type VoteAccountArgs = {
|
|
63
104
|
nodePubkey: PublicKey;
|
|
64
|
-
|
|
65
|
-
authorizedWithdrawerPubkey: PublicKey;
|
|
105
|
+
authorizedWithdrawer: PublicKey;
|
|
66
106
|
commission: number;
|
|
67
|
-
votes: Array<Lockout>;
|
|
68
107
|
rootSlot: number | null;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
epochCredits:
|
|
108
|
+
votes: Lockout[];
|
|
109
|
+
authorizedVoters: AuthorizedVoter[];
|
|
110
|
+
priorVoters: PriorVoter[];
|
|
111
|
+
epochCredits: EpochCredits[];
|
|
112
|
+
lastTimestamp: BlockTimestamp;
|
|
73
113
|
};
|
|
74
114
|
|
|
75
115
|
/**
|
|
@@ -77,30 +117,28 @@ type VoteAccountArgs = {
|
|
|
77
117
|
*/
|
|
78
118
|
export class VoteAccount {
|
|
79
119
|
nodePubkey: PublicKey;
|
|
80
|
-
|
|
81
|
-
authorizedWithdrawerPubkey: PublicKey;
|
|
120
|
+
authorizedWithdrawer: PublicKey;
|
|
82
121
|
commission: number;
|
|
83
|
-
votes: Array<Lockout>;
|
|
84
122
|
rootSlot: number | null;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
epochCredits:
|
|
123
|
+
votes: Lockout[];
|
|
124
|
+
authorizedVoters: AuthorizedVoter[];
|
|
125
|
+
priorVoters: PriorVoter[];
|
|
126
|
+
epochCredits: EpochCredits[];
|
|
127
|
+
lastTimestamp: BlockTimestamp;
|
|
89
128
|
|
|
90
129
|
/**
|
|
91
130
|
* @internal
|
|
92
131
|
*/
|
|
93
132
|
constructor(args: VoteAccountArgs) {
|
|
94
133
|
this.nodePubkey = args.nodePubkey;
|
|
95
|
-
this.
|
|
96
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
134
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
97
135
|
this.commission = args.commission;
|
|
98
|
-
this.votes = args.votes;
|
|
99
136
|
this.rootSlot = args.rootSlot;
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
137
|
+
this.votes = args.votes;
|
|
138
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
139
|
+
this.priorVoters = args.priorVoters;
|
|
103
140
|
this.epochCredits = args.epochCredits;
|
|
141
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
104
142
|
}
|
|
105
143
|
|
|
106
144
|
/**
|
|
@@ -112,7 +150,8 @@ export class VoteAccount {
|
|
|
112
150
|
static fromAccountData(
|
|
113
151
|
buffer: Buffer | Uint8Array | Array<number>,
|
|
114
152
|
): VoteAccount {
|
|
115
|
-
const
|
|
153
|
+
const versionOffset = 4;
|
|
154
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
116
155
|
|
|
117
156
|
let rootSlot: number | null = va.rootSlot;
|
|
118
157
|
if (!va.rootSlotValid) {
|
|
@@ -121,15 +160,49 @@ export class VoteAccount {
|
|
|
121
160
|
|
|
122
161
|
return new VoteAccount({
|
|
123
162
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
124
|
-
|
|
125
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
163
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
126
164
|
commission: va.commission,
|
|
127
165
|
votes: va.votes,
|
|
128
166
|
rootSlot,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
lastEpochCredits: va.lastEpochCredits,
|
|
167
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
168
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
132
169
|
epochCredits: va.epochCredits,
|
|
170
|
+
lastTimestamp: va.lastTimestamp,
|
|
133
171
|
});
|
|
134
172
|
}
|
|
135
173
|
}
|
|
174
|
+
|
|
175
|
+
function parseAuthorizedVoter({epoch, authorizedVoter}: AuthorizedVoter) {
|
|
176
|
+
return {
|
|
177
|
+
epoch,
|
|
178
|
+
authorizedVoter: new PublicKey(authorizedVoter),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function parsePriorVoters({
|
|
183
|
+
authorizedPubkey,
|
|
184
|
+
epochOfLastAuthorizedSwitch,
|
|
185
|
+
targetEpoch,
|
|
186
|
+
}: PriorVoter) {
|
|
187
|
+
return {
|
|
188
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
189
|
+
epochOfLastAuthorizedSwitch,
|
|
190
|
+
targetEpoch,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function getPriorVoters({
|
|
195
|
+
buf,
|
|
196
|
+
idx,
|
|
197
|
+
isEmpty,
|
|
198
|
+
}: {
|
|
199
|
+
buf: PriorVoter[];
|
|
200
|
+
idx: number;
|
|
201
|
+
isEmpty: boolean;
|
|
202
|
+
}): PriorVoter[] {
|
|
203
|
+
if (isEmpty) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
208
|
+
}
|