@snapshot-labs/snapshot.js 0.8.0-beta.0 → 0.8.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/LICENSE +0 -0
- package/dist/sign/index.d.ts +16 -16
- package/dist/snapshot.cjs.js +212 -165
- package/dist/snapshot.esm.js +211 -165
- package/dist/snapshot.min.js +5 -5
- package/dist/utils.d.ts +6 -13
- package/package.json +3 -3
- package/src/networks.json +77 -6
- package/src/sign/index.ts +10 -12
- package/src/utils.ts +73 -117
- package/src/utils/dist/provider.js +0 -47
- /package/src/sign/{types.json → hashedTypes.json} +0 -0
package/dist/snapshot.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
2
2
|
import { getAddress, isAddress } from '@ethersproject/address';
|
|
3
3
|
import { Interface } from '@ethersproject/abi';
|
|
4
4
|
import { Contract } from '@ethersproject/contracts';
|
|
@@ -362,35 +362,29 @@ var Client = /** @class */ (function () {
|
|
|
362
362
|
});
|
|
363
363
|
};
|
|
364
364
|
Client.prototype.send = function (envelop) {
|
|
365
|
-
var _a, _b;
|
|
366
365
|
return __awaiter(this, void 0, void 0, function () {
|
|
367
|
-
var address, init
|
|
368
|
-
return __generator(this, function (
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
e_1 = _c.sent();
|
|
390
|
-
isSequencerError = ((_a = e_1.data) === null || _a === void 0 ? void 0 : _a.hasOwnProperty('error')) && ((_b = e_1.data) === null || _b === void 0 ? void 0 : _b.hasOwnProperty('error_description'));
|
|
391
|
-
return [2 /*return*/, Promise.reject(isSequencerError ? e_1.data : e_1)];
|
|
392
|
-
case 4: return [2 /*return*/];
|
|
393
|
-
}
|
|
366
|
+
var address, init;
|
|
367
|
+
return __generator(this, function (_a) {
|
|
368
|
+
address = this.address;
|
|
369
|
+
if (envelop.sig === '0x' && this.options.relayerURL)
|
|
370
|
+
address = this.options.relayerURL;
|
|
371
|
+
init = {
|
|
372
|
+
method: 'POST',
|
|
373
|
+
headers: {
|
|
374
|
+
Accept: 'application/json',
|
|
375
|
+
'Content-Type': 'application/json'
|
|
376
|
+
},
|
|
377
|
+
body: JSON.stringify(envelop)
|
|
378
|
+
};
|
|
379
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
380
|
+
fetch(address, init)
|
|
381
|
+
.then(function (res) {
|
|
382
|
+
if (res.ok)
|
|
383
|
+
return resolve(res.json());
|
|
384
|
+
throw res;
|
|
385
|
+
})
|
|
386
|
+
.catch(function (e) { return e.json().then(function (json) { return reject(json); }); });
|
|
387
|
+
})];
|
|
394
388
|
});
|
|
395
389
|
});
|
|
396
390
|
};
|
|
@@ -2024,6 +2018,21 @@ var networks = {
|
|
|
2024
2018
|
},
|
|
2025
2019
|
start: 10780012,
|
|
2026
2020
|
logo: "ipfs://QmXAKaNsyv6ctuRenYRJuZ1V4kn1eFwkUtjrjzX6jiKTqe"
|
|
2021
|
+
},
|
|
2022
|
+
"75": {
|
|
2023
|
+
key: "75",
|
|
2024
|
+
name: "Decimal",
|
|
2025
|
+
shortName: "mainnet",
|
|
2026
|
+
chainId: 75,
|
|
2027
|
+
network: "mainnet",
|
|
2028
|
+
multicall: "0x949d1A0757803C51F2EfFFEb5472C861A898B8E8",
|
|
2029
|
+
rpc: [
|
|
2030
|
+
],
|
|
2031
|
+
explorer: {
|
|
2032
|
+
url: "https://explorer.decimalchain.com"
|
|
2033
|
+
},
|
|
2034
|
+
start: 16031065,
|
|
2035
|
+
logo: "ipfs://bafkreihkdhbce5rkogl63xegaarlirjrvbfarxbtbf5mqme3s5grvbjyxm"
|
|
2027
2036
|
},
|
|
2028
2037
|
"80": {
|
|
2029
2038
|
key: "80",
|
|
@@ -2256,7 +2265,7 @@ var networks = {
|
|
|
2256
2265
|
},
|
|
2257
2266
|
"137": {
|
|
2258
2267
|
key: "137",
|
|
2259
|
-
name: "Polygon
|
|
2268
|
+
name: "Polygon PoS",
|
|
2260
2269
|
shortName: "Polygon",
|
|
2261
2270
|
chainId: 137,
|
|
2262
2271
|
network: "mainnet",
|
|
@@ -2275,7 +2284,7 @@ var networks = {
|
|
|
2275
2284
|
apiUrl: "https://api.polygonscan.com"
|
|
2276
2285
|
},
|
|
2277
2286
|
start: 9834491,
|
|
2278
|
-
logo: "ipfs://
|
|
2287
|
+
logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
|
|
2279
2288
|
},
|
|
2280
2289
|
"144": {
|
|
2281
2290
|
key: "144",
|
|
@@ -2323,6 +2332,21 @@ var networks = {
|
|
|
2323
2332
|
},
|
|
2324
2333
|
start: 4720651,
|
|
2325
2334
|
logo: "ipfs://bafkreiabhsxuq35pp4kmrbptdeypd6clhcy3ue7ydpppo6onoo4igcjqia"
|
|
2335
|
+
},
|
|
2336
|
+
"204": {
|
|
2337
|
+
key: "204",
|
|
2338
|
+
name: "opBNB",
|
|
2339
|
+
shortName: "mainnet",
|
|
2340
|
+
chainId: 204,
|
|
2341
|
+
network: "mainnet",
|
|
2342
|
+
multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
2343
|
+
rpc: [
|
|
2344
|
+
],
|
|
2345
|
+
explorer: {
|
|
2346
|
+
url: "http://opbnbscan.com/"
|
|
2347
|
+
},
|
|
2348
|
+
start: 512881,
|
|
2349
|
+
logo: "ipfs://bafkreibll4la7wqerzs7zwxjne2j7ayynbg2wlenemssoahxxj5rbt6c64"
|
|
2326
2350
|
},
|
|
2327
2351
|
"246": {
|
|
2328
2352
|
key: "246",
|
|
@@ -2767,7 +2791,7 @@ var networks = {
|
|
|
2767
2791
|
"wss://archive-en.baobab.klaytn.net/ws"
|
|
2768
2792
|
],
|
|
2769
2793
|
explorer: {
|
|
2770
|
-
url: "https://baobab.scope.klaytn.com
|
|
2794
|
+
url: "https://baobab.scope.klaytn.com"
|
|
2771
2795
|
},
|
|
2772
2796
|
logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
2773
2797
|
},
|
|
@@ -2818,6 +2842,21 @@ var networks = {
|
|
|
2818
2842
|
},
|
|
2819
2843
|
start: 451,
|
|
2820
2844
|
logo: "ipfs://QmYeskHqrEvWHqeAuqett64LxfH52HUXZi2T9BAMmgKvBF"
|
|
2845
|
+
},
|
|
2846
|
+
"1101": {
|
|
2847
|
+
key: "1101",
|
|
2848
|
+
name: "Polygon zkEVM",
|
|
2849
|
+
shortName: "mainnet",
|
|
2850
|
+
chainId: 1101,
|
|
2851
|
+
network: "mainnet",
|
|
2852
|
+
multicall: "0xcA11bde05977b3631167028862bE2a173976CA11",
|
|
2853
|
+
rpc: [
|
|
2854
|
+
],
|
|
2855
|
+
explorer: {
|
|
2856
|
+
url: "https://zkevm.polygonscan.com"
|
|
2857
|
+
},
|
|
2858
|
+
start: 57746,
|
|
2859
|
+
logo: "ipfs://bafkreibfiyvhqnme2vbxxfcku7qkxgjpkg6ywdkplxh4oxlkqsbznyorfm"
|
|
2821
2860
|
},
|
|
2822
2861
|
"1116": {
|
|
2823
2862
|
key: "1116",
|
|
@@ -3109,6 +3148,21 @@ var networks = {
|
|
|
3109
3148
|
},
|
|
3110
3149
|
start: 2607889,
|
|
3111
3150
|
logo: "ipfs://QmPXPCBho3kGLt5rhG9JGkKmzdtLvqZmJqGzzijVCuggWY"
|
|
3151
|
+
},
|
|
3152
|
+
"4337": {
|
|
3153
|
+
key: "4337",
|
|
3154
|
+
name: "Beam",
|
|
3155
|
+
shortName: "Beam",
|
|
3156
|
+
chainId: 4337,
|
|
3157
|
+
network: "mainnet",
|
|
3158
|
+
multicall: "0x4956F15eFdc3dC16645e90Cc356eAFA65fFC65Ec",
|
|
3159
|
+
rpc: [
|
|
3160
|
+
],
|
|
3161
|
+
explorer: {
|
|
3162
|
+
url: "https://subnets.avax.network/beam/"
|
|
3163
|
+
},
|
|
3164
|
+
start: 1,
|
|
3165
|
+
logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF"
|
|
3112
3166
|
},
|
|
3113
3167
|
"4689": {
|
|
3114
3168
|
key: "4689",
|
|
@@ -3303,7 +3357,7 @@ var networks = {
|
|
|
3303
3357
|
"wss://archive-en.cypress.klaytn.net/ws"
|
|
3304
3358
|
],
|
|
3305
3359
|
explorer: {
|
|
3306
|
-
url: "https://scope.klaytn.com
|
|
3360
|
+
url: "https://scope.klaytn.com"
|
|
3307
3361
|
},
|
|
3308
3362
|
logo: "ipfs://QmYACyZcidcFtMo4Uf9H6ZKUxTP2TQPjGzNjcUjqYa64dt"
|
|
3309
3363
|
},
|
|
@@ -3460,6 +3514,22 @@ var networks = {
|
|
|
3460
3514
|
},
|
|
3461
3515
|
start: 79516,
|
|
3462
3516
|
logo: "ipfs://QmTogMDLmDgJjDjUKDHDuc2KVTVDbXf8bXJLFiVe8PRxgo"
|
|
3517
|
+
},
|
|
3518
|
+
"13337": {
|
|
3519
|
+
key: "13337",
|
|
3520
|
+
name: "Beam Testnet",
|
|
3521
|
+
shortName: "testnet",
|
|
3522
|
+
chainId: 13337,
|
|
3523
|
+
network: "testnet",
|
|
3524
|
+
multicall: "0x9BF49b704EE2A095b95c1f2D4EB9010510c41C9E",
|
|
3525
|
+
rpc: [
|
|
3526
|
+
],
|
|
3527
|
+
explorer: {
|
|
3528
|
+
url: "https://subnets-test.avax.network/beam/"
|
|
3529
|
+
},
|
|
3530
|
+
start: 3,
|
|
3531
|
+
logo: "ipfs://QmaKRLxXPdeTsLx7MFLS3CJbhpSbResgoeL4fCgHB1mTsF",
|
|
3532
|
+
testnet: true
|
|
3463
3533
|
},
|
|
3464
3534
|
"16718": {
|
|
3465
3535
|
key: "16718",
|
|
@@ -3797,7 +3867,7 @@ var networks = {
|
|
|
3797
3867
|
},
|
|
3798
3868
|
"80001": {
|
|
3799
3869
|
key: "80001",
|
|
3800
|
-
name: "
|
|
3870
|
+
name: "Polygon Mumbai",
|
|
3801
3871
|
chainId: 80001,
|
|
3802
3872
|
network: "testnet",
|
|
3803
3873
|
testnet: true,
|
|
@@ -3814,7 +3884,7 @@ var networks = {
|
|
|
3814
3884
|
apiUrl: "https://api-mumbai.polygonscan.com"
|
|
3815
3885
|
},
|
|
3816
3886
|
start: 12011090,
|
|
3817
|
-
logo: "ipfs://
|
|
3887
|
+
logo: "ipfs://bafkreihgr7zy7vi5kqddybfaezwuhvssg57qluwmyan4qq7l57nr7w7wey"
|
|
3818
3888
|
},
|
|
3819
3889
|
"84531": {
|
|
3820
3890
|
key: "84531",
|
|
@@ -4592,50 +4662,32 @@ function multicall(network, provider, abi, calls, options) {
|
|
|
4592
4662
|
});
|
|
4593
4663
|
}
|
|
4594
4664
|
function subgraphRequest(url, query, options) {
|
|
4595
|
-
|
|
4665
|
+
if (options === void 0) { options = {}; }
|
|
4596
4666
|
return __awaiter(this, void 0, void 0, function () {
|
|
4597
|
-
var
|
|
4598
|
-
return __generator(this, function (
|
|
4599
|
-
switch (
|
|
4600
|
-
case 0:
|
|
4601
|
-
_b.trys.push([0, 2, , 3]);
|
|
4602
|
-
init = {
|
|
4667
|
+
var res, responseData, data;
|
|
4668
|
+
return __generator(this, function (_a) {
|
|
4669
|
+
switch (_a.label) {
|
|
4670
|
+
case 0: return [4 /*yield*/, fetch(url, {
|
|
4603
4671
|
method: 'POST',
|
|
4604
4672
|
headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers),
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
};
|
|
4608
|
-
return [4 /*yield*/, ofetch(url, init)];
|
|
4673
|
+
body: JSON.stringify({ query: jsonToGraphQLQuery({ query: query }) })
|
|
4674
|
+
})];
|
|
4609
4675
|
case 1:
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
})];
|
|
4676
|
+
res = _a.sent();
|
|
4677
|
+
return [4 /*yield*/, res.text()];
|
|
4678
|
+
case 2:
|
|
4679
|
+
responseData = _a.sent();
|
|
4680
|
+
try {
|
|
4681
|
+
responseData = JSON.parse(responseData);
|
|
4682
|
+
}
|
|
4683
|
+
catch (e) {
|
|
4684
|
+
throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + responseData.substring(0, 400));
|
|
4620
4685
|
}
|
|
4621
|
-
if (
|
|
4622
|
-
|
|
4686
|
+
if (responseData.errors) {
|
|
4687
|
+
throw new Error("Errors found in subgraphRequest: URL: " + url + ", Status: " + res.status + ", Response: " + JSON.stringify(responseData.errors).substring(0, 400));
|
|
4623
4688
|
}
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
e_3 = _b.sent();
|
|
4627
|
-
return [2 /*return*/, Promise.reject(((_a = e_3.data) === null || _a === void 0 ? void 0 : _a.errors) ? e_3.data
|
|
4628
|
-
: {
|
|
4629
|
-
errors: [
|
|
4630
|
-
{
|
|
4631
|
-
message: e_3.statusText || e_3.toString(),
|
|
4632
|
-
extensions: {
|
|
4633
|
-
code: e_3.status || 0
|
|
4634
|
-
}
|
|
4635
|
-
}
|
|
4636
|
-
]
|
|
4637
|
-
})];
|
|
4638
|
-
case 3: return [2 /*return*/];
|
|
4689
|
+
data = responseData.data;
|
|
4690
|
+
return [2 /*return*/, data || {}];
|
|
4639
4691
|
}
|
|
4640
4692
|
});
|
|
4641
4693
|
});
|
|
@@ -4660,39 +4712,20 @@ function getUrl(uri, gateway) {
|
|
|
4660
4712
|
function getJSON(uri, options) {
|
|
4661
4713
|
if (options === void 0) { options = {}; }
|
|
4662
4714
|
return __awaiter(this, void 0, void 0, function () {
|
|
4663
|
-
var url
|
|
4715
|
+
var url;
|
|
4664
4716
|
return __generator(this, function (_a) {
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
url = getUrl(uri, options.gateways) || '';
|
|
4668
|
-
return [4 /*yield*/, ofetch(url, {
|
|
4669
|
-
timeout: options.timeout || 30e3,
|
|
4670
|
-
headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers)
|
|
4671
|
-
})];
|
|
4672
|
-
case 1:
|
|
4673
|
-
body = _a.sent();
|
|
4674
|
-
return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
|
|
4675
|
-
}
|
|
4717
|
+
url = getUrl(uri, options.gateways);
|
|
4718
|
+
return [2 /*return*/, fetch(url).then(function (res) { return res.json(); })];
|
|
4676
4719
|
});
|
|
4677
4720
|
});
|
|
4678
4721
|
}
|
|
4679
|
-
function ipfsGet(gateway, ipfsHash, protocolType
|
|
4722
|
+
function ipfsGet(gateway, ipfsHash, protocolType) {
|
|
4680
4723
|
if (protocolType === void 0) { protocolType = 'ipfs'; }
|
|
4681
|
-
if (options === void 0) { options = {}; }
|
|
4682
4724
|
return __awaiter(this, void 0, void 0, function () {
|
|
4683
|
-
var url
|
|
4725
|
+
var url;
|
|
4684
4726
|
return __generator(this, function (_a) {
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
|
|
4688
|
-
return [4 /*yield*/, ofetch(url, {
|
|
4689
|
-
timeout: options.timeout || 20e3,
|
|
4690
|
-
headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json' }, options.headers)
|
|
4691
|
-
})];
|
|
4692
|
-
case 1:
|
|
4693
|
-
body = _a.sent();
|
|
4694
|
-
return [2 /*return*/, typeof body === 'string' ? JSON.parse(body) : body];
|
|
4695
|
-
}
|
|
4727
|
+
url = "https://" + gateway + "/" + protocolType + "/" + ipfsHash;
|
|
4728
|
+
return [2 /*return*/, fetch(url).then(function (res) { return res.json(); })];
|
|
4696
4729
|
});
|
|
4697
4730
|
});
|
|
4698
4731
|
}
|
|
@@ -4718,18 +4751,17 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4718
4751
|
if (snapshot === void 0) { snapshot = 'latest'; }
|
|
4719
4752
|
if (scoreApiUrl === void 0) { scoreApiUrl = 'https://score.snapshot.org'; }
|
|
4720
4753
|
if (options === void 0) { options = {}; }
|
|
4721
|
-
var _a;
|
|
4722
4754
|
return __awaiter(this, void 0, void 0, function () {
|
|
4723
|
-
var url, params,
|
|
4724
|
-
return __generator(this, function (
|
|
4725
|
-
switch (
|
|
4755
|
+
var url, params, res, obj, e_3;
|
|
4756
|
+
return __generator(this, function (_a) {
|
|
4757
|
+
switch (_a.label) {
|
|
4726
4758
|
case 0:
|
|
4727
4759
|
url = new URL(scoreApiUrl);
|
|
4728
|
-
url.pathname =
|
|
4760
|
+
url.pathname = '/api/scores';
|
|
4729
4761
|
scoreApiUrl = url.toString();
|
|
4730
|
-
|
|
4762
|
+
_a.label = 1;
|
|
4731
4763
|
case 1:
|
|
4732
|
-
|
|
4764
|
+
_a.trys.push([1, 4, , 5]);
|
|
4733
4765
|
params = {
|
|
4734
4766
|
space: space,
|
|
4735
4767
|
network: network,
|
|
@@ -4737,43 +4769,47 @@ function getScores(space, strategies, network, addresses, snapshot, scoreApiUrl,
|
|
|
4737
4769
|
strategies: strategies,
|
|
4738
4770
|
addresses: addresses
|
|
4739
4771
|
};
|
|
4740
|
-
return [4 /*yield*/,
|
|
4772
|
+
return [4 /*yield*/, fetch(scoreApiUrl, {
|
|
4741
4773
|
method: 'POST',
|
|
4742
4774
|
headers: scoreApiHeaders,
|
|
4743
|
-
|
|
4744
|
-
body: { params: params }
|
|
4775
|
+
body: JSON.stringify({ params: params })
|
|
4745
4776
|
})];
|
|
4746
4777
|
case 2:
|
|
4747
|
-
|
|
4748
|
-
return [
|
|
4749
|
-
? body.result
|
|
4750
|
-
: body.result[options.returnValue || 'scores']];
|
|
4778
|
+
res = _a.sent();
|
|
4779
|
+
return [4 /*yield*/, res.json()];
|
|
4751
4780
|
case 3:
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4781
|
+
obj = _a.sent();
|
|
4782
|
+
if (obj.error) {
|
|
4783
|
+
return [2 /*return*/, Promise.reject(obj.error)];
|
|
4784
|
+
}
|
|
4785
|
+
return [2 /*return*/, options.returnValue === 'all'
|
|
4786
|
+
? obj.result
|
|
4787
|
+
: obj.result[options.returnValue || 'scores']];
|
|
4788
|
+
case 4:
|
|
4789
|
+
e_3 = _a.sent();
|
|
4790
|
+
if (e_3.errno) {
|
|
4791
|
+
return [2 /*return*/, Promise.reject({ code: e_3.errno, message: e_3.toString(), data: '' })];
|
|
4792
|
+
}
|
|
4793
|
+
return [2 /*return*/, Promise.reject(e_3)];
|
|
4794
|
+
case 5: return [2 /*return*/];
|
|
4759
4795
|
}
|
|
4760
4796
|
});
|
|
4761
4797
|
});
|
|
4762
4798
|
}
|
|
4763
4799
|
function getVp(address, network, strategies, snapshot, space, delegation, options) {
|
|
4764
|
-
if (options === void 0) { options = {}; }
|
|
4765
|
-
var _a;
|
|
4766
4800
|
return __awaiter(this, void 0, void 0, function () {
|
|
4767
|
-
var
|
|
4768
|
-
return __generator(this, function (
|
|
4769
|
-
switch (
|
|
4801
|
+
var init, res, json, e_4;
|
|
4802
|
+
return __generator(this, function (_a) {
|
|
4803
|
+
switch (_a.label) {
|
|
4770
4804
|
case 0:
|
|
4771
|
-
|
|
4805
|
+
if (!options)
|
|
4806
|
+
options = {};
|
|
4807
|
+
if (!options.url)
|
|
4808
|
+
options.url = 'https://score.snapshot.org';
|
|
4772
4809
|
init = {
|
|
4773
4810
|
method: 'POST',
|
|
4774
4811
|
headers: scoreApiHeaders,
|
|
4775
|
-
|
|
4776
|
-
body: {
|
|
4812
|
+
body: JSON.stringify({
|
|
4777
4813
|
jsonrpc: '2.0',
|
|
4778
4814
|
method: 'get_vp',
|
|
4779
4815
|
params: {
|
|
@@ -4784,41 +4820,47 @@ function getVp(address, network, strategies, snapshot, space, delegation, option
|
|
|
4784
4820
|
space: space,
|
|
4785
4821
|
delegation: delegation
|
|
4786
4822
|
}
|
|
4787
|
-
}
|
|
4823
|
+
})
|
|
4788
4824
|
};
|
|
4789
|
-
|
|
4825
|
+
_a.label = 1;
|
|
4790
4826
|
case 1:
|
|
4791
|
-
|
|
4792
|
-
return [4 /*yield*/,
|
|
4827
|
+
_a.trys.push([1, 4, , 5]);
|
|
4828
|
+
return [4 /*yield*/, fetch(options.url, init)];
|
|
4793
4829
|
case 2:
|
|
4794
|
-
|
|
4795
|
-
return [
|
|
4830
|
+
res = _a.sent();
|
|
4831
|
+
return [4 /*yield*/, res.json()];
|
|
4796
4832
|
case 3:
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
case 4:
|
|
4833
|
+
json = _a.sent();
|
|
4834
|
+
if (json.error)
|
|
4835
|
+
return [2 /*return*/, Promise.reject(json.error)];
|
|
4836
|
+
if (json.result)
|
|
4837
|
+
return [2 /*return*/, json.result];
|
|
4838
|
+
return [3 /*break*/, 5];
|
|
4839
|
+
case 4:
|
|
4840
|
+
e_4 = _a.sent();
|
|
4841
|
+
if (e_4.errno) {
|
|
4842
|
+
return [2 /*return*/, Promise.reject({ code: e_4.errno, message: e_4.toString(), data: '' })];
|
|
4843
|
+
}
|
|
4844
|
+
return [2 /*return*/, Promise.reject(e_4)];
|
|
4845
|
+
case 5: return [2 /*return*/];
|
|
4804
4846
|
}
|
|
4805
4847
|
});
|
|
4806
4848
|
});
|
|
4807
4849
|
}
|
|
4808
4850
|
function validate(validation, author, space, network, snapshot, params, options) {
|
|
4809
|
-
if (options === void 0) { options = {}; }
|
|
4810
|
-
var _a;
|
|
4811
4851
|
return __awaiter(this, void 0, void 0, function () {
|
|
4812
|
-
var
|
|
4813
|
-
return __generator(this, function (
|
|
4814
|
-
switch (
|
|
4852
|
+
var init, res, json, e_5;
|
|
4853
|
+
return __generator(this, function (_a) {
|
|
4854
|
+
switch (_a.label) {
|
|
4815
4855
|
case 0:
|
|
4816
|
-
|
|
4856
|
+
if (!options)
|
|
4857
|
+
options = {};
|
|
4858
|
+
if (!options.url)
|
|
4859
|
+
options.url = 'https://score.snapshot.org';
|
|
4817
4860
|
init = {
|
|
4818
4861
|
method: 'POST',
|
|
4819
4862
|
headers: scoreApiHeaders,
|
|
4820
|
-
|
|
4821
|
-
body: {
|
|
4863
|
+
body: JSON.stringify({
|
|
4822
4864
|
jsonrpc: '2.0',
|
|
4823
4865
|
method: 'validate',
|
|
4824
4866
|
params: {
|
|
@@ -4829,23 +4871,27 @@ function validate(validation, author, space, network, snapshot, params, options)
|
|
|
4829
4871
|
snapshot: snapshot,
|
|
4830
4872
|
params: params
|
|
4831
4873
|
}
|
|
4832
|
-
}
|
|
4874
|
+
})
|
|
4833
4875
|
};
|
|
4834
|
-
|
|
4876
|
+
_a.label = 1;
|
|
4835
4877
|
case 1:
|
|
4836
|
-
|
|
4837
|
-
return [4 /*yield*/,
|
|
4878
|
+
_a.trys.push([1, 4, , 5]);
|
|
4879
|
+
return [4 /*yield*/, fetch(options.url, init)];
|
|
4838
4880
|
case 2:
|
|
4839
|
-
|
|
4840
|
-
return [
|
|
4881
|
+
res = _a.sent();
|
|
4882
|
+
return [4 /*yield*/, res.json()];
|
|
4841
4883
|
case 3:
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4884
|
+
json = _a.sent();
|
|
4885
|
+
if (json.error)
|
|
4886
|
+
return [2 /*return*/, Promise.reject(json.error)];
|
|
4887
|
+
return [2 /*return*/, json.result];
|
|
4888
|
+
case 4:
|
|
4889
|
+
e_5 = _a.sent();
|
|
4890
|
+
if (e_5.errno) {
|
|
4891
|
+
return [2 /*return*/, Promise.reject({ code: e_5.errno, message: e_5.toString(), data: '' })];
|
|
4892
|
+
}
|
|
4893
|
+
return [2 /*return*/, Promise.reject(e_5)];
|
|
4894
|
+
case 5: return [2 /*return*/];
|
|
4849
4895
|
}
|
|
4850
4896
|
});
|
|
4851
4897
|
});
|
|
@@ -4881,7 +4927,7 @@ function getSpaceUri(id, network, options) {
|
|
|
4881
4927
|
if (network === void 0) { network = '1'; }
|
|
4882
4928
|
if (options === void 0) { options = {}; }
|
|
4883
4929
|
return __awaiter(this, void 0, void 0, function () {
|
|
4884
|
-
var
|
|
4930
|
+
var e_6;
|
|
4885
4931
|
return __generator(this, function (_a) {
|
|
4886
4932
|
switch (_a.label) {
|
|
4887
4933
|
case 0:
|
|
@@ -4889,8 +4935,8 @@ function getSpaceUri(id, network, options) {
|
|
|
4889
4935
|
return [4 /*yield*/, getEnsTextRecord(id, 'snapshot', network, options)];
|
|
4890
4936
|
case 1: return [2 /*return*/, _a.sent()];
|
|
4891
4937
|
case 2:
|
|
4892
|
-
|
|
4893
|
-
console.log(
|
|
4938
|
+
e_6 = _a.sent();
|
|
4939
|
+
console.log(e_6);
|
|
4894
4940
|
return [2 /*return*/, null];
|
|
4895
4941
|
case 3: return [2 /*return*/];
|
|
4896
4942
|
}
|