@solana/web3.js 1.41.1 → 1.41.4
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/lib/index.browser.cjs.js +593 -375
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +639 -422
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +610 -378
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +77 -26
- package/lib/index.esm.js +657 -426
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +12157 -12148
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -24
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +9 -5
- package/src/connection.ts +657 -486
- package/src/index.ts +1 -0
- package/src/system-program.ts +39 -10
package/lib/index.browser.esm.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import nacl from 'tweetnacl';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
2
|
+
import { Buffer as Buffer$1 } from 'buffer';
|
|
3
3
|
import BN from 'bn.js';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
6
6
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
7
|
+
import { blob } from '@solana/buffer-layout';
|
|
7
8
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
|
|
8
9
|
import { Client } from 'rpc-websockets';
|
|
9
10
|
import RpcClient from 'jayson/lib/client/browser';
|
|
@@ -11,12 +12,12 @@ import secp256k1 from 'secp256k1';
|
|
|
11
12
|
import sha3 from 'js-sha3';
|
|
12
13
|
|
|
13
14
|
const toBuffer = arr => {
|
|
14
|
-
if (Buffer.isBuffer(arr)) {
|
|
15
|
+
if (Buffer$1.isBuffer(arr)) {
|
|
15
16
|
return arr;
|
|
16
17
|
} else if (arr instanceof Uint8Array) {
|
|
17
|
-
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
18
|
+
return Buffer$1.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
18
19
|
} else {
|
|
19
|
-
return Buffer.from(arr);
|
|
20
|
+
return Buffer$1.from(arr);
|
|
20
21
|
}
|
|
21
22
|
};
|
|
22
23
|
|
|
@@ -1737,7 +1738,7 @@ class Struct {
|
|
|
1737
1738
|
}
|
|
1738
1739
|
|
|
1739
1740
|
encode() {
|
|
1740
|
-
return Buffer.from(serialize(SOLANA_SCHEMA, this));
|
|
1741
|
+
return Buffer$1.from(serialize(SOLANA_SCHEMA, this));
|
|
1741
1742
|
}
|
|
1742
1743
|
|
|
1743
1744
|
static decode(data) {
|
|
@@ -1854,13 +1855,13 @@ class PublicKey extends Struct {
|
|
|
1854
1855
|
|
|
1855
1856
|
|
|
1856
1857
|
toBuffer() {
|
|
1857
|
-
const b = this._bn.toArrayLike(Buffer);
|
|
1858
|
+
const b = this._bn.toArrayLike(Buffer$1);
|
|
1858
1859
|
|
|
1859
1860
|
if (b.length === 32) {
|
|
1860
1861
|
return b;
|
|
1861
1862
|
}
|
|
1862
1863
|
|
|
1863
|
-
const zeroPad = Buffer.alloc(32);
|
|
1864
|
+
const zeroPad = Buffer$1.alloc(32);
|
|
1864
1865
|
b.copy(zeroPad, 32 - b.length);
|
|
1865
1866
|
return zeroPad;
|
|
1866
1867
|
}
|
|
@@ -1882,9 +1883,9 @@ class PublicKey extends Struct {
|
|
|
1882
1883
|
|
|
1883
1884
|
|
|
1884
1885
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1885
|
-
const buffer = Buffer.concat([fromPublicKey.toBuffer(), Buffer.from(seed), programId.toBuffer()]);
|
|
1886
|
+
const buffer = Buffer$1.concat([fromPublicKey.toBuffer(), Buffer$1.from(seed), programId.toBuffer()]);
|
|
1886
1887
|
const hash = sha256(new Uint8Array(buffer)).slice(2);
|
|
1887
|
-
return new PublicKey(Buffer.from(hash, 'hex'));
|
|
1888
|
+
return new PublicKey(Buffer$1.from(hash, 'hex'));
|
|
1888
1889
|
}
|
|
1889
1890
|
/**
|
|
1890
1891
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1894,15 +1895,15 @@ class PublicKey extends Struct {
|
|
|
1894
1895
|
|
|
1895
1896
|
|
|
1896
1897
|
static createProgramAddressSync(seeds, programId) {
|
|
1897
|
-
let buffer = Buffer.alloc(0);
|
|
1898
|
+
let buffer = Buffer$1.alloc(0);
|
|
1898
1899
|
seeds.forEach(function (seed) {
|
|
1899
1900
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1900
1901
|
throw new TypeError(`Max seed length exceeded`);
|
|
1901
1902
|
}
|
|
1902
1903
|
|
|
1903
|
-
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
1904
|
+
buffer = Buffer$1.concat([buffer, toBuffer(seed)]);
|
|
1904
1905
|
});
|
|
1905
|
-
buffer = Buffer.concat([buffer, programId.toBuffer(), Buffer.from('ProgramDerivedAddress')]);
|
|
1906
|
+
buffer = Buffer$1.concat([buffer, programId.toBuffer(), Buffer$1.from('ProgramDerivedAddress')]);
|
|
1906
1907
|
let hash = sha256(new Uint8Array(buffer)).slice(2);
|
|
1907
1908
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1908
1909
|
|
|
@@ -1938,7 +1939,7 @@ class PublicKey extends Struct {
|
|
|
1938
1939
|
|
|
1939
1940
|
while (nonce != 0) {
|
|
1940
1941
|
try {
|
|
1941
|
-
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
|
1942
|
+
const seedsWithNonce = seeds.concat(Buffer$1.from([nonce]));
|
|
1942
1943
|
address = this.createProgramAddressSync(seedsWithNonce, programId);
|
|
1943
1944
|
} catch (err) {
|
|
1944
1945
|
if (err instanceof TypeError) {
|
|
@@ -2114,13 +2115,13 @@ const rustString = (property = 'string') => {
|
|
|
2114
2115
|
|
|
2115
2116
|
rslShim.encode = (str, b, offset) => {
|
|
2116
2117
|
const data = {
|
|
2117
|
-
chars: Buffer.from(str, 'utf8')
|
|
2118
|
+
chars: Buffer$1.from(str, 'utf8')
|
|
2118
2119
|
};
|
|
2119
2120
|
return _encode(data, b, offset);
|
|
2120
2121
|
};
|
|
2121
2122
|
|
|
2122
2123
|
rslShim.alloc = str => {
|
|
2123
|
-
return BufferLayout.u32().span + BufferLayout.u32().span + Buffer.from(str, 'utf8').length;
|
|
2124
|
+
return BufferLayout.u32().span + BufferLayout.u32().span + Buffer$1.from(str, 'utf8').length;
|
|
2124
2125
|
};
|
|
2125
2126
|
|
|
2126
2127
|
return rslShim;
|
|
@@ -2250,16 +2251,16 @@ class Message {
|
|
|
2250
2251
|
encodeLength(dataCount, data.length);
|
|
2251
2252
|
return {
|
|
2252
2253
|
programIdIndex,
|
|
2253
|
-
keyIndicesCount: Buffer.from(keyIndicesCount),
|
|
2254
|
+
keyIndicesCount: Buffer$1.from(keyIndicesCount),
|
|
2254
2255
|
keyIndices: accounts,
|
|
2255
|
-
dataLength: Buffer.from(dataCount),
|
|
2256
|
+
dataLength: Buffer$1.from(dataCount),
|
|
2256
2257
|
data
|
|
2257
2258
|
};
|
|
2258
2259
|
});
|
|
2259
2260
|
let instructionCount = [];
|
|
2260
2261
|
encodeLength(instructionCount, instructions.length);
|
|
2261
|
-
let instructionBuffer = Buffer.alloc(PACKET_DATA_SIZE);
|
|
2262
|
-
Buffer.from(instructionCount).copy(instructionBuffer);
|
|
2262
|
+
let instructionBuffer = Buffer$1.alloc(PACKET_DATA_SIZE);
|
|
2263
|
+
Buffer$1.from(instructionCount).copy(instructionBuffer);
|
|
2263
2264
|
let instructionBufferLength = instructionCount.length;
|
|
2264
2265
|
instructions.forEach(instruction => {
|
|
2265
2266
|
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')]);
|
|
@@ -2269,14 +2270,14 @@ class Message {
|
|
|
2269
2270
|
instructionBuffer = instructionBuffer.slice(0, instructionBufferLength);
|
|
2270
2271
|
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')]);
|
|
2271
2272
|
const transaction = {
|
|
2272
|
-
numRequiredSignatures: Buffer.from([this.header.numRequiredSignatures]),
|
|
2273
|
-
numReadonlySignedAccounts: Buffer.from([this.header.numReadonlySignedAccounts]),
|
|
2274
|
-
numReadonlyUnsignedAccounts: Buffer.from([this.header.numReadonlyUnsignedAccounts]),
|
|
2275
|
-
keyCount: Buffer.from(keyCount),
|
|
2273
|
+
numRequiredSignatures: Buffer$1.from([this.header.numRequiredSignatures]),
|
|
2274
|
+
numReadonlySignedAccounts: Buffer$1.from([this.header.numReadonlySignedAccounts]),
|
|
2275
|
+
numReadonlyUnsignedAccounts: Buffer$1.from([this.header.numReadonlyUnsignedAccounts]),
|
|
2276
|
+
keyCount: Buffer$1.from(keyCount),
|
|
2276
2277
|
keys: this.accountKeys.map(key => toBuffer(key.toBytes())),
|
|
2277
2278
|
recentBlockhash: bs58.decode(this.recentBlockhash)
|
|
2278
2279
|
};
|
|
2279
|
-
let signData = Buffer.alloc(2048);
|
|
2280
|
+
let signData = Buffer$1.alloc(2048);
|
|
2280
2281
|
const length = signDataLayout.encode(transaction, signData);
|
|
2281
2282
|
instructionBuffer.copy(signData, length);
|
|
2282
2283
|
return signData.slice(0, length + instructionBuffer.length);
|
|
@@ -2298,7 +2299,7 @@ class Message {
|
|
|
2298
2299
|
for (let i = 0; i < accountCount; i++) {
|
|
2299
2300
|
const account = byteArray.slice(0, PUBKEY_LENGTH);
|
|
2300
2301
|
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2301
|
-
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2302
|
+
accountKeys.push(bs58.encode(Buffer$1.from(account)));
|
|
2302
2303
|
}
|
|
2303
2304
|
|
|
2304
2305
|
const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
|
|
@@ -2313,7 +2314,7 @@ class Message {
|
|
|
2313
2314
|
byteArray = byteArray.slice(accountCount);
|
|
2314
2315
|
const dataLength = decodeLength(byteArray);
|
|
2315
2316
|
const dataSlice = byteArray.slice(0, dataLength);
|
|
2316
|
-
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2317
|
+
const data = bs58.encode(Buffer$1.from(dataSlice));
|
|
2317
2318
|
byteArray = byteArray.slice(dataLength);
|
|
2318
2319
|
instructions.push({
|
|
2319
2320
|
programIdIndex,
|
|
@@ -2328,7 +2329,7 @@ class Message {
|
|
|
2328
2329
|
numReadonlySignedAccounts,
|
|
2329
2330
|
numReadonlyUnsignedAccounts
|
|
2330
2331
|
},
|
|
2331
|
-
recentBlockhash: bs58.encode(Buffer.from(recentBlockhash)),
|
|
2332
|
+
recentBlockhash: bs58.encode(Buffer$1.from(recentBlockhash)),
|
|
2332
2333
|
accountKeys,
|
|
2333
2334
|
instructions
|
|
2334
2335
|
};
|
|
@@ -2346,7 +2347,7 @@ function assert (condition, message) {
|
|
|
2346
2347
|
/**
|
|
2347
2348
|
* Default (empty) signature
|
|
2348
2349
|
*/
|
|
2349
|
-
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2350
|
+
const DEFAULT_SIGNATURE = Buffer$1.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2350
2351
|
/**
|
|
2351
2352
|
* Account metadata used to define instructions
|
|
2352
2353
|
*/
|
|
@@ -2370,7 +2371,7 @@ class TransactionInstruction {
|
|
|
2370
2371
|
constructor(opts) {
|
|
2371
2372
|
this.keys = void 0;
|
|
2372
2373
|
this.programId = void 0;
|
|
2373
|
-
this.data = Buffer.alloc(0);
|
|
2374
|
+
this.data = Buffer$1.alloc(0);
|
|
2374
2375
|
this.programId = opts.programId;
|
|
2375
2376
|
this.keys = opts.keys;
|
|
2376
2377
|
|
|
@@ -2853,7 +2854,7 @@ class Transaction {
|
|
|
2853
2854
|
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2854
2855
|
}
|
|
2855
2856
|
|
|
2856
|
-
this.signatures[index].signature = Buffer.from(signature);
|
|
2857
|
+
this.signatures[index].signature = Buffer$1.from(signature);
|
|
2857
2858
|
}
|
|
2858
2859
|
/**
|
|
2859
2860
|
* Verify signatures of a complete, signed Transaction
|
|
@@ -2919,15 +2920,15 @@ class Transaction {
|
|
|
2919
2920
|
const signatureCount = [];
|
|
2920
2921
|
encodeLength(signatureCount, signatures.length);
|
|
2921
2922
|
const transactionLength = signatureCount.length + signatures.length * 64 + signData.length;
|
|
2922
|
-
const wireTransaction = Buffer.alloc(transactionLength);
|
|
2923
|
+
const wireTransaction = Buffer$1.alloc(transactionLength);
|
|
2923
2924
|
assert(signatures.length < 256);
|
|
2924
|
-
Buffer.from(signatureCount).copy(wireTransaction, 0);
|
|
2925
|
+
Buffer$1.from(signatureCount).copy(wireTransaction, 0);
|
|
2925
2926
|
signatures.forEach(({
|
|
2926
2927
|
signature
|
|
2927
2928
|
}, index) => {
|
|
2928
2929
|
if (signature !== null) {
|
|
2929
2930
|
assert(signature.length === 64, `signature has invalid length`);
|
|
2930
|
-
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2931
|
+
Buffer$1.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2931
2932
|
}
|
|
2932
2933
|
});
|
|
2933
2934
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
@@ -2978,7 +2979,7 @@ class Transaction {
|
|
|
2978
2979
|
for (let i = 0; i < signatureCount; i++) {
|
|
2979
2980
|
const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
|
|
2980
2981
|
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
2981
|
-
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2982
|
+
signatures.push(bs58.encode(Buffer$1.from(signature)));
|
|
2982
2983
|
}
|
|
2983
2984
|
|
|
2984
2985
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -3067,13 +3068,99 @@ function sleep(ms) {
|
|
|
3067
3068
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
3068
3069
|
}
|
|
3069
3070
|
|
|
3071
|
+
const encodeDecode = (layout) => {
|
|
3072
|
+
const decode = layout.decode.bind(layout);
|
|
3073
|
+
const encode = layout.encode.bind(layout);
|
|
3074
|
+
return { decode, encode };
|
|
3075
|
+
};
|
|
3076
|
+
|
|
3077
|
+
var browser = {};
|
|
3078
|
+
|
|
3079
|
+
Object.defineProperty(browser, "__esModule", { value: true });
|
|
3080
|
+
/**
|
|
3081
|
+
* Convert a little-endian buffer into a BigInt.
|
|
3082
|
+
* @param buf The little-endian buffer to convert
|
|
3083
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
3084
|
+
*/
|
|
3085
|
+
function toBigIntLE(buf) {
|
|
3086
|
+
{
|
|
3087
|
+
const reversed = Buffer.from(buf);
|
|
3088
|
+
reversed.reverse();
|
|
3089
|
+
const hex = reversed.toString('hex');
|
|
3090
|
+
if (hex.length === 0) {
|
|
3091
|
+
return BigInt(0);
|
|
3092
|
+
}
|
|
3093
|
+
return BigInt(`0x${hex}`);
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3096
|
+
var toBigIntLE_1 = browser.toBigIntLE = toBigIntLE;
|
|
3097
|
+
/**
|
|
3098
|
+
* Convert a big-endian buffer into a BigInt
|
|
3099
|
+
* @param buf The big-endian buffer to convert.
|
|
3100
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
3101
|
+
*/
|
|
3102
|
+
function toBigIntBE(buf) {
|
|
3103
|
+
{
|
|
3104
|
+
const hex = buf.toString('hex');
|
|
3105
|
+
if (hex.length === 0) {
|
|
3106
|
+
return BigInt(0);
|
|
3107
|
+
}
|
|
3108
|
+
return BigInt(`0x${hex}`);
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
browser.toBigIntBE = toBigIntBE;
|
|
3112
|
+
/**
|
|
3113
|
+
* Convert a BigInt to a little-endian buffer.
|
|
3114
|
+
* @param num The BigInt to convert.
|
|
3115
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
3116
|
+
* @returns A little-endian buffer representation of num.
|
|
3117
|
+
*/
|
|
3118
|
+
function toBufferLE(num, width) {
|
|
3119
|
+
{
|
|
3120
|
+
const hex = num.toString(16);
|
|
3121
|
+
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3122
|
+
buffer.reverse();
|
|
3123
|
+
return buffer;
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
var toBufferLE_1 = browser.toBufferLE = toBufferLE;
|
|
3127
|
+
/**
|
|
3128
|
+
* Convert a BigInt to a big-endian buffer.
|
|
3129
|
+
* @param num The BigInt to convert.
|
|
3130
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
3131
|
+
* @returns A big-endian buffer representation of num.
|
|
3132
|
+
*/
|
|
3133
|
+
function toBufferBE(num, width) {
|
|
3134
|
+
{
|
|
3135
|
+
const hex = num.toString(16);
|
|
3136
|
+
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
browser.toBufferBE = toBufferBE;
|
|
3140
|
+
|
|
3141
|
+
const bigInt = (length) => (property) => {
|
|
3142
|
+
const layout = blob(length, property);
|
|
3143
|
+
const { encode, decode } = encodeDecode(layout);
|
|
3144
|
+
const bigIntLayout = layout;
|
|
3145
|
+
bigIntLayout.decode = (buffer, offset) => {
|
|
3146
|
+
const src = decode(buffer, offset);
|
|
3147
|
+
return toBigIntLE_1(Buffer.from(src));
|
|
3148
|
+
};
|
|
3149
|
+
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
3150
|
+
const src = toBufferLE_1(bigInt, length);
|
|
3151
|
+
return encode(src, buffer, offset);
|
|
3152
|
+
};
|
|
3153
|
+
return bigIntLayout;
|
|
3154
|
+
};
|
|
3155
|
+
const u64 = bigInt(8);
|
|
3156
|
+
|
|
3070
3157
|
/**
|
|
3071
3158
|
* Populate a buffer of instruction data using an InstructionType
|
|
3072
3159
|
* @internal
|
|
3073
3160
|
*/
|
|
3074
3161
|
function encodeData(type, fields) {
|
|
3075
3162
|
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
3076
|
-
const data = Buffer.alloc(allocLength);
|
|
3163
|
+
const data = Buffer$1.alloc(allocLength);
|
|
3077
3164
|
const layoutFields = Object.assign({
|
|
3078
3165
|
instruction: type.index
|
|
3079
3166
|
}, fields);
|
|
@@ -3456,7 +3543,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
3456
3543
|
},
|
|
3457
3544
|
Transfer: {
|
|
3458
3545
|
index: 2,
|
|
3459
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'),
|
|
3546
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('lamports')])
|
|
3460
3547
|
},
|
|
3461
3548
|
CreateWithSeed: {
|
|
3462
3549
|
index: 3,
|
|
@@ -3492,7 +3579,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
3492
3579
|
},
|
|
3493
3580
|
TransferWithSeed: {
|
|
3494
3581
|
index: 11,
|
|
3495
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'),
|
|
3582
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
|
|
3496
3583
|
}
|
|
3497
3584
|
});
|
|
3498
3585
|
/**
|
|
@@ -3545,7 +3632,7 @@ class SystemProgram {
|
|
|
3545
3632
|
if ('basePubkey' in params) {
|
|
3546
3633
|
const type = SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed;
|
|
3547
3634
|
data = encodeData(type, {
|
|
3548
|
-
lamports: params.lamports,
|
|
3635
|
+
lamports: BigInt(params.lamports),
|
|
3549
3636
|
seed: params.seed,
|
|
3550
3637
|
programId: toBuffer(params.programId.toBuffer())
|
|
3551
3638
|
});
|
|
@@ -3565,7 +3652,7 @@ class SystemProgram {
|
|
|
3565
3652
|
} else {
|
|
3566
3653
|
const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
|
|
3567
3654
|
data = encodeData(type, {
|
|
3568
|
-
lamports: params.lamports
|
|
3655
|
+
lamports: BigInt(params.lamports)
|
|
3569
3656
|
});
|
|
3570
3657
|
keys = [{
|
|
3571
3658
|
pubkey: params.fromPubkey,
|
|
@@ -3973,7 +4060,7 @@ class Loader {
|
|
|
3973
4060
|
|
|
3974
4061
|
while (array.length > 0) {
|
|
3975
4062
|
const bytes = array.slice(0, chunkSize);
|
|
3976
|
-
const data = Buffer.alloc(chunkSize + 16);
|
|
4063
|
+
const data = Buffer$1.alloc(chunkSize + 16);
|
|
3977
4064
|
dataLayout.encode({
|
|
3978
4065
|
instruction: 0,
|
|
3979
4066
|
// Load instruction
|
|
@@ -4008,7 +4095,7 @@ class Loader {
|
|
|
4008
4095
|
|
|
4009
4096
|
{
|
|
4010
4097
|
const dataLayout = BufferLayout.struct([BufferLayout.u32('instruction')]);
|
|
4011
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
4098
|
+
const data = Buffer$1.alloc(dataLayout.span);
|
|
4012
4099
|
dataLayout.encode({
|
|
4013
4100
|
instruction: 1 // Finalize instruction
|
|
4014
4101
|
|
|
@@ -4761,6 +4848,82 @@ module.exports = exports;
|
|
|
4761
4848
|
|
|
4762
4849
|
var crossFetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfill.exports);
|
|
4763
4850
|
|
|
4851
|
+
var objToString = Object.prototype.toString;
|
|
4852
|
+
var objKeys = Object.keys || function(obj) {
|
|
4853
|
+
var keys = [];
|
|
4854
|
+
for (var name in obj) {
|
|
4855
|
+
keys.push(name);
|
|
4856
|
+
}
|
|
4857
|
+
return keys;
|
|
4858
|
+
};
|
|
4859
|
+
|
|
4860
|
+
function stringify(val, isArrayProp) {
|
|
4861
|
+
var i, max, str, keys, key, propVal, toStr;
|
|
4862
|
+
if (val === true) {
|
|
4863
|
+
return "true";
|
|
4864
|
+
}
|
|
4865
|
+
if (val === false) {
|
|
4866
|
+
return "false";
|
|
4867
|
+
}
|
|
4868
|
+
switch (typeof val) {
|
|
4869
|
+
case "object":
|
|
4870
|
+
if (val === null) {
|
|
4871
|
+
return null;
|
|
4872
|
+
} else if (val.toJSON && typeof val.toJSON === "function") {
|
|
4873
|
+
return stringify(val.toJSON(), isArrayProp);
|
|
4874
|
+
} else {
|
|
4875
|
+
toStr = objToString.call(val);
|
|
4876
|
+
if (toStr === "[object Array]") {
|
|
4877
|
+
str = '[';
|
|
4878
|
+
max = val.length - 1;
|
|
4879
|
+
for(i = 0; i < max; i++) {
|
|
4880
|
+
str += stringify(val[i], true) + ',';
|
|
4881
|
+
}
|
|
4882
|
+
if (max > -1) {
|
|
4883
|
+
str += stringify(val[i], true);
|
|
4884
|
+
}
|
|
4885
|
+
return str + ']';
|
|
4886
|
+
} else if (toStr === "[object Object]") {
|
|
4887
|
+
// only object is left
|
|
4888
|
+
keys = objKeys(val).sort();
|
|
4889
|
+
max = keys.length;
|
|
4890
|
+
str = "";
|
|
4891
|
+
i = 0;
|
|
4892
|
+
while (i < max) {
|
|
4893
|
+
key = keys[i];
|
|
4894
|
+
propVal = stringify(val[key], false);
|
|
4895
|
+
if (propVal !== undefined) {
|
|
4896
|
+
if (str) {
|
|
4897
|
+
str += ',';
|
|
4898
|
+
}
|
|
4899
|
+
str += JSON.stringify(key) + ':' + propVal;
|
|
4900
|
+
}
|
|
4901
|
+
i++;
|
|
4902
|
+
}
|
|
4903
|
+
return '{' + str + '}';
|
|
4904
|
+
} else {
|
|
4905
|
+
return JSON.stringify(val);
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
case "function":
|
|
4909
|
+
case "undefined":
|
|
4910
|
+
return isArrayProp ? null : undefined;
|
|
4911
|
+
case "string":
|
|
4912
|
+
return JSON.stringify(val);
|
|
4913
|
+
default:
|
|
4914
|
+
return isFinite(val) ? val : null;
|
|
4915
|
+
}
|
|
4916
|
+
}
|
|
4917
|
+
|
|
4918
|
+
var fastStableStringify = function(val) {
|
|
4919
|
+
var returnVal = stringify(val, false);
|
|
4920
|
+
if (returnVal !== undefined) {
|
|
4921
|
+
return ''+ returnVal;
|
|
4922
|
+
}
|
|
4923
|
+
};
|
|
4924
|
+
|
|
4925
|
+
var fastStableStringify$1 = fastStableStringify;
|
|
4926
|
+
|
|
4764
4927
|
const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
|
|
4765
4928
|
|
|
4766
4929
|
function trailingZeros(n) {
|
|
@@ -4920,13 +5083,19 @@ function makeWebsocketUrl(endpoint) {
|
|
|
4920
5083
|
|
|
4921
5084
|
const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
|
|
4922
5085
|
const RawAccountDataResult = tuple([string(), literal('base64')]);
|
|
4923
|
-
const BufferFromRawAccountData = coerce(instance(Buffer), RawAccountDataResult, value => Buffer.from(value[0], 'base64'));
|
|
5086
|
+
const BufferFromRawAccountData = coerce(instance(Buffer$1), RawAccountDataResult, value => Buffer$1.from(value[0], 'base64'));
|
|
4924
5087
|
/**
|
|
4925
5088
|
* Attempt to use a recent blockhash for up to 30 seconds
|
|
4926
5089
|
* @internal
|
|
4927
5090
|
*/
|
|
4928
5091
|
|
|
4929
5092
|
const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
|
|
5093
|
+
/**
|
|
5094
|
+
* HACK.
|
|
5095
|
+
* Copied from rpc-websockets/dist/lib/client.
|
|
5096
|
+
* Otherwise, `yarn build` fails with:
|
|
5097
|
+
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
|
|
5098
|
+
*/
|
|
4930
5099
|
|
|
4931
5100
|
/**
|
|
4932
5101
|
* @internal
|
|
@@ -5337,7 +5506,7 @@ const KeyedAccountInfoResult = type({
|
|
|
5337
5506
|
pubkey: PublicKeyFromString,
|
|
5338
5507
|
account: AccountInfoResult
|
|
5339
5508
|
});
|
|
5340
|
-
const ParsedOrRawAccountData = coerce(union([instance(Buffer), ParsedAccountDataResult]), union([RawAccountDataResult, ParsedAccountDataResult]), value => {
|
|
5509
|
+
const ParsedOrRawAccountData = coerce(union([instance(Buffer$1), ParsedAccountDataResult]), union([RawAccountDataResult, ParsedAccountDataResult]), value => {
|
|
5341
5510
|
if (Array.isArray(value)) {
|
|
5342
5511
|
return create(value, BufferFromRawAccountData);
|
|
5343
5512
|
} else {
|
|
@@ -5795,14 +5964,9 @@ const LogsNotificationResult = type({
|
|
|
5795
5964
|
* Filter for log subscriptions.
|
|
5796
5965
|
*/
|
|
5797
5966
|
|
|
5798
|
-
function createSubscriptionWarningMessage(id, label) {
|
|
5799
|
-
return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
|
|
5800
|
-
}
|
|
5801
5967
|
/**
|
|
5802
5968
|
* A connection to a fullnode JSON RPC endpoint
|
|
5803
5969
|
*/
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
5970
|
class Connection {
|
|
5807
5971
|
/** @internal */
|
|
5808
5972
|
|
|
@@ -5826,21 +5990,13 @@ class Connection {
|
|
|
5826
5990
|
|
|
5827
5991
|
/** @internal */
|
|
5828
5992
|
|
|
5829
|
-
/** @internal
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
/** @internal */
|
|
5838
|
-
|
|
5839
|
-
/** @internal */
|
|
5840
|
-
|
|
5841
|
-
/** @internal */
|
|
5842
|
-
|
|
5843
|
-
/** @internal */
|
|
5993
|
+
/** @internal
|
|
5994
|
+
* A number that we increment every time an active connection closes.
|
|
5995
|
+
* Used to determine whether the same socket connection that was open
|
|
5996
|
+
* when an async operation started is the same one that's active when
|
|
5997
|
+
* its continuation fires.
|
|
5998
|
+
*
|
|
5999
|
+
*/
|
|
5844
6000
|
|
|
5845
6001
|
/** @internal */
|
|
5846
6002
|
|
|
@@ -5856,7 +6012,19 @@ class Connection {
|
|
|
5856
6012
|
|
|
5857
6013
|
/** @internal */
|
|
5858
6014
|
|
|
5859
|
-
/**
|
|
6015
|
+
/**
|
|
6016
|
+
* Special case.
|
|
6017
|
+
* After a signature is processed, RPCs automatically dispose of the
|
|
6018
|
+
* subscription on the server side. We need to track which of these
|
|
6019
|
+
* subscriptions have been disposed in such a way, so that we know
|
|
6020
|
+
* whether the client is dealing with a not-yet-processed signature
|
|
6021
|
+
* (in which case we must tear down the server subscription) or an
|
|
6022
|
+
* already-processed signature (in which case the client can simply
|
|
6023
|
+
* clear out the subscription locally without telling the server).
|
|
6024
|
+
*
|
|
6025
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
6026
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
6027
|
+
*/
|
|
5860
6028
|
|
|
5861
6029
|
/** @internal */
|
|
5862
6030
|
|
|
@@ -5878,6 +6046,7 @@ class Connection {
|
|
|
5878
6046
|
this._rpcWebSocketConnected = false;
|
|
5879
6047
|
this._rpcWebSocketHeartbeat = null;
|
|
5880
6048
|
this._rpcWebSocketIdleTimeout = null;
|
|
6049
|
+
this._rpcWebSocketGeneration = 0;
|
|
5881
6050
|
this._disableBlockhashCaching = false;
|
|
5882
6051
|
this._pollingBlockhash = false;
|
|
5883
6052
|
this._blockhashInfo = {
|
|
@@ -5886,20 +6055,11 @@ class Connection {
|
|
|
5886
6055
|
transactionSignatures: [],
|
|
5887
6056
|
simulatedSignatures: []
|
|
5888
6057
|
};
|
|
5889
|
-
this.
|
|
5890
|
-
this.
|
|
5891
|
-
this.
|
|
5892
|
-
this.
|
|
5893
|
-
this.
|
|
5894
|
-
this._rootSubscriptions = {};
|
|
5895
|
-
this._signatureSubscriptionCounter = 0;
|
|
5896
|
-
this._signatureSubscriptions = {};
|
|
5897
|
-
this._slotSubscriptionCounter = 0;
|
|
5898
|
-
this._slotSubscriptions = {};
|
|
5899
|
-
this._logsSubscriptionCounter = 0;
|
|
5900
|
-
this._logsSubscriptions = {};
|
|
5901
|
-
this._slotUpdateSubscriptionCounter = 0;
|
|
5902
|
-
this._slotUpdateSubscriptions = {};
|
|
6058
|
+
this._nextClientSubscriptionId = 0;
|
|
6059
|
+
this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
|
|
6060
|
+
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
6061
|
+
this._subscriptionsByHash = {};
|
|
6062
|
+
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
5903
6063
|
let url = new URL(endpoint);
|
|
5904
6064
|
const useHttps = url.protocol === 'https:';
|
|
5905
6065
|
let wsEndpoint;
|
|
@@ -7667,6 +7827,8 @@ class Connection {
|
|
|
7667
7827
|
|
|
7668
7828
|
|
|
7669
7829
|
_wsOnClose(code) {
|
|
7830
|
+
this._rpcWebSocketGeneration++;
|
|
7831
|
+
|
|
7670
7832
|
if (this._rpcWebSocketHeartbeat) {
|
|
7671
7833
|
clearInterval(this._rpcWebSocketHeartbeat);
|
|
7672
7834
|
this._rpcWebSocketHeartbeat = null;
|
|
@@ -7680,85 +7842,20 @@ class Connection {
|
|
|
7680
7842
|
} // implicit close, prepare subscriptions for auto-reconnect
|
|
7681
7843
|
|
|
7682
7844
|
|
|
7683
|
-
this.
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
async _subscribe(sub, rpcMethod, rpcArgs) {
|
|
7691
|
-
if (sub.subscriptionId == null) {
|
|
7692
|
-
sub.subscriptionId = 'subscribing';
|
|
7693
|
-
|
|
7694
|
-
try {
|
|
7695
|
-
const id = await this._rpcWebSocket.call(rpcMethod, rpcArgs);
|
|
7696
|
-
|
|
7697
|
-
if (typeof id === 'number' && sub.subscriptionId === 'subscribing') {
|
|
7698
|
-
// eslint-disable-next-line require-atomic-updates
|
|
7699
|
-
sub.subscriptionId = id;
|
|
7700
|
-
}
|
|
7701
|
-
} catch (err) {
|
|
7702
|
-
if (sub.subscriptionId === 'subscribing') {
|
|
7703
|
-
// eslint-disable-next-line require-atomic-updates
|
|
7704
|
-
sub.subscriptionId = null;
|
|
7705
|
-
}
|
|
7706
|
-
|
|
7707
|
-
if (err instanceof Error) {
|
|
7708
|
-
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
7709
|
-
}
|
|
7710
|
-
}
|
|
7711
|
-
}
|
|
7712
|
-
}
|
|
7713
|
-
/**
|
|
7714
|
-
* @internal
|
|
7715
|
-
*/
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
async _unsubscribe(sub, rpcMethod) {
|
|
7719
|
-
const subscriptionId = sub.subscriptionId;
|
|
7720
|
-
|
|
7721
|
-
if (subscriptionId != null && typeof subscriptionId != 'string') {
|
|
7722
|
-
const unsubscribeId = subscriptionId;
|
|
7723
|
-
|
|
7724
|
-
try {
|
|
7725
|
-
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
7726
|
-
} catch (err) {
|
|
7727
|
-
if (err instanceof Error) {
|
|
7728
|
-
console.error(`${rpcMethod} error:`, err.message);
|
|
7729
|
-
}
|
|
7730
|
-
}
|
|
7731
|
-
}
|
|
7732
|
-
}
|
|
7733
|
-
/**
|
|
7734
|
-
* @internal
|
|
7735
|
-
*/
|
|
7736
|
-
|
|
7737
|
-
|
|
7738
|
-
_resetSubscriptions() {
|
|
7739
|
-
Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7740
|
-
Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7741
|
-
Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7742
|
-
Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7743
|
-
Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7744
|
-
Object.values(this._slotSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7745
|
-
Object.values(this._slotUpdateSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7845
|
+
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
7846
|
+
Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
|
|
7847
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7848
|
+
state: 'pending'
|
|
7849
|
+
};
|
|
7850
|
+
});
|
|
7746
7851
|
}
|
|
7747
7852
|
/**
|
|
7748
7853
|
* @internal
|
|
7749
7854
|
*/
|
|
7750
7855
|
|
|
7751
7856
|
|
|
7752
|
-
_updateSubscriptions() {
|
|
7753
|
-
|
|
7754
|
-
const programKeys = Object.keys(this._programAccountChangeSubscriptions).map(Number);
|
|
7755
|
-
const slotKeys = Object.keys(this._slotSubscriptions).map(Number);
|
|
7756
|
-
const slotUpdateKeys = Object.keys(this._slotUpdateSubscriptions).map(Number);
|
|
7757
|
-
const signatureKeys = Object.keys(this._signatureSubscriptions).map(Number);
|
|
7758
|
-
const rootKeys = Object.keys(this._rootSubscriptions).map(Number);
|
|
7759
|
-
const logsKeys = Object.keys(this._logsSubscriptions).map(Number);
|
|
7760
|
-
|
|
7761
|
-
if (accountKeys.length === 0 && programKeys.length === 0 && slotKeys.length === 0 && slotUpdateKeys.length === 0 && signatureKeys.length === 0 && rootKeys.length === 0 && logsKeys.length === 0) {
|
|
7857
|
+
async _updateSubscriptions() {
|
|
7858
|
+
if (Object.keys(this._subscriptionsByHash).length === 0) {
|
|
7762
7859
|
if (this._rpcWebSocketConnected) {
|
|
7763
7860
|
this._rpcWebSocketConnected = false;
|
|
7764
7861
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
@@ -7790,60 +7887,167 @@ class Connection {
|
|
|
7790
7887
|
return;
|
|
7791
7888
|
}
|
|
7792
7889
|
|
|
7793
|
-
|
|
7794
|
-
const sub = this._accountChangeSubscriptions[id];
|
|
7795
|
-
|
|
7796
|
-
this._subscribe(sub, 'accountSubscribe', this._buildArgs([sub.publicKey], sub.commitment, 'base64'));
|
|
7797
|
-
}
|
|
7890
|
+
const activeWebSocketGeneration = this._rpcWebSocketGeneration;
|
|
7798
7891
|
|
|
7799
|
-
|
|
7800
|
-
|
|
7892
|
+
const isCurrentConnectionStillActive = () => {
|
|
7893
|
+
return activeWebSocketGeneration === this._rpcWebSocketGeneration;
|
|
7894
|
+
};
|
|
7801
7895
|
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7896
|
+
await Promise.all( // Don't be tempted to change this to `Object.entries`. We call
|
|
7897
|
+
// `_updateSubscriptions` recursively when processing the state,
|
|
7898
|
+
// so it's important that we look up the *current* version of
|
|
7899
|
+
// each subscription, every time we process a hash.
|
|
7900
|
+
Object.keys(this._subscriptionsByHash).map(async hash => {
|
|
7901
|
+
const subscription = this._subscriptionsByHash[hash];
|
|
7806
7902
|
|
|
7807
|
-
|
|
7808
|
-
|
|
7903
|
+
if (subscription === undefined) {
|
|
7904
|
+
// This entry has since been deleted. Skip.
|
|
7905
|
+
return;
|
|
7906
|
+
}
|
|
7809
7907
|
|
|
7810
|
-
|
|
7811
|
-
|
|
7908
|
+
switch (subscription.state) {
|
|
7909
|
+
case 'pending':
|
|
7910
|
+
case 'unsubscribed':
|
|
7911
|
+
if (subscription.callbacks.size === 0) {
|
|
7912
|
+
/**
|
|
7913
|
+
* You can end up here when:
|
|
7914
|
+
*
|
|
7915
|
+
* - a subscription has recently unsubscribed
|
|
7916
|
+
* without having new callbacks added to it
|
|
7917
|
+
* while the unsubscribe was in flight, or
|
|
7918
|
+
* - when a pending subscription has its
|
|
7919
|
+
* listeners removed before a request was
|
|
7920
|
+
* sent to the server.
|
|
7921
|
+
*
|
|
7922
|
+
* Being that nobody is interested in this
|
|
7923
|
+
* subscription any longer, delete it.
|
|
7924
|
+
*/
|
|
7925
|
+
delete this._subscriptionsByHash[hash];
|
|
7926
|
+
|
|
7927
|
+
if (subscription.state === 'unsubscribed') {
|
|
7928
|
+
delete this._subscriptionCallbacksByServerSubscriptionId[subscription.serverSubscriptionId];
|
|
7929
|
+
}
|
|
7812
7930
|
|
|
7813
|
-
|
|
7814
|
-
|
|
7931
|
+
await this._updateSubscriptions();
|
|
7932
|
+
return;
|
|
7933
|
+
}
|
|
7815
7934
|
|
|
7816
|
-
|
|
7817
|
-
|
|
7935
|
+
await (async () => {
|
|
7936
|
+
const {
|
|
7937
|
+
args,
|
|
7938
|
+
method
|
|
7939
|
+
} = subscription;
|
|
7818
7940
|
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7941
|
+
try {
|
|
7942
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7943
|
+
state: 'subscribing'
|
|
7944
|
+
};
|
|
7945
|
+
const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
|
|
7946
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7947
|
+
serverSubscriptionId,
|
|
7948
|
+
state: 'subscribed'
|
|
7949
|
+
};
|
|
7950
|
+
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
7951
|
+
await this._updateSubscriptions();
|
|
7952
|
+
} catch (e) {
|
|
7953
|
+
if (e instanceof Error) {
|
|
7954
|
+
console.error(`${method} error for argument`, args, e.message);
|
|
7955
|
+
}
|
|
7956
|
+
|
|
7957
|
+
if (!isCurrentConnectionStillActive()) {
|
|
7958
|
+
return;
|
|
7959
|
+
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
7823
7960
|
|
|
7824
|
-
this._subscribe(sub, 'signatureSubscribe', args);
|
|
7825
|
-
}
|
|
7826
7961
|
|
|
7827
|
-
|
|
7828
|
-
|
|
7962
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7963
|
+
state: 'pending'
|
|
7964
|
+
};
|
|
7965
|
+
await this._updateSubscriptions();
|
|
7966
|
+
}
|
|
7967
|
+
})();
|
|
7968
|
+
break;
|
|
7829
7969
|
|
|
7830
|
-
|
|
7831
|
-
|
|
7970
|
+
case 'subscribed':
|
|
7971
|
+
if (subscription.callbacks.size === 0) {
|
|
7972
|
+
// By the time we successfully set up a subscription
|
|
7973
|
+
// with the server, the client stopped caring about it.
|
|
7974
|
+
// Tear it down now.
|
|
7975
|
+
await (async () => {
|
|
7976
|
+
const {
|
|
7977
|
+
serverSubscriptionId,
|
|
7978
|
+
unsubscribeMethod
|
|
7979
|
+
} = subscription;
|
|
7980
|
+
|
|
7981
|
+
if (this._subscriptionsAutoDisposedByRpc.has(serverSubscriptionId)) {
|
|
7982
|
+
/**
|
|
7983
|
+
* Special case.
|
|
7984
|
+
* If we're dealing with a subscription that has been auto-
|
|
7985
|
+
* disposed by the RPC, then we can skip the RPC call to
|
|
7986
|
+
* tear down the subscription here.
|
|
7987
|
+
*
|
|
7988
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
7989
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
7990
|
+
*/
|
|
7991
|
+
this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
|
|
7992
|
+
} else {
|
|
7993
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7994
|
+
state: 'unsubscribing'
|
|
7995
|
+
};
|
|
7996
|
+
|
|
7997
|
+
try {
|
|
7998
|
+
await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
|
|
7999
|
+
} catch (e) {
|
|
8000
|
+
if (e instanceof Error) {
|
|
8001
|
+
console.error(`${unsubscribeMethod} error:`, e.message);
|
|
8002
|
+
}
|
|
8003
|
+
|
|
8004
|
+
if (!isCurrentConnectionStillActive()) {
|
|
8005
|
+
return;
|
|
8006
|
+
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
8007
|
+
|
|
8008
|
+
|
|
8009
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
8010
|
+
state: 'subscribed'
|
|
8011
|
+
};
|
|
8012
|
+
await this._updateSubscriptions();
|
|
8013
|
+
return;
|
|
8014
|
+
}
|
|
8015
|
+
}
|
|
7832
8016
|
|
|
7833
|
-
|
|
7834
|
-
|
|
7835
|
-
|
|
8017
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
8018
|
+
state: 'unsubscribed'
|
|
8019
|
+
};
|
|
8020
|
+
await this._updateSubscriptions();
|
|
8021
|
+
})();
|
|
8022
|
+
}
|
|
7836
8023
|
|
|
7837
|
-
|
|
7838
|
-
filter = {
|
|
7839
|
-
mentions: [sub.filter.toString()]
|
|
7840
|
-
};
|
|
7841
|
-
} else {
|
|
7842
|
-
filter = sub.filter;
|
|
8024
|
+
break;
|
|
7843
8025
|
}
|
|
8026
|
+
}));
|
|
8027
|
+
}
|
|
8028
|
+
/**
|
|
8029
|
+
* @internal
|
|
8030
|
+
*/
|
|
8031
|
+
|
|
7844
8032
|
|
|
7845
|
-
|
|
8033
|
+
_handleServerNotification(serverSubscriptionId, callbackArgs) {
|
|
8034
|
+
const callbacks = this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId];
|
|
8035
|
+
|
|
8036
|
+
if (callbacks === undefined) {
|
|
8037
|
+
return;
|
|
7846
8038
|
}
|
|
8039
|
+
|
|
8040
|
+
callbacks.forEach(cb => {
|
|
8041
|
+
try {
|
|
8042
|
+
cb( // I failed to find a way to convince TypeScript that `cb` is of type
|
|
8043
|
+
// `TCallback` which is certainly compatible with `Parameters<TCallback>`.
|
|
8044
|
+
// See https://github.com/microsoft/TypeScript/issues/47615
|
|
8045
|
+
// @ts-ignore
|
|
8046
|
+
...callbackArgs);
|
|
8047
|
+
} catch (e) {
|
|
8048
|
+
console.error(e);
|
|
8049
|
+
}
|
|
8050
|
+
});
|
|
7847
8051
|
}
|
|
7848
8052
|
/**
|
|
7849
8053
|
* @internal
|
|
@@ -7851,14 +8055,71 @@ class Connection {
|
|
|
7851
8055
|
|
|
7852
8056
|
|
|
7853
8057
|
_wsOnAccountNotification(notification) {
|
|
7854
|
-
const
|
|
8058
|
+
const {
|
|
8059
|
+
result,
|
|
8060
|
+
subscription
|
|
8061
|
+
} = create(notification, AccountNotificationResult);
|
|
7855
8062
|
|
|
7856
|
-
|
|
7857
|
-
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
8063
|
+
this._handleServerNotification(subscription, [result.value, result.context]);
|
|
8064
|
+
}
|
|
8065
|
+
/**
|
|
8066
|
+
* @internal
|
|
8067
|
+
*/
|
|
8068
|
+
|
|
8069
|
+
|
|
8070
|
+
_makeSubscription(subscriptionConfig,
|
|
8071
|
+
/**
|
|
8072
|
+
* When preparing `args` for a call to `_makeSubscription`, be sure
|
|
8073
|
+
* to carefully apply a default `commitment` property, if necessary.
|
|
8074
|
+
*
|
|
8075
|
+
* - If the user supplied a `commitment` use that.
|
|
8076
|
+
* - Otherwise, if the `Connection::commitment` is set, use that.
|
|
8077
|
+
* - Otherwise, set it to the RPC server default: `finalized`.
|
|
8078
|
+
*
|
|
8079
|
+
* This is extremely important to ensure that these two fundamentally
|
|
8080
|
+
* identical subscriptions produce the same identifying hash:
|
|
8081
|
+
*
|
|
8082
|
+
* - A subscription made without specifying a commitment.
|
|
8083
|
+
* - A subscription made where the commitment specified is the same
|
|
8084
|
+
* as the default applied to the subscription above.
|
|
8085
|
+
*
|
|
8086
|
+
* Example; these two subscriptions must produce the same hash:
|
|
8087
|
+
*
|
|
8088
|
+
* - An `accountSubscribe` subscription for `'PUBKEY'`
|
|
8089
|
+
* - An `accountSubscribe` subscription for `'PUBKEY'` with commitment
|
|
8090
|
+
* `'finalized'`.
|
|
8091
|
+
*
|
|
8092
|
+
* See the 'making a subscription with defaulted params omitted' test
|
|
8093
|
+
* in `connection-subscriptions.ts` for more.
|
|
8094
|
+
*/
|
|
8095
|
+
args) {
|
|
8096
|
+
const clientSubscriptionId = this._nextClientSubscriptionId++;
|
|
8097
|
+
const hash = fastStableStringify$1([subscriptionConfig.method, args], true
|
|
8098
|
+
/* isArrayProp */
|
|
8099
|
+
);
|
|
8100
|
+
const existingSubscription = this._subscriptionsByHash[hash];
|
|
8101
|
+
|
|
8102
|
+
if (existingSubscription === undefined) {
|
|
8103
|
+
this._subscriptionsByHash[hash] = { ...subscriptionConfig,
|
|
8104
|
+
args,
|
|
8105
|
+
callbacks: new Set([subscriptionConfig.callback]),
|
|
8106
|
+
state: 'pending'
|
|
8107
|
+
};
|
|
8108
|
+
} else {
|
|
8109
|
+
existingSubscription.callbacks.add(subscriptionConfig.callback);
|
|
7861
8110
|
}
|
|
8111
|
+
|
|
8112
|
+
this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
|
|
8113
|
+
delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
8114
|
+
const subscription = this._subscriptionsByHash[hash];
|
|
8115
|
+
assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
|
|
8116
|
+
subscription.callbacks.delete(subscriptionConfig.callback);
|
|
8117
|
+
await this._updateSubscriptions();
|
|
8118
|
+
};
|
|
8119
|
+
|
|
8120
|
+
this._updateSubscriptions();
|
|
8121
|
+
|
|
8122
|
+
return clientSubscriptionId;
|
|
7862
8123
|
}
|
|
7863
8124
|
/**
|
|
7864
8125
|
* Register a callback to be invoked whenever the specified account changes
|
|
@@ -7871,35 +8132,24 @@ class Connection {
|
|
|
7871
8132
|
|
|
7872
8133
|
|
|
7873
8134
|
onAccountChange(publicKey, callback, commitment) {
|
|
7874
|
-
const
|
|
7875
|
-
|
|
7876
|
-
publicKey: publicKey.toBase58(),
|
|
7877
|
-
callback,
|
|
7878
|
-
commitment,
|
|
7879
|
-
subscriptionId: null
|
|
7880
|
-
};
|
|
8135
|
+
const args = this._buildArgs([publicKey.toBase58()], commitment || this._commitment || 'finalized', // Apply connection/server default.
|
|
8136
|
+
'base64');
|
|
7881
8137
|
|
|
7882
|
-
this.
|
|
7883
|
-
|
|
7884
|
-
|
|
8138
|
+
return this._makeSubscription({
|
|
8139
|
+
callback,
|
|
8140
|
+
method: 'accountSubscribe',
|
|
8141
|
+
unsubscribeMethod: 'accountUnsubscribe'
|
|
8142
|
+
}, args);
|
|
7885
8143
|
}
|
|
7886
8144
|
/**
|
|
7887
8145
|
* Deregister an account notification callback
|
|
7888
8146
|
*
|
|
7889
|
-
* @param id subscription id to deregister
|
|
8147
|
+
* @param id client subscription id to deregister
|
|
7890
8148
|
*/
|
|
7891
8149
|
|
|
7892
8150
|
|
|
7893
|
-
async removeAccountChangeListener(
|
|
7894
|
-
|
|
7895
|
-
const subInfo = this._accountChangeSubscriptions[id];
|
|
7896
|
-
delete this._accountChangeSubscriptions[id];
|
|
7897
|
-
await this._unsubscribe(subInfo, 'accountUnsubscribe');
|
|
7898
|
-
|
|
7899
|
-
this._updateSubscriptions();
|
|
7900
|
-
} else {
|
|
7901
|
-
console.warn(createSubscriptionWarningMessage(id, 'account change'));
|
|
7902
|
-
}
|
|
8151
|
+
async removeAccountChangeListener(clientSubscriptionId) {
|
|
8152
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'account change');
|
|
7903
8153
|
}
|
|
7904
8154
|
/**
|
|
7905
8155
|
* @internal
|
|
@@ -7907,21 +8157,15 @@ class Connection {
|
|
|
7907
8157
|
|
|
7908
8158
|
|
|
7909
8159
|
_wsOnProgramAccountNotification(notification) {
|
|
7910
|
-
const
|
|
8160
|
+
const {
|
|
8161
|
+
result,
|
|
8162
|
+
subscription
|
|
8163
|
+
} = create(notification, ProgramAccountNotificationResult);
|
|
7911
8164
|
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
context
|
|
7917
|
-
} = res.result;
|
|
7918
|
-
sub.callback({
|
|
7919
|
-
accountId: value.pubkey,
|
|
7920
|
-
accountInfo: value.account
|
|
7921
|
-
}, context);
|
|
7922
|
-
return;
|
|
7923
|
-
}
|
|
7924
|
-
}
|
|
8165
|
+
this._handleServerNotification(subscription, [{
|
|
8166
|
+
accountId: result.value.pubkey,
|
|
8167
|
+
accountInfo: result.value.account
|
|
8168
|
+
}, result.context]);
|
|
7925
8169
|
}
|
|
7926
8170
|
/**
|
|
7927
8171
|
* Register a callback to be invoked whenever accounts owned by the
|
|
@@ -7936,36 +8180,30 @@ class Connection {
|
|
|
7936
8180
|
|
|
7937
8181
|
|
|
7938
8182
|
onProgramAccountChange(programId, callback, commitment, filters) {
|
|
7939
|
-
const
|
|
7940
|
-
|
|
7941
|
-
|
|
8183
|
+
const args = this._buildArgs([programId.toBase58()], commitment || this._commitment || 'finalized', // Apply connection/server default.
|
|
8184
|
+
'base64'
|
|
8185
|
+
/* encoding */
|
|
8186
|
+
, filters ? {
|
|
8187
|
+
filters: filters
|
|
8188
|
+
} : undefined
|
|
8189
|
+
/* extra */
|
|
8190
|
+
);
|
|
8191
|
+
|
|
8192
|
+
return this._makeSubscription({
|
|
7942
8193
|
callback,
|
|
7943
|
-
|
|
7944
|
-
|
|
7945
|
-
|
|
7946
|
-
};
|
|
7947
|
-
|
|
7948
|
-
this._updateSubscriptions();
|
|
7949
|
-
|
|
7950
|
-
return id;
|
|
8194
|
+
method: 'programSubscribe',
|
|
8195
|
+
unsubscribeMethod: 'programUnsubscribe'
|
|
8196
|
+
}, args);
|
|
7951
8197
|
}
|
|
7952
8198
|
/**
|
|
7953
8199
|
* Deregister an account notification callback
|
|
7954
8200
|
*
|
|
7955
|
-
* @param id subscription id to deregister
|
|
8201
|
+
* @param id client subscription id to deregister
|
|
7956
8202
|
*/
|
|
7957
8203
|
|
|
7958
8204
|
|
|
7959
|
-
async removeProgramAccountChangeListener(
|
|
7960
|
-
|
|
7961
|
-
const subInfo = this._programAccountChangeSubscriptions[id];
|
|
7962
|
-
delete this._programAccountChangeSubscriptions[id];
|
|
7963
|
-
await this._unsubscribe(subInfo, 'programUnsubscribe');
|
|
7964
|
-
|
|
7965
|
-
this._updateSubscriptions();
|
|
7966
|
-
} else {
|
|
7967
|
-
console.warn(createSubscriptionWarningMessage(id, 'program account change'));
|
|
7968
|
-
}
|
|
8205
|
+
async removeProgramAccountChangeListener(clientSubscriptionId) {
|
|
8206
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'program account change');
|
|
7969
8207
|
}
|
|
7970
8208
|
/**
|
|
7971
8209
|
* Registers a callback to be invoked whenever logs are emitted.
|
|
@@ -7973,35 +8211,26 @@ class Connection {
|
|
|
7973
8211
|
|
|
7974
8212
|
|
|
7975
8213
|
onLogs(filter, callback, commitment) {
|
|
7976
|
-
const
|
|
7977
|
-
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
commitment,
|
|
7981
|
-
subscriptionId: null
|
|
7982
|
-
};
|
|
7983
|
-
|
|
7984
|
-
this._updateSubscriptions();
|
|
8214
|
+
const args = this._buildArgs([typeof filter === 'object' ? {
|
|
8215
|
+
mentions: [filter.toString()]
|
|
8216
|
+
} : filter], commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8217
|
+
);
|
|
7985
8218
|
|
|
7986
|
-
return
|
|
8219
|
+
return this._makeSubscription({
|
|
8220
|
+
callback,
|
|
8221
|
+
method: 'logsSubscribe',
|
|
8222
|
+
unsubscribeMethod: 'logsUnsubscribe'
|
|
8223
|
+
}, args);
|
|
7987
8224
|
}
|
|
7988
8225
|
/**
|
|
7989
8226
|
* Deregister a logs callback.
|
|
7990
8227
|
*
|
|
7991
|
-
* @param id subscription id to deregister.
|
|
8228
|
+
* @param id client subscription id to deregister.
|
|
7992
8229
|
*/
|
|
7993
8230
|
|
|
7994
8231
|
|
|
7995
|
-
async removeOnLogsListener(
|
|
7996
|
-
|
|
7997
|
-
const subInfo = this._logsSubscriptions[id];
|
|
7998
|
-
delete this._logsSubscriptions[id];
|
|
7999
|
-
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
8000
|
-
|
|
8001
|
-
this._updateSubscriptions();
|
|
8002
|
-
} else {
|
|
8003
|
-
console.warn(createSubscriptionWarningMessage(id, 'logs'));
|
|
8004
|
-
}
|
|
8232
|
+
async removeOnLogsListener(clientSubscriptionId) {
|
|
8233
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'logs');
|
|
8005
8234
|
}
|
|
8006
8235
|
/**
|
|
8007
8236
|
* @internal
|
|
@@ -8009,17 +8238,12 @@ class Connection {
|
|
|
8009
8238
|
|
|
8010
8239
|
|
|
8011
8240
|
_wsOnLogsNotification(notification) {
|
|
8012
|
-
const
|
|
8013
|
-
|
|
8014
|
-
|
|
8015
|
-
|
|
8016
|
-
const sub = this._logsSubscriptions[id];
|
|
8241
|
+
const {
|
|
8242
|
+
result,
|
|
8243
|
+
subscription
|
|
8244
|
+
} = create(notification, LogsNotificationResult);
|
|
8017
8245
|
|
|
8018
|
-
|
|
8019
|
-
sub.callback(res.result.value, res.result.context);
|
|
8020
|
-
return;
|
|
8021
|
-
}
|
|
8022
|
-
}
|
|
8246
|
+
this._handleServerNotification(subscription, [result.value, result.context]);
|
|
8023
8247
|
}
|
|
8024
8248
|
/**
|
|
8025
8249
|
* @internal
|
|
@@ -8027,14 +8251,12 @@ class Connection {
|
|
|
8027
8251
|
|
|
8028
8252
|
|
|
8029
8253
|
_wsOnSlotNotification(notification) {
|
|
8030
|
-
const
|
|
8254
|
+
const {
|
|
8255
|
+
result,
|
|
8256
|
+
subscription
|
|
8257
|
+
} = create(notification, SlotNotificationResult);
|
|
8031
8258
|
|
|
8032
|
-
|
|
8033
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8034
|
-
sub.callback(res.result);
|
|
8035
|
-
return;
|
|
8036
|
-
}
|
|
8037
|
-
}
|
|
8259
|
+
this._handleServerNotification(subscription, [result]);
|
|
8038
8260
|
}
|
|
8039
8261
|
/**
|
|
8040
8262
|
* Register a callback to be invoked upon slot changes
|
|
@@ -8045,33 +8267,23 @@ class Connection {
|
|
|
8045
8267
|
|
|
8046
8268
|
|
|
8047
8269
|
onSlotChange(callback) {
|
|
8048
|
-
|
|
8049
|
-
this._slotSubscriptions[id] = {
|
|
8270
|
+
return this._makeSubscription({
|
|
8050
8271
|
callback,
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
return id;
|
|
8272
|
+
method: 'slotSubscribe',
|
|
8273
|
+
unsubscribeMethod: 'slotUnsubscribe'
|
|
8274
|
+
}, []
|
|
8275
|
+
/* args */
|
|
8276
|
+
);
|
|
8057
8277
|
}
|
|
8058
8278
|
/**
|
|
8059
8279
|
* Deregister a slot notification callback
|
|
8060
8280
|
*
|
|
8061
|
-
* @param id subscription id to deregister
|
|
8281
|
+
* @param id client subscription id to deregister
|
|
8062
8282
|
*/
|
|
8063
8283
|
|
|
8064
8284
|
|
|
8065
|
-
async removeSlotChangeListener(
|
|
8066
|
-
|
|
8067
|
-
const subInfo = this._slotSubscriptions[id];
|
|
8068
|
-
delete this._slotSubscriptions[id];
|
|
8069
|
-
await this._unsubscribe(subInfo, 'slotUnsubscribe');
|
|
8070
|
-
|
|
8071
|
-
this._updateSubscriptions();
|
|
8072
|
-
} else {
|
|
8073
|
-
console.warn(createSubscriptionWarningMessage(id, 'slot change'));
|
|
8074
|
-
}
|
|
8285
|
+
async removeSlotChangeListener(clientSubscriptionId) {
|
|
8286
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot change');
|
|
8075
8287
|
}
|
|
8076
8288
|
/**
|
|
8077
8289
|
* @internal
|
|
@@ -8079,14 +8291,12 @@ class Connection {
|
|
|
8079
8291
|
|
|
8080
8292
|
|
|
8081
8293
|
_wsOnSlotUpdatesNotification(notification) {
|
|
8082
|
-
const
|
|
8294
|
+
const {
|
|
8295
|
+
result,
|
|
8296
|
+
subscription
|
|
8297
|
+
} = create(notification, SlotUpdateNotificationResult);
|
|
8083
8298
|
|
|
8084
|
-
|
|
8085
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8086
|
-
sub.callback(res.result);
|
|
8087
|
-
return;
|
|
8088
|
-
}
|
|
8089
|
-
}
|
|
8299
|
+
this._handleServerNotification(subscription, [result]);
|
|
8090
8300
|
}
|
|
8091
8301
|
/**
|
|
8092
8302
|
* Register a callback to be invoked upon slot updates. {@link SlotUpdate}'s
|
|
@@ -8098,32 +8308,36 @@ class Connection {
|
|
|
8098
8308
|
|
|
8099
8309
|
|
|
8100
8310
|
onSlotUpdate(callback) {
|
|
8101
|
-
|
|
8102
|
-
this._slotUpdateSubscriptions[id] = {
|
|
8311
|
+
return this._makeSubscription({
|
|
8103
8312
|
callback,
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
return id;
|
|
8313
|
+
method: 'slotsUpdatesSubscribe',
|
|
8314
|
+
unsubscribeMethod: 'slotsUpdatesUnsubscribe'
|
|
8315
|
+
}, []
|
|
8316
|
+
/* args */
|
|
8317
|
+
);
|
|
8110
8318
|
}
|
|
8111
8319
|
/**
|
|
8112
8320
|
* Deregister a slot update notification callback
|
|
8113
8321
|
*
|
|
8114
|
-
* @param id subscription id to deregister
|
|
8322
|
+
* @param id client subscription id to deregister
|
|
8323
|
+
*/
|
|
8324
|
+
|
|
8325
|
+
|
|
8326
|
+
async removeSlotUpdateListener(clientSubscriptionId) {
|
|
8327
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot update');
|
|
8328
|
+
}
|
|
8329
|
+
/**
|
|
8330
|
+
* @internal
|
|
8115
8331
|
*/
|
|
8116
8332
|
|
|
8117
8333
|
|
|
8118
|
-
async
|
|
8119
|
-
|
|
8120
|
-
const subInfo = this._slotUpdateSubscriptions[id];
|
|
8121
|
-
delete this._slotUpdateSubscriptions[id];
|
|
8122
|
-
await this._unsubscribe(subInfo, 'slotsUpdatesUnsubscribe');
|
|
8334
|
+
async _unsubscribeClientSubscription(clientSubscriptionId, subscriptionName) {
|
|
8335
|
+
const dispose = this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
8123
8336
|
|
|
8124
|
-
|
|
8337
|
+
if (dispose) {
|
|
8338
|
+
await dispose();
|
|
8125
8339
|
} else {
|
|
8126
|
-
console.warn(
|
|
8340
|
+
console.warn('Ignored unsubscribe request because an active subscription with id ' + `\`${clientSubscriptionId}\` for '${subscriptionName}' events ` + 'could not be found.');
|
|
8127
8341
|
}
|
|
8128
8342
|
}
|
|
8129
8343
|
|
|
@@ -8170,30 +8384,34 @@ class Connection {
|
|
|
8170
8384
|
|
|
8171
8385
|
|
|
8172
8386
|
_wsOnSignatureNotification(notification) {
|
|
8173
|
-
const
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8387
|
+
const {
|
|
8388
|
+
result,
|
|
8389
|
+
subscription
|
|
8390
|
+
} = create(notification, SignatureNotificationResult);
|
|
8391
|
+
|
|
8392
|
+
if (result.value !== 'receivedSignature') {
|
|
8393
|
+
/**
|
|
8394
|
+
* Special case.
|
|
8395
|
+
* After a signature is processed, RPCs automatically dispose of the
|
|
8396
|
+
* subscription on the server side. We need to track which of these
|
|
8397
|
+
* subscriptions have been disposed in such a way, so that we know
|
|
8398
|
+
* whether the client is dealing with a not-yet-processed signature
|
|
8399
|
+
* (in which case we must tear down the server subscription) or an
|
|
8400
|
+
* already-processed signature (in which case the client can simply
|
|
8401
|
+
* clear out the subscription locally without telling the server).
|
|
8402
|
+
*
|
|
8403
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
8404
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
8405
|
+
*/
|
|
8406
|
+
this._subscriptionsAutoDisposedByRpc.add(subscription);
|
|
8407
|
+
}
|
|
8408
|
+
|
|
8409
|
+
this._handleServerNotification(subscription, result.value === 'receivedSignature' ? [{
|
|
8410
|
+
type: 'received'
|
|
8411
|
+
}, result.context] : [{
|
|
8412
|
+
type: 'status',
|
|
8413
|
+
result: result.value
|
|
8414
|
+
}, result.context]);
|
|
8197
8415
|
}
|
|
8198
8416
|
/**
|
|
8199
8417
|
* Register a callback to be invoked upon signature updates
|
|
@@ -8206,23 +8424,26 @@ class Connection {
|
|
|
8206
8424
|
|
|
8207
8425
|
|
|
8208
8426
|
onSignature(signature, callback, commitment) {
|
|
8209
|
-
const
|
|
8210
|
-
|
|
8211
|
-
|
|
8427
|
+
const args = this._buildArgs([signature], commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8428
|
+
);
|
|
8429
|
+
|
|
8430
|
+
const clientSubscriptionId = this._makeSubscription({
|
|
8212
8431
|
callback: (notification, context) => {
|
|
8213
8432
|
if (notification.type === 'status') {
|
|
8214
|
-
callback(notification.result, context);
|
|
8433
|
+
callback(notification.result, context); // Signatures subscriptions are auto-removed by the RPC service
|
|
8434
|
+
// so no need to explicitly send an unsubscribe message.
|
|
8435
|
+
|
|
8436
|
+
try {
|
|
8437
|
+
this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
|
|
8438
|
+
} catch {// Already removed.
|
|
8439
|
+
}
|
|
8215
8440
|
}
|
|
8216
8441
|
},
|
|
8217
|
-
|
|
8218
|
-
|
|
8219
|
-
|
|
8220
|
-
subscriptionId: null
|
|
8221
|
-
};
|
|
8222
|
-
|
|
8223
|
-
this._updateSubscriptions();
|
|
8442
|
+
method: 'signatureSubscribe',
|
|
8443
|
+
unsubscribeMethod: 'signatureUnsubscribe'
|
|
8444
|
+
}, args);
|
|
8224
8445
|
|
|
8225
|
-
return
|
|
8446
|
+
return clientSubscriptionId;
|
|
8226
8447
|
}
|
|
8227
8448
|
/**
|
|
8228
8449
|
* Register a callback to be invoked when a transaction is
|
|
@@ -8237,35 +8458,43 @@ class Connection {
|
|
|
8237
8458
|
|
|
8238
8459
|
|
|
8239
8460
|
onSignatureWithOptions(signature, callback, options) {
|
|
8240
|
-
const
|
|
8241
|
-
|
|
8242
|
-
|
|
8243
|
-
|
|
8244
|
-
options
|
|
8245
|
-
|
|
8461
|
+
const {
|
|
8462
|
+
commitment,
|
|
8463
|
+
...extra
|
|
8464
|
+
} = { ...options,
|
|
8465
|
+
commitment: options && options.commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8466
|
+
|
|
8246
8467
|
};
|
|
8247
8468
|
|
|
8248
|
-
this.
|
|
8469
|
+
const args = this._buildArgs([signature], commitment, undefined
|
|
8470
|
+
/* encoding */
|
|
8471
|
+
, extra);
|
|
8472
|
+
|
|
8473
|
+
const clientSubscriptionId = this._makeSubscription({
|
|
8474
|
+
callback: (notification, context) => {
|
|
8475
|
+
callback(notification, context); // Signatures subscriptions are auto-removed by the RPC service
|
|
8476
|
+
// so no need to explicitly send an unsubscribe message.
|
|
8477
|
+
|
|
8478
|
+
try {
|
|
8479
|
+
this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
|
|
8480
|
+
} catch {// Already removed.
|
|
8481
|
+
}
|
|
8482
|
+
},
|
|
8483
|
+
method: 'signatureSubscribe',
|
|
8484
|
+
unsubscribeMethod: 'signatureUnsubscribe'
|
|
8485
|
+
}, args);
|
|
8249
8486
|
|
|
8250
|
-
return
|
|
8487
|
+
return clientSubscriptionId;
|
|
8251
8488
|
}
|
|
8252
8489
|
/**
|
|
8253
8490
|
* Deregister a signature notification callback
|
|
8254
8491
|
*
|
|
8255
|
-
* @param id subscription id to deregister
|
|
8492
|
+
* @param id client subscription id to deregister
|
|
8256
8493
|
*/
|
|
8257
8494
|
|
|
8258
8495
|
|
|
8259
|
-
async removeSignatureListener(
|
|
8260
|
-
|
|
8261
|
-
const subInfo = this._signatureSubscriptions[id];
|
|
8262
|
-
delete this._signatureSubscriptions[id];
|
|
8263
|
-
await this._unsubscribe(subInfo, 'signatureUnsubscribe');
|
|
8264
|
-
|
|
8265
|
-
this._updateSubscriptions();
|
|
8266
|
-
} else {
|
|
8267
|
-
console.warn(createSubscriptionWarningMessage(id, 'signature result'));
|
|
8268
|
-
}
|
|
8496
|
+
async removeSignatureListener(clientSubscriptionId) {
|
|
8497
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'signature result');
|
|
8269
8498
|
}
|
|
8270
8499
|
/**
|
|
8271
8500
|
* @internal
|
|
@@ -8273,14 +8502,12 @@ class Connection {
|
|
|
8273
8502
|
|
|
8274
8503
|
|
|
8275
8504
|
_wsOnRootNotification(notification) {
|
|
8276
|
-
const
|
|
8505
|
+
const {
|
|
8506
|
+
result,
|
|
8507
|
+
subscription
|
|
8508
|
+
} = create(notification, RootNotificationResult);
|
|
8277
8509
|
|
|
8278
|
-
|
|
8279
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8280
|
-
sub.callback(res.result);
|
|
8281
|
-
return;
|
|
8282
|
-
}
|
|
8283
|
-
}
|
|
8510
|
+
this._handleServerNotification(subscription, [result]);
|
|
8284
8511
|
}
|
|
8285
8512
|
/**
|
|
8286
8513
|
* Register a callback to be invoked upon root changes
|
|
@@ -8291,33 +8518,23 @@ class Connection {
|
|
|
8291
8518
|
|
|
8292
8519
|
|
|
8293
8520
|
onRootChange(callback) {
|
|
8294
|
-
|
|
8295
|
-
this._rootSubscriptions[id] = {
|
|
8521
|
+
return this._makeSubscription({
|
|
8296
8522
|
callback,
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
return id;
|
|
8523
|
+
method: 'rootSubscribe',
|
|
8524
|
+
unsubscribeMethod: 'rootUnsubscribe'
|
|
8525
|
+
}, []
|
|
8526
|
+
/* args */
|
|
8527
|
+
);
|
|
8303
8528
|
}
|
|
8304
8529
|
/**
|
|
8305
8530
|
* Deregister a root notification callback
|
|
8306
8531
|
*
|
|
8307
|
-
* @param id subscription id to deregister
|
|
8532
|
+
* @param id client subscription id to deregister
|
|
8308
8533
|
*/
|
|
8309
8534
|
|
|
8310
8535
|
|
|
8311
|
-
async removeRootChangeListener(
|
|
8312
|
-
|
|
8313
|
-
const subInfo = this._rootSubscriptions[id];
|
|
8314
|
-
delete this._rootSubscriptions[id];
|
|
8315
|
-
await this._unsubscribe(subInfo, 'rootUnsubscribe');
|
|
8316
|
-
|
|
8317
|
-
this._updateSubscriptions();
|
|
8318
|
-
} else {
|
|
8319
|
-
console.warn(createSubscriptionWarningMessage(id, 'root change'));
|
|
8320
|
-
}
|
|
8536
|
+
async removeRootChangeListener(clientSubscriptionId) {
|
|
8537
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'root change');
|
|
8321
8538
|
}
|
|
8322
8539
|
|
|
8323
8540
|
}
|
|
@@ -8447,7 +8664,7 @@ class Ed25519Program {
|
|
|
8447
8664
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
8448
8665
|
const messageDataOffset = signatureOffset + signature.length;
|
|
8449
8666
|
const numSignatures = 1;
|
|
8450
|
-
const instructionData = Buffer.alloc(messageDataOffset + message.length);
|
|
8667
|
+
const instructionData = Buffer$1.alloc(messageDataOffset + message.length);
|
|
8451
8668
|
const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
|
|
8452
8669
|
: instructionIndex;
|
|
8453
8670
|
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
@@ -9318,7 +9535,7 @@ class Secp256k1Program {
|
|
|
9318
9535
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
9319
9536
|
|
|
9320
9537
|
try {
|
|
9321
|
-
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
9538
|
+
return Buffer$1.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
9322
9539
|
} catch (error) {
|
|
9323
9540
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
9324
9541
|
}
|
|
@@ -9363,9 +9580,9 @@ class Secp256k1Program {
|
|
|
9363
9580
|
|
|
9364
9581
|
if (typeof rawAddress === 'string') {
|
|
9365
9582
|
if (rawAddress.startsWith('0x')) {
|
|
9366
|
-
ethAddress = Buffer.from(rawAddress.substr(2), 'hex');
|
|
9583
|
+
ethAddress = Buffer$1.from(rawAddress.substr(2), 'hex');
|
|
9367
9584
|
} else {
|
|
9368
|
-
ethAddress = Buffer.from(rawAddress, 'hex');
|
|
9585
|
+
ethAddress = Buffer$1.from(rawAddress, 'hex');
|
|
9369
9586
|
}
|
|
9370
9587
|
} else {
|
|
9371
9588
|
ethAddress = rawAddress;
|
|
@@ -9377,7 +9594,7 @@ class Secp256k1Program {
|
|
|
9377
9594
|
const signatureOffset = dataStart + ethAddress.length;
|
|
9378
9595
|
const messageDataOffset = signatureOffset + signature.length + 1;
|
|
9379
9596
|
const numSignatures = 1;
|
|
9380
|
-
const instructionData = Buffer.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
|
9597
|
+
const instructionData = Buffer$1.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
|
9381
9598
|
SECP256K1_INSTRUCTION_LAYOUT.encode({
|
|
9382
9599
|
numSignatures,
|
|
9383
9600
|
signatureOffset,
|
|
@@ -9416,7 +9633,7 @@ class Secp256k1Program {
|
|
|
9416
9633
|
const privateKey = toBuffer(pkey);
|
|
9417
9634
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
9418
9635
|
|
|
9419
|
-
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
9636
|
+
const messageHash = Buffer$1.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
9420
9637
|
const {
|
|
9421
9638
|
signature,
|
|
9422
9639
|
recid: recoveryId
|
|
@@ -9501,7 +9718,7 @@ class ValidatorInfo {
|
|
|
9501
9718
|
|
|
9502
9719
|
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
|
9503
9720
|
if (configKeys[1].isSigner) {
|
|
9504
|
-
const rawInfo = rustString().decode(Buffer.from(byteArray));
|
|
9721
|
+
const rawInfo = rustString().decode(Buffer$1.from(byteArray));
|
|
9505
9722
|
const info = JSON.parse(rawInfo);
|
|
9506
9723
|
assert$7(info, InfoString);
|
|
9507
9724
|
return new ValidatorInfo(configKeys[1].publicKey, info);
|
|
@@ -9997,5 +10214,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9997
10214
|
|
|
9998
10215
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9999
10216
|
|
|
10000
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, 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, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10217
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, 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, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10001
10218
|
//# sourceMappingURL=index.browser.esm.js.map
|