@solana/web3.js 1.66.2 → 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 +134 -21
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +134 -21
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +134 -21
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.esm.js +134 -21
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +134 -21
- 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 +134 -21
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/bpf-loader.ts +2 -2
- package/src/connection.ts +134 -19
package/lib/index.cjs.js
CHANGED
|
@@ -3259,12 +3259,12 @@ class BpfLoader {
|
|
|
3259
3259
|
return Loader.getMinNumSignatures(dataLength);
|
|
3260
3260
|
}
|
|
3261
3261
|
/**
|
|
3262
|
-
* Load a
|
|
3262
|
+
* Load a SBF program
|
|
3263
3263
|
*
|
|
3264
3264
|
* @param connection The connection to use
|
|
3265
3265
|
* @param payer Account that will pay program loading fees
|
|
3266
3266
|
* @param program Account to load the program into
|
|
3267
|
-
* @param elf The entire ELF containing the
|
|
3267
|
+
* @param elf The entire ELF containing the SBF program
|
|
3268
3268
|
* @param loaderProgramId The program id of the BPF loader to use
|
|
3269
3269
|
* @return true if program was loaded successfully, false if program was already loaded
|
|
3270
3270
|
*/
|
|
@@ -4701,6 +4701,10 @@ class Connection {
|
|
|
4701
4701
|
|
|
4702
4702
|
/** @internal */
|
|
4703
4703
|
|
|
4704
|
+
/** @internal */
|
|
4705
|
+
|
|
4706
|
+
/** @internal */
|
|
4707
|
+
|
|
4704
4708
|
/**
|
|
4705
4709
|
* Special case.
|
|
4706
4710
|
* After a signature is processed, RPCs automatically dispose of the
|
|
@@ -4746,6 +4750,8 @@ class Connection {
|
|
|
4746
4750
|
};
|
|
4747
4751
|
this._nextClientSubscriptionId = 0;
|
|
4748
4752
|
this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
|
|
4753
|
+
this._subscriptionHashByClientSubscriptionId = {};
|
|
4754
|
+
this._subscriptionStateChangeCallbacksByHash = {};
|
|
4749
4755
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
4750
4756
|
this._subscriptionsByHash = {};
|
|
4751
4757
|
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
@@ -5275,12 +5281,13 @@ class Connection {
|
|
|
5275
5281
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5276
5282
|
const subscriptionCommitment = commitment || this.commitment;
|
|
5277
5283
|
let timeoutId;
|
|
5278
|
-
let
|
|
5284
|
+
let signatureSubscriptionId;
|
|
5285
|
+
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5279
5286
|
let done = false;
|
|
5280
5287
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5281
5288
|
try {
|
|
5282
|
-
|
|
5283
|
-
|
|
5289
|
+
signatureSubscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
5290
|
+
signatureSubscriptionId = undefined;
|
|
5284
5291
|
const response = {
|
|
5285
5292
|
context,
|
|
5286
5293
|
value: result
|
|
@@ -5291,6 +5298,48 @@ class Connection {
|
|
|
5291
5298
|
response
|
|
5292
5299
|
});
|
|
5293
5300
|
}, subscriptionCommitment);
|
|
5301
|
+
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5302
|
+
if (signatureSubscriptionId == null) {
|
|
5303
|
+
resolveSubscriptionSetup();
|
|
5304
|
+
} else {
|
|
5305
|
+
disposeSignatureSubscriptionStateChangeObserver = this._onSubscriptionStateChange(signatureSubscriptionId, nextState => {
|
|
5306
|
+
if (nextState === 'subscribed') {
|
|
5307
|
+
resolveSubscriptionSetup();
|
|
5308
|
+
}
|
|
5309
|
+
});
|
|
5310
|
+
}
|
|
5311
|
+
});
|
|
5312
|
+
|
|
5313
|
+
(async () => {
|
|
5314
|
+
await subscriptionSetupPromise;
|
|
5315
|
+
if (done) return;
|
|
5316
|
+
const response = await this.getSignatureStatus(rawSignature);
|
|
5317
|
+
if (done) return;
|
|
5318
|
+
|
|
5319
|
+
if (response == null) {
|
|
5320
|
+
return;
|
|
5321
|
+
}
|
|
5322
|
+
|
|
5323
|
+
const {
|
|
5324
|
+
context,
|
|
5325
|
+
value
|
|
5326
|
+
} = response;
|
|
5327
|
+
|
|
5328
|
+
if (value !== null && value !== void 0 && value.err) {
|
|
5329
|
+
reject(value.err);
|
|
5330
|
+
}
|
|
5331
|
+
|
|
5332
|
+
if (value) {
|
|
5333
|
+
done = true;
|
|
5334
|
+
resolve({
|
|
5335
|
+
__type: exports.TransactionStatus.PROCESSED,
|
|
5336
|
+
response: {
|
|
5337
|
+
context,
|
|
5338
|
+
value
|
|
5339
|
+
}
|
|
5340
|
+
});
|
|
5341
|
+
}
|
|
5342
|
+
})();
|
|
5294
5343
|
} catch (err) {
|
|
5295
5344
|
reject(err);
|
|
5296
5345
|
}
|
|
@@ -5363,8 +5412,12 @@ class Connection {
|
|
|
5363
5412
|
} finally {
|
|
5364
5413
|
clearTimeout(timeoutId);
|
|
5365
5414
|
|
|
5366
|
-
if (
|
|
5367
|
-
|
|
5415
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5416
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5417
|
+
}
|
|
5418
|
+
|
|
5419
|
+
if (signatureSubscriptionId) {
|
|
5420
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5368
5421
|
}
|
|
5369
5422
|
}
|
|
5370
5423
|
|
|
@@ -6866,9 +6919,9 @@ class Connection {
|
|
|
6866
6919
|
|
|
6867
6920
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
6868
6921
|
Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
|
|
6869
|
-
this.
|
|
6922
|
+
this._setSubscription(hash, { ...subscription,
|
|
6870
6923
|
state: 'pending'
|
|
6871
|
-
};
|
|
6924
|
+
});
|
|
6872
6925
|
});
|
|
6873
6926
|
}
|
|
6874
6927
|
/**
|
|
@@ -6876,6 +6929,53 @@ class Connection {
|
|
|
6876
6929
|
*/
|
|
6877
6930
|
|
|
6878
6931
|
|
|
6932
|
+
_setSubscription(hash, nextSubscription) {
|
|
6933
|
+
var _this$_subscriptionsB;
|
|
6934
|
+
|
|
6935
|
+
const prevState = (_this$_subscriptionsB = this._subscriptionsByHash[hash]) === null || _this$_subscriptionsB === void 0 ? void 0 : _this$_subscriptionsB.state;
|
|
6936
|
+
this._subscriptionsByHash[hash] = nextSubscription;
|
|
6937
|
+
|
|
6938
|
+
if (prevState !== nextSubscription.state) {
|
|
6939
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6940
|
+
|
|
6941
|
+
if (stateChangeCallbacks) {
|
|
6942
|
+
stateChangeCallbacks.forEach(cb => {
|
|
6943
|
+
try {
|
|
6944
|
+
cb(nextSubscription.state); // eslint-disable-next-line no-empty
|
|
6945
|
+
} catch {}
|
|
6946
|
+
});
|
|
6947
|
+
}
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
/**
|
|
6951
|
+
* @internal
|
|
6952
|
+
*/
|
|
6953
|
+
|
|
6954
|
+
|
|
6955
|
+
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
6956
|
+
var _this$_subscriptionSt;
|
|
6957
|
+
|
|
6958
|
+
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
6959
|
+
|
|
6960
|
+
if (hash == null) {
|
|
6961
|
+
return () => {};
|
|
6962
|
+
}
|
|
6963
|
+
|
|
6964
|
+
const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
|
|
6965
|
+
stateChangeCallbacks.add(callback);
|
|
6966
|
+
return () => {
|
|
6967
|
+
stateChangeCallbacks.delete(callback);
|
|
6968
|
+
|
|
6969
|
+
if (stateChangeCallbacks.size === 0) {
|
|
6970
|
+
delete this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6971
|
+
}
|
|
6972
|
+
};
|
|
6973
|
+
}
|
|
6974
|
+
/**
|
|
6975
|
+
* @internal
|
|
6976
|
+
*/
|
|
6977
|
+
|
|
6978
|
+
|
|
6879
6979
|
async _updateSubscriptions() {
|
|
6880
6980
|
if (Object.keys(this._subscriptionsByHash).length === 0) {
|
|
6881
6981
|
if (this._rpcWebSocketConnected) {
|
|
@@ -6961,14 +7061,17 @@ class Connection {
|
|
|
6961
7061
|
} = subscription;
|
|
6962
7062
|
|
|
6963
7063
|
try {
|
|
6964
|
-
this.
|
|
7064
|
+
this._setSubscription(hash, { ...subscription,
|
|
6965
7065
|
state: 'subscribing'
|
|
6966
|
-
};
|
|
7066
|
+
});
|
|
7067
|
+
|
|
6967
7068
|
const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
|
|
6968
|
-
|
|
7069
|
+
|
|
7070
|
+
this._setSubscription(hash, { ...subscription,
|
|
6969
7071
|
serverSubscriptionId,
|
|
6970
7072
|
state: 'subscribed'
|
|
6971
|
-
};
|
|
7073
|
+
});
|
|
7074
|
+
|
|
6972
7075
|
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
6973
7076
|
await this._updateSubscriptions();
|
|
6974
7077
|
} catch (e) {
|
|
@@ -6981,9 +7084,10 @@ class Connection {
|
|
|
6981
7084
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
6982
7085
|
|
|
6983
7086
|
|
|
6984
|
-
this.
|
|
7087
|
+
this._setSubscription(hash, { ...subscription,
|
|
6985
7088
|
state: 'pending'
|
|
6986
|
-
};
|
|
7089
|
+
});
|
|
7090
|
+
|
|
6987
7091
|
await this._updateSubscriptions();
|
|
6988
7092
|
}
|
|
6989
7093
|
})();
|
|
@@ -7012,9 +7116,13 @@ class Connection {
|
|
|
7012
7116
|
*/
|
|
7013
7117
|
this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
|
|
7014
7118
|
} else {
|
|
7015
|
-
this.
|
|
7119
|
+
this._setSubscription(hash, { ...subscription,
|
|
7120
|
+
state: 'unsubscribing'
|
|
7121
|
+
});
|
|
7122
|
+
|
|
7123
|
+
this._setSubscription(hash, { ...subscription,
|
|
7016
7124
|
state: 'unsubscribing'
|
|
7017
|
-
};
|
|
7125
|
+
});
|
|
7018
7126
|
|
|
7019
7127
|
try {
|
|
7020
7128
|
await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
|
|
@@ -7028,17 +7136,19 @@ class Connection {
|
|
|
7028
7136
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
7029
7137
|
|
|
7030
7138
|
|
|
7031
|
-
this.
|
|
7139
|
+
this._setSubscription(hash, { ...subscription,
|
|
7032
7140
|
state: 'subscribed'
|
|
7033
|
-
};
|
|
7141
|
+
});
|
|
7142
|
+
|
|
7034
7143
|
await this._updateSubscriptions();
|
|
7035
7144
|
return;
|
|
7036
7145
|
}
|
|
7037
7146
|
}
|
|
7038
7147
|
|
|
7039
|
-
this.
|
|
7148
|
+
this._setSubscription(hash, { ...subscription,
|
|
7040
7149
|
state: 'unsubscribed'
|
|
7041
|
-
};
|
|
7150
|
+
});
|
|
7151
|
+
|
|
7042
7152
|
await this._updateSubscriptions();
|
|
7043
7153
|
})();
|
|
7044
7154
|
}
|
|
@@ -7131,8 +7241,11 @@ class Connection {
|
|
|
7131
7241
|
existingSubscription.callbacks.add(subscriptionConfig.callback);
|
|
7132
7242
|
}
|
|
7133
7243
|
|
|
7244
|
+
this._subscriptionHashByClientSubscriptionId[clientSubscriptionId] = hash;
|
|
7245
|
+
|
|
7134
7246
|
this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
|
|
7135
7247
|
delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
7248
|
+
delete this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
7136
7249
|
const subscription = this._subscriptionsByHash[hash];
|
|
7137
7250
|
assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
|
|
7138
7251
|
subscription.callbacks.delete(subscriptionConfig.callback);
|