@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/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
[![Build status][travis-image]][travis-url]
|
|
2
1
|
[![codecov][codecov-image]][codecov-url]
|
|
3
2
|
<br>
|
|
4
3
|
[![npm][npm-image]][npm-url]
|
|
@@ -7,8 +6,6 @@
|
|
|
7
6
|
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
8
7
|
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
9
8
|
|
|
10
|
-
[travis-image]: https://api.travis-ci.org/solana-labs/solana-web3.js.svg?branch=master
|
|
11
|
-
[travis-url]: https://travis-ci.org/solana-labs/solana-web3.js
|
|
12
9
|
[codecov-image]: https://codecov.io/gh/solana-labs/solana-web3.js/branch/master/graph/badge.svg
|
|
13
10
|
[codecov-url]: https://codecov.io/gh/solana-labs/solana-web3.js
|
|
14
11
|
[npm-image]: https://img.shields.io/npm/v/@solana/web3.js.svg?style=flat
|
|
@@ -60,7 +57,7 @@ Install the latest Solana release from https://docs.solana.com/cli/install-solan
|
|
|
60
57
|
|
|
61
58
|
**Use `solana-test-validator` from the latest Solana release**
|
|
62
59
|
|
|
63
|
-
###
|
|
60
|
+
### SBF program development
|
|
64
61
|
|
|
65
62
|
**Use `cargo build-bpf` from the latest Solana release**
|
|
66
63
|
|
package/lib/index.browser.cjs.js
CHANGED
|
@@ -3253,12 +3253,12 @@ class BpfLoader {
|
|
|
3253
3253
|
return Loader.getMinNumSignatures(dataLength);
|
|
3254
3254
|
}
|
|
3255
3255
|
/**
|
|
3256
|
-
* Load a
|
|
3256
|
+
* Load a SBF program
|
|
3257
3257
|
*
|
|
3258
3258
|
* @param connection The connection to use
|
|
3259
3259
|
* @param payer Account that will pay program loading fees
|
|
3260
3260
|
* @param program Account to load the program into
|
|
3261
|
-
* @param elf The entire ELF containing the
|
|
3261
|
+
* @param elf The entire ELF containing the SBF program
|
|
3262
3262
|
* @param loaderProgramId The program id of the BPF loader to use
|
|
3263
3263
|
* @return true if program was loaded successfully, false if program was already loaded
|
|
3264
3264
|
*/
|
|
@@ -4635,6 +4635,10 @@ class Connection {
|
|
|
4635
4635
|
|
|
4636
4636
|
/** @internal */
|
|
4637
4637
|
|
|
4638
|
+
/** @internal */
|
|
4639
|
+
|
|
4640
|
+
/** @internal */
|
|
4641
|
+
|
|
4638
4642
|
/**
|
|
4639
4643
|
* Special case.
|
|
4640
4644
|
* After a signature is processed, RPCs automatically dispose of the
|
|
@@ -4680,6 +4684,8 @@ class Connection {
|
|
|
4680
4684
|
};
|
|
4681
4685
|
this._nextClientSubscriptionId = 0;
|
|
4682
4686
|
this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
|
|
4687
|
+
this._subscriptionHashByClientSubscriptionId = {};
|
|
4688
|
+
this._subscriptionStateChangeCallbacksByHash = {};
|
|
4683
4689
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
4684
4690
|
this._subscriptionsByHash = {};
|
|
4685
4691
|
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
@@ -5209,12 +5215,13 @@ class Connection {
|
|
|
5209
5215
|
assert(decodedSignature.length === 64, 'signature has invalid length');
|
|
5210
5216
|
const subscriptionCommitment = commitment || this.commitment;
|
|
5211
5217
|
let timeoutId;
|
|
5212
|
-
let
|
|
5218
|
+
let signatureSubscriptionId;
|
|
5219
|
+
let disposeSignatureSubscriptionStateChangeObserver;
|
|
5213
5220
|
let done = false;
|
|
5214
5221
|
const confirmationPromise = new Promise((resolve, reject) => {
|
|
5215
5222
|
try {
|
|
5216
|
-
|
|
5217
|
-
|
|
5223
|
+
signatureSubscriptionId = this.onSignature(rawSignature, (result, context) => {
|
|
5224
|
+
signatureSubscriptionId = undefined;
|
|
5218
5225
|
const response = {
|
|
5219
5226
|
context,
|
|
5220
5227
|
value: result
|
|
@@ -5225,6 +5232,48 @@ class Connection {
|
|
|
5225
5232
|
response
|
|
5226
5233
|
});
|
|
5227
5234
|
}, subscriptionCommitment);
|
|
5235
|
+
const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
|
|
5236
|
+
if (signatureSubscriptionId == null) {
|
|
5237
|
+
resolveSubscriptionSetup();
|
|
5238
|
+
} else {
|
|
5239
|
+
disposeSignatureSubscriptionStateChangeObserver = this._onSubscriptionStateChange(signatureSubscriptionId, nextState => {
|
|
5240
|
+
if (nextState === 'subscribed') {
|
|
5241
|
+
resolveSubscriptionSetup();
|
|
5242
|
+
}
|
|
5243
|
+
});
|
|
5244
|
+
}
|
|
5245
|
+
});
|
|
5246
|
+
|
|
5247
|
+
(async () => {
|
|
5248
|
+
await subscriptionSetupPromise;
|
|
5249
|
+
if (done) return;
|
|
5250
|
+
const response = await this.getSignatureStatus(rawSignature);
|
|
5251
|
+
if (done) return;
|
|
5252
|
+
|
|
5253
|
+
if (response == null) {
|
|
5254
|
+
return;
|
|
5255
|
+
}
|
|
5256
|
+
|
|
5257
|
+
const {
|
|
5258
|
+
context,
|
|
5259
|
+
value
|
|
5260
|
+
} = response;
|
|
5261
|
+
|
|
5262
|
+
if (value !== null && value !== void 0 && value.err) {
|
|
5263
|
+
reject(value.err);
|
|
5264
|
+
}
|
|
5265
|
+
|
|
5266
|
+
if (value) {
|
|
5267
|
+
done = true;
|
|
5268
|
+
resolve({
|
|
5269
|
+
__type: exports.TransactionStatus.PROCESSED,
|
|
5270
|
+
response: {
|
|
5271
|
+
context,
|
|
5272
|
+
value
|
|
5273
|
+
}
|
|
5274
|
+
});
|
|
5275
|
+
}
|
|
5276
|
+
})();
|
|
5228
5277
|
} catch (err) {
|
|
5229
5278
|
reject(err);
|
|
5230
5279
|
}
|
|
@@ -5297,8 +5346,12 @@ class Connection {
|
|
|
5297
5346
|
} finally {
|
|
5298
5347
|
clearTimeout(timeoutId);
|
|
5299
5348
|
|
|
5300
|
-
if (
|
|
5301
|
-
|
|
5349
|
+
if (disposeSignatureSubscriptionStateChangeObserver) {
|
|
5350
|
+
disposeSignatureSubscriptionStateChangeObserver();
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5353
|
+
if (signatureSubscriptionId) {
|
|
5354
|
+
this.removeSignatureListener(signatureSubscriptionId);
|
|
5302
5355
|
}
|
|
5303
5356
|
}
|
|
5304
5357
|
|
|
@@ -5673,7 +5726,7 @@ class Connection {
|
|
|
5673
5726
|
const res = superstruct.create(unsafeRes, jsonRpcResultAndContext(superstruct.nullable(superstruct.number())));
|
|
5674
5727
|
|
|
5675
5728
|
if ('error' in res) {
|
|
5676
|
-
throw new SolanaJSONRPCError(res.error, 'failed to get
|
|
5729
|
+
throw new SolanaJSONRPCError(res.error, 'failed to get fee for message');
|
|
5677
5730
|
}
|
|
5678
5731
|
|
|
5679
5732
|
if (res.result === null) {
|
|
@@ -6800,9 +6853,9 @@ class Connection {
|
|
|
6800
6853
|
|
|
6801
6854
|
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
6802
6855
|
Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
|
|
6803
|
-
this.
|
|
6856
|
+
this._setSubscription(hash, { ...subscription,
|
|
6804
6857
|
state: 'pending'
|
|
6805
|
-
};
|
|
6858
|
+
});
|
|
6806
6859
|
});
|
|
6807
6860
|
}
|
|
6808
6861
|
/**
|
|
@@ -6810,6 +6863,53 @@ class Connection {
|
|
|
6810
6863
|
*/
|
|
6811
6864
|
|
|
6812
6865
|
|
|
6866
|
+
_setSubscription(hash, nextSubscription) {
|
|
6867
|
+
var _this$_subscriptionsB;
|
|
6868
|
+
|
|
6869
|
+
const prevState = (_this$_subscriptionsB = this._subscriptionsByHash[hash]) === null || _this$_subscriptionsB === void 0 ? void 0 : _this$_subscriptionsB.state;
|
|
6870
|
+
this._subscriptionsByHash[hash] = nextSubscription;
|
|
6871
|
+
|
|
6872
|
+
if (prevState !== nextSubscription.state) {
|
|
6873
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6874
|
+
|
|
6875
|
+
if (stateChangeCallbacks) {
|
|
6876
|
+
stateChangeCallbacks.forEach(cb => {
|
|
6877
|
+
try {
|
|
6878
|
+
cb(nextSubscription.state); // eslint-disable-next-line no-empty
|
|
6879
|
+
} catch {}
|
|
6880
|
+
});
|
|
6881
|
+
}
|
|
6882
|
+
}
|
|
6883
|
+
}
|
|
6884
|
+
/**
|
|
6885
|
+
* @internal
|
|
6886
|
+
*/
|
|
6887
|
+
|
|
6888
|
+
|
|
6889
|
+
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
6890
|
+
var _this$_subscriptionSt;
|
|
6891
|
+
|
|
6892
|
+
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
6893
|
+
|
|
6894
|
+
if (hash == null) {
|
|
6895
|
+
return () => {};
|
|
6896
|
+
}
|
|
6897
|
+
|
|
6898
|
+
const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
|
|
6899
|
+
stateChangeCallbacks.add(callback);
|
|
6900
|
+
return () => {
|
|
6901
|
+
stateChangeCallbacks.delete(callback);
|
|
6902
|
+
|
|
6903
|
+
if (stateChangeCallbacks.size === 0) {
|
|
6904
|
+
delete this._subscriptionStateChangeCallbacksByHash[hash];
|
|
6905
|
+
}
|
|
6906
|
+
};
|
|
6907
|
+
}
|
|
6908
|
+
/**
|
|
6909
|
+
* @internal
|
|
6910
|
+
*/
|
|
6911
|
+
|
|
6912
|
+
|
|
6813
6913
|
async _updateSubscriptions() {
|
|
6814
6914
|
if (Object.keys(this._subscriptionsByHash).length === 0) {
|
|
6815
6915
|
if (this._rpcWebSocketConnected) {
|
|
@@ -6895,14 +6995,17 @@ class Connection {
|
|
|
6895
6995
|
} = subscription;
|
|
6896
6996
|
|
|
6897
6997
|
try {
|
|
6898
|
-
this.
|
|
6998
|
+
this._setSubscription(hash, { ...subscription,
|
|
6899
6999
|
state: 'subscribing'
|
|
6900
|
-
};
|
|
7000
|
+
});
|
|
7001
|
+
|
|
6901
7002
|
const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
|
|
6902
|
-
|
|
7003
|
+
|
|
7004
|
+
this._setSubscription(hash, { ...subscription,
|
|
6903
7005
|
serverSubscriptionId,
|
|
6904
7006
|
state: 'subscribed'
|
|
6905
|
-
};
|
|
7007
|
+
});
|
|
7008
|
+
|
|
6906
7009
|
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
6907
7010
|
await this._updateSubscriptions();
|
|
6908
7011
|
} catch (e) {
|
|
@@ -6915,9 +7018,10 @@ class Connection {
|
|
|
6915
7018
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
6916
7019
|
|
|
6917
7020
|
|
|
6918
|
-
this.
|
|
7021
|
+
this._setSubscription(hash, { ...subscription,
|
|
6919
7022
|
state: 'pending'
|
|
6920
|
-
};
|
|
7023
|
+
});
|
|
7024
|
+
|
|
6921
7025
|
await this._updateSubscriptions();
|
|
6922
7026
|
}
|
|
6923
7027
|
})();
|
|
@@ -6946,9 +7050,13 @@ class Connection {
|
|
|
6946
7050
|
*/
|
|
6947
7051
|
this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
|
|
6948
7052
|
} else {
|
|
6949
|
-
this.
|
|
7053
|
+
this._setSubscription(hash, { ...subscription,
|
|
7054
|
+
state: 'unsubscribing'
|
|
7055
|
+
});
|
|
7056
|
+
|
|
7057
|
+
this._setSubscription(hash, { ...subscription,
|
|
6950
7058
|
state: 'unsubscribing'
|
|
6951
|
-
};
|
|
7059
|
+
});
|
|
6952
7060
|
|
|
6953
7061
|
try {
|
|
6954
7062
|
await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
|
|
@@ -6962,17 +7070,19 @@ class Connection {
|
|
|
6962
7070
|
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
6963
7071
|
|
|
6964
7072
|
|
|
6965
|
-
this.
|
|
7073
|
+
this._setSubscription(hash, { ...subscription,
|
|
6966
7074
|
state: 'subscribed'
|
|
6967
|
-
};
|
|
7075
|
+
});
|
|
7076
|
+
|
|
6968
7077
|
await this._updateSubscriptions();
|
|
6969
7078
|
return;
|
|
6970
7079
|
}
|
|
6971
7080
|
}
|
|
6972
7081
|
|
|
6973
|
-
this.
|
|
7082
|
+
this._setSubscription(hash, { ...subscription,
|
|
6974
7083
|
state: 'unsubscribed'
|
|
6975
|
-
};
|
|
7084
|
+
});
|
|
7085
|
+
|
|
6976
7086
|
await this._updateSubscriptions();
|
|
6977
7087
|
})();
|
|
6978
7088
|
}
|
|
@@ -7065,8 +7175,11 @@ class Connection {
|
|
|
7065
7175
|
existingSubscription.callbacks.add(subscriptionConfig.callback);
|
|
7066
7176
|
}
|
|
7067
7177
|
|
|
7178
|
+
this._subscriptionHashByClientSubscriptionId[clientSubscriptionId] = hash;
|
|
7179
|
+
|
|
7068
7180
|
this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
|
|
7069
7181
|
delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
7182
|
+
delete this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
7070
7183
|
const subscription = this._subscriptionsByHash[hash];
|
|
7071
7184
|
assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
|
|
7072
7185
|
subscription.callbacks.delete(subscriptionConfig.callback);
|