@solana/web3.js 1.39.1 → 1.41.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 +211 -27
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +209 -28
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +211 -27
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +86 -3
- package/lib/index.esm.js +209 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +211 -27
- 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/package.json +3 -3
- package/src/compute-budget.ts +189 -0
- package/src/connection.ts +50 -12
- package/src/index.ts +1 -0
- package/src/publickey.ts +31 -7
- package/src/stake-program.ts +2 -2
- package/src/transaction.ts +5 -6
package/lib/index.browser.esm.js
CHANGED
|
@@ -1893,7 +1893,7 @@ class PublicKey extends Struct {
|
|
|
1893
1893
|
/* eslint-disable require-await */
|
|
1894
1894
|
|
|
1895
1895
|
|
|
1896
|
-
static
|
|
1896
|
+
static createProgramAddressSync(seeds, programId) {
|
|
1897
1897
|
let buffer = Buffer.alloc(0);
|
|
1898
1898
|
seeds.forEach(function (seed) {
|
|
1899
1899
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
@@ -1912,6 +1912,17 @@ class PublicKey extends Struct {
|
|
|
1912
1912
|
|
|
1913
1913
|
return new PublicKey(publicKeyBytes);
|
|
1914
1914
|
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Async version of createProgramAddressSync
|
|
1917
|
+
* For backwards compatibility
|
|
1918
|
+
*/
|
|
1919
|
+
|
|
1920
|
+
/* eslint-disable require-await */
|
|
1921
|
+
|
|
1922
|
+
|
|
1923
|
+
static async createProgramAddress(seeds, programId) {
|
|
1924
|
+
return this.createProgramAddressSync(seeds, programId);
|
|
1925
|
+
}
|
|
1915
1926
|
/**
|
|
1916
1927
|
* Find a valid program address
|
|
1917
1928
|
*
|
|
@@ -1921,14 +1932,14 @@ class PublicKey extends Struct {
|
|
|
1921
1932
|
*/
|
|
1922
1933
|
|
|
1923
1934
|
|
|
1924
|
-
static
|
|
1935
|
+
static findProgramAddressSync(seeds, programId) {
|
|
1925
1936
|
let nonce = 255;
|
|
1926
1937
|
let address;
|
|
1927
1938
|
|
|
1928
1939
|
while (nonce != 0) {
|
|
1929
1940
|
try {
|
|
1930
1941
|
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
|
1931
|
-
address =
|
|
1942
|
+
address = this.createProgramAddressSync(seedsWithNonce, programId);
|
|
1932
1943
|
} catch (err) {
|
|
1933
1944
|
if (err instanceof TypeError) {
|
|
1934
1945
|
throw err;
|
|
@@ -1943,13 +1954,23 @@ class PublicKey extends Struct {
|
|
|
1943
1954
|
|
|
1944
1955
|
throw new Error(`Unable to find a viable program address nonce`);
|
|
1945
1956
|
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Async version of findProgramAddressSync
|
|
1959
|
+
* For backwards compatibility
|
|
1960
|
+
*/
|
|
1961
|
+
|
|
1962
|
+
|
|
1963
|
+
static async findProgramAddress(seeds, programId) {
|
|
1964
|
+
return this.findProgramAddressSync(seeds, programId);
|
|
1965
|
+
}
|
|
1946
1966
|
/**
|
|
1947
1967
|
* Check that a pubkey is on the ed25519 curve.
|
|
1948
1968
|
*/
|
|
1949
1969
|
|
|
1950
1970
|
|
|
1951
|
-
static isOnCurve(
|
|
1952
|
-
|
|
1971
|
+
static isOnCurve(pubkeyData) {
|
|
1972
|
+
const pubkey = new PublicKey(pubkeyData);
|
|
1973
|
+
return is_on_curve(pubkey.toBytes()) == 1;
|
|
1953
1974
|
}
|
|
1954
1975
|
|
|
1955
1976
|
}
|
|
@@ -2436,13 +2457,11 @@ class Transaction {
|
|
|
2436
2457
|
nonceInstruction: this.nonceInfo.nonceInstruction.toJSON()
|
|
2437
2458
|
} : null,
|
|
2438
2459
|
instructions: this.instructions.map(instruction => instruction.toJSON()),
|
|
2439
|
-
|
|
2440
|
-
publicKey
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
signature: signature ? [...signature] : null
|
|
2445
|
-
}))
|
|
2460
|
+
signers: this.signatures.map(({
|
|
2461
|
+
publicKey
|
|
2462
|
+
}) => {
|
|
2463
|
+
return publicKey.toJSON();
|
|
2464
|
+
})
|
|
2446
2465
|
};
|
|
2447
2466
|
}
|
|
2448
2467
|
/**
|
|
@@ -2474,7 +2493,7 @@ class Transaction {
|
|
|
2474
2493
|
compileMessage() {
|
|
2475
2494
|
if (this._message) {
|
|
2476
2495
|
if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
|
|
2477
|
-
throw new Error('Transaction mutated after being populated from Message');
|
|
2496
|
+
throw new Error('Transaction message mutated after being populated from Message');
|
|
2478
2497
|
}
|
|
2479
2498
|
|
|
2480
2499
|
return this._message;
|
|
@@ -4053,6 +4072,136 @@ class BpfLoader {
|
|
|
4053
4072
|
|
|
4054
4073
|
}
|
|
4055
4074
|
|
|
4075
|
+
/**
|
|
4076
|
+
* Compute Budget Instruction class
|
|
4077
|
+
*/
|
|
4078
|
+
|
|
4079
|
+
class ComputeBudgetInstruction {
|
|
4080
|
+
/**
|
|
4081
|
+
* @internal
|
|
4082
|
+
*/
|
|
4083
|
+
constructor() {}
|
|
4084
|
+
/**
|
|
4085
|
+
* Decode a compute budget instruction and retrieve the instruction type.
|
|
4086
|
+
*/
|
|
4087
|
+
|
|
4088
|
+
|
|
4089
|
+
static decodeInstructionType(instruction) {
|
|
4090
|
+
this.checkProgramId(instruction.programId);
|
|
4091
|
+
const instructionTypeLayout = BufferLayout.u8('instruction');
|
|
4092
|
+
const typeIndex = instructionTypeLayout.decode(instruction.data);
|
|
4093
|
+
let type;
|
|
4094
|
+
|
|
4095
|
+
for (const [ixType, layout] of Object.entries(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS)) {
|
|
4096
|
+
if (layout.index == typeIndex) {
|
|
4097
|
+
type = ixType;
|
|
4098
|
+
break;
|
|
4099
|
+
}
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
if (!type) {
|
|
4103
|
+
throw new Error('Instruction type incorrect; not a ComputeBudgetInstruction');
|
|
4104
|
+
}
|
|
4105
|
+
|
|
4106
|
+
return type;
|
|
4107
|
+
}
|
|
4108
|
+
/**
|
|
4109
|
+
* Decode request units compute budget instruction and retrieve the instruction params.
|
|
4110
|
+
*/
|
|
4111
|
+
|
|
4112
|
+
|
|
4113
|
+
static decodeRequestUnits(instruction) {
|
|
4114
|
+
this.checkProgramId(instruction.programId);
|
|
4115
|
+
const {
|
|
4116
|
+
units,
|
|
4117
|
+
additionalFee
|
|
4118
|
+
} = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits, instruction.data);
|
|
4119
|
+
return {
|
|
4120
|
+
units,
|
|
4121
|
+
additionalFee
|
|
4122
|
+
};
|
|
4123
|
+
}
|
|
4124
|
+
/**
|
|
4125
|
+
* Decode request heap frame compute budget instruction and retrieve the instruction params.
|
|
4126
|
+
*/
|
|
4127
|
+
|
|
4128
|
+
|
|
4129
|
+
static decodeRequestHeapFrame(instruction) {
|
|
4130
|
+
this.checkProgramId(instruction.programId);
|
|
4131
|
+
const {
|
|
4132
|
+
bytes
|
|
4133
|
+
} = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame, instruction.data);
|
|
4134
|
+
return {
|
|
4135
|
+
bytes
|
|
4136
|
+
};
|
|
4137
|
+
}
|
|
4138
|
+
/**
|
|
4139
|
+
* @internal
|
|
4140
|
+
*/
|
|
4141
|
+
|
|
4142
|
+
|
|
4143
|
+
static checkProgramId(programId) {
|
|
4144
|
+
if (!programId.equals(ComputeBudgetProgram.programId)) {
|
|
4145
|
+
throw new Error('invalid instruction; programId is not ComputeBudgetProgram');
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4149
|
+
}
|
|
4150
|
+
/**
|
|
4151
|
+
* An enumeration of valid ComputeBudgetInstructionType's
|
|
4152
|
+
*/
|
|
4153
|
+
|
|
4154
|
+
/**
|
|
4155
|
+
* An enumeration of valid ComputeBudget InstructionType's
|
|
4156
|
+
* @internal
|
|
4157
|
+
*/
|
|
4158
|
+
const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
4159
|
+
RequestUnits: {
|
|
4160
|
+
index: 0,
|
|
4161
|
+
layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('units'), BufferLayout.u32('additionalFee')])
|
|
4162
|
+
},
|
|
4163
|
+
RequestHeapFrame: {
|
|
4164
|
+
index: 1,
|
|
4165
|
+
layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')])
|
|
4166
|
+
}
|
|
4167
|
+
});
|
|
4168
|
+
/**
|
|
4169
|
+
* Factory class for transaction instructions to interact with the Compute Budget program
|
|
4170
|
+
*/
|
|
4171
|
+
|
|
4172
|
+
class ComputeBudgetProgram {
|
|
4173
|
+
/**
|
|
4174
|
+
* @internal
|
|
4175
|
+
*/
|
|
4176
|
+
constructor() {}
|
|
4177
|
+
/**
|
|
4178
|
+
* Public key that identifies the Compute Budget program
|
|
4179
|
+
*/
|
|
4180
|
+
|
|
4181
|
+
|
|
4182
|
+
static requestUnits(params) {
|
|
4183
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestUnits;
|
|
4184
|
+
const data = encodeData(type, params);
|
|
4185
|
+
return new TransactionInstruction({
|
|
4186
|
+
keys: [],
|
|
4187
|
+
programId: this.programId,
|
|
4188
|
+
data
|
|
4189
|
+
});
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
static requestHeapFrame(params) {
|
|
4193
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.RequestHeapFrame;
|
|
4194
|
+
const data = encodeData(type, params);
|
|
4195
|
+
return new TransactionInstruction({
|
|
4196
|
+
keys: [],
|
|
4197
|
+
programId: this.programId,
|
|
4198
|
+
data
|
|
4199
|
+
});
|
|
4200
|
+
}
|
|
4201
|
+
|
|
4202
|
+
}
|
|
4203
|
+
ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
|
|
4204
|
+
|
|
4056
4205
|
var browserPonyfill = {exports: {}};
|
|
4057
4206
|
|
|
4058
4207
|
(function (module, exports) {
|
|
@@ -5648,9 +5797,14 @@ const LogsNotificationResult = type({
|
|
|
5648
5797
|
* Filter for log subscriptions.
|
|
5649
5798
|
*/
|
|
5650
5799
|
|
|
5800
|
+
function createSubscriptionWarningMessage(id, label) {
|
|
5801
|
+
return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
|
|
5802
|
+
}
|
|
5651
5803
|
/**
|
|
5652
5804
|
* A connection to a fullnode JSON RPC endpoint
|
|
5653
5805
|
*/
|
|
5806
|
+
|
|
5807
|
+
|
|
5654
5808
|
class Connection {
|
|
5655
5809
|
/** @internal */
|
|
5656
5810
|
|
|
@@ -6850,6 +7004,33 @@ class Connection {
|
|
|
6850
7004
|
});
|
|
6851
7005
|
return res;
|
|
6852
7006
|
}
|
|
7007
|
+
/**
|
|
7008
|
+
* Fetch transaction details for a batch of confirmed transactions.
|
|
7009
|
+
* Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
|
|
7010
|
+
*/
|
|
7011
|
+
|
|
7012
|
+
|
|
7013
|
+
async getTransactions(signatures, commitment) {
|
|
7014
|
+
const batch = signatures.map(signature => {
|
|
7015
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
7016
|
+
|
|
7017
|
+
return {
|
|
7018
|
+
methodName: 'getTransaction',
|
|
7019
|
+
args
|
|
7020
|
+
};
|
|
7021
|
+
});
|
|
7022
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
7023
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
7024
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
7025
|
+
|
|
7026
|
+
if ('error' in res) {
|
|
7027
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
7028
|
+
}
|
|
7029
|
+
|
|
7030
|
+
return res.result;
|
|
7031
|
+
});
|
|
7032
|
+
return res;
|
|
7033
|
+
}
|
|
6853
7034
|
/**
|
|
6854
7035
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6855
7036
|
* for a confirmed block.
|
|
@@ -7719,7 +7900,7 @@ class Connection {
|
|
|
7719
7900
|
|
|
7720
7901
|
this._updateSubscriptions();
|
|
7721
7902
|
} else {
|
|
7722
|
-
|
|
7903
|
+
console.warn(createSubscriptionWarningMessage(id, 'account change'));
|
|
7723
7904
|
}
|
|
7724
7905
|
}
|
|
7725
7906
|
/**
|
|
@@ -7785,7 +7966,7 @@ class Connection {
|
|
|
7785
7966
|
|
|
7786
7967
|
this._updateSubscriptions();
|
|
7787
7968
|
} else {
|
|
7788
|
-
|
|
7969
|
+
console.warn(createSubscriptionWarningMessage(id, 'program account change'));
|
|
7789
7970
|
}
|
|
7790
7971
|
}
|
|
7791
7972
|
/**
|
|
@@ -7814,15 +7995,15 @@ class Connection {
|
|
|
7814
7995
|
|
|
7815
7996
|
|
|
7816
7997
|
async removeOnLogsListener(id) {
|
|
7817
|
-
if (
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
const subInfo = this._logsSubscriptions[id];
|
|
7822
|
-
delete this._logsSubscriptions[id];
|
|
7823
|
-
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
7998
|
+
if (this._logsSubscriptions[id]) {
|
|
7999
|
+
const subInfo = this._logsSubscriptions[id];
|
|
8000
|
+
delete this._logsSubscriptions[id];
|
|
8001
|
+
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
7824
8002
|
|
|
7825
|
-
|
|
8003
|
+
this._updateSubscriptions();
|
|
8004
|
+
} else {
|
|
8005
|
+
console.warn(createSubscriptionWarningMessage(id, 'logs'));
|
|
8006
|
+
}
|
|
7826
8007
|
}
|
|
7827
8008
|
/**
|
|
7828
8009
|
* @internal
|
|
@@ -7891,7 +8072,7 @@ class Connection {
|
|
|
7891
8072
|
|
|
7892
8073
|
this._updateSubscriptions();
|
|
7893
8074
|
} else {
|
|
7894
|
-
|
|
8075
|
+
console.warn(createSubscriptionWarningMessage(id, 'slot change'));
|
|
7895
8076
|
}
|
|
7896
8077
|
}
|
|
7897
8078
|
/**
|
|
@@ -7944,7 +8125,7 @@ class Connection {
|
|
|
7944
8125
|
|
|
7945
8126
|
this._updateSubscriptions();
|
|
7946
8127
|
} else {
|
|
7947
|
-
|
|
8128
|
+
console.warn(createSubscriptionWarningMessage(id, 'slot update'));
|
|
7948
8129
|
}
|
|
7949
8130
|
}
|
|
7950
8131
|
|
|
@@ -8085,7 +8266,7 @@ class Connection {
|
|
|
8085
8266
|
|
|
8086
8267
|
this._updateSubscriptions();
|
|
8087
8268
|
} else {
|
|
8088
|
-
|
|
8269
|
+
console.warn(createSubscriptionWarningMessage(id, 'signature result'));
|
|
8089
8270
|
}
|
|
8090
8271
|
}
|
|
8091
8272
|
/**
|
|
@@ -8137,7 +8318,7 @@ class Connection {
|
|
|
8137
8318
|
|
|
8138
8319
|
this._updateSubscriptions();
|
|
8139
8320
|
} else {
|
|
8140
|
-
|
|
8321
|
+
console.warn(createSubscriptionWarningMessage(id, 'root change'));
|
|
8141
8322
|
}
|
|
8142
8323
|
}
|
|
8143
8324
|
|
|
@@ -9818,5 +9999,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9818
9999
|
|
|
9819
10000
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9820
10001
|
|
|
9821
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10002
|
+
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, 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 };
|
|
9822
10003
|
//# sourceMappingURL=index.browser.esm.js.map
|