@solana/web3.js 1.87.3 → 2.0.0-experimental.0099b2a

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.
Files changed (113) hide show
  1. package/README.md +56 -112
  2. package/dist/index.browser.cjs +927 -0
  3. package/dist/index.browser.cjs.map +1 -0
  4. package/dist/index.browser.js +876 -0
  5. package/dist/index.browser.js.map +1 -0
  6. package/dist/index.development.js +4180 -0
  7. package/dist/index.development.js.map +1 -0
  8. package/dist/index.native.js +865 -0
  9. package/dist/index.native.js.map +1 -0
  10. package/dist/index.node.cjs +916 -0
  11. package/dist/index.node.cjs.map +1 -0
  12. package/dist/index.node.js +865 -0
  13. package/dist/index.node.js.map +1 -0
  14. package/dist/index.production.min.js +87 -0
  15. package/dist/types/airdrop-confirmer.d.ts +20 -0
  16. package/dist/types/airdrop.d.ts +23 -0
  17. package/dist/types/cached-abortable-iterable.d.ts +11 -0
  18. package/dist/types/index.d.ts +15 -0
  19. package/dist/types/rpc-default-config.d.ts +3 -0
  20. package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
  21. package/dist/types/rpc-request-coalescer.d.ts +5 -0
  22. package/dist/types/rpc-request-deduplication.d.ts +2 -0
  23. package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
  24. package/dist/types/rpc-transport.d.ts +4 -0
  25. package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
  26. package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
  27. package/dist/types/rpc-websocket-transport.d.ts +13 -0
  28. package/dist/types/rpc.d.ts +7 -0
  29. package/dist/types/send-transaction.d.ts +37 -0
  30. package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
  31. package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
  32. package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
  33. package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
  34. package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
  35. package/dist/types/transaction-confirmation.d.ts +37 -0
  36. package/package.json +85 -109
  37. package/lib/index.browser.cjs.js +0 -10296
  38. package/lib/index.browser.cjs.js.map +0 -1
  39. package/lib/index.browser.esm.js +0 -10193
  40. package/lib/index.browser.esm.js.map +0 -1
  41. package/lib/index.cjs.js +0 -12589
  42. package/lib/index.cjs.js.map +0 -1
  43. package/lib/index.d.ts +0 -3947
  44. package/lib/index.esm.js +0 -12480
  45. package/lib/index.esm.js.map +0 -1
  46. package/lib/index.iife.js +0 -26233
  47. package/lib/index.iife.js.map +0 -1
  48. package/lib/index.iife.min.js +0 -20
  49. package/lib/index.iife.min.js.map +0 -1
  50. package/lib/index.native.js +0 -10296
  51. package/lib/index.native.js.map +0 -1
  52. package/src/__forks__/browser/fetch-impl.ts +0 -4
  53. package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
  54. package/src/__forks__/react-native/fetch-impl.ts +0 -4
  55. package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
  56. package/src/account-data.ts +0 -39
  57. package/src/account.ts +0 -55
  58. package/src/blockhash.ts +0 -4
  59. package/src/bpf-loader-deprecated.ts +0 -5
  60. package/src/bpf-loader.ts +0 -45
  61. package/src/connection.ts +0 -6796
  62. package/src/epoch-schedule.ts +0 -102
  63. package/src/errors.ts +0 -50
  64. package/src/fee-calculator.ts +0 -18
  65. package/src/fetch-impl.ts +0 -16
  66. package/src/index.ts +0 -24
  67. package/src/instruction.ts +0 -58
  68. package/src/keypair.ts +0 -102
  69. package/src/layout.ts +0 -188
  70. package/src/loader.ts +0 -267
  71. package/src/message/account-keys.ts +0 -79
  72. package/src/message/compiled-keys.ts +0 -165
  73. package/src/message/index.ts +0 -47
  74. package/src/message/legacy.ts +0 -326
  75. package/src/message/v0.ts +0 -496
  76. package/src/message/versioned.ts +0 -36
  77. package/src/nonce-account.ts +0 -82
  78. package/src/programs/address-lookup-table/index.ts +0 -435
  79. package/src/programs/address-lookup-table/state.ts +0 -84
  80. package/src/programs/compute-budget.ts +0 -281
  81. package/src/programs/ed25519.ts +0 -157
  82. package/src/programs/index.ts +0 -7
  83. package/src/programs/secp256k1.ts +0 -228
  84. package/src/programs/stake.ts +0 -935
  85. package/src/programs/system.ts +0 -1048
  86. package/src/programs/vote.ts +0 -543
  87. package/src/publickey.ts +0 -259
  88. package/src/rpc-websocket-factory.ts +0 -4
  89. package/src/rpc-websocket.ts +0 -79
  90. package/src/sysvar.ts +0 -37
  91. package/src/timing.ts +0 -23
  92. package/src/transaction/constants.ts +0 -12
  93. package/src/transaction/expiry-custom-errors.ts +0 -48
  94. package/src/transaction/index.ts +0 -5
  95. package/src/transaction/legacy.ts +0 -948
  96. package/src/transaction/message.ts +0 -140
  97. package/src/transaction/versioned.ts +0 -126
  98. package/src/utils/assert.ts +0 -8
  99. package/src/utils/bigint.ts +0 -43
  100. package/src/utils/borsh-schema.ts +0 -38
  101. package/src/utils/cluster.ts +0 -35
  102. package/src/utils/ed25519.ts +0 -43
  103. package/src/utils/index.ts +0 -5
  104. package/src/utils/makeWebsocketUrl.ts +0 -26
  105. package/src/utils/promise-timeout.ts +0 -14
  106. package/src/utils/secp256k1.ts +0 -11
  107. package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
  108. package/src/utils/send-and-confirm-transaction.ts +0 -98
  109. package/src/utils/shortvec-encoding.ts +0 -28
  110. package/src/utils/sleep.ts +0 -4
  111. package/src/utils/to-buffer.ts +0 -11
  112. package/src/validator-info.ts +0 -104
  113. package/src/vote-account.ts +0 -236
package/src/message/v0.ts DELETED
@@ -1,496 +0,0 @@
1
- import bs58 from 'bs58';
2
- import * as BufferLayout from '@solana/buffer-layout';
3
-
4
- import * as Layout from '../layout';
5
- import {Blockhash} from '../blockhash';
6
- import {
7
- MessageHeader,
8
- MessageAddressTableLookup,
9
- MessageCompiledInstruction,
10
- } from './index';
11
- import {PublicKey, PUBLIC_KEY_LENGTH} from '../publickey';
12
- import * as shortvec from '../utils/shortvec-encoding';
13
- import assert from '../utils/assert';
14
- import {PACKET_DATA_SIZE, VERSION_PREFIX_MASK} from '../transaction/constants';
15
- import {TransactionInstruction} from '../transaction';
16
- import {AddressLookupTableAccount} from '../programs';
17
- import {CompiledKeys} from './compiled-keys';
18
- import {AccountKeysFromLookups, MessageAccountKeys} from './account-keys';
19
-
20
- /**
21
- * Message constructor arguments
22
- */
23
- export type MessageV0Args = {
24
- /** The message header, identifying signed and read-only `accountKeys` */
25
- header: MessageHeader;
26
- /** The static account keys used by this transaction */
27
- staticAccountKeys: PublicKey[];
28
- /** The hash of a recent ledger block */
29
- recentBlockhash: Blockhash;
30
- /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
31
- compiledInstructions: MessageCompiledInstruction[];
32
- /** Instructions that will be executed in sequence and committed in one atomic transaction if all succeed. */
33
- addressTableLookups: MessageAddressTableLookup[];
34
- };
35
-
36
- export type CompileV0Args = {
37
- payerKey: PublicKey;
38
- instructions: Array<TransactionInstruction>;
39
- recentBlockhash: Blockhash;
40
- addressLookupTableAccounts?: Array<AddressLookupTableAccount>;
41
- };
42
-
43
- export type GetAccountKeysArgs =
44
- | {
45
- accountKeysFromLookups?: AccountKeysFromLookups | null;
46
- }
47
- | {
48
- addressLookupTableAccounts?: AddressLookupTableAccount[] | null;
49
- };
50
-
51
- export class MessageV0 {
52
- header: MessageHeader;
53
- staticAccountKeys: Array<PublicKey>;
54
- recentBlockhash: Blockhash;
55
- compiledInstructions: Array<MessageCompiledInstruction>;
56
- addressTableLookups: Array<MessageAddressTableLookup>;
57
-
58
- constructor(args: MessageV0Args) {
59
- this.header = args.header;
60
- this.staticAccountKeys = args.staticAccountKeys;
61
- this.recentBlockhash = args.recentBlockhash;
62
- this.compiledInstructions = args.compiledInstructions;
63
- this.addressTableLookups = args.addressTableLookups;
64
- }
65
-
66
- get version(): 0 {
67
- return 0;
68
- }
69
-
70
- get numAccountKeysFromLookups(): number {
71
- let count = 0;
72
- for (const lookup of this.addressTableLookups) {
73
- count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
74
- }
75
- return count;
76
- }
77
-
78
- getAccountKeys(args?: GetAccountKeysArgs): MessageAccountKeys {
79
- let accountKeysFromLookups: AccountKeysFromLookups | undefined;
80
- if (
81
- args &&
82
- 'accountKeysFromLookups' in args &&
83
- args.accountKeysFromLookups
84
- ) {
85
- if (
86
- this.numAccountKeysFromLookups !=
87
- args.accountKeysFromLookups.writable.length +
88
- args.accountKeysFromLookups.readonly.length
89
- ) {
90
- throw new Error(
91
- 'Failed to get account keys because of a mismatch in the number of account keys from lookups',
92
- );
93
- }
94
- accountKeysFromLookups = args.accountKeysFromLookups;
95
- } else if (
96
- args &&
97
- 'addressLookupTableAccounts' in args &&
98
- args.addressLookupTableAccounts
99
- ) {
100
- accountKeysFromLookups = this.resolveAddressTableLookups(
101
- args.addressLookupTableAccounts,
102
- );
103
- } else if (this.addressTableLookups.length > 0) {
104
- throw new Error(
105
- 'Failed to get account keys because address table lookups were not resolved',
106
- );
107
- }
108
- return new MessageAccountKeys(
109
- this.staticAccountKeys,
110
- accountKeysFromLookups,
111
- );
112
- }
113
-
114
- isAccountSigner(index: number): boolean {
115
- return index < this.header.numRequiredSignatures;
116
- }
117
-
118
- isAccountWritable(index: number): boolean {
119
- const numSignedAccounts = this.header.numRequiredSignatures;
120
- const numStaticAccountKeys = this.staticAccountKeys.length;
121
- if (index >= numStaticAccountKeys) {
122
- const lookupAccountKeysIndex = index - numStaticAccountKeys;
123
- const numWritableLookupAccountKeys = this.addressTableLookups.reduce(
124
- (count, lookup) => count + lookup.writableIndexes.length,
125
- 0,
126
- );
127
- return lookupAccountKeysIndex < numWritableLookupAccountKeys;
128
- } else if (index >= this.header.numRequiredSignatures) {
129
- const unsignedAccountIndex = index - numSignedAccounts;
130
- const numUnsignedAccounts = numStaticAccountKeys - numSignedAccounts;
131
- const numWritableUnsignedAccounts =
132
- numUnsignedAccounts - this.header.numReadonlyUnsignedAccounts;
133
- return unsignedAccountIndex < numWritableUnsignedAccounts;
134
- } else {
135
- const numWritableSignedAccounts =
136
- numSignedAccounts - this.header.numReadonlySignedAccounts;
137
- return index < numWritableSignedAccounts;
138
- }
139
- }
140
-
141
- resolveAddressTableLookups(
142
- addressLookupTableAccounts: AddressLookupTableAccount[],
143
- ): AccountKeysFromLookups {
144
- const accountKeysFromLookups: AccountKeysFromLookups = {
145
- writable: [],
146
- readonly: [],
147
- };
148
-
149
- for (const tableLookup of this.addressTableLookups) {
150
- const tableAccount = addressLookupTableAccounts.find(account =>
151
- account.key.equals(tableLookup.accountKey),
152
- );
153
- if (!tableAccount) {
154
- throw new Error(
155
- `Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`,
156
- );
157
- }
158
-
159
- for (const index of tableLookup.writableIndexes) {
160
- if (index < tableAccount.state.addresses.length) {
161
- accountKeysFromLookups.writable.push(
162
- tableAccount.state.addresses[index],
163
- );
164
- } else {
165
- throw new Error(
166
- `Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
167
- );
168
- }
169
- }
170
-
171
- for (const index of tableLookup.readonlyIndexes) {
172
- if (index < tableAccount.state.addresses.length) {
173
- accountKeysFromLookups.readonly.push(
174
- tableAccount.state.addresses[index],
175
- );
176
- } else {
177
- throw new Error(
178
- `Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`,
179
- );
180
- }
181
- }
182
- }
183
-
184
- return accountKeysFromLookups;
185
- }
186
-
187
- static compile(args: CompileV0Args): MessageV0 {
188
- const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
189
-
190
- const addressTableLookups = new Array<MessageAddressTableLookup>();
191
- const accountKeysFromLookups: AccountKeysFromLookups = {
192
- writable: new Array(),
193
- readonly: new Array(),
194
- };
195
- const lookupTableAccounts = args.addressLookupTableAccounts || [];
196
- for (const lookupTable of lookupTableAccounts) {
197
- const extractResult = compiledKeys.extractTableLookup(lookupTable);
198
- if (extractResult !== undefined) {
199
- const [addressTableLookup, {writable, readonly}] = extractResult;
200
- addressTableLookups.push(addressTableLookup);
201
- accountKeysFromLookups.writable.push(...writable);
202
- accountKeysFromLookups.readonly.push(...readonly);
203
- }
204
- }
205
-
206
- const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
207
- const accountKeys = new MessageAccountKeys(
208
- staticAccountKeys,
209
- accountKeysFromLookups,
210
- );
211
- const compiledInstructions = accountKeys.compileInstructions(
212
- args.instructions,
213
- );
214
- return new MessageV0({
215
- header,
216
- staticAccountKeys,
217
- recentBlockhash: args.recentBlockhash,
218
- compiledInstructions,
219
- addressTableLookups,
220
- });
221
- }
222
-
223
- serialize(): Uint8Array {
224
- const encodedStaticAccountKeysLength = Array<number>();
225
- shortvec.encodeLength(
226
- encodedStaticAccountKeysLength,
227
- this.staticAccountKeys.length,
228
- );
229
-
230
- const serializedInstructions = this.serializeInstructions();
231
- const encodedInstructionsLength = Array<number>();
232
- shortvec.encodeLength(
233
- encodedInstructionsLength,
234
- this.compiledInstructions.length,
235
- );
236
-
237
- const serializedAddressTableLookups = this.serializeAddressTableLookups();
238
- const encodedAddressTableLookupsLength = Array<number>();
239
- shortvec.encodeLength(
240
- encodedAddressTableLookupsLength,
241
- this.addressTableLookups.length,
242
- );
243
-
244
- const messageLayout = BufferLayout.struct<{
245
- prefix: number;
246
- header: MessageHeader;
247
- staticAccountKeysLength: Uint8Array;
248
- staticAccountKeys: Array<Uint8Array>;
249
- recentBlockhash: Uint8Array;
250
- instructionsLength: Uint8Array;
251
- serializedInstructions: Uint8Array;
252
- addressTableLookupsLength: Uint8Array;
253
- serializedAddressTableLookups: Uint8Array;
254
- }>([
255
- BufferLayout.u8('prefix'),
256
- BufferLayout.struct<MessageHeader>(
257
- [
258
- BufferLayout.u8('numRequiredSignatures'),
259
- BufferLayout.u8('numReadonlySignedAccounts'),
260
- BufferLayout.u8('numReadonlyUnsignedAccounts'),
261
- ],
262
- 'header',
263
- ),
264
- BufferLayout.blob(
265
- encodedStaticAccountKeysLength.length,
266
- 'staticAccountKeysLength',
267
- ),
268
- BufferLayout.seq(
269
- Layout.publicKey(),
270
- this.staticAccountKeys.length,
271
- 'staticAccountKeys',
272
- ),
273
- Layout.publicKey('recentBlockhash'),
274
- BufferLayout.blob(encodedInstructionsLength.length, 'instructionsLength'),
275
- BufferLayout.blob(
276
- serializedInstructions.length,
277
- 'serializedInstructions',
278
- ),
279
- BufferLayout.blob(
280
- encodedAddressTableLookupsLength.length,
281
- 'addressTableLookupsLength',
282
- ),
283
- BufferLayout.blob(
284
- serializedAddressTableLookups.length,
285
- 'serializedAddressTableLookups',
286
- ),
287
- ]);
288
-
289
- const serializedMessage = new Uint8Array(PACKET_DATA_SIZE);
290
- const MESSAGE_VERSION_0_PREFIX = 1 << 7;
291
- const serializedMessageLength = messageLayout.encode(
292
- {
293
- prefix: MESSAGE_VERSION_0_PREFIX,
294
- header: this.header,
295
- staticAccountKeysLength: new Uint8Array(encodedStaticAccountKeysLength),
296
- staticAccountKeys: this.staticAccountKeys.map(key => key.toBytes()),
297
- recentBlockhash: bs58.decode(this.recentBlockhash),
298
- instructionsLength: new Uint8Array(encodedInstructionsLength),
299
- serializedInstructions,
300
- addressTableLookupsLength: new Uint8Array(
301
- encodedAddressTableLookupsLength,
302
- ),
303
- serializedAddressTableLookups,
304
- },
305
- serializedMessage,
306
- );
307
- return serializedMessage.slice(0, serializedMessageLength);
308
- }
309
-
310
- private serializeInstructions(): Uint8Array {
311
- let serializedLength = 0;
312
- const serializedInstructions = new Uint8Array(PACKET_DATA_SIZE);
313
- for (const instruction of this.compiledInstructions) {
314
- const encodedAccountKeyIndexesLength = Array<number>();
315
- shortvec.encodeLength(
316
- encodedAccountKeyIndexesLength,
317
- instruction.accountKeyIndexes.length,
318
- );
319
-
320
- const encodedDataLength = Array<number>();
321
- shortvec.encodeLength(encodedDataLength, instruction.data.length);
322
-
323
- const instructionLayout = BufferLayout.struct<{
324
- programIdIndex: number;
325
- encodedAccountKeyIndexesLength: Uint8Array;
326
- accountKeyIndexes: number[];
327
- encodedDataLength: Uint8Array;
328
- data: Uint8Array;
329
- }>([
330
- BufferLayout.u8('programIdIndex'),
331
- BufferLayout.blob(
332
- encodedAccountKeyIndexesLength.length,
333
- 'encodedAccountKeyIndexesLength',
334
- ),
335
- BufferLayout.seq(
336
- BufferLayout.u8(),
337
- instruction.accountKeyIndexes.length,
338
- 'accountKeyIndexes',
339
- ),
340
- BufferLayout.blob(encodedDataLength.length, 'encodedDataLength'),
341
- BufferLayout.blob(instruction.data.length, 'data'),
342
- ]);
343
-
344
- serializedLength += instructionLayout.encode(
345
- {
346
- programIdIndex: instruction.programIdIndex,
347
- encodedAccountKeyIndexesLength: new Uint8Array(
348
- encodedAccountKeyIndexesLength,
349
- ),
350
- accountKeyIndexes: instruction.accountKeyIndexes,
351
- encodedDataLength: new Uint8Array(encodedDataLength),
352
- data: instruction.data,
353
- },
354
- serializedInstructions,
355
- serializedLength,
356
- );
357
- }
358
-
359
- return serializedInstructions.slice(0, serializedLength);
360
- }
361
-
362
- private serializeAddressTableLookups(): Uint8Array {
363
- let serializedLength = 0;
364
- const serializedAddressTableLookups = new Uint8Array(PACKET_DATA_SIZE);
365
- for (const lookup of this.addressTableLookups) {
366
- const encodedWritableIndexesLength = Array<number>();
367
- shortvec.encodeLength(
368
- encodedWritableIndexesLength,
369
- lookup.writableIndexes.length,
370
- );
371
-
372
- const encodedReadonlyIndexesLength = Array<number>();
373
- shortvec.encodeLength(
374
- encodedReadonlyIndexesLength,
375
- lookup.readonlyIndexes.length,
376
- );
377
-
378
- const addressTableLookupLayout = BufferLayout.struct<{
379
- accountKey: Uint8Array;
380
- encodedWritableIndexesLength: Uint8Array;
381
- writableIndexes: number[];
382
- encodedReadonlyIndexesLength: Uint8Array;
383
- readonlyIndexes: number[];
384
- }>([
385
- Layout.publicKey('accountKey'),
386
- BufferLayout.blob(
387
- encodedWritableIndexesLength.length,
388
- 'encodedWritableIndexesLength',
389
- ),
390
- BufferLayout.seq(
391
- BufferLayout.u8(),
392
- lookup.writableIndexes.length,
393
- 'writableIndexes',
394
- ),
395
- BufferLayout.blob(
396
- encodedReadonlyIndexesLength.length,
397
- 'encodedReadonlyIndexesLength',
398
- ),
399
- BufferLayout.seq(
400
- BufferLayout.u8(),
401
- lookup.readonlyIndexes.length,
402
- 'readonlyIndexes',
403
- ),
404
- ]);
405
-
406
- serializedLength += addressTableLookupLayout.encode(
407
- {
408
- accountKey: lookup.accountKey.toBytes(),
409
- encodedWritableIndexesLength: new Uint8Array(
410
- encodedWritableIndexesLength,
411
- ),
412
- writableIndexes: lookup.writableIndexes,
413
- encodedReadonlyIndexesLength: new Uint8Array(
414
- encodedReadonlyIndexesLength,
415
- ),
416
- readonlyIndexes: lookup.readonlyIndexes,
417
- },
418
- serializedAddressTableLookups,
419
- serializedLength,
420
- );
421
- }
422
-
423
- return serializedAddressTableLookups.slice(0, serializedLength);
424
- }
425
-
426
- static deserialize(serializedMessage: Uint8Array): MessageV0 {
427
- let byteArray = [...serializedMessage];
428
-
429
- const prefix = byteArray.shift() as number;
430
- const maskedPrefix = prefix & VERSION_PREFIX_MASK;
431
- assert(
432
- prefix !== maskedPrefix,
433
- `Expected versioned message but received legacy message`,
434
- );
435
-
436
- const version = maskedPrefix;
437
- assert(
438
- version === 0,
439
- `Expected versioned message with version 0 but found version ${version}`,
440
- );
441
-
442
- const header: MessageHeader = {
443
- numRequiredSignatures: byteArray.shift() as number,
444
- numReadonlySignedAccounts: byteArray.shift() as number,
445
- numReadonlyUnsignedAccounts: byteArray.shift() as number,
446
- };
447
-
448
- const staticAccountKeys = [];
449
- const staticAccountKeysLength = shortvec.decodeLength(byteArray);
450
- for (let i = 0; i < staticAccountKeysLength; i++) {
451
- staticAccountKeys.push(
452
- new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH)),
453
- );
454
- }
455
-
456
- const recentBlockhash = bs58.encode(byteArray.splice(0, PUBLIC_KEY_LENGTH));
457
-
458
- const instructionCount = shortvec.decodeLength(byteArray);
459
- const compiledInstructions: MessageCompiledInstruction[] = [];
460
- for (let i = 0; i < instructionCount; i++) {
461
- const programIdIndex = byteArray.shift() as number;
462
- const accountKeyIndexesLength = shortvec.decodeLength(byteArray);
463
- const accountKeyIndexes = byteArray.splice(0, accountKeyIndexesLength);
464
- const dataLength = shortvec.decodeLength(byteArray);
465
- const data = new Uint8Array(byteArray.splice(0, dataLength));
466
- compiledInstructions.push({
467
- programIdIndex,
468
- accountKeyIndexes,
469
- data,
470
- });
471
- }
472
-
473
- const addressTableLookupsCount = shortvec.decodeLength(byteArray);
474
- const addressTableLookups: MessageAddressTableLookup[] = [];
475
- for (let i = 0; i < addressTableLookupsCount; i++) {
476
- const accountKey = new PublicKey(byteArray.splice(0, PUBLIC_KEY_LENGTH));
477
- const writableIndexesLength = shortvec.decodeLength(byteArray);
478
- const writableIndexes = byteArray.splice(0, writableIndexesLength);
479
- const readonlyIndexesLength = shortvec.decodeLength(byteArray);
480
- const readonlyIndexes = byteArray.splice(0, readonlyIndexesLength);
481
- addressTableLookups.push({
482
- accountKey,
483
- writableIndexes,
484
- readonlyIndexes,
485
- });
486
- }
487
-
488
- return new MessageV0({
489
- header,
490
- staticAccountKeys,
491
- recentBlockhash,
492
- compiledInstructions,
493
- addressTableLookups,
494
- });
495
- }
496
- }
@@ -1,36 +0,0 @@
1
- import {VERSION_PREFIX_MASK} from '../transaction/constants';
2
- import {Message} from './legacy';
3
- import {MessageV0} from './v0';
4
-
5
- export type VersionedMessage = Message | MessageV0;
6
- // eslint-disable-next-line no-redeclare
7
- export const VersionedMessage = {
8
- deserializeMessageVersion(serializedMessage: Uint8Array): 'legacy' | number {
9
- const prefix = serializedMessage[0];
10
- const maskedPrefix = prefix & VERSION_PREFIX_MASK;
11
-
12
- // if the highest bit of the prefix is not set, the message is not versioned
13
- if (maskedPrefix === prefix) {
14
- return 'legacy';
15
- }
16
-
17
- // the lower 7 bits of the prefix indicate the message version
18
- return maskedPrefix;
19
- },
20
-
21
- deserialize: (serializedMessage: Uint8Array): VersionedMessage => {
22
- const version =
23
- VersionedMessage.deserializeMessageVersion(serializedMessage);
24
- if (version === 'legacy') {
25
- return Message.from(serializedMessage);
26
- }
27
-
28
- if (version === 0) {
29
- return MessageV0.deserialize(serializedMessage);
30
- } else {
31
- throw new Error(
32
- `Transaction message version ${version} deserialization is not supported`,
33
- );
34
- }
35
- },
36
- };
@@ -1,82 +0,0 @@
1
- import * as BufferLayout from '@solana/buffer-layout';
2
- import {Buffer} from 'buffer';
3
-
4
- import * as Layout from './layout';
5
- import {PublicKey} from './publickey';
6
- import type {FeeCalculator} from './fee-calculator';
7
- import {FeeCalculatorLayout} from './fee-calculator';
8
- import {toBuffer} from './utils/to-buffer';
9
-
10
- /**
11
- * See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
12
- *
13
- * @internal
14
- */
15
- const NonceAccountLayout = BufferLayout.struct<
16
- Readonly<{
17
- authorizedPubkey: Uint8Array;
18
- feeCalculator: Readonly<{
19
- lamportsPerSignature: number;
20
- }>;
21
- nonce: Uint8Array;
22
- state: number;
23
- version: number;
24
- }>
25
- >([
26
- BufferLayout.u32('version'),
27
- BufferLayout.u32('state'),
28
- Layout.publicKey('authorizedPubkey'),
29
- Layout.publicKey('nonce'),
30
- BufferLayout.struct<Readonly<{lamportsPerSignature: number}>>(
31
- [FeeCalculatorLayout],
32
- 'feeCalculator',
33
- ),
34
- ]);
35
-
36
- export const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
37
-
38
- /**
39
- * A durable nonce is a 32 byte value encoded as a base58 string.
40
- */
41
- export type DurableNonce = string;
42
-
43
- type NonceAccountArgs = {
44
- authorizedPubkey: PublicKey;
45
- nonce: DurableNonce;
46
- feeCalculator: FeeCalculator;
47
- };
48
-
49
- /**
50
- * NonceAccount class
51
- */
52
- export class NonceAccount {
53
- authorizedPubkey: PublicKey;
54
- nonce: DurableNonce;
55
- feeCalculator: FeeCalculator;
56
-
57
- /**
58
- * @internal
59
- */
60
- constructor(args: NonceAccountArgs) {
61
- this.authorizedPubkey = args.authorizedPubkey;
62
- this.nonce = args.nonce;
63
- this.feeCalculator = args.feeCalculator;
64
- }
65
-
66
- /**
67
- * Deserialize NonceAccount from the account data.
68
- *
69
- * @param buffer account data
70
- * @return NonceAccount
71
- */
72
- static fromAccountData(
73
- buffer: Buffer | Uint8Array | Array<number>,
74
- ): NonceAccount {
75
- const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
76
- return new NonceAccount({
77
- authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
78
- nonce: new PublicKey(nonceAccount.nonce).toString(),
79
- feeCalculator: nonceAccount.feeCalculator,
80
- });
81
- }
82
- }