@solana/web3.js 1.57.0 → 1.58.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/lib/index.browser.cjs.js +377 -116
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +377 -117
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +377 -116
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +82 -1
- package/lib/index.esm.js +377 -117
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +377 -116
- 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 +377 -116
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +106 -2
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +90 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +147 -0
package/lib/index.iife.js
CHANGED
|
@@ -11087,6 +11087,129 @@ var solanaWeb3 = (function (exports) {
|
|
|
11087
11087
|
}
|
|
11088
11088
|
}
|
|
11089
11089
|
|
|
11090
|
+
function assert$1 (condition, message) {
|
|
11091
|
+
if (!condition) {
|
|
11092
|
+
throw new Error(message || 'Assertion failed');
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
|
|
11096
|
+
class CompiledKeys {
|
|
11097
|
+
constructor(payer, keyMetaMap) {
|
|
11098
|
+
this.payer = void 0;
|
|
11099
|
+
this.keyMetaMap = void 0;
|
|
11100
|
+
this.payer = payer;
|
|
11101
|
+
this.keyMetaMap = keyMetaMap;
|
|
11102
|
+
}
|
|
11103
|
+
|
|
11104
|
+
static compile(instructions, payer) {
|
|
11105
|
+
const keyMetaMap = new Map();
|
|
11106
|
+
|
|
11107
|
+
const getOrInsertDefault = pubkey => {
|
|
11108
|
+
const address = pubkey.toBase58();
|
|
11109
|
+
let keyMeta = keyMetaMap.get(address);
|
|
11110
|
+
|
|
11111
|
+
if (keyMeta === undefined) {
|
|
11112
|
+
keyMeta = {
|
|
11113
|
+
isSigner: false,
|
|
11114
|
+
isWritable: false,
|
|
11115
|
+
isInvoked: false
|
|
11116
|
+
};
|
|
11117
|
+
keyMetaMap.set(address, keyMeta);
|
|
11118
|
+
}
|
|
11119
|
+
|
|
11120
|
+
return keyMeta;
|
|
11121
|
+
};
|
|
11122
|
+
|
|
11123
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
11124
|
+
payerKeyMeta.isSigner = true;
|
|
11125
|
+
payerKeyMeta.isWritable = true;
|
|
11126
|
+
|
|
11127
|
+
for (const ix of instructions) {
|
|
11128
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
11129
|
+
|
|
11130
|
+
for (const accountMeta of ix.keys) {
|
|
11131
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
11132
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
11133
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
11134
|
+
}
|
|
11135
|
+
}
|
|
11136
|
+
|
|
11137
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
11138
|
+
}
|
|
11139
|
+
|
|
11140
|
+
getMessageComponents() {
|
|
11141
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
11142
|
+
assert$1(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
11143
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
11144
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
11145
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
11146
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
11147
|
+
const header = {
|
|
11148
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
11149
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
11150
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
11151
|
+
}; // sanity checks
|
|
11152
|
+
|
|
11153
|
+
{
|
|
11154
|
+
assert$1(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
11155
|
+
const [payerAddress] = writableSigners[0];
|
|
11156
|
+
assert$1(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
11157
|
+
}
|
|
11158
|
+
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
11159
|
+
return [header, staticAccountKeys];
|
|
11160
|
+
}
|
|
11161
|
+
|
|
11162
|
+
extractTableLookup(lookupTable) {
|
|
11163
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
11164
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
11165
|
+
|
|
11166
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
11167
|
+
return;
|
|
11168
|
+
}
|
|
11169
|
+
|
|
11170
|
+
return [{
|
|
11171
|
+
accountKey: lookupTable.key,
|
|
11172
|
+
writableIndexes,
|
|
11173
|
+
readonlyIndexes
|
|
11174
|
+
}, {
|
|
11175
|
+
writable: drainedWritableKeys,
|
|
11176
|
+
readonly: drainedReadonlyKeys
|
|
11177
|
+
}];
|
|
11178
|
+
}
|
|
11179
|
+
/** @internal */
|
|
11180
|
+
|
|
11181
|
+
|
|
11182
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
11183
|
+
const lookupTableIndexes = new Array();
|
|
11184
|
+
const drainedKeys = new Array();
|
|
11185
|
+
|
|
11186
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
11187
|
+
if (keyMetaFilter(keyMeta)) {
|
|
11188
|
+
const key = new PublicKey(address);
|
|
11189
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
11190
|
+
|
|
11191
|
+
if (lookupTableIndex >= 0) {
|
|
11192
|
+
assert$1(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
11193
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
11194
|
+
drainedKeys.push(key);
|
|
11195
|
+
this.keyMetaMap.delete(address);
|
|
11196
|
+
}
|
|
11197
|
+
}
|
|
11198
|
+
}
|
|
11199
|
+
|
|
11200
|
+
return [lookupTableIndexes, drainedKeys];
|
|
11201
|
+
}
|
|
11202
|
+
|
|
11203
|
+
}
|
|
11204
|
+
|
|
11205
|
+
/**
|
|
11206
|
+
* An instruction to execute by a program
|
|
11207
|
+
*
|
|
11208
|
+
* @property {number} programIdIndex
|
|
11209
|
+
* @property {number[]} accounts
|
|
11210
|
+
* @property {string} data
|
|
11211
|
+
*/
|
|
11212
|
+
|
|
11090
11213
|
/**
|
|
11091
11214
|
* List of instructions to be processed atomically
|
|
11092
11215
|
*/
|
|
@@ -11124,6 +11247,27 @@ var solanaWeb3 = (function (exports) {
|
|
|
11124
11247
|
return [];
|
|
11125
11248
|
}
|
|
11126
11249
|
|
|
11250
|
+
getAccountKeys() {
|
|
11251
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
11252
|
+
}
|
|
11253
|
+
|
|
11254
|
+
static compile(args) {
|
|
11255
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
11256
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
11257
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
11258
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
11259
|
+
programIdIndex: ix.programIdIndex,
|
|
11260
|
+
accounts: ix.accountKeyIndexes,
|
|
11261
|
+
data: bs58$1.encode(ix.data)
|
|
11262
|
+
}));
|
|
11263
|
+
return new Message({
|
|
11264
|
+
header,
|
|
11265
|
+
accountKeys: staticAccountKeys,
|
|
11266
|
+
recentBlockhash: args.recentBlockhash,
|
|
11267
|
+
instructions
|
|
11268
|
+
});
|
|
11269
|
+
}
|
|
11270
|
+
|
|
11127
11271
|
isAccountSigner(index) {
|
|
11128
11272
|
return index < this.header.numRequiredSignatures;
|
|
11129
11273
|
}
|
|
@@ -11213,7 +11357,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
11213
11357
|
for (let i = 0; i < accountCount; i++) {
|
|
11214
11358
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
11215
11359
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
11216
|
-
accountKeys.push(
|
|
11360
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
11217
11361
|
}
|
|
11218
11362
|
|
|
11219
11363
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -11252,141 +11396,87 @@ var solanaWeb3 = (function (exports) {
|
|
|
11252
11396
|
|
|
11253
11397
|
}
|
|
11254
11398
|
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
}
|
|
11259
|
-
}
|
|
11399
|
+
/**
|
|
11400
|
+
* Message constructor arguments
|
|
11401
|
+
*/
|
|
11260
11402
|
|
|
11261
|
-
class
|
|
11262
|
-
constructor(
|
|
11263
|
-
this.
|
|
11264
|
-
this.
|
|
11265
|
-
this.
|
|
11266
|
-
this.
|
|
11403
|
+
class MessageV0 {
|
|
11404
|
+
constructor(args) {
|
|
11405
|
+
this.header = void 0;
|
|
11406
|
+
this.staticAccountKeys = void 0;
|
|
11407
|
+
this.recentBlockhash = void 0;
|
|
11408
|
+
this.compiledInstructions = void 0;
|
|
11409
|
+
this.addressTableLookups = void 0;
|
|
11410
|
+
this.header = args.header;
|
|
11411
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
11412
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
11413
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
11414
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
11267
11415
|
}
|
|
11268
11416
|
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
const getOrInsertDefault = pubkey => {
|
|
11273
|
-
const address = pubkey.toBase58();
|
|
11274
|
-
let keyMeta = keyMetaMap.get(address);
|
|
11275
|
-
|
|
11276
|
-
if (keyMeta === undefined) {
|
|
11277
|
-
keyMeta = {
|
|
11278
|
-
isSigner: false,
|
|
11279
|
-
isWritable: false,
|
|
11280
|
-
isInvoked: false
|
|
11281
|
-
};
|
|
11282
|
-
keyMetaMap.set(address, keyMeta);
|
|
11283
|
-
}
|
|
11284
|
-
|
|
11285
|
-
return keyMeta;
|
|
11286
|
-
};
|
|
11287
|
-
|
|
11288
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
11289
|
-
payerKeyMeta.isSigner = true;
|
|
11290
|
-
payerKeyMeta.isWritable = true;
|
|
11417
|
+
get version() {
|
|
11418
|
+
return 0;
|
|
11419
|
+
}
|
|
11291
11420
|
|
|
11292
|
-
|
|
11293
|
-
|
|
11421
|
+
get numAccountKeysFromLookups() {
|
|
11422
|
+
let count = 0;
|
|
11294
11423
|
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
11298
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
11299
|
-
}
|
|
11424
|
+
for (const lookup of this.addressTableLookups) {
|
|
11425
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
11300
11426
|
}
|
|
11301
11427
|
|
|
11302
|
-
return
|
|
11428
|
+
return count;
|
|
11303
11429
|
}
|
|
11304
11430
|
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
assert$1(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
11308
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
11309
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
11310
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
11311
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
11312
|
-
const header = {
|
|
11313
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
11314
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
11315
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
11316
|
-
}; // sanity checks
|
|
11317
|
-
|
|
11318
|
-
{
|
|
11319
|
-
assert$1(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
11320
|
-
const [payerAddress] = writableSigners[0];
|
|
11321
|
-
assert$1(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
11322
|
-
}
|
|
11323
|
-
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
11324
|
-
return [header, staticAccountKeys];
|
|
11325
|
-
}
|
|
11431
|
+
getAccountKeys(args) {
|
|
11432
|
+
let accountKeysFromLookups;
|
|
11326
11433
|
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11434
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
11435
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
11436
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
11437
|
+
}
|
|
11330
11438
|
|
|
11331
|
-
|
|
11332
|
-
|
|
11439
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
11440
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
11441
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
11442
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
11443
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
11333
11444
|
}
|
|
11334
11445
|
|
|
11335
|
-
return
|
|
11336
|
-
accountKey: lookupTable.key,
|
|
11337
|
-
writableIndexes,
|
|
11338
|
-
readonlyIndexes
|
|
11339
|
-
}, {
|
|
11340
|
-
writable: drainedWritableKeys,
|
|
11341
|
-
readonly: drainedReadonlyKeys
|
|
11342
|
-
}];
|
|
11446
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
11343
11447
|
}
|
|
11344
|
-
/** @internal */
|
|
11345
11448
|
|
|
11449
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
11450
|
+
const accountKeysFromLookups = {
|
|
11451
|
+
writable: [],
|
|
11452
|
+
readonly: []
|
|
11453
|
+
};
|
|
11346
11454
|
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
const drainedKeys = new Array();
|
|
11455
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
11456
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
11350
11457
|
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
11458
|
+
if (!tableAccount) {
|
|
11459
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
11460
|
+
}
|
|
11355
11461
|
|
|
11356
|
-
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
|
|
11360
|
-
|
|
11462
|
+
for (const index of tableLookup.writableIndexes) {
|
|
11463
|
+
if (index < tableAccount.state.addresses.length) {
|
|
11464
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
11465
|
+
} else {
|
|
11466
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
11361
11467
|
}
|
|
11362
11468
|
}
|
|
11363
|
-
}
|
|
11364
|
-
|
|
11365
|
-
return [lookupTableIndexes, drainedKeys];
|
|
11366
|
-
}
|
|
11367
|
-
|
|
11368
|
-
}
|
|
11369
|
-
|
|
11370
|
-
/**
|
|
11371
|
-
* Message constructor arguments
|
|
11372
|
-
*/
|
|
11373
11469
|
|
|
11374
|
-
|
|
11375
|
-
|
|
11376
|
-
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
11383
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
11384
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
11385
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
11386
|
-
}
|
|
11470
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
11471
|
+
if (index < tableAccount.state.addresses.length) {
|
|
11472
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
11473
|
+
} else {
|
|
11474
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
11475
|
+
}
|
|
11476
|
+
}
|
|
11477
|
+
}
|
|
11387
11478
|
|
|
11388
|
-
|
|
11389
|
-
return 0;
|
|
11479
|
+
return accountKeysFromLookups;
|
|
11390
11480
|
}
|
|
11391
11481
|
|
|
11392
11482
|
static compile(args) {
|
|
@@ -12318,6 +12408,114 @@ var solanaWeb3 = (function (exports) {
|
|
|
12318
12408
|
|
|
12319
12409
|
}
|
|
12320
12410
|
|
|
12411
|
+
class TransactionMessage {
|
|
12412
|
+
constructor(args) {
|
|
12413
|
+
this.accountKeys = void 0;
|
|
12414
|
+
this.instructions = void 0;
|
|
12415
|
+
this.recentBlockhash = void 0;
|
|
12416
|
+
this.accountKeys = args.accountKeys;
|
|
12417
|
+
this.instructions = args.instructions;
|
|
12418
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
12419
|
+
}
|
|
12420
|
+
|
|
12421
|
+
static decompile(message, args) {
|
|
12422
|
+
const {
|
|
12423
|
+
header,
|
|
12424
|
+
compiledInstructions,
|
|
12425
|
+
recentBlockhash
|
|
12426
|
+
} = message;
|
|
12427
|
+
const {
|
|
12428
|
+
numRequiredSignatures,
|
|
12429
|
+
numReadonlySignedAccounts,
|
|
12430
|
+
numReadonlyUnsignedAccounts
|
|
12431
|
+
} = header;
|
|
12432
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
12433
|
+
assert$1(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
12434
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
12435
|
+
assert$1(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
12436
|
+
const accountKeys = message.getAccountKeys(args);
|
|
12437
|
+
const instructions = [];
|
|
12438
|
+
|
|
12439
|
+
for (const compiledIx of compiledInstructions) {
|
|
12440
|
+
const keys = [];
|
|
12441
|
+
|
|
12442
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
12443
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
12444
|
+
|
|
12445
|
+
if (pubkey === undefined) {
|
|
12446
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
12447
|
+
}
|
|
12448
|
+
|
|
12449
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
12450
|
+
let isWritable;
|
|
12451
|
+
|
|
12452
|
+
if (isSigner) {
|
|
12453
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
12454
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
12455
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
12456
|
+
} else {
|
|
12457
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
12458
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
12459
|
+
}
|
|
12460
|
+
|
|
12461
|
+
keys.push({
|
|
12462
|
+
pubkey,
|
|
12463
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
12464
|
+
isWritable
|
|
12465
|
+
});
|
|
12466
|
+
}
|
|
12467
|
+
|
|
12468
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
12469
|
+
|
|
12470
|
+
if (programId === undefined) {
|
|
12471
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
12472
|
+
}
|
|
12473
|
+
|
|
12474
|
+
instructions.push(new TransactionInstruction({
|
|
12475
|
+
programId,
|
|
12476
|
+
data: toBuffer(compiledIx.data),
|
|
12477
|
+
keys
|
|
12478
|
+
}));
|
|
12479
|
+
}
|
|
12480
|
+
|
|
12481
|
+
return new TransactionMessage({
|
|
12482
|
+
accountKeys,
|
|
12483
|
+
instructions,
|
|
12484
|
+
recentBlockhash
|
|
12485
|
+
});
|
|
12486
|
+
}
|
|
12487
|
+
|
|
12488
|
+
compileToLegacyMessage() {
|
|
12489
|
+
const payerKey = this.accountKeys.get(0);
|
|
12490
|
+
|
|
12491
|
+
if (payerKey === undefined) {
|
|
12492
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
12493
|
+
}
|
|
12494
|
+
|
|
12495
|
+
return Message.compile({
|
|
12496
|
+
payerKey,
|
|
12497
|
+
recentBlockhash: this.recentBlockhash,
|
|
12498
|
+
instructions: this.instructions
|
|
12499
|
+
});
|
|
12500
|
+
}
|
|
12501
|
+
|
|
12502
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
12503
|
+
const payerKey = this.accountKeys.get(0);
|
|
12504
|
+
|
|
12505
|
+
if (payerKey === undefined) {
|
|
12506
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
12507
|
+
}
|
|
12508
|
+
|
|
12509
|
+
return MessageV0.compile({
|
|
12510
|
+
payerKey,
|
|
12511
|
+
recentBlockhash: this.recentBlockhash,
|
|
12512
|
+
instructions: this.instructions,
|
|
12513
|
+
addressLookupTableAccounts
|
|
12514
|
+
});
|
|
12515
|
+
}
|
|
12516
|
+
|
|
12517
|
+
}
|
|
12518
|
+
|
|
12321
12519
|
/**
|
|
12322
12520
|
* Versioned transaction class
|
|
12323
12521
|
*/
|
|
@@ -19786,10 +19984,44 @@ var solanaWeb3 = (function (exports) {
|
|
|
19786
19984
|
}
|
|
19787
19985
|
/**
|
|
19788
19986
|
* Simulate a transaction
|
|
19987
|
+
*
|
|
19988
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
19989
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
19789
19990
|
*/
|
|
19790
19991
|
|
|
19791
19992
|
|
|
19792
|
-
|
|
19993
|
+
/**
|
|
19994
|
+
* Simulate a transaction
|
|
19995
|
+
*/
|
|
19996
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
19997
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
19998
|
+
if ('message' in transactionOrMessage) {
|
|
19999
|
+
const versionedTx = transactionOrMessage;
|
|
20000
|
+
const wireTransaction = versionedTx.serialize();
|
|
20001
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
20002
|
+
|
|
20003
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
20004
|
+
throw new Error('Invalid arguments');
|
|
20005
|
+
}
|
|
20006
|
+
|
|
20007
|
+
const config = configOrSigners || {};
|
|
20008
|
+
config.encoding = 'base64';
|
|
20009
|
+
|
|
20010
|
+
if (!('commitment' in config)) {
|
|
20011
|
+
config.commitment = this.commitment;
|
|
20012
|
+
}
|
|
20013
|
+
|
|
20014
|
+
const args = [encodedTransaction, config];
|
|
20015
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
20016
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
20017
|
+
|
|
20018
|
+
if ('error' in res) {
|
|
20019
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
20020
|
+
}
|
|
20021
|
+
|
|
20022
|
+
return res.result;
|
|
20023
|
+
}
|
|
20024
|
+
|
|
19793
20025
|
let transaction;
|
|
19794
20026
|
|
|
19795
20027
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -19805,6 +20037,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
19805
20037
|
transaction._message = transaction._json = undefined;
|
|
19806
20038
|
}
|
|
19807
20039
|
|
|
20040
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
20041
|
+
throw new Error('Invalid arguments');
|
|
20042
|
+
}
|
|
20043
|
+
|
|
20044
|
+
const signers = configOrSigners;
|
|
20045
|
+
|
|
19808
20046
|
if (transaction.nonceInfo && signers) {
|
|
19809
20047
|
transaction.sign(...signers);
|
|
19810
20048
|
} else {
|
|
@@ -19885,12 +20123,34 @@ var solanaWeb3 = (function (exports) {
|
|
|
19885
20123
|
|
|
19886
20124
|
return res.result;
|
|
19887
20125
|
}
|
|
20126
|
+
/**
|
|
20127
|
+
* Sign and send a transaction
|
|
20128
|
+
*
|
|
20129
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
20130
|
+
* VersionedTransaction}
|
|
20131
|
+
*/
|
|
20132
|
+
|
|
20133
|
+
|
|
19888
20134
|
/**
|
|
19889
20135
|
* Sign and send a transaction
|
|
19890
20136
|
*/
|
|
20137
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
20138
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
20139
|
+
if ('message' in transaction) {
|
|
20140
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
20141
|
+
throw new Error('Invalid arguments');
|
|
20142
|
+
}
|
|
20143
|
+
|
|
20144
|
+
const wireTransaction = transaction.serialize();
|
|
20145
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
20146
|
+
}
|
|
20147
|
+
|
|
20148
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
20149
|
+
throw new Error('Invalid arguments');
|
|
20150
|
+
}
|
|
19891
20151
|
|
|
20152
|
+
const signers = signersOrOptions;
|
|
19892
20153
|
|
|
19893
|
-
async sendTransaction(transaction, signers, options) {
|
|
19894
20154
|
if (transaction.nonceInfo) {
|
|
19895
20155
|
transaction.sign(...signers);
|
|
19896
20156
|
} else {
|
|
@@ -24648,6 +24908,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
24648
24908
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
24649
24909
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
24650
24910
|
exports.TransactionInstruction = TransactionInstruction;
|
|
24911
|
+
exports.TransactionMessage = TransactionMessage;
|
|
24651
24912
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
24652
24913
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
24653
24914
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|