@solana/web3.js 1.30.1 → 1.32.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 +2 -2
- package/lib/index.browser.esm.js +443 -268
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +453 -279
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +121 -19
- package/lib/index.esm.js +447 -276
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +29025 -28864
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +30 -30
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +145 -20
- package/package.json +7 -12
- package/src/account.ts +1 -1
- package/src/connection.ts +313 -41
- package/src/keypair.ts +1 -1
- package/src/publickey.ts +4 -0
- package/src/secp256k1-program.ts +5 -5
- package/src/sysvar.ts +16 -4
- package/src/transaction.ts +4 -1
- package/src/util/cluster.ts +2 -2
- package/src/util/send-and-confirm-transaction.ts +1 -0
- package/src/vote-account.ts +104 -31
package/lib/index.browser.esm.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as nacl from 'tweetnacl';
|
|
3
|
-
import nacl__default from 'tweetnacl';
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
4
2
|
import { Buffer } from 'buffer';
|
|
5
3
|
import BN from 'bn.js';
|
|
6
4
|
import bs58 from 'bs58';
|
|
@@ -10,7 +8,7 @@ import { coerce, instance, string, tuple, literal, unknown, union, type, optiona
|
|
|
10
8
|
import { Client } from 'rpc-websockets';
|
|
11
9
|
import RpcClient from 'jayson/lib/client/browser';
|
|
12
10
|
import secp256k1 from 'secp256k1';
|
|
13
|
-
import
|
|
11
|
+
import sha3 from 'js-sha3';
|
|
14
12
|
|
|
15
13
|
const toBuffer = arr => {
|
|
16
14
|
if (Buffer.isBuffer(arr)) {
|
|
@@ -1718,8 +1716,7 @@ class Struct {
|
|
|
1718
1716
|
class Enum extends Struct {
|
|
1719
1717
|
constructor(properties) {
|
|
1720
1718
|
super(properties);
|
|
1721
|
-
|
|
1722
|
-
_defineProperty(this, "enum", '');
|
|
1719
|
+
this.enum = '';
|
|
1723
1720
|
|
|
1724
1721
|
if (Object.keys(properties).length !== 1) {
|
|
1725
1722
|
throw new Error('Enum can only take single value');
|
|
@@ -1759,8 +1756,7 @@ class PublicKey extends Struct {
|
|
|
1759
1756
|
*/
|
|
1760
1757
|
constructor(value) {
|
|
1761
1758
|
super({});
|
|
1762
|
-
|
|
1763
|
-
_defineProperty(this, "_bn", void 0);
|
|
1759
|
+
this._bn = void 0;
|
|
1764
1760
|
|
|
1765
1761
|
if (isPublicKeyData(value)) {
|
|
1766
1762
|
this._bn = value._bn;
|
|
@@ -1770,7 +1766,7 @@ class PublicKey extends Struct {
|
|
|
1770
1766
|
const decoded = bs58.decode(value);
|
|
1771
1767
|
|
|
1772
1768
|
if (decoded.length != 32) {
|
|
1773
|
-
throw new Error(
|
|
1769
|
+
throw new Error(`Invalid public key input`);
|
|
1774
1770
|
}
|
|
1775
1771
|
|
|
1776
1772
|
this._bn = new BN(decoded);
|
|
@@ -1779,7 +1775,7 @@ class PublicKey extends Struct {
|
|
|
1779
1775
|
}
|
|
1780
1776
|
|
|
1781
1777
|
if (this._bn.byteLength() > 32) {
|
|
1782
|
-
throw new Error(
|
|
1778
|
+
throw new Error(`Invalid public key input`);
|
|
1783
1779
|
}
|
|
1784
1780
|
}
|
|
1785
1781
|
}
|
|
@@ -1802,6 +1798,10 @@ class PublicKey extends Struct {
|
|
|
1802
1798
|
toBase58() {
|
|
1803
1799
|
return bs58.encode(this.toBytes());
|
|
1804
1800
|
}
|
|
1801
|
+
|
|
1802
|
+
toJSON() {
|
|
1803
|
+
return this.toBase58();
|
|
1804
|
+
}
|
|
1805
1805
|
/**
|
|
1806
1806
|
* Return the byte array representation of the public key
|
|
1807
1807
|
*/
|
|
@@ -1859,7 +1859,7 @@ class PublicKey extends Struct {
|
|
|
1859
1859
|
let buffer = Buffer.alloc(0);
|
|
1860
1860
|
seeds.forEach(function (seed) {
|
|
1861
1861
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1862
|
-
throw new TypeError(
|
|
1862
|
+
throw new TypeError(`Max seed length exceeded`);
|
|
1863
1863
|
}
|
|
1864
1864
|
|
|
1865
1865
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
@@ -1869,7 +1869,7 @@ class PublicKey extends Struct {
|
|
|
1869
1869
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1870
1870
|
|
|
1871
1871
|
if (is_on_curve(publicKeyBytes)) {
|
|
1872
|
-
throw new Error(
|
|
1872
|
+
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1873
1873
|
}
|
|
1874
1874
|
|
|
1875
1875
|
return new PublicKey(publicKeyBytes);
|
|
@@ -1903,7 +1903,7 @@ class PublicKey extends Struct {
|
|
|
1903
1903
|
return [address, nonce];
|
|
1904
1904
|
}
|
|
1905
1905
|
|
|
1906
|
-
throw new Error(
|
|
1906
|
+
throw new Error(`Unable to find a viable program address nonce`);
|
|
1907
1907
|
}
|
|
1908
1908
|
/**
|
|
1909
1909
|
* Check that a pubkey is on the ed25519 curve.
|
|
@@ -1915,15 +1915,13 @@ class PublicKey extends Struct {
|
|
|
1915
1915
|
}
|
|
1916
1916
|
|
|
1917
1917
|
}
|
|
1918
|
-
|
|
1919
|
-
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
1920
|
-
|
|
1918
|
+
PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
1921
1919
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
1922
1920
|
kind: 'struct',
|
|
1923
1921
|
fields: [['_bn', 'u256']]
|
|
1924
1922
|
}); // @ts-ignore
|
|
1925
1923
|
|
|
1926
|
-
let naclLowLevel =
|
|
1924
|
+
let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
|
|
1927
1925
|
// This function and its dependents were sourced from:
|
|
1928
1926
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
1929
1927
|
|
|
@@ -1990,7 +1988,7 @@ class Account {
|
|
|
1990
1988
|
* @param secretKey Secret key for the account
|
|
1991
1989
|
*/
|
|
1992
1990
|
constructor(secretKey) {
|
|
1993
|
-
|
|
1991
|
+
this._keypair = void 0;
|
|
1994
1992
|
|
|
1995
1993
|
if (secretKey) {
|
|
1996
1994
|
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
@@ -2126,16 +2124,11 @@ const PUBKEY_LENGTH = 32;
|
|
|
2126
2124
|
|
|
2127
2125
|
class Message {
|
|
2128
2126
|
constructor(args) {
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
_defineProperty(this, "instructions", void 0);
|
|
2136
|
-
|
|
2137
|
-
_defineProperty(this, "indexToProgramIds", new Map());
|
|
2138
|
-
|
|
2127
|
+
this.header = void 0;
|
|
2128
|
+
this.accountKeys = void 0;
|
|
2129
|
+
this.recentBlockhash = void 0;
|
|
2130
|
+
this.instructions = void 0;
|
|
2131
|
+
this.indexToProgramIds = new Map();
|
|
2139
2132
|
this.header = args.header;
|
|
2140
2133
|
this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
|
|
2141
2134
|
this.recentBlockhash = args.recentBlockhash;
|
|
@@ -2309,12 +2302,9 @@ class TransactionInstruction {
|
|
|
2309
2302
|
* Program input
|
|
2310
2303
|
*/
|
|
2311
2304
|
constructor(opts) {
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
_defineProperty(this, "data", Buffer.alloc(0));
|
|
2317
|
-
|
|
2305
|
+
this.keys = void 0;
|
|
2306
|
+
this.programId = void 0;
|
|
2307
|
+
this.data = Buffer.alloc(0);
|
|
2318
2308
|
this.programId = opts.programId;
|
|
2319
2309
|
this.keys = opts.keys;
|
|
2320
2310
|
|
|
@@ -2356,16 +2346,11 @@ class Transaction {
|
|
|
2356
2346
|
* Construct an empty Transaction
|
|
2357
2347
|
*/
|
|
2358
2348
|
constructor(opts) {
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
_defineProperty(this, "recentBlockhash", void 0);
|
|
2366
|
-
|
|
2367
|
-
_defineProperty(this, "nonceInfo", void 0);
|
|
2368
|
-
|
|
2349
|
+
this.signatures = [];
|
|
2350
|
+
this.feePayer = void 0;
|
|
2351
|
+
this.instructions = [];
|
|
2352
|
+
this.recentBlockhash = void 0;
|
|
2353
|
+
this.nonceInfo = void 0;
|
|
2369
2354
|
opts && Object.assign(this, opts);
|
|
2370
2355
|
}
|
|
2371
2356
|
/**
|
|
@@ -2429,7 +2414,7 @@ class Transaction {
|
|
|
2429
2414
|
|
|
2430
2415
|
for (let i = 0; i < this.instructions.length; i++) {
|
|
2431
2416
|
if (this.instructions[i].programId === undefined) {
|
|
2432
|
-
throw new Error(
|
|
2417
|
+
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2433
2418
|
}
|
|
2434
2419
|
}
|
|
2435
2420
|
|
|
@@ -2456,8 +2441,9 @@ class Transaction {
|
|
|
2456
2441
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
2457
2442
|
|
|
2458
2443
|
accountMetas.sort(function (x, y) {
|
|
2444
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
2459
2445
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
2460
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
2446
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
2461
2447
|
return checkSigner || checkWritable;
|
|
2462
2448
|
}); // Cull duplicate account metas
|
|
2463
2449
|
|
|
@@ -2504,7 +2490,7 @@ class Transaction {
|
|
|
2504
2490
|
console.warn('Transaction references a signature that is unnecessary, ' + 'only the fee payer and instruction signer accounts should sign a transaction. ' + 'This behavior is deprecated and will throw an error in the next major version release.');
|
|
2505
2491
|
}
|
|
2506
2492
|
} else {
|
|
2507
|
-
throw new Error(
|
|
2493
|
+
throw new Error(`unknown signer: ${signature.publicKey.toString()}`);
|
|
2508
2494
|
}
|
|
2509
2495
|
}
|
|
2510
2496
|
|
|
@@ -2711,7 +2697,7 @@ class Transaction {
|
|
|
2711
2697
|
_partialSign(message, ...signers) {
|
|
2712
2698
|
const signData = message.serialize();
|
|
2713
2699
|
signers.forEach(signer => {
|
|
2714
|
-
const signature =
|
|
2700
|
+
const signature = nacl.sign.detached(signData, signer.secretKey);
|
|
2715
2701
|
|
|
2716
2702
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2717
2703
|
});
|
|
@@ -2739,7 +2725,7 @@ class Transaction {
|
|
|
2739
2725
|
const index = this.signatures.findIndex(sigpair => pubkey.equals(sigpair.publicKey));
|
|
2740
2726
|
|
|
2741
2727
|
if (index < 0) {
|
|
2742
|
-
throw new Error(
|
|
2728
|
+
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2743
2729
|
}
|
|
2744
2730
|
|
|
2745
2731
|
this.signatures[index].signature = Buffer.from(signature);
|
|
@@ -2767,7 +2753,7 @@ class Transaction {
|
|
|
2767
2753
|
return false;
|
|
2768
2754
|
}
|
|
2769
2755
|
} else {
|
|
2770
|
-
if (!
|
|
2756
|
+
if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
2771
2757
|
return false;
|
|
2772
2758
|
}
|
|
2773
2759
|
}
|
|
@@ -2815,12 +2801,12 @@ class Transaction {
|
|
|
2815
2801
|
signature
|
|
2816
2802
|
}, index) => {
|
|
2817
2803
|
if (signature !== null) {
|
|
2818
|
-
assert(signature.length === 64,
|
|
2804
|
+
assert(signature.length === 64, `signature has invalid length`);
|
|
2819
2805
|
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2820
2806
|
}
|
|
2821
2807
|
});
|
|
2822
2808
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
2823
|
-
assert(wireTransaction.length <= PACKET_DATA_SIZE,
|
|
2809
|
+
assert(wireTransaction.length <= PACKET_DATA_SIZE, `Transaction too large: ${wireTransaction.length} > ${PACKET_DATA_SIZE}`);
|
|
2824
2810
|
return wireTransaction;
|
|
2825
2811
|
}
|
|
2826
2812
|
/**
|
|
@@ -2913,11 +2899,14 @@ class Transaction {
|
|
|
2913
2899
|
}
|
|
2914
2900
|
|
|
2915
2901
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2902
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2903
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2916
2904
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2917
2905
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2918
2906
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2907
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2908
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2919
2909
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2920
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2921
2910
|
|
|
2922
2911
|
/**
|
|
2923
2912
|
* Sign, send and confirm a transaction.
|
|
@@ -2933,13 +2922,14 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
|
|
|
2933
2922
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2934
2923
|
const sendOptions = options && {
|
|
2935
2924
|
skipPreflight: options.skipPreflight,
|
|
2936
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2925
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2926
|
+
maxRetries: options.maxRetries
|
|
2937
2927
|
};
|
|
2938
2928
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2939
2929
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2940
2930
|
|
|
2941
2931
|
if (status.err) {
|
|
2942
|
-
throw new Error(
|
|
2932
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2943
2933
|
}
|
|
2944
2934
|
|
|
2945
2935
|
return signature;
|
|
@@ -2982,7 +2972,7 @@ function decodeData(type, buffer) {
|
|
|
2982
2972
|
}
|
|
2983
2973
|
|
|
2984
2974
|
if (data.instruction !== type.index) {
|
|
2985
|
-
throw new Error(
|
|
2975
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2986
2976
|
}
|
|
2987
2977
|
|
|
2988
2978
|
return data;
|
|
@@ -3016,12 +3006,9 @@ class NonceAccount {
|
|
|
3016
3006
|
* @internal
|
|
3017
3007
|
*/
|
|
3018
3008
|
constructor(args) {
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
_defineProperty(this, "feeCalculator", void 0);
|
|
3024
|
-
|
|
3009
|
+
this.authorizedPubkey = void 0;
|
|
3010
|
+
this.nonce = void 0;
|
|
3011
|
+
this.feeCalculator = void 0;
|
|
3025
3012
|
this.authorizedPubkey = args.authorizedPubkey;
|
|
3026
3013
|
this.nonce = args.nonce;
|
|
3027
3014
|
this.feeCalculator = args.feeCalculator;
|
|
@@ -3322,7 +3309,7 @@ class SystemInstruction {
|
|
|
3322
3309
|
|
|
3323
3310
|
static checkKeyLength(keys, expectedLength) {
|
|
3324
3311
|
if (keys.length < expectedLength) {
|
|
3325
|
-
throw new Error(
|
|
3312
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
3326
3313
|
}
|
|
3327
3314
|
}
|
|
3328
3315
|
|
|
@@ -3754,8 +3741,7 @@ class SystemProgram {
|
|
|
3754
3741
|
}
|
|
3755
3742
|
|
|
3756
3743
|
}
|
|
3757
|
-
|
|
3758
|
-
_defineProperty(SystemProgram, "programId", new PublicKey('11111111111111111111111111111111'));
|
|
3744
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3759
3745
|
|
|
3760
3746
|
// rest of the Transaction fields
|
|
3761
3747
|
//
|
|
@@ -3924,8 +3910,7 @@ class Loader {
|
|
|
3924
3910
|
}
|
|
3925
3911
|
|
|
3926
3912
|
}
|
|
3927
|
-
|
|
3928
|
-
_defineProperty(Loader, "chunkSize", CHUNK_SIZE);
|
|
3913
|
+
Loader.chunkSize = CHUNK_SIZE;
|
|
3929
3914
|
|
|
3930
3915
|
const BPF_LOADER_PROGRAM_ID = new PublicKey('BPFLoader2111111111111111111111111111111111');
|
|
3931
3916
|
/**
|
|
@@ -4564,16 +4549,11 @@ class EpochSchedule {
|
|
|
4564
4549
|
|
|
4565
4550
|
/** The first slot of `firstNormalEpoch` */
|
|
4566
4551
|
constructor(slotsPerEpoch, leaderScheduleSlotOffset, warmup, firstNormalEpoch, firstNormalSlot) {
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
_defineProperty(this, "firstNormalEpoch", void 0);
|
|
4574
|
-
|
|
4575
|
-
_defineProperty(this, "firstNormalSlot", void 0);
|
|
4576
|
-
|
|
4552
|
+
this.slotsPerEpoch = void 0;
|
|
4553
|
+
this.leaderScheduleSlotOffset = void 0;
|
|
4554
|
+
this.warmup = void 0;
|
|
4555
|
+
this.firstNormalEpoch = void 0;
|
|
4556
|
+
this.firstNormalSlot = void 0;
|
|
4577
4557
|
this.slotsPerEpoch = slotsPerEpoch;
|
|
4578
4558
|
this.leaderScheduleSlotOffset = leaderScheduleSlotOffset;
|
|
4579
4559
|
this.warmup = warmup;
|
|
@@ -4625,9 +4605,7 @@ class EpochSchedule {
|
|
|
4625
4605
|
class SendTransactionError extends Error {
|
|
4626
4606
|
constructor(message, logs) {
|
|
4627
4607
|
super(message);
|
|
4628
|
-
|
|
4629
|
-
_defineProperty(this, "logs", void 0);
|
|
4630
|
-
|
|
4608
|
+
this.logs = void 0;
|
|
4631
4609
|
this.logs = logs;
|
|
4632
4610
|
}
|
|
4633
4611
|
|
|
@@ -4854,16 +4832,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4854
4832
|
let fetchWithMiddleware;
|
|
4855
4833
|
|
|
4856
4834
|
if (fetchMiddleware) {
|
|
4857
|
-
fetchWithMiddleware = (url, options) => {
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
}
|
|
4865
|
-
});
|
|
4835
|
+
fetchWithMiddleware = async (url, options) => {
|
|
4836
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
4837
|
+
try {
|
|
4838
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
4839
|
+
} catch (error) {
|
|
4840
|
+
reject(error);
|
|
4841
|
+
}
|
|
4866
4842
|
});
|
|
4843
|
+
return await fetch(...modifiedFetchArgs);
|
|
4867
4844
|
};
|
|
4868
4845
|
}
|
|
4869
4846
|
|
|
@@ -4906,7 +4883,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4906
4883
|
break;
|
|
4907
4884
|
}
|
|
4908
4885
|
|
|
4909
|
-
console.log(
|
|
4886
|
+
console.log(`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`);
|
|
4910
4887
|
await sleep(waitTime);
|
|
4911
4888
|
waitTime *= 2;
|
|
4912
4889
|
}
|
|
@@ -4916,7 +4893,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4916
4893
|
if (res.ok) {
|
|
4917
4894
|
callback(null, text);
|
|
4918
4895
|
} else {
|
|
4919
|
-
callback(new Error(
|
|
4896
|
+
callback(new Error(`${res.status} ${res.statusText}: ${text}`));
|
|
4920
4897
|
}
|
|
4921
4898
|
} catch (err) {
|
|
4922
4899
|
if (err instanceof Error) callback(err);
|
|
@@ -5356,6 +5333,7 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
5356
5333
|
const TokenBalanceResult = type({
|
|
5357
5334
|
accountIndex: number(),
|
|
5358
5335
|
mint: string(),
|
|
5336
|
+
owner: optional(string()),
|
|
5359
5337
|
uiTokenAmount: TokenAmountResult
|
|
5360
5338
|
});
|
|
5361
5339
|
/**
|
|
@@ -5396,8 +5374,31 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
5396
5374
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
5397
5375
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
5398
5376
|
});
|
|
5377
|
+
/**
|
|
5378
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
5379
|
+
*/
|
|
5380
|
+
|
|
5381
|
+
const GetBlockRpcResult = jsonRpcResult(nullable(type({
|
|
5382
|
+
blockhash: string(),
|
|
5383
|
+
previousBlockhash: string(),
|
|
5384
|
+
parentSlot: number(),
|
|
5385
|
+
transactions: array(type({
|
|
5386
|
+
transaction: ConfirmedTransactionResult,
|
|
5387
|
+
meta: nullable(ConfirmedTransactionMetaResult)
|
|
5388
|
+
})),
|
|
5389
|
+
rewards: optional(array(type({
|
|
5390
|
+
pubkey: string(),
|
|
5391
|
+
lamports: number(),
|
|
5392
|
+
postBalance: nullable(number()),
|
|
5393
|
+
rewardType: nullable(string())
|
|
5394
|
+
}))),
|
|
5395
|
+
blockTime: nullable(number()),
|
|
5396
|
+
blockHeight: nullable(number())
|
|
5397
|
+
})));
|
|
5399
5398
|
/**
|
|
5400
5399
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
5400
|
+
*
|
|
5401
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
5401
5402
|
*/
|
|
5402
5403
|
|
|
5403
5404
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -5417,10 +5418,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
|
5417
5418
|
blockTime: nullable(number())
|
|
5418
5419
|
})));
|
|
5419
5420
|
/**
|
|
5420
|
-
* Expected JSON RPC response for the "
|
|
5421
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
5421
5422
|
*/
|
|
5422
5423
|
|
|
5423
|
-
const
|
|
5424
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
5424
5425
|
blockhash: string(),
|
|
5425
5426
|
previousBlockhash: string(),
|
|
5426
5427
|
parentSlot: number(),
|
|
@@ -5428,20 +5429,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
|
5428
5429
|
blockTime: nullable(number())
|
|
5429
5430
|
})));
|
|
5430
5431
|
/**
|
|
5431
|
-
* Expected JSON RPC response for the "
|
|
5432
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
5432
5433
|
*/
|
|
5433
5434
|
|
|
5434
|
-
const
|
|
5435
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
5435
5436
|
slot: number(),
|
|
5436
5437
|
meta: ConfirmedTransactionMetaResult,
|
|
5437
5438
|
blockTime: optional(nullable(number())),
|
|
5438
5439
|
transaction: ConfirmedTransactionResult
|
|
5439
5440
|
})));
|
|
5440
5441
|
/**
|
|
5441
|
-
* Expected JSON RPC response for the "
|
|
5442
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
5442
5443
|
*/
|
|
5443
5444
|
|
|
5444
|
-
const
|
|
5445
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
5445
5446
|
slot: number(),
|
|
5446
5447
|
transaction: ParsedConfirmedTransactionResult,
|
|
5447
5448
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -5449,6 +5450,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
|
5449
5450
|
})));
|
|
5450
5451
|
/**
|
|
5451
5452
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
5453
|
+
*
|
|
5454
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
5452
5455
|
*/
|
|
5453
5456
|
|
|
5454
5457
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -5457,6 +5460,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
|
5457
5460
|
lamportsPerSignature: number()
|
|
5458
5461
|
})
|
|
5459
5462
|
}));
|
|
5463
|
+
/**
|
|
5464
|
+
* Expected JSON RPC response for the "getLatestBlockhash" message
|
|
5465
|
+
*/
|
|
5466
|
+
|
|
5467
|
+
const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
|
|
5468
|
+
blockhash: string(),
|
|
5469
|
+
lastValidBlockHeight: number()
|
|
5470
|
+
}));
|
|
5460
5471
|
const PerfSampleResult = type({
|
|
5461
5472
|
slot: number(),
|
|
5462
5473
|
numTransactions: number(),
|
|
@@ -5581,67 +5592,39 @@ class Connection {
|
|
|
5581
5592
|
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
5582
5593
|
*/
|
|
5583
5594
|
constructor(endpoint, commitmentOrConfig) {
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
_defineProperty(this, "_rpcWebSocket", void 0);
|
|
5599
|
-
|
|
5600
|
-
_defineProperty(this, "_rpcWebSocketConnected", false);
|
|
5601
|
-
|
|
5602
|
-
_defineProperty(this, "_rpcWebSocketHeartbeat", null);
|
|
5603
|
-
|
|
5604
|
-
_defineProperty(this, "_rpcWebSocketIdleTimeout", null);
|
|
5605
|
-
|
|
5606
|
-
_defineProperty(this, "_disableBlockhashCaching", false);
|
|
5607
|
-
|
|
5608
|
-
_defineProperty(this, "_pollingBlockhash", false);
|
|
5609
|
-
|
|
5610
|
-
_defineProperty(this, "_blockhashInfo", {
|
|
5595
|
+
this._commitment = void 0;
|
|
5596
|
+
this._confirmTransactionInitialTimeout = void 0;
|
|
5597
|
+
this._rpcEndpoint = void 0;
|
|
5598
|
+
this._rpcWsEndpoint = void 0;
|
|
5599
|
+
this._rpcClient = void 0;
|
|
5600
|
+
this._rpcRequest = void 0;
|
|
5601
|
+
this._rpcBatchRequest = void 0;
|
|
5602
|
+
this._rpcWebSocket = void 0;
|
|
5603
|
+
this._rpcWebSocketConnected = false;
|
|
5604
|
+
this._rpcWebSocketHeartbeat = null;
|
|
5605
|
+
this._rpcWebSocketIdleTimeout = null;
|
|
5606
|
+
this._disableBlockhashCaching = false;
|
|
5607
|
+
this._pollingBlockhash = false;
|
|
5608
|
+
this._blockhashInfo = {
|
|
5611
5609
|
recentBlockhash: null,
|
|
5612
5610
|
lastFetch: 0,
|
|
5613
5611
|
transactionSignatures: [],
|
|
5614
5612
|
simulatedSignatures: []
|
|
5615
|
-
}
|
|
5616
|
-
|
|
5617
|
-
|
|
5618
|
-
|
|
5619
|
-
|
|
5620
|
-
|
|
5621
|
-
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5631
|
-
_defineProperty(this, "_signatureSubscriptions", {});
|
|
5632
|
-
|
|
5633
|
-
_defineProperty(this, "_slotSubscriptionCounter", 0);
|
|
5634
|
-
|
|
5635
|
-
_defineProperty(this, "_slotSubscriptions", {});
|
|
5636
|
-
|
|
5637
|
-
_defineProperty(this, "_logsSubscriptionCounter", 0);
|
|
5638
|
-
|
|
5639
|
-
_defineProperty(this, "_logsSubscriptions", {});
|
|
5640
|
-
|
|
5641
|
-
_defineProperty(this, "_slotUpdateSubscriptionCounter", 0);
|
|
5642
|
-
|
|
5643
|
-
_defineProperty(this, "_slotUpdateSubscriptions", {});
|
|
5644
|
-
|
|
5613
|
+
};
|
|
5614
|
+
this._accountChangeSubscriptionCounter = 0;
|
|
5615
|
+
this._accountChangeSubscriptions = {};
|
|
5616
|
+
this._programAccountChangeSubscriptionCounter = 0;
|
|
5617
|
+
this._programAccountChangeSubscriptions = {};
|
|
5618
|
+
this._rootSubscriptionCounter = 0;
|
|
5619
|
+
this._rootSubscriptions = {};
|
|
5620
|
+
this._signatureSubscriptionCounter = 0;
|
|
5621
|
+
this._signatureSubscriptions = {};
|
|
5622
|
+
this._slotSubscriptionCounter = 0;
|
|
5623
|
+
this._slotSubscriptions = {};
|
|
5624
|
+
this._logsSubscriptionCounter = 0;
|
|
5625
|
+
this._logsSubscriptions = {};
|
|
5626
|
+
this._slotUpdateSubscriptionCounter = 0;
|
|
5627
|
+
this._slotUpdateSubscriptions = {};
|
|
5645
5628
|
let url = new URL(endpoint);
|
|
5646
5629
|
const useHttps = url.protocol === 'https:';
|
|
5647
5630
|
let wsEndpoint;
|
|
@@ -5987,13 +5970,25 @@ class Connection {
|
|
|
5987
5970
|
*/
|
|
5988
5971
|
|
|
5989
5972
|
|
|
5990
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
5973
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
5991
5974
|
const keys = publicKeys.map(key => key.toBase58());
|
|
5975
|
+
let commitment;
|
|
5976
|
+
let encoding = 'base64';
|
|
5992
5977
|
|
|
5993
|
-
|
|
5978
|
+
if (configOrCommitment) {
|
|
5979
|
+
if (typeof configOrCommitment === 'string') {
|
|
5980
|
+
commitment = configOrCommitment;
|
|
5981
|
+
encoding = 'base64';
|
|
5982
|
+
} else {
|
|
5983
|
+
commitment = configOrCommitment.commitment;
|
|
5984
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
5985
|
+
}
|
|
5986
|
+
}
|
|
5987
|
+
|
|
5988
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
5994
5989
|
|
|
5995
5990
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
5996
|
-
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(
|
|
5991
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
|
|
5997
5992
|
|
|
5998
5993
|
if ('error' in res) {
|
|
5999
5994
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -6015,7 +6010,7 @@ class Connection {
|
|
|
6015
6010
|
const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
|
|
6016
6011
|
|
|
6017
6012
|
if ('error' in res) {
|
|
6018
|
-
throw new Error(
|
|
6013
|
+
throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
|
|
6019
6014
|
}
|
|
6020
6015
|
|
|
6021
6016
|
return res.result;
|
|
@@ -6151,7 +6146,7 @@ class Connection {
|
|
|
6151
6146
|
|
|
6152
6147
|
if (response === null) {
|
|
6153
6148
|
const duration = (Date.now() - start) / 1000;
|
|
6154
|
-
throw new Error(
|
|
6149
|
+
throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
|
6155
6150
|
}
|
|
6156
6151
|
|
|
6157
6152
|
return response;
|
|
@@ -6417,6 +6412,8 @@ class Connection {
|
|
|
6417
6412
|
/**
|
|
6418
6413
|
* Fetch a recent blockhash from the cluster, return with context
|
|
6419
6414
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
6415
|
+
*
|
|
6416
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
6420
6417
|
*/
|
|
6421
6418
|
|
|
6422
6419
|
|
|
@@ -6452,6 +6449,8 @@ class Connection {
|
|
|
6452
6449
|
}
|
|
6453
6450
|
/**
|
|
6454
6451
|
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
|
|
6452
|
+
*
|
|
6453
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
|
|
6455
6454
|
*/
|
|
6456
6455
|
|
|
6457
6456
|
|
|
@@ -6474,9 +6473,34 @@ class Connection {
|
|
|
6474
6473
|
value: value !== null ? value.feeCalculator : null
|
|
6475
6474
|
};
|
|
6476
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
6478
|
+
*/
|
|
6479
|
+
|
|
6480
|
+
|
|
6481
|
+
async getFeeForMessage(message, commitment) {
|
|
6482
|
+
const wireMessage = message.serialize().toString('base64');
|
|
6483
|
+
|
|
6484
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
6485
|
+
|
|
6486
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
6487
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
6488
|
+
|
|
6489
|
+
if ('error' in res) {
|
|
6490
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
6491
|
+
}
|
|
6492
|
+
|
|
6493
|
+
if (res.result === null) {
|
|
6494
|
+
throw new Error('invalid blockhash');
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
return res.result;
|
|
6498
|
+
}
|
|
6477
6499
|
/**
|
|
6478
6500
|
* Fetch a recent blockhash from the cluster
|
|
6479
6501
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6502
|
+
*
|
|
6503
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
6480
6504
|
*/
|
|
6481
6505
|
|
|
6482
6506
|
|
|
@@ -6488,6 +6512,38 @@ class Connection {
|
|
|
6488
6512
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
6489
6513
|
}
|
|
6490
6514
|
}
|
|
6515
|
+
/**
|
|
6516
|
+
* Fetch the latest blockhash from the cluster
|
|
6517
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6518
|
+
*/
|
|
6519
|
+
|
|
6520
|
+
|
|
6521
|
+
async getLatestBlockhash(commitment) {
|
|
6522
|
+
try {
|
|
6523
|
+
const res = await this.getLatestBlockhashAndContext(commitment);
|
|
6524
|
+
return res.value;
|
|
6525
|
+
} catch (e) {
|
|
6526
|
+
throw new Error('failed to get recent blockhash: ' + e);
|
|
6527
|
+
}
|
|
6528
|
+
}
|
|
6529
|
+
/**
|
|
6530
|
+
* Fetch the latest blockhash from the cluster
|
|
6531
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6532
|
+
*/
|
|
6533
|
+
|
|
6534
|
+
|
|
6535
|
+
async getLatestBlockhashAndContext(commitment) {
|
|
6536
|
+
const args = this._buildArgs([], commitment);
|
|
6537
|
+
|
|
6538
|
+
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
6539
|
+
const res = create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
6540
|
+
|
|
6541
|
+
if ('error' in res) {
|
|
6542
|
+
throw new Error('failed to get latest blockhash: ' + res.error.message);
|
|
6543
|
+
}
|
|
6544
|
+
|
|
6545
|
+
return res.result;
|
|
6546
|
+
}
|
|
6491
6547
|
/**
|
|
6492
6548
|
* Fetch the node version
|
|
6493
6549
|
*/
|
|
@@ -6526,8 +6582,8 @@ class Connection {
|
|
|
6526
6582
|
async getBlock(slot, opts) {
|
|
6527
6583
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6528
6584
|
|
|
6529
|
-
const unsafeRes = await this._rpcRequest('
|
|
6530
|
-
const res = create(unsafeRes,
|
|
6585
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6586
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
6531
6587
|
|
|
6532
6588
|
if ('error' in res) {
|
|
6533
6589
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6551,18 +6607,18 @@ class Connection {
|
|
|
6551
6607
|
};
|
|
6552
6608
|
}
|
|
6553
6609
|
/**
|
|
6554
|
-
* Fetch a
|
|
6610
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6555
6611
|
*/
|
|
6556
6612
|
|
|
6557
6613
|
|
|
6558
6614
|
async getTransaction(signature, opts) {
|
|
6559
6615
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6560
6616
|
|
|
6561
|
-
const unsafeRes = await this._rpcRequest('
|
|
6562
|
-
const res = create(unsafeRes,
|
|
6617
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6618
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6563
6619
|
|
|
6564
6620
|
if ('error' in res) {
|
|
6565
|
-
throw new Error('failed to get
|
|
6621
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6566
6622
|
}
|
|
6567
6623
|
|
|
6568
6624
|
const result = res.result;
|
|
@@ -6573,6 +6629,49 @@ class Connection {
|
|
|
6573
6629
|
}
|
|
6574
6630
|
};
|
|
6575
6631
|
}
|
|
6632
|
+
/**
|
|
6633
|
+
* Fetch parsed transaction details for a confirmed or finalized transaction
|
|
6634
|
+
*/
|
|
6635
|
+
|
|
6636
|
+
|
|
6637
|
+
async getParsedTransaction(signature, commitment) {
|
|
6638
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6639
|
+
|
|
6640
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6641
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6642
|
+
|
|
6643
|
+
if ('error' in res) {
|
|
6644
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6645
|
+
}
|
|
6646
|
+
|
|
6647
|
+
return res.result;
|
|
6648
|
+
}
|
|
6649
|
+
/**
|
|
6650
|
+
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6651
|
+
*/
|
|
6652
|
+
|
|
6653
|
+
|
|
6654
|
+
async getParsedTransactions(signatures, commitment) {
|
|
6655
|
+
const batch = signatures.map(signature => {
|
|
6656
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6657
|
+
|
|
6658
|
+
return {
|
|
6659
|
+
methodName: 'getTransaction',
|
|
6660
|
+
args
|
|
6661
|
+
};
|
|
6662
|
+
});
|
|
6663
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6664
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
6665
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6666
|
+
|
|
6667
|
+
if ('error' in res) {
|
|
6668
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
6669
|
+
}
|
|
6670
|
+
|
|
6671
|
+
return res.result;
|
|
6672
|
+
});
|
|
6673
|
+
return res;
|
|
6674
|
+
}
|
|
6576
6675
|
/**
|
|
6577
6676
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6578
6677
|
* for a confirmed block.
|
|
@@ -6582,18 +6681,39 @@ class Connection {
|
|
|
6582
6681
|
|
|
6583
6682
|
|
|
6584
6683
|
async getConfirmedBlock(slot, commitment) {
|
|
6585
|
-
const
|
|
6586
|
-
|
|
6587
|
-
|
|
6684
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
|
|
6685
|
+
|
|
6686
|
+
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6687
|
+
const res = create(unsafeRes, GetConfirmedBlockRpcResult);
|
|
6688
|
+
|
|
6689
|
+
if ('error' in res) {
|
|
6690
|
+
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
6691
|
+
}
|
|
6692
|
+
|
|
6693
|
+
const result = res.result;
|
|
6588
6694
|
|
|
6589
6695
|
if (!result) {
|
|
6590
6696
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6591
6697
|
}
|
|
6592
6698
|
|
|
6593
|
-
|
|
6699
|
+
const block = { ...result,
|
|
6594
6700
|
transactions: result.transactions.map(({
|
|
6595
6701
|
transaction,
|
|
6596
6702
|
meta
|
|
6703
|
+
}) => {
|
|
6704
|
+
const message = new Message(transaction.message);
|
|
6705
|
+
return {
|
|
6706
|
+
meta,
|
|
6707
|
+
transaction: { ...transaction,
|
|
6708
|
+
message
|
|
6709
|
+
}
|
|
6710
|
+
};
|
|
6711
|
+
})
|
|
6712
|
+
};
|
|
6713
|
+
return { ...block,
|
|
6714
|
+
transactions: block.transactions.map(({
|
|
6715
|
+
transaction,
|
|
6716
|
+
meta
|
|
6597
6717
|
}) => {
|
|
6598
6718
|
return {
|
|
6599
6719
|
meta,
|
|
@@ -6610,7 +6730,7 @@ class Connection {
|
|
|
6610
6730
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6611
6731
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6612
6732
|
|
|
6613
|
-
const unsafeRes = await this._rpcRequest('
|
|
6733
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6614
6734
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
6615
6735
|
|
|
6616
6736
|
if ('error' in res) {
|
|
@@ -6619,8 +6739,36 @@ class Connection {
|
|
|
6619
6739
|
|
|
6620
6740
|
return res.result;
|
|
6621
6741
|
}
|
|
6742
|
+
/**
|
|
6743
|
+
* Fetch a list of Signatures from the cluster for a block, excluding rewards
|
|
6744
|
+
*/
|
|
6745
|
+
|
|
6746
|
+
|
|
6747
|
+
async getBlockSignatures(slot, commitment) {
|
|
6748
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
|
|
6749
|
+
transactionDetails: 'signatures',
|
|
6750
|
+
rewards: false
|
|
6751
|
+
});
|
|
6752
|
+
|
|
6753
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6754
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6755
|
+
|
|
6756
|
+
if ('error' in res) {
|
|
6757
|
+
throw new Error('failed to get block: ' + res.error.message);
|
|
6758
|
+
}
|
|
6759
|
+
|
|
6760
|
+
const result = res.result;
|
|
6761
|
+
|
|
6762
|
+
if (!result) {
|
|
6763
|
+
throw new Error('Block ' + slot + ' not found');
|
|
6764
|
+
}
|
|
6765
|
+
|
|
6766
|
+
return result;
|
|
6767
|
+
}
|
|
6622
6768
|
/**
|
|
6623
6769
|
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
|
6770
|
+
*
|
|
6771
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
|
|
6624
6772
|
*/
|
|
6625
6773
|
|
|
6626
6774
|
|
|
@@ -6631,7 +6779,7 @@ class Connection {
|
|
|
6631
6779
|
});
|
|
6632
6780
|
|
|
6633
6781
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6634
|
-
const res = create(unsafeRes,
|
|
6782
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6635
6783
|
|
|
6636
6784
|
if ('error' in res) {
|
|
6637
6785
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6647,24 +6795,33 @@ class Connection {
|
|
|
6647
6795
|
}
|
|
6648
6796
|
/**
|
|
6649
6797
|
* Fetch a transaction details for a confirmed transaction
|
|
6798
|
+
*
|
|
6799
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6650
6800
|
*/
|
|
6651
6801
|
|
|
6652
6802
|
|
|
6653
6803
|
async getConfirmedTransaction(signature, commitment) {
|
|
6654
|
-
const
|
|
6655
|
-
|
|
6656
|
-
|
|
6804
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
6805
|
+
|
|
6806
|
+
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6807
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6808
|
+
|
|
6809
|
+
if ('error' in res) {
|
|
6810
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6811
|
+
}
|
|
6812
|
+
|
|
6813
|
+
const result = res.result;
|
|
6657
6814
|
if (!result) return result;
|
|
6658
|
-
const
|
|
6659
|
-
|
|
6660
|
-
signatures
|
|
6661
|
-
} = result.transaction;
|
|
6815
|
+
const message = new Message(result.transaction.message);
|
|
6816
|
+
const signatures = result.transaction.signatures;
|
|
6662
6817
|
return { ...result,
|
|
6663
6818
|
transaction: Transaction.populate(message, signatures)
|
|
6664
6819
|
};
|
|
6665
6820
|
}
|
|
6666
6821
|
/**
|
|
6667
6822
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6823
|
+
*
|
|
6824
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6668
6825
|
*/
|
|
6669
6826
|
|
|
6670
6827
|
|
|
@@ -6672,7 +6829,7 @@ class Connection {
|
|
|
6672
6829
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6673
6830
|
|
|
6674
6831
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6675
|
-
const res = create(unsafeRes,
|
|
6832
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6676
6833
|
|
|
6677
6834
|
if ('error' in res) {
|
|
6678
6835
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6682,6 +6839,8 @@ class Connection {
|
|
|
6682
6839
|
}
|
|
6683
6840
|
/**
|
|
6684
6841
|
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6842
|
+
*
|
|
6843
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
|
|
6685
6844
|
*/
|
|
6686
6845
|
|
|
6687
6846
|
|
|
@@ -6696,7 +6855,7 @@ class Connection {
|
|
|
6696
6855
|
});
|
|
6697
6856
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6698
6857
|
const res = unsafeRes.map(unsafeRes => {
|
|
6699
|
-
const res = create(unsafeRes,
|
|
6858
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6700
6859
|
|
|
6701
6860
|
if ('error' in res) {
|
|
6702
6861
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -6925,7 +7084,7 @@ class Connection {
|
|
|
6925
7084
|
await sleep(MS_PER_SLOT / 2);
|
|
6926
7085
|
}
|
|
6927
7086
|
|
|
6928
|
-
throw new Error(
|
|
7087
|
+
throw new Error(`Unable to obtain a new blockhash after ${Date.now() - startTime}ms`);
|
|
6929
7088
|
} finally {
|
|
6930
7089
|
this._pollingBlockhash = false;
|
|
6931
7090
|
}
|
|
@@ -7086,6 +7245,10 @@ class Connection {
|
|
|
7086
7245
|
const skipPreflight = options && options.skipPreflight;
|
|
7087
7246
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
7088
7247
|
|
|
7248
|
+
if (options && options.maxRetries) {
|
|
7249
|
+
config.maxRetries = options.maxRetries;
|
|
7250
|
+
}
|
|
7251
|
+
|
|
7089
7252
|
if (skipPreflight) {
|
|
7090
7253
|
config.skipPreflight = skipPreflight;
|
|
7091
7254
|
}
|
|
@@ -7182,7 +7345,7 @@ class Connection {
|
|
|
7182
7345
|
}
|
|
7183
7346
|
|
|
7184
7347
|
if (err instanceof Error) {
|
|
7185
|
-
console.error(
|
|
7348
|
+
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
7186
7349
|
}
|
|
7187
7350
|
}
|
|
7188
7351
|
}
|
|
@@ -7202,7 +7365,7 @@ class Connection {
|
|
|
7202
7365
|
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
7203
7366
|
} catch (err) {
|
|
7204
7367
|
if (err instanceof Error) {
|
|
7205
|
-
console.error(
|
|
7368
|
+
console.error(`${rpcMethod} error:`, err.message);
|
|
7206
7369
|
}
|
|
7207
7370
|
}
|
|
7208
7371
|
}
|
|
@@ -7367,7 +7530,7 @@ class Connection {
|
|
|
7367
7530
|
|
|
7368
7531
|
this._updateSubscriptions();
|
|
7369
7532
|
} else {
|
|
7370
|
-
throw new Error(
|
|
7533
|
+
throw new Error(`Unknown account change id: ${id}`);
|
|
7371
7534
|
}
|
|
7372
7535
|
}
|
|
7373
7536
|
/**
|
|
@@ -7433,7 +7596,7 @@ class Connection {
|
|
|
7433
7596
|
|
|
7434
7597
|
this._updateSubscriptions();
|
|
7435
7598
|
} else {
|
|
7436
|
-
throw new Error(
|
|
7599
|
+
throw new Error(`Unknown program account change id: ${id}`);
|
|
7437
7600
|
}
|
|
7438
7601
|
}
|
|
7439
7602
|
/**
|
|
@@ -7463,7 +7626,7 @@ class Connection {
|
|
|
7463
7626
|
|
|
7464
7627
|
async removeOnLogsListener(id) {
|
|
7465
7628
|
if (!this._logsSubscriptions[id]) {
|
|
7466
|
-
throw new Error(
|
|
7629
|
+
throw new Error(`Unknown logs id: ${id}`);
|
|
7467
7630
|
}
|
|
7468
7631
|
|
|
7469
7632
|
const subInfo = this._logsSubscriptions[id];
|
|
@@ -7539,7 +7702,7 @@ class Connection {
|
|
|
7539
7702
|
|
|
7540
7703
|
this._updateSubscriptions();
|
|
7541
7704
|
} else {
|
|
7542
|
-
throw new Error(
|
|
7705
|
+
throw new Error(`Unknown slot change id: ${id}`);
|
|
7543
7706
|
}
|
|
7544
7707
|
}
|
|
7545
7708
|
/**
|
|
@@ -7592,7 +7755,7 @@ class Connection {
|
|
|
7592
7755
|
|
|
7593
7756
|
this._updateSubscriptions();
|
|
7594
7757
|
} else {
|
|
7595
|
-
throw new Error(
|
|
7758
|
+
throw new Error(`Unknown slot update id: ${id}`);
|
|
7596
7759
|
}
|
|
7597
7760
|
}
|
|
7598
7761
|
|
|
@@ -7733,7 +7896,7 @@ class Connection {
|
|
|
7733
7896
|
|
|
7734
7897
|
this._updateSubscriptions();
|
|
7735
7898
|
} else {
|
|
7736
|
-
throw new Error(
|
|
7899
|
+
throw new Error(`Unknown signature result id: ${id}`);
|
|
7737
7900
|
}
|
|
7738
7901
|
}
|
|
7739
7902
|
/**
|
|
@@ -7785,7 +7948,7 @@ class Connection {
|
|
|
7785
7948
|
|
|
7786
7949
|
this._updateSubscriptions();
|
|
7787
7950
|
} else {
|
|
7788
|
-
throw new Error(
|
|
7951
|
+
throw new Error(`Unknown root change id: ${id}`);
|
|
7789
7952
|
}
|
|
7790
7953
|
}
|
|
7791
7954
|
|
|
@@ -7806,7 +7969,7 @@ class Keypair {
|
|
|
7806
7969
|
* @param keypair ed25519 keypair
|
|
7807
7970
|
*/
|
|
7808
7971
|
constructor(keypair) {
|
|
7809
|
-
|
|
7972
|
+
this._keypair = void 0;
|
|
7810
7973
|
|
|
7811
7974
|
if (keypair) {
|
|
7812
7975
|
this._keypair = keypair;
|
|
@@ -7910,8 +8073,8 @@ class Ed25519Program {
|
|
|
7910
8073
|
signature,
|
|
7911
8074
|
instructionIndex
|
|
7912
8075
|
} = params;
|
|
7913
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES$1,
|
|
7914
|
-
assert(signature.length === SIGNATURE_BYTES,
|
|
8076
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
|
|
8077
|
+
assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
7915
8078
|
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
7916
8079
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
7917
8080
|
const messageDataOffset = signatureOffset + signature.length;
|
|
@@ -7949,12 +8112,12 @@ class Ed25519Program {
|
|
|
7949
8112
|
message,
|
|
7950
8113
|
instructionIndex
|
|
7951
8114
|
} = params;
|
|
7952
|
-
assert(privateKey.length === PRIVATE_KEY_BYTES$1,
|
|
8115
|
+
assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
7953
8116
|
|
|
7954
8117
|
try {
|
|
7955
8118
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
7956
8119
|
const publicKey = keypair.publicKey.toBytes();
|
|
7957
|
-
const signature =
|
|
8120
|
+
const signature = nacl.sign.detached(message, keypair.secretKey);
|
|
7958
8121
|
return this.createInstructionWithPublicKey({
|
|
7959
8122
|
publicKey,
|
|
7960
8123
|
message,
|
|
@@ -7962,13 +8125,12 @@ class Ed25519Program {
|
|
|
7962
8125
|
instructionIndex
|
|
7963
8126
|
});
|
|
7964
8127
|
} catch (error) {
|
|
7965
|
-
throw new Error(
|
|
8128
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
7966
8129
|
}
|
|
7967
8130
|
}
|
|
7968
8131
|
|
|
7969
8132
|
}
|
|
7970
|
-
|
|
7971
|
-
_defineProperty(Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
|
|
8133
|
+
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7972
8134
|
|
|
7973
8135
|
/**
|
|
7974
8136
|
* Address of the stake config account which configures the rate
|
|
@@ -7991,10 +8153,8 @@ class Authorized {
|
|
|
7991
8153
|
* @param withdrawer the withdraw authority
|
|
7992
8154
|
*/
|
|
7993
8155
|
constructor(staker, withdrawer) {
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
_defineProperty(this, "withdrawer", void 0);
|
|
7997
|
-
|
|
8156
|
+
this.staker = void 0;
|
|
8157
|
+
this.withdrawer = void 0;
|
|
7998
8158
|
this.staker = staker;
|
|
7999
8159
|
this.withdrawer = withdrawer;
|
|
8000
8160
|
}
|
|
@@ -8015,12 +8175,9 @@ class Lockup {
|
|
|
8015
8175
|
* Create a new Lockup object
|
|
8016
8176
|
*/
|
|
8017
8177
|
constructor(unixTimestamp, epoch, custodian) {
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
_defineProperty(this, "custodian", void 0);
|
|
8023
|
-
|
|
8178
|
+
this.unixTimestamp = void 0;
|
|
8179
|
+
this.epoch = void 0;
|
|
8180
|
+
this.custodian = void 0;
|
|
8024
8181
|
this.unixTimestamp = unixTimestamp;
|
|
8025
8182
|
this.epoch = epoch;
|
|
8026
8183
|
this.custodian = custodian;
|
|
@@ -8035,7 +8192,7 @@ class Lockup {
|
|
|
8035
8192
|
* Create stake account transaction params
|
|
8036
8193
|
*/
|
|
8037
8194
|
|
|
8038
|
-
|
|
8195
|
+
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
8039
8196
|
|
|
8040
8197
|
/**
|
|
8041
8198
|
* Stake Instruction class
|
|
@@ -8248,7 +8405,7 @@ class StakeInstruction {
|
|
|
8248
8405
|
|
|
8249
8406
|
static checkKeyLength(keys, expectedLength) {
|
|
8250
8407
|
if (keys.length < expectedLength) {
|
|
8251
|
-
throw new Error(
|
|
8408
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
8252
8409
|
}
|
|
8253
8410
|
}
|
|
8254
8411
|
|
|
@@ -8723,10 +8880,8 @@ class StakeProgram {
|
|
|
8723
8880
|
}
|
|
8724
8881
|
|
|
8725
8882
|
}
|
|
8726
|
-
|
|
8727
|
-
|
|
8728
|
-
|
|
8729
|
-
_defineProperty(StakeProgram, "space", 200);
|
|
8883
|
+
StakeProgram.programId = new PublicKey('Stake11111111111111111111111111111111111111');
|
|
8884
|
+
StakeProgram.space = 200;
|
|
8730
8885
|
|
|
8731
8886
|
const {
|
|
8732
8887
|
publicKeyCreate,
|
|
@@ -8756,12 +8911,12 @@ class Secp256k1Program {
|
|
|
8756
8911
|
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
8757
8912
|
*/
|
|
8758
8913
|
static publicKeyToEthAddress(publicKey) {
|
|
8759
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES,
|
|
8914
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8760
8915
|
|
|
8761
8916
|
try {
|
|
8762
|
-
return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8917
|
+
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8763
8918
|
} catch (error) {
|
|
8764
|
-
throw new Error(
|
|
8919
|
+
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8765
8920
|
}
|
|
8766
8921
|
}
|
|
8767
8922
|
/**
|
|
@@ -8812,7 +8967,7 @@ class Secp256k1Program {
|
|
|
8812
8967
|
ethAddress = rawAddress;
|
|
8813
8968
|
}
|
|
8814
8969
|
|
|
8815
|
-
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES,
|
|
8970
|
+
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES, `Address must be ${ETHEREUM_ADDRESS_BYTES} bytes but received ${ethAddress.length} bytes`);
|
|
8816
8971
|
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
|
8817
8972
|
const ethAddressOffset = dataStart;
|
|
8818
8973
|
const signatureOffset = dataStart + ethAddress.length;
|
|
@@ -8851,13 +9006,13 @@ class Secp256k1Program {
|
|
|
8851
9006
|
message,
|
|
8852
9007
|
instructionIndex
|
|
8853
9008
|
} = params;
|
|
8854
|
-
assert(pkey.length === PRIVATE_KEY_BYTES,
|
|
9009
|
+
assert(pkey.length === PRIVATE_KEY_BYTES, `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`);
|
|
8855
9010
|
|
|
8856
9011
|
try {
|
|
8857
9012
|
const privateKey = toBuffer(pkey);
|
|
8858
9013
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
8859
9014
|
|
|
8860
|
-
const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
|
|
9015
|
+
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
8861
9016
|
const {
|
|
8862
9017
|
signature,
|
|
8863
9018
|
recid: recoveryId
|
|
@@ -8870,13 +9025,12 @@ class Secp256k1Program {
|
|
|
8870
9025
|
instructionIndex
|
|
8871
9026
|
});
|
|
8872
9027
|
} catch (error) {
|
|
8873
|
-
throw new Error(
|
|
9028
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
8874
9029
|
}
|
|
8875
9030
|
}
|
|
8876
9031
|
|
|
8877
9032
|
}
|
|
8878
|
-
|
|
8879
|
-
_defineProperty(Secp256k1Program, "programId", new PublicKey('KeccakSecp256k11111111111111111111111111111'));
|
|
9033
|
+
Secp256k1Program.programId = new PublicKey('KeccakSecp256k11111111111111111111111111111');
|
|
8880
9034
|
|
|
8881
9035
|
const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
|
|
8882
9036
|
/**
|
|
@@ -8909,10 +9063,8 @@ class ValidatorInfo {
|
|
|
8909
9063
|
* @param info validator information
|
|
8910
9064
|
*/
|
|
8911
9065
|
constructor(key, info) {
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
_defineProperty(this, "info", void 0);
|
|
8915
|
-
|
|
9066
|
+
this.key = void 0;
|
|
9067
|
+
this.info = void 0;
|
|
8916
9068
|
this.key = key;
|
|
8917
9069
|
this.info = info;
|
|
8918
9070
|
}
|
|
@@ -8964,9 +9116,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
8964
9116
|
*
|
|
8965
9117
|
* @internal
|
|
8966
9118
|
*/
|
|
8967
|
-
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('
|
|
8968
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(
|
|
8969
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('
|
|
9119
|
+
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
|
|
9120
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
|
|
9121
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
|
|
9122
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
|
|
8970
9123
|
|
|
8971
9124
|
/**
|
|
8972
9125
|
* VoteAccount class
|
|
@@ -8976,36 +9129,24 @@ class VoteAccount {
|
|
|
8976
9129
|
* @internal
|
|
8977
9130
|
*/
|
|
8978
9131
|
constructor(args) {
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
8984
|
-
|
|
8985
|
-
|
|
8986
|
-
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
_defineProperty(this, "rootSlot", void 0);
|
|
8990
|
-
|
|
8991
|
-
_defineProperty(this, "epoch", void 0);
|
|
8992
|
-
|
|
8993
|
-
_defineProperty(this, "credits", void 0);
|
|
8994
|
-
|
|
8995
|
-
_defineProperty(this, "lastEpochCredits", void 0);
|
|
8996
|
-
|
|
8997
|
-
_defineProperty(this, "epochCredits", void 0);
|
|
8998
|
-
|
|
9132
|
+
this.nodePubkey = void 0;
|
|
9133
|
+
this.authorizedWithdrawer = void 0;
|
|
9134
|
+
this.commission = void 0;
|
|
9135
|
+
this.rootSlot = void 0;
|
|
9136
|
+
this.votes = void 0;
|
|
9137
|
+
this.authorizedVoters = void 0;
|
|
9138
|
+
this.priorVoters = void 0;
|
|
9139
|
+
this.epochCredits = void 0;
|
|
9140
|
+
this.lastTimestamp = void 0;
|
|
8999
9141
|
this.nodePubkey = args.nodePubkey;
|
|
9000
|
-
this.
|
|
9001
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
9142
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
9002
9143
|
this.commission = args.commission;
|
|
9003
|
-
this.votes = args.votes;
|
|
9004
9144
|
this.rootSlot = args.rootSlot;
|
|
9005
|
-
this.
|
|
9006
|
-
this.
|
|
9007
|
-
this.
|
|
9145
|
+
this.votes = args.votes;
|
|
9146
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
9147
|
+
this.priorVoters = args.priorVoters;
|
|
9008
9148
|
this.epochCredits = args.epochCredits;
|
|
9149
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
9009
9150
|
}
|
|
9010
9151
|
/**
|
|
9011
9152
|
* Deserialize VoteAccount from the account data.
|
|
@@ -9016,7 +9157,8 @@ class VoteAccount {
|
|
|
9016
9157
|
|
|
9017
9158
|
|
|
9018
9159
|
static fromAccountData(buffer) {
|
|
9019
|
-
const
|
|
9160
|
+
const versionOffset = 4;
|
|
9161
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
9020
9162
|
let rootSlot = va.rootSlot;
|
|
9021
9163
|
|
|
9022
9164
|
if (!va.rootSlotValid) {
|
|
@@ -9025,20 +9167,53 @@ class VoteAccount {
|
|
|
9025
9167
|
|
|
9026
9168
|
return new VoteAccount({
|
|
9027
9169
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
9028
|
-
|
|
9029
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
9170
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
9030
9171
|
commission: va.commission,
|
|
9031
9172
|
votes: va.votes,
|
|
9032
9173
|
rootSlot,
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9174
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
9175
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
9176
|
+
epochCredits: va.epochCredits,
|
|
9177
|
+
lastTimestamp: va.lastTimestamp
|
|
9037
9178
|
});
|
|
9038
9179
|
}
|
|
9039
9180
|
|
|
9040
9181
|
}
|
|
9041
9182
|
|
|
9183
|
+
function parseAuthorizedVoter({
|
|
9184
|
+
epoch,
|
|
9185
|
+
authorizedVoter
|
|
9186
|
+
}) {
|
|
9187
|
+
return {
|
|
9188
|
+
epoch,
|
|
9189
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
9190
|
+
};
|
|
9191
|
+
}
|
|
9192
|
+
|
|
9193
|
+
function parsePriorVoters({
|
|
9194
|
+
authorizedPubkey,
|
|
9195
|
+
epochOfLastAuthorizedSwitch,
|
|
9196
|
+
targetEpoch
|
|
9197
|
+
}) {
|
|
9198
|
+
return {
|
|
9199
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
9200
|
+
epochOfLastAuthorizedSwitch,
|
|
9201
|
+
targetEpoch
|
|
9202
|
+
};
|
|
9203
|
+
}
|
|
9204
|
+
|
|
9205
|
+
function getPriorVoters({
|
|
9206
|
+
buf,
|
|
9207
|
+
idx,
|
|
9208
|
+
isEmpty
|
|
9209
|
+
}) {
|
|
9210
|
+
if (isEmpty) {
|
|
9211
|
+
return [];
|
|
9212
|
+
}
|
|
9213
|
+
|
|
9214
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
9215
|
+
}
|
|
9216
|
+
|
|
9042
9217
|
/**
|
|
9043
9218
|
* Send and confirm a raw transaction
|
|
9044
9219
|
*
|
|
@@ -9058,7 +9233,7 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, options)
|
|
|
9058
9233
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
9059
9234
|
|
|
9060
9235
|
if (status.err) {
|
|
9061
|
-
throw new Error(
|
|
9236
|
+
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
9062
9237
|
}
|
|
9063
9238
|
|
|
9064
9239
|
return signature;
|
|
@@ -9068,12 +9243,12 @@ const endpoint = {
|
|
|
9068
9243
|
http: {
|
|
9069
9244
|
devnet: 'http://api.devnet.solana.com',
|
|
9070
9245
|
testnet: 'http://api.testnet.solana.com',
|
|
9071
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
9246
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
9072
9247
|
},
|
|
9073
9248
|
https: {
|
|
9074
9249
|
devnet: 'https://api.devnet.solana.com',
|
|
9075
9250
|
testnet: 'https://api.testnet.solana.com',
|
|
9076
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
9251
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
9077
9252
|
}
|
|
9078
9253
|
};
|
|
9079
9254
|
|
|
@@ -9090,7 +9265,7 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9090
9265
|
const url = endpoint[key][cluster];
|
|
9091
9266
|
|
|
9092
9267
|
if (!url) {
|
|
9093
|
-
throw new Error(
|
|
9268
|
+
throw new Error(`Unknown ${key} cluster: ${cluster}`);
|
|
9094
9269
|
}
|
|
9095
9270
|
|
|
9096
9271
|
return url;
|
|
@@ -9102,5 +9277,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9102
9277
|
|
|
9103
9278
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9104
9279
|
|
|
9105
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9280
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9106
9281
|
//# sourceMappingURL=index.browser.esm.js.map
|