@solana/web3.js 0.98.0 → 1.0.1
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 +10 -55
- package/lib/index.browser.esm.js +48 -24
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +101 -56
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +88 -64
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +42 -25
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +27 -45
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
- package/bin/bpf-sdk-install.sh +0 -38
- package/bin/localnet.sh +0 -161
- package/bpf-sdk/LICENSE +0 -13
- package/bpf-sdk/c/README.md +0 -44
- package/bpf-sdk/c/bpf.ld +0 -20
- package/bpf-sdk/c/bpf.mk +0 -249
- package/bpf-sdk/c/inc/deserialize_deprecated.h +0 -115
- package/bpf-sdk/c/inc/solana_sdk.h +0 -669
- package/bpf-sdk/c/inc/stdio.h +0 -4
- package/bpf-sdk/c/inc/stdlib.h +0 -2
- package/bpf-sdk/c/inc/string.h +0 -7
- package/bpf-sdk/c/inc/sys/param.h +0 -1
- package/bpf-sdk/c/inc/wchar.h +0 -1
- package/bpf-sdk/env.sh +0 -39
- package/bpf-sdk/rust/bpf.ld +0 -20
- package/bpf-sdk/rust/build.sh +0 -21
- package/bpf-sdk/rust/clean.sh +0 -17
- package/bpf-sdk/rust/xargo-build.sh +0 -29
- package/bpf-sdk/scripts/dump.sh +0 -45
- package/bpf-sdk/scripts/install.sh +0 -178
- package/bpf-sdk/scripts/objcopy.sh +0 -6
- package/bpf-sdk/scripts/package.sh +0 -19
- package/bpf-sdk/scripts/strip.sh +0 -23
- package/bpf-sdk/version.txt +0 -2
- package/doc/assets/css/main.css +0 -2660
- package/doc/assets/images/icons.png +0 -0
- package/doc/assets/images/icons@2x.png +0 -0
- package/doc/assets/images/widgets.png +0 -0
- package/doc/assets/images/widgets@2x.png +0 -0
- package/doc/assets/js/main.js +0 -248
- package/doc/assets/js/search.js +0 -1
- package/doc/classes/account.html +0 -244
- package/doc/classes/authorized.html +0 -234
- package/doc/classes/bpfloader.html +0 -267
- package/doc/classes/connection.html +0 -2354
- package/doc/classes/loader.html +0 -275
- package/doc/classes/lockup.html +0 -250
- package/doc/classes/message.html +0 -326
- package/doc/classes/nonceaccount.html +0 -233
- package/doc/classes/publickey.html +0 -411
- package/doc/classes/secp256k1program.html +0 -308
- package/doc/classes/stakeinstruction.html +0 -403
- package/doc/classes/stakeprogram.html +0 -503
- package/doc/classes/systeminstruction.html +0 -563
- package/doc/classes/systemprogram.html +0 -503
- package/doc/classes/transaction.html +0 -688
- package/doc/classes/transactioninstruction.html +0 -240
- package/doc/classes/validatorinfo.html +0 -279
- package/doc/classes/voteaccount.html +0 -331
- package/doc/index.html +0 -640
- package/doc/interfaces/feecalculator.html +0 -166
- package/doc/modules.html +0 -4682
- package/examples/README.md +0 -10
- package/examples/account.html +0 -24
- package/examples/account.js +0 -10
- package/examples/bpf-c-noop/.gitignore +0 -1
- package/examples/bpf-c-noop/makefile +0 -1
- package/examples/bpf-c-noop/src/noop/noop.c +0 -19
- package/examples/bpf-rust-noop/.gitignore +0 -3
- package/examples/bpf-rust-noop/Cargo.toml +0 -23
- package/examples/bpf-rust-noop/Xargo.toml +0 -2
- package/examples/bpf-rust-noop/src/lib.rs +0 -70
- package/examples/get-balance.html +0 -37
- package/examples/get-balance.js +0 -18
package/lib/index.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import
|
|
2
|
+
import * as nacl from 'tweetnacl';
|
|
3
|
+
import nacl__default from 'tweetnacl';
|
|
3
4
|
import { Buffer } from 'buffer';
|
|
4
5
|
import BN from 'bn.js';
|
|
5
6
|
import bs58 from 'bs58';
|
|
6
7
|
import { sha256 } from 'crypto-hash';
|
|
7
|
-
import
|
|
8
|
+
import * as BufferLayout from 'buffer-layout';
|
|
8
9
|
import invariant from 'assert';
|
|
9
10
|
import { parse, format } from 'url';
|
|
10
11
|
import fetch from 'node-fetch';
|
|
@@ -166,7 +167,7 @@ class PublicKey {
|
|
|
166
167
|
|
|
167
168
|
} // @ts-ignore
|
|
168
169
|
|
|
169
|
-
let naclLowLevel =
|
|
170
|
+
let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
|
|
170
171
|
// This function and its dependents were sourced from:
|
|
171
172
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
172
173
|
|
|
@@ -234,9 +235,9 @@ class Account {
|
|
|
234
235
|
_defineProperty(this, "_keypair", void 0);
|
|
235
236
|
|
|
236
237
|
if (secretKey) {
|
|
237
|
-
this._keypair = sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
238
|
+
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
238
239
|
} else {
|
|
239
|
-
this._keypair = sign.keyPair();
|
|
240
|
+
this._keypair = nacl.sign.keyPair();
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
/**
|
|
@@ -265,14 +266,14 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
|
|
|
265
266
|
*/
|
|
266
267
|
|
|
267
268
|
const publicKey = (property = 'publicKey') => {
|
|
268
|
-
return blob(32, property);
|
|
269
|
+
return BufferLayout.blob(32, property);
|
|
269
270
|
};
|
|
270
271
|
/**
|
|
271
272
|
* Layout for a Rust String type
|
|
272
273
|
*/
|
|
273
274
|
|
|
274
275
|
const rustString = (property = 'string') => {
|
|
275
|
-
const rsl = struct([u32('length'), u32('lengthPadding'), blob(offset(u32(), -8), 'chars')], property);
|
|
276
|
+
const rsl = BufferLayout.struct([BufferLayout.u32('length'), BufferLayout.u32('lengthPadding'), BufferLayout.blob(BufferLayout.offset(BufferLayout.u32(), -8), 'chars')], property);
|
|
276
277
|
|
|
277
278
|
const _decode = rsl.decode.bind(rsl);
|
|
278
279
|
|
|
@@ -292,7 +293,7 @@ const rustString = (property = 'string') => {
|
|
|
292
293
|
};
|
|
293
294
|
|
|
294
295
|
rsl.alloc = str => {
|
|
295
|
-
return u32().span + u32().span + Buffer.from(str, 'utf8').length;
|
|
296
|
+
return BufferLayout.u32().span + BufferLayout.u32().span + Buffer.from(str, 'utf8').length;
|
|
296
297
|
};
|
|
297
298
|
|
|
298
299
|
return rsl;
|
|
@@ -302,14 +303,14 @@ const rustString = (property = 'string') => {
|
|
|
302
303
|
*/
|
|
303
304
|
|
|
304
305
|
const authorized = (property = 'authorized') => {
|
|
305
|
-
return struct([publicKey('staker'), publicKey('withdrawer')], property);
|
|
306
|
+
return BufferLayout.struct([publicKey('staker'), publicKey('withdrawer')], property);
|
|
306
307
|
};
|
|
307
308
|
/**
|
|
308
309
|
* Layout for a Lockup object
|
|
309
310
|
*/
|
|
310
311
|
|
|
311
312
|
const lockup = (property = 'lockup') => {
|
|
312
|
-
return struct([ns64('unixTimestamp'), ns64('epoch'), publicKey('custodian')], property);
|
|
313
|
+
return BufferLayout.struct([BufferLayout.ns64('unixTimestamp'), BufferLayout.ns64('epoch'), publicKey('custodian')], property);
|
|
313
314
|
};
|
|
314
315
|
function getAlloc(type, fields) {
|
|
315
316
|
let alloc = 0;
|
|
@@ -356,6 +357,36 @@ function encodeLength(bytes, len) {
|
|
|
356
357
|
}
|
|
357
358
|
}
|
|
358
359
|
|
|
360
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
361
|
+
/**
|
|
362
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
function guardedShift(byteArray) {
|
|
366
|
+
if (byteArray.length === 0) {
|
|
367
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
return byteArray.shift();
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
374
|
+
* the array.
|
|
375
|
+
*/
|
|
376
|
+
|
|
377
|
+
function guardedSplice(byteArray, ...args) {
|
|
378
|
+
var _args$;
|
|
379
|
+
|
|
380
|
+
const [start] = args;
|
|
381
|
+
|
|
382
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
383
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
384
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return byteArray.splice(...args);
|
|
388
|
+
}
|
|
389
|
+
|
|
359
390
|
/**
|
|
360
391
|
* The message header, identifying signed and read-only account
|
|
361
392
|
*
|
|
@@ -419,12 +450,12 @@ class Message {
|
|
|
419
450
|
Buffer.from(instructionCount).copy(instructionBuffer);
|
|
420
451
|
let instructionBufferLength = instructionCount.length;
|
|
421
452
|
instructions.forEach(instruction => {
|
|
422
|
-
const instructionLayout = struct([u8('programIdIndex'), blob(instruction.keyIndicesCount.length, 'keyIndicesCount'), seq(u8('keyIndex'), instruction.keyIndices.length, 'keyIndices'), blob(instruction.dataLength.length, 'dataLength'), seq(u8('userdatum'), instruction.data.length, 'data')]);
|
|
453
|
+
const instructionLayout = BufferLayout.struct([BufferLayout.u8('programIdIndex'), BufferLayout.blob(instruction.keyIndicesCount.length, 'keyIndicesCount'), BufferLayout.seq(BufferLayout.u8('keyIndex'), instruction.keyIndices.length, 'keyIndices'), BufferLayout.blob(instruction.dataLength.length, 'dataLength'), BufferLayout.seq(BufferLayout.u8('userdatum'), instruction.data.length, 'data')]);
|
|
423
454
|
const length = instructionLayout.encode(instruction, instructionBuffer, instructionBufferLength);
|
|
424
455
|
instructionBufferLength += length;
|
|
425
456
|
});
|
|
426
457
|
instructionBuffer = instructionBuffer.slice(0, instructionBufferLength);
|
|
427
|
-
const signDataLayout = struct([blob(1, 'numRequiredSignatures'), blob(1, 'numReadonlySignedAccounts'), blob(1, 'numReadonlyUnsignedAccounts'), blob(keyCount.length, 'keyCount'), seq(publicKey('key'), numKeys, 'keys'), publicKey('recentBlockhash')]);
|
|
458
|
+
const signDataLayout = BufferLayout.struct([BufferLayout.blob(1, 'numRequiredSignatures'), BufferLayout.blob(1, 'numReadonlySignedAccounts'), BufferLayout.blob(1, 'numReadonlyUnsignedAccounts'), BufferLayout.blob(keyCount.length, 'keyCount'), BufferLayout.seq(publicKey('key'), numKeys, 'keys'), publicKey('recentBlockhash')]);
|
|
428
459
|
const transaction = {
|
|
429
460
|
numRequiredSignatures: Buffer.from([this.header.numRequiredSignatures]),
|
|
430
461
|
numReadonlySignedAccounts: Buffer.from([this.header.numReadonlySignedAccounts]),
|
|
@@ -446,32 +477,28 @@ class Message {
|
|
|
446
477
|
static from(buffer) {
|
|
447
478
|
// Slice up wire data
|
|
448
479
|
let byteArray = [...buffer];
|
|
449
|
-
const numRequiredSignatures = byteArray
|
|
450
|
-
const numReadonlySignedAccounts = byteArray
|
|
451
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
480
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
481
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
482
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
452
483
|
const accountCount = decodeLength(byteArray);
|
|
453
484
|
let accountKeys = [];
|
|
454
485
|
|
|
455
486
|
for (let i = 0; i < accountCount; i++) {
|
|
456
|
-
const account = byteArray
|
|
457
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
487
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
458
488
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
459
489
|
}
|
|
460
490
|
|
|
461
|
-
const recentBlockhash = byteArray
|
|
462
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
491
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
463
492
|
const instructionCount = decodeLength(byteArray);
|
|
464
493
|
let instructions = [];
|
|
465
494
|
|
|
466
495
|
for (let i = 0; i < instructionCount; i++) {
|
|
467
|
-
const programIdIndex = byteArray
|
|
496
|
+
const programIdIndex = guardedShift(byteArray);
|
|
468
497
|
const accountCount = decodeLength(byteArray);
|
|
469
|
-
const accounts = byteArray
|
|
470
|
-
byteArray = byteArray.slice(accountCount);
|
|
498
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
471
499
|
const dataLength = decodeLength(byteArray);
|
|
472
|
-
const dataSlice = byteArray
|
|
500
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
473
501
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
474
|
-
byteArray = byteArray.slice(dataLength);
|
|
475
502
|
instructions.push({
|
|
476
503
|
programIdIndex,
|
|
477
504
|
accounts,
|
|
@@ -942,7 +969,7 @@ class Transaction {
|
|
|
942
969
|
_partialSign(message, ...signers) {
|
|
943
970
|
const signData = message.serialize();
|
|
944
971
|
signers.forEach(signer => {
|
|
945
|
-
const signature =
|
|
972
|
+
const signature = nacl__default.sign.detached(signData, signer.secretKey);
|
|
946
973
|
|
|
947
974
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
948
975
|
});
|
|
@@ -998,7 +1025,7 @@ class Transaction {
|
|
|
998
1025
|
return false;
|
|
999
1026
|
}
|
|
1000
1027
|
} else {
|
|
1001
|
-
if (!
|
|
1028
|
+
if (!nacl__default.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
1002
1029
|
return false;
|
|
1003
1030
|
}
|
|
1004
1031
|
}
|
|
@@ -1096,8 +1123,7 @@ class Transaction {
|
|
|
1096
1123
|
let signatures = [];
|
|
1097
1124
|
|
|
1098
1125
|
for (let i = 0; i < signatureCount; i++) {
|
|
1099
|
-
const signature = byteArray
|
|
1100
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
1126
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1101
1127
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1102
1128
|
}
|
|
1103
1129
|
|
|
@@ -1229,7 +1255,7 @@ function decodeData(type, buffer) {
|
|
|
1229
1255
|
* @internal
|
|
1230
1256
|
*/
|
|
1231
1257
|
|
|
1232
|
-
const FeeCalculatorLayout = nu64('lamportsPerSignature');
|
|
1258
|
+
const FeeCalculatorLayout = BufferLayout.nu64('lamportsPerSignature');
|
|
1233
1259
|
/**
|
|
1234
1260
|
* Calculator for transaction fees.
|
|
1235
1261
|
*/
|
|
@@ -1240,7 +1266,7 @@ const FeeCalculatorLayout = nu64('lamportsPerSignature');
|
|
|
1240
1266
|
* @internal
|
|
1241
1267
|
*/
|
|
1242
1268
|
|
|
1243
|
-
const NonceAccountLayout = struct([u32('version'), u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
1269
|
+
const NonceAccountLayout = BufferLayout.struct([BufferLayout.u32('version'), BufferLayout.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
1244
1270
|
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
1245
1271
|
|
|
1246
1272
|
/**
|
|
@@ -1305,7 +1331,7 @@ class SystemInstruction {
|
|
|
1305
1331
|
|
|
1306
1332
|
static decodeInstructionType(instruction) {
|
|
1307
1333
|
this.checkProgramId(instruction.programId);
|
|
1308
|
-
const instructionTypeLayout = u32('instruction');
|
|
1334
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
1309
1335
|
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
1310
1336
|
let type;
|
|
1311
1337
|
|
|
@@ -1578,51 +1604,51 @@ class SystemInstruction {
|
|
|
1578
1604
|
const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
1579
1605
|
Create: {
|
|
1580
1606
|
index: 0,
|
|
1581
|
-
layout: struct([u32('instruction'), ns64('lamports'), ns64('space'), publicKey('programId')])
|
|
1607
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports'), BufferLayout.ns64('space'), publicKey('programId')])
|
|
1582
1608
|
},
|
|
1583
1609
|
Assign: {
|
|
1584
1610
|
index: 1,
|
|
1585
|
-
layout: struct([u32('instruction'), publicKey('programId')])
|
|
1611
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('programId')])
|
|
1586
1612
|
},
|
|
1587
1613
|
Transfer: {
|
|
1588
1614
|
index: 2,
|
|
1589
|
-
layout: struct([u32('instruction'), ns64('lamports')])
|
|
1615
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
1590
1616
|
},
|
|
1591
1617
|
CreateWithSeed: {
|
|
1592
1618
|
index: 3,
|
|
1593
|
-
layout: struct([u32('instruction'), publicKey('base'), rustString('seed'), ns64('lamports'), ns64('space'), publicKey('programId')])
|
|
1619
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('base'), rustString('seed'), BufferLayout.ns64('lamports'), BufferLayout.ns64('space'), publicKey('programId')])
|
|
1594
1620
|
},
|
|
1595
1621
|
AdvanceNonceAccount: {
|
|
1596
1622
|
index: 4,
|
|
1597
|
-
layout: struct([u32('instruction')])
|
|
1623
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
1598
1624
|
},
|
|
1599
1625
|
WithdrawNonceAccount: {
|
|
1600
1626
|
index: 5,
|
|
1601
|
-
layout: struct([u32('instruction'), ns64('lamports')])
|
|
1627
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
1602
1628
|
},
|
|
1603
1629
|
InitializeNonceAccount: {
|
|
1604
1630
|
index: 6,
|
|
1605
|
-
layout: struct([u32('instruction'), publicKey('authorized')])
|
|
1631
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('authorized')])
|
|
1606
1632
|
},
|
|
1607
1633
|
AuthorizeNonceAccount: {
|
|
1608
1634
|
index: 7,
|
|
1609
|
-
layout: struct([u32('instruction'), publicKey('authorized')])
|
|
1635
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('authorized')])
|
|
1610
1636
|
},
|
|
1611
1637
|
Allocate: {
|
|
1612
1638
|
index: 8,
|
|
1613
|
-
layout: struct([u32('instruction'), ns64('space')])
|
|
1639
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('space')])
|
|
1614
1640
|
},
|
|
1615
1641
|
AllocateWithSeed: {
|
|
1616
1642
|
index: 9,
|
|
1617
|
-
layout: struct([u32('instruction'), publicKey('base'), rustString('seed'), ns64('space'), publicKey('programId')])
|
|
1643
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('base'), rustString('seed'), BufferLayout.ns64('space'), publicKey('programId')])
|
|
1618
1644
|
},
|
|
1619
1645
|
AssignWithSeed: {
|
|
1620
1646
|
index: 10,
|
|
1621
|
-
layout: struct([u32('instruction'), publicKey('base'), rustString('seed'), publicKey('programId')])
|
|
1647
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('base'), rustString('seed'), publicKey('programId')])
|
|
1622
1648
|
},
|
|
1623
1649
|
TransferWithSeed: {
|
|
1624
1650
|
index: 11,
|
|
1625
|
-
layout: struct([u32('instruction'), ns64('lamports'), rustString('seed'), publicKey('programId')])
|
|
1651
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports'), rustString('seed'), publicKey('programId')])
|
|
1626
1652
|
}
|
|
1627
1653
|
});
|
|
1628
1654
|
/**
|
|
@@ -2103,9 +2129,9 @@ class Loader {
|
|
|
2103
2129
|
});
|
|
2104
2130
|
}
|
|
2105
2131
|
}
|
|
2106
|
-
const dataLayout = struct([u32('instruction'), u32('offset'), u32('bytesLength'), u32('bytesLengthPadding'), seq(u8('byte'), offset(u32(), -8), 'bytes')]);
|
|
2132
|
+
const dataLayout = BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.u32('offset'), BufferLayout.u32('bytesLength'), BufferLayout.u32('bytesLengthPadding'), BufferLayout.seq(BufferLayout.u8('byte'), BufferLayout.offset(BufferLayout.u32(), -8), 'bytes')]);
|
|
2107
2133
|
const chunkSize = Loader.chunkSize;
|
|
2108
|
-
let offset
|
|
2134
|
+
let offset = 0;
|
|
2109
2135
|
let array = data;
|
|
2110
2136
|
let transactions = [];
|
|
2111
2137
|
|
|
@@ -2115,7 +2141,7 @@ class Loader {
|
|
|
2115
2141
|
dataLayout.encode({
|
|
2116
2142
|
instruction: 0,
|
|
2117
2143
|
// Load instruction
|
|
2118
|
-
offset
|
|
2144
|
+
offset,
|
|
2119
2145
|
bytes
|
|
2120
2146
|
}, data);
|
|
2121
2147
|
const transaction = new Transaction().add({
|
|
@@ -2136,14 +2162,14 @@ class Loader {
|
|
|
2136
2162
|
await sleep(1000 / REQUESTS_PER_SECOND);
|
|
2137
2163
|
}
|
|
2138
2164
|
|
|
2139
|
-
offset
|
|
2165
|
+
offset += chunkSize;
|
|
2140
2166
|
array = array.slice(chunkSize);
|
|
2141
2167
|
}
|
|
2142
2168
|
|
|
2143
2169
|
await Promise.all(transactions); // Finalize the account loaded with program data for execution
|
|
2144
2170
|
|
|
2145
2171
|
{
|
|
2146
|
-
const dataLayout = struct([u32('instruction')]);
|
|
2172
|
+
const dataLayout = BufferLayout.struct([BufferLayout.u32('instruction')]);
|
|
2147
2173
|
const data = Buffer.alloc(dataLayout.span);
|
|
2148
2174
|
dataLayout.encode({
|
|
2149
2175
|
instruction: 1 // Finalize instruction
|
|
@@ -4820,7 +4846,7 @@ class StakeInstruction {
|
|
|
4820
4846
|
|
|
4821
4847
|
static decodeInstructionType(instruction) {
|
|
4822
4848
|
this.checkProgramId(instruction.programId);
|
|
4823
|
-
const instructionTypeLayout = u32('instruction');
|
|
4849
|
+
const instructionTypeLayout = BufferLayout.u32('instruction');
|
|
4824
4850
|
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
4825
4851
|
let type;
|
|
4826
4852
|
|
|
@@ -5016,31 +5042,31 @@ class StakeInstruction {
|
|
|
5016
5042
|
const STAKE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
5017
5043
|
Initialize: {
|
|
5018
5044
|
index: 0,
|
|
5019
|
-
layout: struct([u32('instruction'), authorized(), lockup()])
|
|
5045
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), authorized(), lockup()])
|
|
5020
5046
|
},
|
|
5021
5047
|
Authorize: {
|
|
5022
5048
|
index: 1,
|
|
5023
|
-
layout: struct([u32('instruction'), publicKey('newAuthorized'), u32('stakeAuthorizationType')])
|
|
5049
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('newAuthorized'), BufferLayout.u32('stakeAuthorizationType')])
|
|
5024
5050
|
},
|
|
5025
5051
|
Delegate: {
|
|
5026
5052
|
index: 2,
|
|
5027
|
-
layout: struct([u32('instruction')])
|
|
5053
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
5028
5054
|
},
|
|
5029
5055
|
Split: {
|
|
5030
5056
|
index: 3,
|
|
5031
|
-
layout: struct([u32('instruction'), ns64('lamports')])
|
|
5057
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
5032
5058
|
},
|
|
5033
5059
|
Withdraw: {
|
|
5034
5060
|
index: 4,
|
|
5035
|
-
layout: struct([u32('instruction'), ns64('lamports')])
|
|
5061
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), BufferLayout.ns64('lamports')])
|
|
5036
5062
|
},
|
|
5037
5063
|
Deactivate: {
|
|
5038
5064
|
index: 5,
|
|
5039
|
-
layout: struct([u32('instruction')])
|
|
5065
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction')])
|
|
5040
5066
|
},
|
|
5041
5067
|
AuthorizeWithSeed: {
|
|
5042
5068
|
index: 8,
|
|
5043
|
-
layout: struct([u32('instruction'), publicKey('newAuthorized'), u32('stakeAuthorizationType'), rustString('authoritySeed'), publicKey('authorityOwner')])
|
|
5069
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), publicKey('newAuthorized'), BufferLayout.u32('stakeAuthorizationType'), rustString('authoritySeed'), publicKey('authorityOwner')])
|
|
5044
5070
|
}
|
|
5045
5071
|
});
|
|
5046
5072
|
/**
|
|
@@ -5467,7 +5493,7 @@ const SIGNATURE_OFFSETS_SERIALIZED_SIZE = 11;
|
|
|
5467
5493
|
* @property {number} recoveryId
|
|
5468
5494
|
*/
|
|
5469
5495
|
|
|
5470
|
-
const SECP256K1_INSTRUCTION_LAYOUT = struct([u8('numSignatures'), u16('signatureOffset'), u8('signatureInstructionIndex'), u16('ethAddressOffset'), u8('ethAddressInstructionIndex'), u16('messageDataOffset'), u16('messageDataSize'), u8('messageInstructionIndex'), blob(20, 'ethAddress'), blob(64, 'signature'), u8('recoveryId')]);
|
|
5496
|
+
const SECP256K1_INSTRUCTION_LAYOUT = BufferLayout.struct([BufferLayout.u8('numSignatures'), BufferLayout.u16('signatureOffset'), BufferLayout.u8('signatureInstructionIndex'), BufferLayout.u16('ethAddressOffset'), BufferLayout.u8('ethAddressInstructionIndex'), BufferLayout.u16('messageDataOffset'), BufferLayout.u16('messageDataSize'), BufferLayout.u8('messageInstructionIndex'), BufferLayout.blob(20, 'ethAddress'), BufferLayout.blob(64, 'signature'), BufferLayout.u8('recoveryId')]);
|
|
5471
5497
|
class Secp256k1Program {
|
|
5472
5498
|
/**
|
|
5473
5499
|
* @internal
|
|
@@ -5664,10 +5690,8 @@ class ValidatorInfo {
|
|
|
5664
5690
|
const configKeys = [];
|
|
5665
5691
|
|
|
5666
5692
|
for (let i = 0; i < 2; i++) {
|
|
5667
|
-
const publicKey = new PublicKey(byteArray
|
|
5668
|
-
|
|
5669
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
5670
|
-
byteArray = byteArray.slice(1);
|
|
5693
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
5694
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
5671
5695
|
configKeys.push({
|
|
5672
5696
|
publicKey,
|
|
5673
5697
|
isSigner
|
|
@@ -5695,9 +5719,9 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
5695
5719
|
*
|
|
5696
5720
|
* @internal
|
|
5697
5721
|
*/
|
|
5698
|
-
const VoteAccountLayout = struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), u8('commission'), nu64(), // votes.length
|
|
5699
|
-
seq(struct([nu64('slot'), u32('confirmationCount')]), offset(u32(), -8), 'votes'), u8('rootSlotValid'), nu64('rootSlot'), nu64('epoch'), nu64('credits'), nu64('lastEpochCredits'), nu64(), // epochCredits.length
|
|
5700
|
-
seq(struct([nu64('epoch'), nu64('credits'), nu64('prevCredits')]), offset(u32(), -8), 'epochCredits')]);
|
|
5722
|
+
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedVoterPubkey'), publicKey('authorizedWithdrawerPubkey'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
|
|
5723
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('lastEpochCredits'), BufferLayout.nu64(), // epochCredits.length
|
|
5724
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits')]);
|
|
5701
5725
|
|
|
5702
5726
|
/**
|
|
5703
5727
|
* VoteAccount class
|