@solana/web3.js 1.47.3 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -11
- package/lib/index.browser.cjs.js +520 -217
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +518 -218
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +520 -217
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +337 -230
- package/lib/index.esm.js +518 -218
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +582 -279
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +10328 -0
- package/lib/index.native.js.map +1 -0
- package/package.json +3 -1
- package/src/__forks__/react-native/fetch-impl.ts +4 -0
- package/src/address-lookup-table-program.ts +433 -0
- package/src/connection.ts +48 -6
- package/src/index.ts +1 -0
- package/src/layout.ts +16 -4
- package/src/util/__forks__/react-native/url-impl.ts +2 -0
- package/src/util/{url.ts → makeWebsocketUrl.ts} +2 -0
- package/src/util/url-impl.ts +2 -0
package/lib/index.cjs.js
CHANGED
|
@@ -7,8 +7,8 @@ var buffer = require('buffer');
|
|
|
7
7
|
var BN = require('bn.js');
|
|
8
8
|
var bs58 = require('bs58');
|
|
9
9
|
var borsh = require('borsh');
|
|
10
|
-
var BufferLayout = require('@solana/buffer-layout');
|
|
11
10
|
var bigintBuffer = require('bigint-buffer');
|
|
11
|
+
var BufferLayout = require('@solana/buffer-layout');
|
|
12
12
|
var superstruct = require('superstruct');
|
|
13
13
|
var rpcWebsockets = require('rpc-websockets');
|
|
14
14
|
var RpcClient = require('jayson/lib/client/browser');
|
|
@@ -2128,18 +2128,6 @@ class Account {
|
|
|
2128
2128
|
|
|
2129
2129
|
}
|
|
2130
2130
|
|
|
2131
|
-
const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
|
|
2132
|
-
|
|
2133
|
-
/**
|
|
2134
|
-
* Maximum over-the-wire size of a Transaction
|
|
2135
|
-
*
|
|
2136
|
-
* 1280 is IPv6 minimum MTU
|
|
2137
|
-
* 40 bytes is the size of the IPv6 header
|
|
2138
|
-
* 8 bytes is the size of the fragment header
|
|
2139
|
-
*/
|
|
2140
|
-
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2141
|
-
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2142
|
-
|
|
2143
2131
|
/**
|
|
2144
2132
|
* Layout for a public key
|
|
2145
2133
|
*/
|
|
@@ -2201,17 +2189,170 @@ const voteInit = (property = 'voteInit') => {
|
|
|
2201
2189
|
return BufferLayout__namespace.struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), BufferLayout__namespace.u8('commission')], property);
|
|
2202
2190
|
};
|
|
2203
2191
|
function getAlloc(type, fields) {
|
|
2204
|
-
|
|
2205
|
-
type.layout.fields.forEach(item => {
|
|
2192
|
+
const getItemAlloc = item => {
|
|
2206
2193
|
if (item.span >= 0) {
|
|
2207
|
-
|
|
2194
|
+
return item.span;
|
|
2208
2195
|
} else if (typeof item.alloc === 'function') {
|
|
2209
|
-
|
|
2210
|
-
}
|
|
2196
|
+
return item.alloc(fields[item.property]);
|
|
2197
|
+
} else if ('count' in item && 'elementLayout' in item) {
|
|
2198
|
+
const field = fields[item.property];
|
|
2199
|
+
|
|
2200
|
+
if (Array.isArray(field)) {
|
|
2201
|
+
return field.length * getItemAlloc(item.elementLayout);
|
|
2202
|
+
}
|
|
2203
|
+
} // Couldn't determine allocated size of layout
|
|
2204
|
+
|
|
2205
|
+
|
|
2206
|
+
return 0;
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
let alloc = 0;
|
|
2210
|
+
type.layout.fields.forEach(item => {
|
|
2211
|
+
alloc += getItemAlloc(item);
|
|
2211
2212
|
});
|
|
2212
2213
|
return alloc;
|
|
2213
2214
|
}
|
|
2214
2215
|
|
|
2216
|
+
const encodeDecode = layout => {
|
|
2217
|
+
const decode = layout.decode.bind(layout);
|
|
2218
|
+
const encode = layout.encode.bind(layout);
|
|
2219
|
+
return {
|
|
2220
|
+
decode,
|
|
2221
|
+
encode
|
|
2222
|
+
};
|
|
2223
|
+
};
|
|
2224
|
+
|
|
2225
|
+
const bigInt = length => property => {
|
|
2226
|
+
const layout = BufferLayout.blob(length, property);
|
|
2227
|
+
const {
|
|
2228
|
+
encode,
|
|
2229
|
+
decode
|
|
2230
|
+
} = encodeDecode(layout);
|
|
2231
|
+
const bigIntLayout = layout;
|
|
2232
|
+
|
|
2233
|
+
bigIntLayout.decode = (buffer$1, offset) => {
|
|
2234
|
+
const src = decode(buffer$1, offset);
|
|
2235
|
+
return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
|
|
2236
|
+
};
|
|
2237
|
+
|
|
2238
|
+
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
2239
|
+
const src = bigintBuffer.toBufferLE(bigInt, length);
|
|
2240
|
+
return encode(src, buffer, offset);
|
|
2241
|
+
};
|
|
2242
|
+
|
|
2243
|
+
return bigIntLayout;
|
|
2244
|
+
};
|
|
2245
|
+
|
|
2246
|
+
const u64 = bigInt(8);
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* Populate a buffer of instruction data using an InstructionType
|
|
2250
|
+
* @internal
|
|
2251
|
+
*/
|
|
2252
|
+
function encodeData(type, fields) {
|
|
2253
|
+
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
2254
|
+
const data = buffer.Buffer.alloc(allocLength);
|
|
2255
|
+
const layoutFields = Object.assign({
|
|
2256
|
+
instruction: type.index
|
|
2257
|
+
}, fields);
|
|
2258
|
+
type.layout.encode(layoutFields, data);
|
|
2259
|
+
return data;
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Decode instruction data buffer using an InstructionType
|
|
2263
|
+
* @internal
|
|
2264
|
+
*/
|
|
2265
|
+
|
|
2266
|
+
function decodeData(type, buffer) {
|
|
2267
|
+
let data;
|
|
2268
|
+
|
|
2269
|
+
try {
|
|
2270
|
+
data = type.layout.decode(buffer);
|
|
2271
|
+
} catch (err) {
|
|
2272
|
+
throw new Error('invalid instruction; ' + err);
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
if (data.instruction !== type.index) {
|
|
2276
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
return data;
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
/**
|
|
2283
|
+
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
|
2284
|
+
*
|
|
2285
|
+
* @internal
|
|
2286
|
+
*/
|
|
2287
|
+
|
|
2288
|
+
const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
|
|
2289
|
+
/**
|
|
2290
|
+
* Calculator for transaction fees.
|
|
2291
|
+
*/
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
|
|
2295
|
+
*
|
|
2296
|
+
* @internal
|
|
2297
|
+
*/
|
|
2298
|
+
|
|
2299
|
+
const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
2300
|
+
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
2301
|
+
|
|
2302
|
+
/**
|
|
2303
|
+
* NonceAccount class
|
|
2304
|
+
*/
|
|
2305
|
+
class NonceAccount {
|
|
2306
|
+
/**
|
|
2307
|
+
* @internal
|
|
2308
|
+
*/
|
|
2309
|
+
constructor(args) {
|
|
2310
|
+
this.authorizedPubkey = void 0;
|
|
2311
|
+
this.nonce = void 0;
|
|
2312
|
+
this.feeCalculator = void 0;
|
|
2313
|
+
this.authorizedPubkey = args.authorizedPubkey;
|
|
2314
|
+
this.nonce = args.nonce;
|
|
2315
|
+
this.feeCalculator = args.feeCalculator;
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Deserialize NonceAccount from the account data.
|
|
2319
|
+
*
|
|
2320
|
+
* @param buffer account data
|
|
2321
|
+
* @return NonceAccount
|
|
2322
|
+
*/
|
|
2323
|
+
|
|
2324
|
+
|
|
2325
|
+
static fromAccountData(buffer) {
|
|
2326
|
+
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
|
|
2327
|
+
return new NonceAccount({
|
|
2328
|
+
authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
|
|
2329
|
+
nonce: new PublicKey(nonceAccount.nonce).toString(),
|
|
2330
|
+
feeCalculator: nonceAccount.feeCalculator
|
|
2331
|
+
});
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2337
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2338
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2339
|
+
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2340
|
+
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2341
|
+
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2342
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2343
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2344
|
+
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2345
|
+
|
|
2346
|
+
/**
|
|
2347
|
+
* Maximum over-the-wire size of a Transaction
|
|
2348
|
+
*
|
|
2349
|
+
* 1280 is IPv6 minimum MTU
|
|
2350
|
+
* 40 bytes is the size of the IPv6 header
|
|
2351
|
+
* 8 bytes is the size of the fragment header
|
|
2352
|
+
*/
|
|
2353
|
+
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2354
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2355
|
+
|
|
2215
2356
|
function decodeLength(bytes) {
|
|
2216
2357
|
let len = 0;
|
|
2217
2358
|
let size = 0;
|
|
@@ -3096,201 +3237,34 @@ class Transaction {
|
|
|
3096
3237
|
transaction.feePayer = message.accountKeys[0];
|
|
3097
3238
|
}
|
|
3098
3239
|
|
|
3099
|
-
signatures.forEach((signature, index) => {
|
|
3100
|
-
const sigPubkeyPair = {
|
|
3101
|
-
signature: signature == bs58__default["default"].encode(DEFAULT_SIGNATURE) ? null : bs58__default["default"].decode(signature),
|
|
3102
|
-
publicKey: message.accountKeys[index]
|
|
3103
|
-
};
|
|
3104
|
-
transaction.signatures.push(sigPubkeyPair);
|
|
3105
|
-
});
|
|
3106
|
-
message.instructions.forEach(instruction => {
|
|
3107
|
-
const keys = instruction.accounts.map(account => {
|
|
3108
|
-
const pubkey = message.accountKeys[account];
|
|
3109
|
-
return {
|
|
3110
|
-
pubkey,
|
|
3111
|
-
isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
|
|
3112
|
-
isWritable: message.isAccountWritable(account)
|
|
3113
|
-
};
|
|
3114
|
-
});
|
|
3115
|
-
transaction.instructions.push(new TransactionInstruction({
|
|
3116
|
-
keys,
|
|
3117
|
-
programId: message.accountKeys[instruction.programIdIndex],
|
|
3118
|
-
data: bs58__default["default"].decode(instruction.data)
|
|
3119
|
-
}));
|
|
3120
|
-
});
|
|
3121
|
-
transaction._message = message;
|
|
3122
|
-
transaction._json = transaction.toJSON();
|
|
3123
|
-
return transaction;
|
|
3124
|
-
}
|
|
3125
|
-
|
|
3126
|
-
}
|
|
3127
|
-
|
|
3128
|
-
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
3129
|
-
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
3130
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
3131
|
-
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
3132
|
-
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
3133
|
-
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
3134
|
-
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
3135
|
-
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
3136
|
-
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
3137
|
-
|
|
3138
|
-
/**
|
|
3139
|
-
* Sign, send and confirm a transaction.
|
|
3140
|
-
*
|
|
3141
|
-
* If `commitment` option is not specified, defaults to 'max' commitment.
|
|
3142
|
-
*
|
|
3143
|
-
* @param {Connection} connection
|
|
3144
|
-
* @param {Transaction} transaction
|
|
3145
|
-
* @param {Array<Signer>} signers
|
|
3146
|
-
* @param {ConfirmOptions} [options]
|
|
3147
|
-
* @returns {Promise<TransactionSignature>}
|
|
3148
|
-
*/
|
|
3149
|
-
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
3150
|
-
const sendOptions = options && {
|
|
3151
|
-
skipPreflight: options.skipPreflight,
|
|
3152
|
-
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
3153
|
-
maxRetries: options.maxRetries,
|
|
3154
|
-
minContextSlot: options.minContextSlot
|
|
3155
|
-
};
|
|
3156
|
-
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
3157
|
-
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
3158
|
-
signature: signature,
|
|
3159
|
-
blockhash: transaction.recentBlockhash,
|
|
3160
|
-
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
3161
|
-
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
3162
|
-
|
|
3163
|
-
if (status.err) {
|
|
3164
|
-
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
3165
|
-
}
|
|
3166
|
-
|
|
3167
|
-
return signature;
|
|
3168
|
-
}
|
|
3169
|
-
|
|
3170
|
-
// zzz
|
|
3171
|
-
function sleep(ms) {
|
|
3172
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
/**
|
|
3176
|
-
* Populate a buffer of instruction data using an InstructionType
|
|
3177
|
-
* @internal
|
|
3178
|
-
*/
|
|
3179
|
-
function encodeData(type, fields) {
|
|
3180
|
-
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
3181
|
-
const data = buffer.Buffer.alloc(allocLength);
|
|
3182
|
-
const layoutFields = Object.assign({
|
|
3183
|
-
instruction: type.index
|
|
3184
|
-
}, fields);
|
|
3185
|
-
type.layout.encode(layoutFields, data);
|
|
3186
|
-
return data;
|
|
3187
|
-
}
|
|
3188
|
-
/**
|
|
3189
|
-
* Decode instruction data buffer using an InstructionType
|
|
3190
|
-
* @internal
|
|
3191
|
-
*/
|
|
3192
|
-
|
|
3193
|
-
function decodeData(type, buffer) {
|
|
3194
|
-
let data;
|
|
3195
|
-
|
|
3196
|
-
try {
|
|
3197
|
-
data = type.layout.decode(buffer);
|
|
3198
|
-
} catch (err) {
|
|
3199
|
-
throw new Error('invalid instruction; ' + err);
|
|
3200
|
-
}
|
|
3201
|
-
|
|
3202
|
-
if (data.instruction !== type.index) {
|
|
3203
|
-
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
3204
|
-
}
|
|
3205
|
-
|
|
3206
|
-
return data;
|
|
3207
|
-
}
|
|
3208
|
-
|
|
3209
|
-
/**
|
|
3210
|
-
* https://github.com/solana-labs/solana/blob/90bedd7e067b5b8f3ddbb45da00a4e9cabb22c62/sdk/src/fee_calculator.rs#L7-L11
|
|
3211
|
-
*
|
|
3212
|
-
* @internal
|
|
3213
|
-
*/
|
|
3214
|
-
|
|
3215
|
-
const FeeCalculatorLayout = BufferLayout__namespace.nu64('lamportsPerSignature');
|
|
3216
|
-
/**
|
|
3217
|
-
* Calculator for transaction fees.
|
|
3218
|
-
*/
|
|
3219
|
-
|
|
3220
|
-
/**
|
|
3221
|
-
* See https://github.com/solana-labs/solana/blob/0ea2843ec9cdc517572b8e62c959f41b55cf4453/sdk/src/nonce_state.rs#L29-L32
|
|
3222
|
-
*
|
|
3223
|
-
* @internal
|
|
3224
|
-
*/
|
|
3225
|
-
|
|
3226
|
-
const NonceAccountLayout = BufferLayout__namespace.struct([BufferLayout__namespace.u32('version'), BufferLayout__namespace.u32('state'), publicKey('authorizedPubkey'), publicKey('nonce'), BufferLayout__namespace.struct([FeeCalculatorLayout], 'feeCalculator')]);
|
|
3227
|
-
const NONCE_ACCOUNT_LENGTH = NonceAccountLayout.span;
|
|
3228
|
-
|
|
3229
|
-
/**
|
|
3230
|
-
* NonceAccount class
|
|
3231
|
-
*/
|
|
3232
|
-
class NonceAccount {
|
|
3233
|
-
/**
|
|
3234
|
-
* @internal
|
|
3235
|
-
*/
|
|
3236
|
-
constructor(args) {
|
|
3237
|
-
this.authorizedPubkey = void 0;
|
|
3238
|
-
this.nonce = void 0;
|
|
3239
|
-
this.feeCalculator = void 0;
|
|
3240
|
-
this.authorizedPubkey = args.authorizedPubkey;
|
|
3241
|
-
this.nonce = args.nonce;
|
|
3242
|
-
this.feeCalculator = args.feeCalculator;
|
|
3243
|
-
}
|
|
3244
|
-
/**
|
|
3245
|
-
* Deserialize NonceAccount from the account data.
|
|
3246
|
-
*
|
|
3247
|
-
* @param buffer account data
|
|
3248
|
-
* @return NonceAccount
|
|
3249
|
-
*/
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
static fromAccountData(buffer) {
|
|
3253
|
-
const nonceAccount = NonceAccountLayout.decode(toBuffer(buffer), 0);
|
|
3254
|
-
return new NonceAccount({
|
|
3255
|
-
authorizedPubkey: new PublicKey(nonceAccount.authorizedPubkey),
|
|
3256
|
-
nonce: new PublicKey(nonceAccount.nonce).toString(),
|
|
3257
|
-
feeCalculator: nonceAccount.feeCalculator
|
|
3258
|
-
});
|
|
3259
|
-
}
|
|
3260
|
-
|
|
3261
|
-
}
|
|
3262
|
-
|
|
3263
|
-
const encodeDecode = layout => {
|
|
3264
|
-
const decode = layout.decode.bind(layout);
|
|
3265
|
-
const encode = layout.encode.bind(layout);
|
|
3266
|
-
return {
|
|
3267
|
-
decode,
|
|
3268
|
-
encode
|
|
3269
|
-
};
|
|
3270
|
-
};
|
|
3271
|
-
|
|
3272
|
-
const bigInt = length => property => {
|
|
3273
|
-
const layout = BufferLayout.blob(length, property);
|
|
3274
|
-
const {
|
|
3275
|
-
encode,
|
|
3276
|
-
decode
|
|
3277
|
-
} = encodeDecode(layout);
|
|
3278
|
-
const bigIntLayout = layout;
|
|
3279
|
-
|
|
3280
|
-
bigIntLayout.decode = (buffer$1, offset) => {
|
|
3281
|
-
const src = decode(buffer$1, offset);
|
|
3282
|
-
return bigintBuffer.toBigIntLE(buffer.Buffer.from(src));
|
|
3283
|
-
};
|
|
3284
|
-
|
|
3285
|
-
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
3286
|
-
const src = bigintBuffer.toBufferLE(bigInt, length);
|
|
3287
|
-
return encode(src, buffer, offset);
|
|
3288
|
-
};
|
|
3289
|
-
|
|
3290
|
-
return bigIntLayout;
|
|
3291
|
-
};
|
|
3240
|
+
signatures.forEach((signature, index) => {
|
|
3241
|
+
const sigPubkeyPair = {
|
|
3242
|
+
signature: signature == bs58__default["default"].encode(DEFAULT_SIGNATURE) ? null : bs58__default["default"].decode(signature),
|
|
3243
|
+
publicKey: message.accountKeys[index]
|
|
3244
|
+
};
|
|
3245
|
+
transaction.signatures.push(sigPubkeyPair);
|
|
3246
|
+
});
|
|
3247
|
+
message.instructions.forEach(instruction => {
|
|
3248
|
+
const keys = instruction.accounts.map(account => {
|
|
3249
|
+
const pubkey = message.accountKeys[account];
|
|
3250
|
+
return {
|
|
3251
|
+
pubkey,
|
|
3252
|
+
isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
|
|
3253
|
+
isWritable: message.isAccountWritable(account)
|
|
3254
|
+
};
|
|
3255
|
+
});
|
|
3256
|
+
transaction.instructions.push(new TransactionInstruction({
|
|
3257
|
+
keys,
|
|
3258
|
+
programId: message.accountKeys[instruction.programIdIndex],
|
|
3259
|
+
data: bs58__default["default"].decode(instruction.data)
|
|
3260
|
+
}));
|
|
3261
|
+
});
|
|
3262
|
+
transaction._message = message;
|
|
3263
|
+
transaction._json = transaction.toJSON();
|
|
3264
|
+
return transaction;
|
|
3265
|
+
}
|
|
3292
3266
|
|
|
3293
|
-
|
|
3267
|
+
}
|
|
3294
3268
|
|
|
3295
3269
|
/**
|
|
3296
3270
|
* Create account system transaction params
|
|
@@ -4007,6 +3981,312 @@ class SystemProgram {
|
|
|
4007
3981
|
}
|
|
4008
3982
|
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
4009
3983
|
|
|
3984
|
+
/**
|
|
3985
|
+
* An enumeration of valid address lookup table InstructionType's
|
|
3986
|
+
* @internal
|
|
3987
|
+
*/
|
|
3988
|
+
const LOOKUP_TABLE_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
3989
|
+
CreateLookupTable: {
|
|
3990
|
+
index: 0,
|
|
3991
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64('recentSlot'), BufferLayout__namespace.u8('bumpSeed')])
|
|
3992
|
+
},
|
|
3993
|
+
FreezeLookupTable: {
|
|
3994
|
+
index: 1,
|
|
3995
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
|
|
3996
|
+
},
|
|
3997
|
+
ExtendLookupTable: {
|
|
3998
|
+
index: 2,
|
|
3999
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction'), u64(), BufferLayout__namespace.seq(publicKey(), BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'addresses')])
|
|
4000
|
+
},
|
|
4001
|
+
DeactivateLookupTable: {
|
|
4002
|
+
index: 3,
|
|
4003
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
|
|
4004
|
+
},
|
|
4005
|
+
CloseLookupTable: {
|
|
4006
|
+
index: 4,
|
|
4007
|
+
layout: BufferLayout__namespace.struct([BufferLayout__namespace.u32('instruction')])
|
|
4008
|
+
}
|
|
4009
|
+
});
|
|
4010
|
+
class AddressLookupTableInstruction {
|
|
4011
|
+
/**
|
|
4012
|
+
* @internal
|
|
4013
|
+
*/
|
|
4014
|
+
constructor() {}
|
|
4015
|
+
|
|
4016
|
+
static decodeInstructionType(instruction) {
|
|
4017
|
+
this.checkProgramId(instruction.programId);
|
|
4018
|
+
const instructionTypeLayout = BufferLayout__namespace.u32('instruction');
|
|
4019
|
+
const index = instructionTypeLayout.decode(instruction.data);
|
|
4020
|
+
let type;
|
|
4021
|
+
|
|
4022
|
+
for (const [layoutType, layout] of Object.entries(LOOKUP_TABLE_INSTRUCTION_LAYOUTS)) {
|
|
4023
|
+
if (layout.index == index) {
|
|
4024
|
+
type = layoutType;
|
|
4025
|
+
break;
|
|
4026
|
+
}
|
|
4027
|
+
}
|
|
4028
|
+
|
|
4029
|
+
if (!type) {
|
|
4030
|
+
throw new Error('Invalid Instruction. Should be a LookupTable Instruction');
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
return type;
|
|
4034
|
+
}
|
|
4035
|
+
|
|
4036
|
+
static decodeCreateLookupTable(instruction) {
|
|
4037
|
+
this.checkProgramId(instruction.programId);
|
|
4038
|
+
this.checkKeysLength(instruction.keys, 4);
|
|
4039
|
+
const {
|
|
4040
|
+
recentSlot
|
|
4041
|
+
} = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable, instruction.data);
|
|
4042
|
+
return {
|
|
4043
|
+
authority: instruction.keys[1].pubkey,
|
|
4044
|
+
payer: instruction.keys[2].pubkey,
|
|
4045
|
+
recentSlot: Number(recentSlot)
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
|
|
4049
|
+
static decodeExtendLookupTable(instruction) {
|
|
4050
|
+
this.checkProgramId(instruction.programId);
|
|
4051
|
+
|
|
4052
|
+
if (instruction.keys.length < 2) {
|
|
4053
|
+
throw new Error(`invalid instruction; found ${instruction.keys.length} keys, expected at least 2`);
|
|
4054
|
+
}
|
|
4055
|
+
|
|
4056
|
+
const {
|
|
4057
|
+
addresses
|
|
4058
|
+
} = decodeData(LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable, instruction.data);
|
|
4059
|
+
return {
|
|
4060
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4061
|
+
authority: instruction.keys[1].pubkey,
|
|
4062
|
+
payer: instruction.keys.length > 2 ? instruction.keys[2].pubkey : undefined,
|
|
4063
|
+
addresses: addresses.map(buffer => new PublicKey(buffer))
|
|
4064
|
+
};
|
|
4065
|
+
}
|
|
4066
|
+
|
|
4067
|
+
static decodeCloseLookupTable(instruction) {
|
|
4068
|
+
this.checkProgramId(instruction.programId);
|
|
4069
|
+
this.checkKeysLength(instruction.keys, 3);
|
|
4070
|
+
return {
|
|
4071
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4072
|
+
authority: instruction.keys[1].pubkey,
|
|
4073
|
+
recipient: instruction.keys[2].pubkey
|
|
4074
|
+
};
|
|
4075
|
+
}
|
|
4076
|
+
|
|
4077
|
+
static decodeFreezeLookupTable(instruction) {
|
|
4078
|
+
this.checkProgramId(instruction.programId);
|
|
4079
|
+
this.checkKeysLength(instruction.keys, 2);
|
|
4080
|
+
return {
|
|
4081
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4082
|
+
authority: instruction.keys[1].pubkey
|
|
4083
|
+
};
|
|
4084
|
+
}
|
|
4085
|
+
|
|
4086
|
+
static decodeDeactivateLookupTable(instruction) {
|
|
4087
|
+
this.checkProgramId(instruction.programId);
|
|
4088
|
+
this.checkKeysLength(instruction.keys, 2);
|
|
4089
|
+
return {
|
|
4090
|
+
lookupTable: instruction.keys[0].pubkey,
|
|
4091
|
+
authority: instruction.keys[1].pubkey
|
|
4092
|
+
};
|
|
4093
|
+
}
|
|
4094
|
+
/**
|
|
4095
|
+
* @internal
|
|
4096
|
+
*/
|
|
4097
|
+
|
|
4098
|
+
|
|
4099
|
+
static checkProgramId(programId) {
|
|
4100
|
+
if (!programId.equals(AddressLookupTableProgram.programId)) {
|
|
4101
|
+
throw new Error('invalid instruction; programId is not AddressLookupTable Program');
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
/**
|
|
4105
|
+
* @internal
|
|
4106
|
+
*/
|
|
4107
|
+
|
|
4108
|
+
|
|
4109
|
+
static checkKeysLength(keys, expectedLength) {
|
|
4110
|
+
if (keys.length < expectedLength) {
|
|
4111
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
4112
|
+
}
|
|
4113
|
+
}
|
|
4114
|
+
|
|
4115
|
+
}
|
|
4116
|
+
class AddressLookupTableProgram {
|
|
4117
|
+
/**
|
|
4118
|
+
* @internal
|
|
4119
|
+
*/
|
|
4120
|
+
constructor() {}
|
|
4121
|
+
|
|
4122
|
+
static createLookupTable(params) {
|
|
4123
|
+
const [lookupTableAddress, bumpSeed] = PublicKey.findProgramAddressSync([params.authority.toBuffer(), bigintBuffer.toBufferLE(BigInt(params.recentSlot), 8)], this.programId);
|
|
4124
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CreateLookupTable;
|
|
4125
|
+
const data = encodeData(type, {
|
|
4126
|
+
recentSlot: BigInt(params.recentSlot),
|
|
4127
|
+
bumpSeed: bumpSeed
|
|
4128
|
+
});
|
|
4129
|
+
const keys = [{
|
|
4130
|
+
pubkey: lookupTableAddress,
|
|
4131
|
+
isSigner: false,
|
|
4132
|
+
isWritable: true
|
|
4133
|
+
}, {
|
|
4134
|
+
pubkey: params.authority,
|
|
4135
|
+
isSigner: true,
|
|
4136
|
+
isWritable: false
|
|
4137
|
+
}, {
|
|
4138
|
+
pubkey: params.payer,
|
|
4139
|
+
isSigner: true,
|
|
4140
|
+
isWritable: true
|
|
4141
|
+
}, {
|
|
4142
|
+
pubkey: SystemProgram.programId,
|
|
4143
|
+
isSigner: false,
|
|
4144
|
+
isWritable: false
|
|
4145
|
+
}];
|
|
4146
|
+
return [new TransactionInstruction({
|
|
4147
|
+
programId: this.programId,
|
|
4148
|
+
keys: keys,
|
|
4149
|
+
data: data
|
|
4150
|
+
}), lookupTableAddress];
|
|
4151
|
+
}
|
|
4152
|
+
|
|
4153
|
+
static freezeLookupTable(params) {
|
|
4154
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.FreezeLookupTable;
|
|
4155
|
+
const data = encodeData(type);
|
|
4156
|
+
const keys = [{
|
|
4157
|
+
pubkey: params.lookupTable,
|
|
4158
|
+
isSigner: false,
|
|
4159
|
+
isWritable: true
|
|
4160
|
+
}, {
|
|
4161
|
+
pubkey: params.authority,
|
|
4162
|
+
isSigner: true,
|
|
4163
|
+
isWritable: false
|
|
4164
|
+
}];
|
|
4165
|
+
return new TransactionInstruction({
|
|
4166
|
+
programId: this.programId,
|
|
4167
|
+
keys: keys,
|
|
4168
|
+
data: data
|
|
4169
|
+
});
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
static extendLookupTable(params) {
|
|
4173
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.ExtendLookupTable;
|
|
4174
|
+
const data = encodeData(type, {
|
|
4175
|
+
addresses: params.addresses.map(addr => addr.toBytes())
|
|
4176
|
+
});
|
|
4177
|
+
const keys = [{
|
|
4178
|
+
pubkey: params.lookupTable,
|
|
4179
|
+
isSigner: false,
|
|
4180
|
+
isWritable: true
|
|
4181
|
+
}, {
|
|
4182
|
+
pubkey: params.authority,
|
|
4183
|
+
isSigner: true,
|
|
4184
|
+
isWritable: false
|
|
4185
|
+
}];
|
|
4186
|
+
|
|
4187
|
+
if (params.payer) {
|
|
4188
|
+
keys.push({
|
|
4189
|
+
pubkey: params.payer,
|
|
4190
|
+
isSigner: true,
|
|
4191
|
+
isWritable: true
|
|
4192
|
+
}, {
|
|
4193
|
+
pubkey: SystemProgram.programId,
|
|
4194
|
+
isSigner: false,
|
|
4195
|
+
isWritable: false
|
|
4196
|
+
});
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
return new TransactionInstruction({
|
|
4200
|
+
programId: this.programId,
|
|
4201
|
+
keys: keys,
|
|
4202
|
+
data: data
|
|
4203
|
+
});
|
|
4204
|
+
}
|
|
4205
|
+
|
|
4206
|
+
static deactivateLookupTable(params) {
|
|
4207
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.DeactivateLookupTable;
|
|
4208
|
+
const data = encodeData(type);
|
|
4209
|
+
const keys = [{
|
|
4210
|
+
pubkey: params.lookupTable,
|
|
4211
|
+
isSigner: false,
|
|
4212
|
+
isWritable: true
|
|
4213
|
+
}, {
|
|
4214
|
+
pubkey: params.authority,
|
|
4215
|
+
isSigner: true,
|
|
4216
|
+
isWritable: false
|
|
4217
|
+
}];
|
|
4218
|
+
return new TransactionInstruction({
|
|
4219
|
+
programId: this.programId,
|
|
4220
|
+
keys: keys,
|
|
4221
|
+
data: data
|
|
4222
|
+
});
|
|
4223
|
+
}
|
|
4224
|
+
|
|
4225
|
+
static closeLookupTable(params) {
|
|
4226
|
+
const type = LOOKUP_TABLE_INSTRUCTION_LAYOUTS.CloseLookupTable;
|
|
4227
|
+
const data = encodeData(type);
|
|
4228
|
+
const keys = [{
|
|
4229
|
+
pubkey: params.lookupTable,
|
|
4230
|
+
isSigner: false,
|
|
4231
|
+
isWritable: true
|
|
4232
|
+
}, {
|
|
4233
|
+
pubkey: params.authority,
|
|
4234
|
+
isSigner: true,
|
|
4235
|
+
isWritable: false
|
|
4236
|
+
}, {
|
|
4237
|
+
pubkey: params.recipient,
|
|
4238
|
+
isSigner: false,
|
|
4239
|
+
isWritable: true
|
|
4240
|
+
}];
|
|
4241
|
+
return new TransactionInstruction({
|
|
4242
|
+
programId: this.programId,
|
|
4243
|
+
keys: keys,
|
|
4244
|
+
data: data
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4247
|
+
|
|
4248
|
+
}
|
|
4249
|
+
AddressLookupTableProgram.programId = new PublicKey('AddressLookupTab1e1111111111111111111111111');
|
|
4250
|
+
|
|
4251
|
+
const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
|
|
4252
|
+
|
|
4253
|
+
/**
|
|
4254
|
+
* Sign, send and confirm a transaction.
|
|
4255
|
+
*
|
|
4256
|
+
* If `commitment` option is not specified, defaults to 'max' commitment.
|
|
4257
|
+
*
|
|
4258
|
+
* @param {Connection} connection
|
|
4259
|
+
* @param {Transaction} transaction
|
|
4260
|
+
* @param {Array<Signer>} signers
|
|
4261
|
+
* @param {ConfirmOptions} [options]
|
|
4262
|
+
* @returns {Promise<TransactionSignature>}
|
|
4263
|
+
*/
|
|
4264
|
+
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
4265
|
+
const sendOptions = options && {
|
|
4266
|
+
skipPreflight: options.skipPreflight,
|
|
4267
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
4268
|
+
maxRetries: options.maxRetries,
|
|
4269
|
+
minContextSlot: options.minContextSlot
|
|
4270
|
+
};
|
|
4271
|
+
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
4272
|
+
const status = transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null ? (await connection.confirmTransaction({
|
|
4273
|
+
signature: signature,
|
|
4274
|
+
blockhash: transaction.recentBlockhash,
|
|
4275
|
+
lastValidBlockHeight: transaction.lastValidBlockHeight
|
|
4276
|
+
}, options && options.commitment)).value : (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
4277
|
+
|
|
4278
|
+
if (status.err) {
|
|
4279
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
4280
|
+
}
|
|
4281
|
+
|
|
4282
|
+
return signature;
|
|
4283
|
+
}
|
|
4284
|
+
|
|
4285
|
+
// zzz
|
|
4286
|
+
function sleep(ms) {
|
|
4287
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
4288
|
+
}
|
|
4289
|
+
|
|
4010
4290
|
// rest of the Transaction fields
|
|
4011
4291
|
//
|
|
4012
4292
|
// TODO: replace 300 with a proper constant for the size of the other
|
|
@@ -4475,6 +4755,8 @@ var fastStableStringify = function(val) {
|
|
|
4475
4755
|
|
|
4476
4756
|
var fastStableStringify$1 = fastStableStringify;
|
|
4477
4757
|
|
|
4758
|
+
const URL = globalThis.URL;
|
|
4759
|
+
|
|
4478
4760
|
const DESTROY_TIMEOUT_MS = 5000;
|
|
4479
4761
|
class AgentManager {
|
|
4480
4762
|
static _newAgent(useHttps) {
|
|
@@ -4924,7 +5206,11 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
|
|
|
4924
5206
|
data: superstruct.array(superstruct.string()),
|
|
4925
5207
|
rentEpoch: superstruct.optional(superstruct.number())
|
|
4926
5208
|
}))))),
|
|
4927
|
-
unitsConsumed: superstruct.optional(superstruct.number())
|
|
5209
|
+
unitsConsumed: superstruct.optional(superstruct.number()),
|
|
5210
|
+
returnData: superstruct.optional(superstruct.nullable(superstruct.type({
|
|
5211
|
+
programId: superstruct.string(),
|
|
5212
|
+
data: superstruct.tuple([superstruct.string(), superstruct.literal('base64')])
|
|
5213
|
+
})))
|
|
4928
5214
|
}));
|
|
4929
5215
|
|
|
4930
5216
|
/**
|
|
@@ -6810,8 +7096,15 @@ class Connection {
|
|
|
6810
7096
|
*/
|
|
6811
7097
|
|
|
6812
7098
|
|
|
6813
|
-
async getBlock(slot,
|
|
6814
|
-
const
|
|
7099
|
+
async getBlock(slot, rawConfig) {
|
|
7100
|
+
const {
|
|
7101
|
+
commitment,
|
|
7102
|
+
config
|
|
7103
|
+
} = extractCommitmentFromConfig(rawConfig);
|
|
7104
|
+
|
|
7105
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined
|
|
7106
|
+
/* encoding */
|
|
7107
|
+
, config);
|
|
6815
7108
|
|
|
6816
7109
|
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6817
7110
|
const res = superstruct.create(unsafeRes, GetBlockRpcResult);
|
|
@@ -6897,8 +7190,15 @@ class Connection {
|
|
|
6897
7190
|
*/
|
|
6898
7191
|
|
|
6899
7192
|
|
|
6900
|
-
async getTransaction(signature,
|
|
6901
|
-
const
|
|
7193
|
+
async getTransaction(signature, rawConfig) {
|
|
7194
|
+
const {
|
|
7195
|
+
commitment,
|
|
7196
|
+
config
|
|
7197
|
+
} = extractCommitmentFromConfig(rawConfig);
|
|
7198
|
+
|
|
7199
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, undefined
|
|
7200
|
+
/* encoding */
|
|
7201
|
+
, config);
|
|
6902
7202
|
|
|
6903
7203
|
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6904
7204
|
const res = superstruct.create(unsafeRes, GetTransactionRpcResult);
|
|
@@ -10046,6 +10346,8 @@ function clusterApiUrl(cluster, tls) {
|
|
|
10046
10346
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
10047
10347
|
|
|
10048
10348
|
exports.Account = Account;
|
|
10349
|
+
exports.AddressLookupTableInstruction = AddressLookupTableInstruction;
|
|
10350
|
+
exports.AddressLookupTableProgram = AddressLookupTableProgram;
|
|
10049
10351
|
exports.Authorized = Authorized;
|
|
10050
10352
|
exports.BLOCKHASH_CACHE_TIMEOUT_MS = BLOCKHASH_CACHE_TIMEOUT_MS;
|
|
10051
10353
|
exports.BPF_LOADER_DEPRECATED_PROGRAM_ID = BPF_LOADER_DEPRECATED_PROGRAM_ID;
|
|
@@ -10061,6 +10363,7 @@ exports.EpochSchedule = EpochSchedule;
|
|
|
10061
10363
|
exports.FeeCalculatorLayout = FeeCalculatorLayout;
|
|
10062
10364
|
exports.Keypair = Keypair;
|
|
10063
10365
|
exports.LAMPORTS_PER_SOL = LAMPORTS_PER_SOL;
|
|
10366
|
+
exports.LOOKUP_TABLE_INSTRUCTION_LAYOUTS = LOOKUP_TABLE_INSTRUCTION_LAYOUTS;
|
|
10064
10367
|
exports.Loader = Loader;
|
|
10065
10368
|
exports.Lockup = Lockup;
|
|
10066
10369
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|