@solana/web3.js 1.66.1 → 1.66.3
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 +1 -4
- package/lib/index.browser.cjs.js +135 -22
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +135 -22
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +135 -22
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.esm.js +135 -22
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +135 -22
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +1 -1
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +135 -22
- package/lib/index.native.js.map +1 -1
- package/package.json +10 -11
- package/src/bpf-loader.ts +2 -2
- package/src/connection.ts +135 -20
package/lib/index.d.ts
CHANGED
|
@@ -3088,6 +3088,8 @@ declare module '@solana/web3.js' {
|
|
|
3088
3088
|
memo: string | null;
|
|
3089
3089
|
/** The unix timestamp of when the transaction was processed */
|
|
3090
3090
|
blockTime?: number | null;
|
|
3091
|
+
/** Cluster confirmation status, if available. Possible values: `processed`, `confirmed`, `finalized` */
|
|
3092
|
+
confirmationStatus?: TransactionConfirmationStatus;
|
|
3091
3093
|
};
|
|
3092
3094
|
/**
|
|
3093
3095
|
* An object defining headers to be passed to the RPC server
|
|
@@ -3930,12 +3932,12 @@ declare module '@solana/web3.js' {
|
|
|
3930
3932
|
*/
|
|
3931
3933
|
static getMinNumSignatures(dataLength: number): number;
|
|
3932
3934
|
/**
|
|
3933
|
-
* Load a
|
|
3935
|
+
* Load a SBF program
|
|
3934
3936
|
*
|
|
3935
3937
|
* @param connection The connection to use
|
|
3936
3938
|
* @param payer Account that will pay program loading fees
|
|
3937
3939
|
* @param program Account to load the program into
|
|
3938
|
-
* @param elf The entire ELF containing the
|
|
3940
|
+
* @param elf The entire ELF containing the SBF program
|
|
3939
3941
|
* @param loaderProgramId The program id of the BPF loader to use
|
|
3940
3942
|
* @return true if program was loaded successfully, false if program was already loaded
|
|
3941
3943
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -3226,12 +3226,12 @@ class BpfLoader {
|
|
|
3226
3226
|
return Loader.getMinNumSignatures(dataLength);
|
|
3227
3227
|
}
|
|
3228
3228
|
/**
|
|
3229
|
-
* Load a
|
|
3229
|
+
* Load a SBF program
|
|
3230
3230
|
*
|
|
3231
3231
|
* @param connection The connection to use
|
|
3232
3232
|
* @param payer Account that will pay program loading fees
|
|
3233
3233
|
* @param program Account to load the program into
|
|
3234
|
-
* @param elf The entire ELF containing the
|
|
3234
|
+
* @param elf The entire ELF containing the SBF program
|
|
3235
3235
|
* @param loaderProgramId The program id of the BPF loader to use
|
|
3236
3236
|
* @return true if program was loaded successfully, false if program was already loaded
|
|
3237
3237
|
*/
|
|
@@ -4668,6 +4668,10 @@ class Connection {
|
|
|
4668
4668
|
|
|
4669
4669
|
/** @internal */
|
|
4670
4670
|
|
|
4671
|
+
/** @internal */
|
|
4672
|
+
|
|
4673
|
+
/** @internal */
|
|
4674
|
+
|
|
4671
4675
|
/**
|
|
4672
4676
|
* Special case.
|
|
4673
4677
|
* After a signature is processed, RPCs automatically dispose of the
|
|
@@ -4713,6 +4717,8 @@ class Connection {
|
|
|
4713
4717
|
};
|
|
4714
4718
|
this._nextClientSubscriptionId = 0;
|
|
4715
4719
|
this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
|
|
4720
|
+
this._subscriptionHashByClientSubscriptionId = {};
|
|
4721
|
+
this._subscriptionStateChangeCallbacksByHash = {};
|
|
4716
4722
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
4717
4723
|
this._subscriptionsByHash = {};
|
|
4718
4724
|
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
@@ -5242,12 +5248,13 @@ class Connection {
|
|
|
5242
5248
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5243
5249
|
const subscriptionCommitment = commitment || this.commitment;
|
|
5244
5250
|
let timeoutId;
|
|
5245
|
-
let
|
|
5251
|
+
let signatureSubscriptionId;
|
|
5252
|
+
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5246
5253
|
let done = false;
|
|
5247
5254
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5248
5255
|
try {
|
|
5249
|
-
|
|
5250
|
-
|
|
5256
|
+
signatureSubscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
5257
|
+
signatureSubscriptionId = undefined;
|
|
5251
5258
|
const response = {
|
|
5252
5259
|
context,
|
|
5253
5260
|
value: result
|
|
@@ -5258,6 +5265,48 @@ class Connection {
|
|
|
5258
5265
|
response
|
|
5259
5266
|
});
|
|
5260
5267
|
}, subscriptionCommitment);
|
|
5268
|
+
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5269
|
+
if (signatureSubscriptionId == null) {
|
|
5270
|
+
resolveSubscriptionSetup();
|
|
5271
|
+
} else {
|
|
5272
|
+
disposeSignatureSubscriptionStateChangeObserver = this._onSubscriptionStateChange(signatureSubscriptionId, nextState => {
|
|
5273
|
+
if (nextState === 'subscribed') {
|
|
5274
|
+
resolveSubscriptionSetup();
|
|
5275
|
+
}
|
|
5276
|
+
});
|
|
5277
|
+
}
|
|
5278
|
+
});
|
|
5279
|
+
|
|
5280
|
+
(async () => {
|
|
5281
|
+
await subscriptionSetupPromise;
|
|
5282
|
+
if (done) return;
|
|
5283
|
+
const response = await this.getSignatureStatus(rawSignature);
|
|
5284
|
+
if (done) return;
|
|
5285
|
+
|
|
5286
|
+
if (response == null) {
|
|
5287
|
+
return;
|
|
5288
|
+
}
|
|
5289
|
+
|
|
5290
|
+
const {
|
|
5291
|
+
context,
|
|
5292
|
+
value
|
|
5293
|
+
} = response;
|
|
5294
|
+
|
|
5295
|
+
if (value !== null && value !== void 0 && value.err) {
|
|
5296
|
+
reject(value.err);
|
|
5297
|
+
}
|
|
5298
|
+
|
|
5299
|
+
if (value) {
|
|
5300
|
+
done = true;
|
|
5301
|
+
resolve({
|
|
5302
|
+
__type: TransactionStatus.PROCESSED,
|
|
5303
|
+
response: {
|
|
5304
|
+
context,
|
|
5305
|
+
value
|
|
5306
|
+
}
|
|
5307
|
+
});
|
|
5308
|
+
}
|
|
5309
|
+
})();
|
|
5261
5310
|
} catch (err) {
|
|
5262
5311
|
reject(err);
|
|
5263
5312
|
}
|
|
@@ -5330,8 +5379,12 @@ class Connection {
|
|
|
5330
5379
|
} finally {
|
|
5331
5380
|
clearTimeout(timeoutId);
|
|
5332
5381
|
|
|
5333
|
-
if (
|
|
5334
|
-
|
|
5382
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5383
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5384
|
+
}
|
|
5385
|
+
|
|
5386
|
+
if (signatureSubscriptionId) {
|
|
5387
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5335
5388
|
}
|
|
5336
5389
|
}
|
|
5337
5390
|
|
|
@@ -5706,7 +5759,7 @@ class Connection {
|
|
|
5706
5759
|
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
5707
5760
|
|
|
5708
5761
|
if ('error' in res) {
|
|
5709
|
-
throw new SolanaJSONRPCError(res.error, 'failed to get
|
|
5762
|
+
throw new SolanaJSONRPCError(res.error, 'failed to get fee for message');
|
|
5710
5763
|
}
|
|
5711
5764
|
|
|
5712
5765
|
if (res.result === null) {
|
|
@@ -6833,9 +6886,9 @@ class Connection {
|
|
|
6833
6886
|
|
|
6834
6887
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
6835
6888
|
Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
|
|
6836
|
-
this.
|
|
6889
|
+
this._setSubscription(hash, { ...subscription,
|
|
6837
6890
|
state: 'pending'
|
|
6838
|
-
};
|
|
6891
|
+
});
|
|
6839
6892
|
});
|
|
6840
6893
|
}
|
|
6841
6894
|
/**
|
|
@@ -6843,6 +6896,53 @@ class Connection {
|
|
|
6843
6896
|
*/
|
|
6844
6897
|
|
|
6845
6898
|
|
|
6899
|
+
_setSubscription(hash, nextSubscription) {
|
|
6900
|
+
var _this$_subscriptionsB;
|
|
6901
|
+
|
|
6902
|
+
const prevState = (_this$_subscriptionsB = this._subscriptionsByHash[hash]) === null || _this$_subscriptionsB === void 0 ? void 0 : _this$_subscriptionsB.state;
|
|
6903
|
+
this._subscriptionsByHash[hash] = nextSubscription;
|
|
6904
|
+
|
|
6905
|
+
if (prevState !== nextSubscription.state) {
|
|
6906
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6907
|
+
|
|
6908
|
+
if (stateChangeCallbacks) {
|
|
6909
|
+
stateChangeCallbacks.forEach(cb => {
|
|
6910
|
+
try {
|
|
6911
|
+
cb(nextSubscription.state); // eslint-disable-next-line no-empty
|
|
6912
|
+
} catch {}
|
|
6913
|
+
});
|
|
6914
|
+
}
|
|
6915
|
+
}
|
|
6916
|
+
}
|
|
6917
|
+
/**
|
|
6918
|
+
* @internal
|
|
6919
|
+
*/
|
|
6920
|
+
|
|
6921
|
+
|
|
6922
|
+
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
6923
|
+
var _this$_subscriptionSt;
|
|
6924
|
+
|
|
6925
|
+
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
6926
|
+
|
|
6927
|
+
if (hash == null) {
|
|
6928
|
+
return () => {};
|
|
6929
|
+
}
|
|
6930
|
+
|
|
6931
|
+
const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
|
|
6932
|
+
stateChangeCallbacks.add(callback);
|
|
6933
|
+
return () => {
|
|
6934
|
+
stateChangeCallbacks.delete(callback);
|
|
6935
|
+
|
|
6936
|
+
if (stateChangeCallbacks.size === 0) {
|
|
6937
|
+
delete this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6938
|
+
}
|
|
6939
|
+
};
|
|
6940
|
+
}
|
|
6941
|
+
/**
|
|
6942
|
+
* @internal
|
|
6943
|
+
*/
|
|
6944
|
+
|
|
6945
|
+
|
|
6846
6946
|
async _updateSubscriptions() {
|
|
6847
6947
|
if (Object.keys(this._subscriptionsByHash).length === 0) {
|
|
6848
6948
|
if (this._rpcWebSocketConnected) {
|
|
@@ -6928,14 +7028,17 @@ class Connection {
|
|
|
6928
7028
|
} = subscription;
|
|
6929
7029
|
|
|
6930
7030
|
try {
|
|
6931
|
-
this.
|
|
7031
|
+
this._setSubscription(hash, { ...subscription,
|
|
6932
7032
|
state: 'subscribing'
|
|
6933
|
-
};
|
|
7033
|
+
});
|
|
7034
|
+
|
|
6934
7035
|
const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
|
|
6935
|
-
|
|
7036
|
+
|
|
7037
|
+
this._setSubscription(hash, { ...subscription,
|
|
6936
7038
|
serverSubscriptionId,
|
|
6937
7039
|
state: 'subscribed'
|
|
6938
|
-
};
|
|
7040
|
+
});
|
|
7041
|
+
|
|
6939
7042
|
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
6940
7043
|
await this._updateSubscriptions();
|
|
6941
7044
|
} catch (e) {
|
|
@@ -6948,9 +7051,10 @@ class Connection {
|
|
|
6948
7051
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
6949
7052
|
|
|
6950
7053
|
|
|
6951
|
-
this.
|
|
7054
|
+
this._setSubscription(hash, { ...subscription,
|
|
6952
7055
|
state: 'pending'
|
|
6953
|
-
};
|
|
7056
|
+
});
|
|
7057
|
+
|
|
6954
7058
|
await this._updateSubscriptions();
|
|
6955
7059
|
}
|
|
6956
7060
|
})();
|
|
@@ -6979,9 +7083,13 @@ class Connection {
|
|
|
6979
7083
|
*/
|
|
6980
7084
|
this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
|
|
6981
7085
|
} else {
|
|
6982
|
-
this.
|
|
7086
|
+
this._setSubscription(hash, { ...subscription,
|
|
7087
|
+
state: 'unsubscribing'
|
|
7088
|
+
});
|
|
7089
|
+
|
|
7090
|
+
this._setSubscription(hash, { ...subscription,
|
|
6983
7091
|
state: 'unsubscribing'
|
|
6984
|
-
};
|
|
7092
|
+
});
|
|
6985
7093
|
|
|
6986
7094
|
try {
|
|
6987
7095
|
await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
|
|
@@ -6995,17 +7103,19 @@ class Connection {
|
|
|
6995
7103
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
6996
7104
|
|
|
6997
7105
|
|
|
6998
|
-
this.
|
|
7106
|
+
this._setSubscription(hash, { ...subscription,
|
|
6999
7107
|
state: 'subscribed'
|
|
7000
|
-
};
|
|
7108
|
+
});
|
|
7109
|
+
|
|
7001
7110
|
await this._updateSubscriptions();
|
|
7002
7111
|
return;
|
|
7003
7112
|
}
|
|
7004
7113
|
}
|
|
7005
7114
|
|
|
7006
|
-
this.
|
|
7115
|
+
this._setSubscription(hash, { ...subscription,
|
|
7007
7116
|
state: 'unsubscribed'
|
|
7008
|
-
};
|
|
7117
|
+
});
|
|
7118
|
+
|
|
7009
7119
|
await this._updateSubscriptions();
|
|
7010
7120
|
})();
|
|
7011
7121
|
}
|
|
@@ -7098,8 +7208,11 @@ class Connection {
|
|
|
7098
7208
|
existingSubscription.callbacks.add(subscriptionConfig.callback);
|
|
7099
7209
|
}
|
|
7100
7210
|
|
|
7211
|
+
this._subscriptionHashByClientSubscriptionId[clientSubscriptionId] = hash;
|
|
7212
|
+
|
|
7101
7213
|
this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
|
|
7102
7214
|
delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
7215
|
+
delete this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
7103
7216
|
const subscription = this._subscriptionsByHash[hash];
|
|
7104
7217
|
assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
|
|
7105
7218
|
subscription.callbacks.delete(subscriptionConfig.callback);
|