@dorafactory/maci-sdk 0.1.3-pre.46.beta.16 → 0.1.3-pre.46.beta.17
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/dist/index.js +830 -1191
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +831 -1192
- package/dist/index.mjs.map +1 -1
- package/dist/libs/api/client.d.ts +0 -4
- package/dist/libs/api/types.d.ts +1 -59
- package/dist/libs/const.d.ts +2 -2
- package/dist/libs/contract/contract.d.ts +177 -37
- package/dist/libs/contract/utils.d.ts +18 -0
- package/dist/libs/http/http.d.ts +4 -2
- package/dist/libs/maci/maci.d.ts +51 -22
- package/dist/maci.d.ts +41 -31
- package/dist/operator.d.ts +2 -2
- package/dist/types/index.d.ts +22 -11
- package/dist/voter.d.ts +7 -17
- package/package.json +18 -14
- package/src/libs/api/client.ts +0 -11
- package/src/libs/api/types.ts +1 -59
- package/src/libs/const.ts +8 -8
- package/src/libs/contract/contract.ts +658 -652
- package/src/libs/contract/utils.ts +35 -0
- package/src/libs/http/http.ts +75 -60
- package/src/libs/maci/maci.ts +204 -544
- package/src/libs/query/event.ts +4 -4
- package/src/libs/query/operator.ts +8 -10
- package/src/libs/query/round.ts +11 -10
- package/src/maci.ts +18 -11
- package/src/operator.ts +14 -8
- package/src/types/index.ts +20 -11
- package/src/voter.ts +32 -21
package/dist/index.js
CHANGED
|
@@ -247,12 +247,19 @@ function handleError(error) {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
// src/libs/http/http.ts
|
|
250
|
+
var DEFAULT_RETRIES = 5;
|
|
251
|
+
var DEFAULT_RETRY_DELAY = 200;
|
|
252
|
+
async function sleep(ms) {
|
|
253
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
254
|
+
}
|
|
250
255
|
var Http = class {
|
|
251
|
-
constructor(apiEndpoint,
|
|
256
|
+
constructor(apiEndpoint, restEndpoints, customFetch, defaultOptions, retries, retryDelay) {
|
|
252
257
|
this.customFetch = customFetch;
|
|
253
258
|
this.apiEndpoint = apiEndpoint;
|
|
254
|
-
this.
|
|
259
|
+
this.restEndpoints = Array.isArray(restEndpoints) ? restEndpoints : [restEndpoints];
|
|
255
260
|
this.defaultOptions = defaultOptions;
|
|
261
|
+
this.retries = retries ?? DEFAULT_RETRIES;
|
|
262
|
+
this.retryDelay = retryDelay ?? DEFAULT_RETRY_DELAY;
|
|
256
263
|
}
|
|
257
264
|
getFetch() {
|
|
258
265
|
return this.customFetch || fetch;
|
|
@@ -265,10 +272,7 @@ var Http = class {
|
|
|
265
272
|
...options
|
|
266
273
|
});
|
|
267
274
|
if (!response.ok) {
|
|
268
|
-
throw new HttpError(
|
|
269
|
-
`HTTP error! status: ${response.status}`,
|
|
270
|
-
response.status
|
|
271
|
-
);
|
|
275
|
+
throw new HttpError(`HTTP error! status: ${response.status}`, response.status);
|
|
272
276
|
}
|
|
273
277
|
return response;
|
|
274
278
|
} catch (error) {
|
|
@@ -297,25 +301,16 @@ var Http = class {
|
|
|
297
301
|
if (!response.ok) {
|
|
298
302
|
const errorData = await response.json();
|
|
299
303
|
if (errorData.errors?.[0]?.message?.includes("Syntax Error")) {
|
|
300
|
-
throw new GraphQLError(
|
|
301
|
-
`GraphQL syntax error: ${errorData.errors[0].message}`
|
|
302
|
-
);
|
|
304
|
+
throw new GraphQLError(`GraphQL syntax error: ${errorData.errors[0].message}`);
|
|
303
305
|
}
|
|
304
306
|
if (errorData.errors?.length > 0) {
|
|
305
|
-
throw new GraphQLError(
|
|
306
|
-
errorData.errors[0].message || "Unknown GraphQL error"
|
|
307
|
-
);
|
|
307
|
+
throw new GraphQLError(errorData.errors[0].message || "Unknown GraphQL error");
|
|
308
308
|
}
|
|
309
|
-
throw new HttpError(
|
|
310
|
-
`HTTP error: ${JSON.stringify(errorData)}`,
|
|
311
|
-
response.status
|
|
312
|
-
);
|
|
309
|
+
throw new HttpError(`HTTP error: ${JSON.stringify(errorData)}`, response.status);
|
|
313
310
|
}
|
|
314
311
|
const data = await response.json();
|
|
315
312
|
if (data.errors) {
|
|
316
|
-
throw new GraphQLError(
|
|
317
|
-
data.errors[0]?.message || "GraphQL query failed"
|
|
318
|
-
);
|
|
313
|
+
throw new GraphQLError(data.errors[0]?.message || "GraphQL query failed");
|
|
319
314
|
}
|
|
320
315
|
return data;
|
|
321
316
|
} catch (error) {
|
|
@@ -325,39 +320,51 @@ var Http = class {
|
|
|
325
320
|
if (error instanceof SyntaxError) {
|
|
326
321
|
throw new ParseError("Failed to parse JSON response");
|
|
327
322
|
}
|
|
328
|
-
throw new HttpError(
|
|
329
|
-
`Failed to fetch GraphQL: ${error.message}`,
|
|
330
|
-
500
|
|
331
|
-
);
|
|
323
|
+
throw new HttpError(`Failed to fetch GraphQL: ${error.message}`, 500);
|
|
332
324
|
}
|
|
333
325
|
}
|
|
334
326
|
async fetchRest(path, options) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
...options
|
|
340
|
-
});
|
|
341
|
-
if (!response.ok) {
|
|
342
|
-
throw new HttpError(
|
|
343
|
-
`HTTP error! status: ${response.status}`,
|
|
344
|
-
response.status
|
|
345
|
-
);
|
|
346
|
-
}
|
|
327
|
+
let lastError;
|
|
328
|
+
let restIndex = 0;
|
|
329
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
330
|
+
const endpoint = this.restEndpoints[restIndex];
|
|
347
331
|
try {
|
|
348
|
-
|
|
332
|
+
const fetchFn = this.getFetch();
|
|
333
|
+
const response = await fetchFn(`${endpoint}${path}`, {
|
|
334
|
+
...this.defaultOptions,
|
|
335
|
+
...options
|
|
336
|
+
});
|
|
337
|
+
if (!response.ok) {
|
|
338
|
+
throw new HttpError(`HTTP error! status: ${response.status}`, response.status);
|
|
339
|
+
}
|
|
340
|
+
try {
|
|
341
|
+
return await response.json();
|
|
342
|
+
} catch {
|
|
343
|
+
throw new ParseError("Failed to parse JSON response");
|
|
344
|
+
}
|
|
349
345
|
} catch (error) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
346
|
+
if (error instanceof HttpError && error.code >= 400 && error.code < 500) {
|
|
347
|
+
throw error;
|
|
348
|
+
}
|
|
349
|
+
lastError = error;
|
|
350
|
+
const nextIndex = (restIndex + 1) % this.restEndpoints.length;
|
|
351
|
+
const delay = this.retryDelay;
|
|
352
|
+
console.warn(
|
|
353
|
+
`[Http] REST request failed (attempt ${attempt + 1}/${this.retries + 1}) on ${endpoint}${path}: ${error?.message ?? error}` + (attempt < this.retries ? ` \u2014 retrying on ${this.restEndpoints[nextIndex]} in ${delay}ms` : " \u2014 all retries exhausted")
|
|
354
|
+
);
|
|
355
|
+
restIndex = nextIndex;
|
|
356
|
+
if (attempt < this.retries) {
|
|
357
|
+
await sleep(delay);
|
|
358
|
+
}
|
|
355
359
|
}
|
|
356
|
-
throw new HttpError(
|
|
357
|
-
`Failed to fetch REST: ${error.message}`,
|
|
358
|
-
500
|
|
359
|
-
);
|
|
360
360
|
}
|
|
361
|
+
if (lastError instanceof BaseError) {
|
|
362
|
+
throw lastError;
|
|
363
|
+
}
|
|
364
|
+
throw new HttpError(
|
|
365
|
+
`Failed to fetch REST: ${lastError?.message ?? "unknown error"}`,
|
|
366
|
+
500
|
|
367
|
+
);
|
|
361
368
|
}
|
|
362
369
|
async fetchAllGraphqlPages(query, variables) {
|
|
363
370
|
let hasNextPage = true;
|
|
@@ -476,9 +483,9 @@ function getDefaultParams(network = "mainnet") {
|
|
|
476
483
|
return {
|
|
477
484
|
network: "mainnet",
|
|
478
485
|
chainId: "vota-ash",
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
apiEndpoint: "https://
|
|
486
|
+
rpcEndpoints: ["https://vota-rpc.dorafactory.org", "https://vota-archive-rpc.dorafactory.org"],
|
|
487
|
+
restEndpoints: ["https://vota-rest.dorafactory.org", "https://vota-archive-rest.dorafactory.org"],
|
|
488
|
+
apiEndpoint: "https://maci-graphql.dorafactory.org",
|
|
482
489
|
saasApiEndpoint: "https://maci-xl-api.dorafactory.org",
|
|
483
490
|
certificateApiEndpoint: "https://vota-certificate-api.dorafactory.org/api/v1",
|
|
484
491
|
registryAddress: "dora1smg5qp5trjdkcekdjssqpjehdjf6n4cjss0clyvqcud3t3u3948s8rmgg4",
|
|
@@ -496,9 +503,9 @@ function getDefaultParams(network = "mainnet") {
|
|
|
496
503
|
return {
|
|
497
504
|
network: "testnet",
|
|
498
505
|
chainId: "vota-testnet",
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
apiEndpoint: "https://
|
|
506
|
+
rpcEndpoints: ["https://vota-testnet-rpc.dorafactory.org"],
|
|
507
|
+
restEndpoints: ["https://vota-testnet-rest.dorafactory.org"],
|
|
508
|
+
apiEndpoint: "https://maci-testnet-graphql.dorafactory.org",
|
|
502
509
|
saasApiEndpoint: "https://maci-xl-testnet-api.dorafactory.org",
|
|
503
510
|
certificateApiEndpoint: "https://vota-testnet-certificate-api.dorafactory.org/api/v1",
|
|
504
511
|
registryAddress: "dora13c8aecstyxrhax9znvvh5zey89edrmd2k5va57pxvpe3fxtfsfeqlhsjnd",
|
|
@@ -1851,14 +1858,14 @@ var Operator = class {
|
|
|
1851
1858
|
const ROUNDS_QUERY = `query {
|
|
1852
1859
|
activeRoundsCount: rounds(filter: {
|
|
1853
1860
|
period: {notEqualTo: "Ended"},
|
|
1854
|
-
|
|
1861
|
+
operatorAddress: {equalTo: "${operatorResponse.operatorAddress}"},
|
|
1855
1862
|
caller: {equalTo: "${this.amaciRegistryContract}"}
|
|
1856
1863
|
}) {
|
|
1857
1864
|
totalCount
|
|
1858
1865
|
}
|
|
1859
1866
|
completedRoundsCount: rounds(filter: {
|
|
1860
1867
|
period: {equalTo: "Ended"},
|
|
1861
|
-
|
|
1868
|
+
operatorAddress: {equalTo: "${operatorResponse.operatorAddress}"},
|
|
1862
1869
|
caller: {equalTo: "${this.amaciRegistryContract}"}
|
|
1863
1870
|
}) {
|
|
1864
1871
|
totalCount
|
|
@@ -1923,10 +1930,9 @@ var Operator = class {
|
|
|
1923
1930
|
delayReason
|
|
1924
1931
|
delayType
|
|
1925
1932
|
id
|
|
1926
|
-
nodeId
|
|
1927
1933
|
operatorAddress
|
|
1928
1934
|
timestamp
|
|
1929
|
-
|
|
1935
|
+
contractAddress
|
|
1930
1936
|
}
|
|
1931
1937
|
}
|
|
1932
1938
|
}
|
|
@@ -2001,14 +2007,14 @@ var Operator = class {
|
|
|
2001
2007
|
const ROUNDS_QUERY = `query {
|
|
2002
2008
|
activeRoundsCount: rounds(filter: {
|
|
2003
2009
|
period: {notEqualTo: "Ended"},
|
|
2004
|
-
|
|
2010
|
+
operatorAddress: {equalTo: "${operator.operatorAddress}"},
|
|
2005
2011
|
caller: {equalTo: "${this.amaciRegistryContract}"}
|
|
2006
2012
|
}) {
|
|
2007
2013
|
totalCount
|
|
2008
2014
|
}
|
|
2009
2015
|
completedRoundsCount: rounds(filter: {
|
|
2010
2016
|
period: {equalTo: "Ended"},
|
|
2011
|
-
|
|
2017
|
+
operatorAddress: {equalTo: "${operator.operatorAddress}"},
|
|
2012
2018
|
caller: {equalTo: "${this.amaciRegistryContract}"}
|
|
2013
2019
|
}) {
|
|
2014
2020
|
totalCount
|
|
@@ -2084,10 +2090,9 @@ var Operator = class {
|
|
|
2084
2090
|
delayReason
|
|
2085
2091
|
delayType
|
|
2086
2092
|
id
|
|
2087
|
-
nodeId
|
|
2088
2093
|
operatorAddress
|
|
2089
2094
|
timestamp
|
|
2090
|
-
|
|
2095
|
+
contractAddress
|
|
2091
2096
|
}
|
|
2092
2097
|
}
|
|
2093
2098
|
}
|
|
@@ -2095,7 +2100,7 @@ var Operator = class {
|
|
|
2095
2100
|
const ROUNDS_QUERY = `query ($limit: Int, $after: Cursor) {
|
|
2096
2101
|
rounds(first: $limit, after: $after,
|
|
2097
2102
|
filter: {
|
|
2098
|
-
|
|
2103
|
+
operatorAddress: {equalTo: "${address}"},
|
|
2099
2104
|
votingEnd: { greaterThanOrEqualTo: "${endNanosTimestamp}" }
|
|
2100
2105
|
},
|
|
2101
2106
|
orderBy: [TIMESTAMP_DESC]
|
|
@@ -2112,7 +2117,7 @@ var Operator = class {
|
|
|
2112
2117
|
txHash
|
|
2113
2118
|
caller
|
|
2114
2119
|
admin
|
|
2115
|
-
|
|
2120
|
+
operatorAddress
|
|
2116
2121
|
contractAddress
|
|
2117
2122
|
circuitName
|
|
2118
2123
|
timestamp
|
|
@@ -2304,7 +2309,7 @@ var Round = class {
|
|
|
2304
2309
|
txHash
|
|
2305
2310
|
caller
|
|
2306
2311
|
admin
|
|
2307
|
-
|
|
2312
|
+
operatorAddress
|
|
2308
2313
|
contractAddress
|
|
2309
2314
|
circuitName
|
|
2310
2315
|
timestamp
|
|
@@ -2332,7 +2337,9 @@ var Round = class {
|
|
|
2332
2337
|
maciType
|
|
2333
2338
|
voiceCreditAmount
|
|
2334
2339
|
preDeactivateRoot
|
|
2335
|
-
|
|
2340
|
+
operator {
|
|
2341
|
+
identity
|
|
2342
|
+
}
|
|
2336
2343
|
}
|
|
2337
2344
|
}`;
|
|
2338
2345
|
const response = await this.http.fetchGraphql(ROUND_QUERY, "");
|
|
@@ -2347,7 +2354,7 @@ var Round = class {
|
|
|
2347
2354
|
}
|
|
2348
2355
|
response.data.round.operatorLogoUrl = "";
|
|
2349
2356
|
response.data.round.operatorMoniker = "";
|
|
2350
|
-
const identity = response.data.round.identity;
|
|
2357
|
+
const identity = response.data.round.operator?.identity ?? "";
|
|
2351
2358
|
const keybaseUrl = `https://keybase.io/_/api/1.0/user/lookup.json?key_suffix=${identity}`;
|
|
2352
2359
|
const keybaseResponse = await this.http.fetch(keybaseUrl);
|
|
2353
2360
|
const keybaseData = await keybaseResponse.json();
|
|
@@ -2393,7 +2400,7 @@ var Round = class {
|
|
|
2393
2400
|
"txHash",
|
|
2394
2401
|
"caller",
|
|
2395
2402
|
"admin",
|
|
2396
|
-
"
|
|
2403
|
+
"operatorAddress",
|
|
2397
2404
|
"contractAddress",
|
|
2398
2405
|
"circuitName",
|
|
2399
2406
|
"timestamp",
|
|
@@ -2420,8 +2427,7 @@ var Round = class {
|
|
|
2420
2427
|
"codeId",
|
|
2421
2428
|
"maciType",
|
|
2422
2429
|
"voiceCreditAmount",
|
|
2423
|
-
"preDeactivateRoot"
|
|
2424
|
-
"identity"
|
|
2430
|
+
"preDeactivateRoot"
|
|
2425
2431
|
// 'funds',
|
|
2426
2432
|
];
|
|
2427
2433
|
if (fields && fields.length > 0) {
|
|
@@ -2477,7 +2483,7 @@ var Round = class {
|
|
|
2477
2483
|
txHash
|
|
2478
2484
|
caller
|
|
2479
2485
|
admin
|
|
2480
|
-
|
|
2486
|
+
operatorAddress
|
|
2481
2487
|
contractAddress
|
|
2482
2488
|
circuitName
|
|
2483
2489
|
timestamp
|
|
@@ -2554,7 +2560,7 @@ var Round = class {
|
|
|
2554
2560
|
txHash
|
|
2555
2561
|
caller
|
|
2556
2562
|
admin
|
|
2557
|
-
|
|
2563
|
+
operatorAddress
|
|
2558
2564
|
contractAddress
|
|
2559
2565
|
circuitName
|
|
2560
2566
|
timestamp
|
|
@@ -2669,7 +2675,7 @@ var Round = class {
|
|
|
2669
2675
|
txHash
|
|
2670
2676
|
caller
|
|
2671
2677
|
admin
|
|
2672
|
-
|
|
2678
|
+
operatorAddress
|
|
2673
2679
|
contractAddress
|
|
2674
2680
|
circuitName
|
|
2675
2681
|
timestamp
|
|
@@ -2736,7 +2742,7 @@ var Round = class {
|
|
|
2736
2742
|
}
|
|
2737
2743
|
const ROUND_HISTORY_QUERY = `query ($limit: Int!, $after: Cursor) {
|
|
2738
2744
|
rounds(first: $limit, after: $after, filter:{
|
|
2739
|
-
|
|
2745
|
+
operatorAddress:{
|
|
2740
2746
|
equalTo: "${operator}"
|
|
2741
2747
|
}
|
|
2742
2748
|
}, orderBy: [TIMESTAMP_DESC]){
|
|
@@ -2753,7 +2759,7 @@ var Round = class {
|
|
|
2753
2759
|
txHash
|
|
2754
2760
|
caller
|
|
2755
2761
|
admin
|
|
2756
|
-
|
|
2762
|
+
operatorAddress
|
|
2757
2763
|
contractAddress
|
|
2758
2764
|
circuitName
|
|
2759
2765
|
timestamp
|
|
@@ -3086,12 +3092,12 @@ query signUpEvents($limit: Int, $after: Cursor) {
|
|
|
3086
3092
|
}
|
|
3087
3093
|
async fetchAllDeactivateLogs(contractAddress) {
|
|
3088
3094
|
const DEACTIVATE_MESSAGE_QUERY = `query ($limit: Int, $offset: Int) {
|
|
3089
|
-
|
|
3095
|
+
uploadedDeactivateMessages(
|
|
3090
3096
|
first: $limit,
|
|
3091
3097
|
offset: $offset,
|
|
3092
3098
|
orderBy: [BLOCK_HEIGHT_ASC],
|
|
3093
3099
|
filter: {
|
|
3094
|
-
|
|
3100
|
+
contractAddress: {
|
|
3095
3101
|
equalTo: "${contractAddress}"
|
|
3096
3102
|
},
|
|
3097
3103
|
}
|
|
@@ -3107,8 +3113,8 @@ query signUpEvents($limit: Int, $after: Cursor) {
|
|
|
3107
3113
|
timestamp
|
|
3108
3114
|
txHash
|
|
3109
3115
|
deactivateMessage
|
|
3110
|
-
|
|
3111
|
-
|
|
3116
|
+
contractAddress
|
|
3117
|
+
operatorAddress
|
|
3112
3118
|
}
|
|
3113
3119
|
}
|
|
3114
3120
|
}`;
|
|
@@ -4631,20 +4637,45 @@ var DEFAULT_DELAY_CONFIG = {
|
|
|
4631
4637
|
};
|
|
4632
4638
|
|
|
4633
4639
|
// src/libs/contract/contract.ts
|
|
4640
|
+
function toUtf8(str) {
|
|
4641
|
+
return new TextEncoder().encode(str);
|
|
4642
|
+
}
|
|
4643
|
+
var DEFAULT_GAS_PRICE = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
4644
|
+
var DEFAULT_RETRIES2 = 5;
|
|
4645
|
+
var DEFAULT_RETRY_DELAY2 = 200;
|
|
4646
|
+
async function sleep2(ms) {
|
|
4647
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4648
|
+
}
|
|
4649
|
+
async function resolveFee(signingClient, address, msgs, fee, granter) {
|
|
4650
|
+
let stdFee;
|
|
4651
|
+
if (typeof fee === "object") {
|
|
4652
|
+
stdFee = fee;
|
|
4653
|
+
} else {
|
|
4654
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
4655
|
+
const gasEstimation = await signingClient.simulate(address, msgs, "");
|
|
4656
|
+
stdFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), DEFAULT_GAS_PRICE);
|
|
4657
|
+
}
|
|
4658
|
+
if (granter) {
|
|
4659
|
+
return { ...stdFee, granter };
|
|
4660
|
+
}
|
|
4661
|
+
return stdFee;
|
|
4662
|
+
}
|
|
4634
4663
|
var Contract = class {
|
|
4635
4664
|
constructor({
|
|
4636
4665
|
network,
|
|
4637
|
-
|
|
4666
|
+
rpcEndpoints,
|
|
4638
4667
|
registryAddress,
|
|
4639
4668
|
saasAddress,
|
|
4640
4669
|
apiSaasAddress,
|
|
4641
4670
|
maciCodeId,
|
|
4642
4671
|
oracleCodeId,
|
|
4643
4672
|
feegrantOperator,
|
|
4644
|
-
whitelistBackendPubkey
|
|
4673
|
+
whitelistBackendPubkey,
|
|
4674
|
+
retries,
|
|
4675
|
+
retryDelay
|
|
4645
4676
|
}) {
|
|
4646
4677
|
this.network = network;
|
|
4647
|
-
this.
|
|
4678
|
+
this.rpcUrls = rpcEndpoints;
|
|
4648
4679
|
this.registryAddress = registryAddress;
|
|
4649
4680
|
this.saasAddress = saasAddress;
|
|
4650
4681
|
this.apiSaasAddress = apiSaasAddress;
|
|
@@ -4652,106 +4683,79 @@ var Contract = class {
|
|
|
4652
4683
|
this.oracleCodeId = oracleCodeId;
|
|
4653
4684
|
this.feegrantOperator = feegrantOperator;
|
|
4654
4685
|
this.whitelistBackendPubkey = whitelistBackendPubkey;
|
|
4686
|
+
this.retries = retries ?? DEFAULT_RETRIES2;
|
|
4687
|
+
this.retryDelay = retryDelay ?? DEFAULT_RETRY_DELAY2;
|
|
4655
4688
|
}
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4678
|
-
operator: params.operator,
|
|
4679
|
-
registrationMode: params.registrationMode,
|
|
4680
|
-
roundInfo,
|
|
4681
|
-
voiceCreditMode: params.voiceCreditMode,
|
|
4682
|
-
voteOptionMap: params.voteOptionMap,
|
|
4683
|
-
votingTime
|
|
4684
|
-
},
|
|
4685
|
-
fee,
|
|
4686
|
-
void 0,
|
|
4687
|
-
[{ denom: FEE_DENOM, amount: DEFAULT_BASE_FEE }]
|
|
4688
|
-
);
|
|
4689
|
-
let contractAddress = "";
|
|
4690
|
-
let pollId = "";
|
|
4691
|
-
for (const event of res.events) {
|
|
4692
|
-
if (event.type === "wasm") {
|
|
4693
|
-
const actionEvent = event.attributes.find(
|
|
4694
|
-
(attr) => attr.key === "action"
|
|
4689
|
+
/**
|
|
4690
|
+
* Execute fn with primary-first multi-endpoint failover and exponential backoff retry.
|
|
4691
|
+
* Every call starts from rpcUrls[0] (primary). On failure the next endpoint is tried
|
|
4692
|
+
* in order, cycling back to the primary once all endpoints have been exhausted.
|
|
4693
|
+
* Retries only on connection-level errors; tx-level rejections fail fast.
|
|
4694
|
+
*/
|
|
4695
|
+
async withRetry(fn) {
|
|
4696
|
+
let lastError;
|
|
4697
|
+
let urlIndex = 0;
|
|
4698
|
+
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
4699
|
+
const rpcEndpoint = this.rpcUrls[urlIndex];
|
|
4700
|
+
try {
|
|
4701
|
+
return await fn(rpcEndpoint);
|
|
4702
|
+
} catch (err) {
|
|
4703
|
+
if (err instanceof import_stargate2.BroadcastTxError) {
|
|
4704
|
+
throw err;
|
|
4705
|
+
}
|
|
4706
|
+
lastError = err;
|
|
4707
|
+
const nextIndex = (urlIndex + 1) % this.rpcUrls.length;
|
|
4708
|
+
const delay = this.retryDelay;
|
|
4709
|
+
console.warn(
|
|
4710
|
+
`[Contract] RPC request failed (attempt ${attempt + 1}/${this.retries + 1}) on ${rpcEndpoint}: ${err?.message ?? err}` + (attempt < this.retries ? ` \u2014 retrying on ${this.rpcUrls[nextIndex]} in ${delay}ms` : " \u2014 all retries exhausted")
|
|
4695
4711
|
);
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
);
|
|
4700
|
-
const pollIdEvent = event.attributes.find(
|
|
4701
|
-
(attr) => attr.key === "poll_id"
|
|
4702
|
-
);
|
|
4703
|
-
if (roundAddrEvent) {
|
|
4704
|
-
contractAddress = roundAddrEvent.value.toString();
|
|
4705
|
-
}
|
|
4706
|
-
if (pollIdEvent) {
|
|
4707
|
-
pollId = pollIdEvent.value.toString();
|
|
4708
|
-
}
|
|
4709
|
-
if (contractAddress) {
|
|
4710
|
-
break;
|
|
4711
|
-
}
|
|
4712
|
+
urlIndex = nextIndex;
|
|
4713
|
+
if (attempt < this.retries) {
|
|
4714
|
+
await sleep2(delay);
|
|
4712
4715
|
}
|
|
4713
4716
|
}
|
|
4714
4717
|
}
|
|
4715
|
-
|
|
4716
|
-
...res,
|
|
4717
|
-
contractAddress,
|
|
4718
|
-
pollId
|
|
4719
|
-
};
|
|
4718
|
+
throw lastError;
|
|
4720
4719
|
}
|
|
4720
|
+
// ==================== Query Methods (unchanged) ====================
|
|
4721
4721
|
async queryRoundInfo({ signer, roundAddress }) {
|
|
4722
|
-
|
|
4723
|
-
rpcEndpoint:
|
|
4724
|
-
|
|
4725
|
-
contractAddress: roundAddress
|
|
4722
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4723
|
+
const client = await createAMaciQueryClientBy({ rpcEndpoint, contractAddress: roundAddress });
|
|
4724
|
+
return client.getRoundInfo();
|
|
4726
4725
|
});
|
|
4727
|
-
const roundInfo = await client.getRoundInfo();
|
|
4728
|
-
return roundInfo;
|
|
4729
4726
|
}
|
|
4730
4727
|
async getStateIdx({
|
|
4731
4728
|
contractAddress,
|
|
4732
4729
|
pubkey
|
|
4733
4730
|
}) {
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4731
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4732
|
+
const client = await createAMaciQueryClientBy({ rpcEndpoint, contractAddress });
|
|
4733
|
+
return client.signuped({ pubkey });
|
|
4737
4734
|
});
|
|
4738
|
-
const stateIdx = await client.signuped({ pubkey });
|
|
4739
|
-
return stateIdx;
|
|
4740
4735
|
}
|
|
4741
4736
|
async getPollId({ contractAddress }) {
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4737
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4738
|
+
const client = await createAMaciQueryClientBy({ rpcEndpoint, contractAddress });
|
|
4739
|
+
return client.getPollId();
|
|
4740
|
+
});
|
|
4741
|
+
}
|
|
4742
|
+
async isApiSaasOperator({ signer, operator }) {
|
|
4743
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4744
|
+
const client = await createApiSaasClientBy({
|
|
4745
|
+
rpcEndpoint,
|
|
4746
|
+
wallet: signer,
|
|
4747
|
+
contractAddress: this.apiSaasAddress
|
|
4748
|
+
});
|
|
4749
|
+
return client.isOperator({ address: operator });
|
|
4745
4750
|
});
|
|
4746
|
-
const pollId = await client.getPollId();
|
|
4747
|
-
return pollId;
|
|
4748
4751
|
}
|
|
4752
|
+
// ==================== Client Accessors ====================
|
|
4749
4753
|
async registryClient({
|
|
4750
4754
|
signer,
|
|
4751
4755
|
contractAddress
|
|
4752
4756
|
}) {
|
|
4753
4757
|
return createRegistryClientBy({
|
|
4754
|
-
rpcEndpoint: this.
|
|
4758
|
+
rpcEndpoint: this.rpcUrls[0],
|
|
4755
4759
|
wallet: signer,
|
|
4756
4760
|
contractAddress
|
|
4757
4761
|
});
|
|
@@ -4761,20 +4765,20 @@ var Contract = class {
|
|
|
4761
4765
|
contractAddress
|
|
4762
4766
|
}) {
|
|
4763
4767
|
return createAMaciClientBy({
|
|
4764
|
-
rpcEndpoint: this.
|
|
4768
|
+
rpcEndpoint: this.rpcUrls[0],
|
|
4765
4769
|
wallet: signer,
|
|
4766
4770
|
contractAddress
|
|
4767
4771
|
});
|
|
4768
4772
|
}
|
|
4769
4773
|
async amaciQueryClient({ contractAddress }) {
|
|
4770
4774
|
return createAMaciQueryClientBy({
|
|
4771
|
-
rpcEndpoint: this.
|
|
4775
|
+
rpcEndpoint: this.rpcUrls[0],
|
|
4772
4776
|
contractAddress
|
|
4773
4777
|
});
|
|
4774
4778
|
}
|
|
4775
4779
|
async registryQueryClient() {
|
|
4776
4780
|
return createRegistryQueryClientBy({
|
|
4777
|
-
rpcEndpoint: this.
|
|
4781
|
+
rpcEndpoint: this.rpcUrls[0],
|
|
4778
4782
|
contractAddress: this.registryAddress
|
|
4779
4783
|
});
|
|
4780
4784
|
}
|
|
@@ -4783,13 +4787,53 @@ var Contract = class {
|
|
|
4783
4787
|
contractAddress
|
|
4784
4788
|
}) {
|
|
4785
4789
|
return createApiSaasClientBy({
|
|
4786
|
-
rpcEndpoint: this.
|
|
4790
|
+
rpcEndpoint: this.rpcUrls[0],
|
|
4787
4791
|
wallet: signer,
|
|
4788
4792
|
contractAddress
|
|
4789
4793
|
});
|
|
4790
4794
|
}
|
|
4791
4795
|
async contractClient({ signer }) {
|
|
4792
|
-
return createContractClientByWallet(this.
|
|
4796
|
+
return createContractClientByWallet(this.rpcUrls[0], signer);
|
|
4797
|
+
}
|
|
4798
|
+
// ==================== Write Transaction Methods ====================
|
|
4799
|
+
async createAMaciRound(params) {
|
|
4800
|
+
const { signer } = params;
|
|
4801
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4802
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
4803
|
+
const [{ address }] = await signer.getAccounts();
|
|
4804
|
+
const msg = {
|
|
4805
|
+
create_round: {
|
|
4806
|
+
certification_system: params.certificationSystem ?? "0",
|
|
4807
|
+
circuit_type: params.circuitType.toString(),
|
|
4808
|
+
deactivate_enabled: params.deactivateEnabled,
|
|
4809
|
+
operator: params.operator,
|
|
4810
|
+
registration_mode: params.registrationMode,
|
|
4811
|
+
round_info: {
|
|
4812
|
+
title: params.title,
|
|
4813
|
+
description: params.description ?? "",
|
|
4814
|
+
link: params.link ?? ""
|
|
4815
|
+
},
|
|
4816
|
+
voice_credit_mode: params.voiceCreditMode,
|
|
4817
|
+
vote_option_map: params.voteOptionMap,
|
|
4818
|
+
voting_time: {
|
|
4819
|
+
start_time: (BigInt(params.startVoting.getTime()) * 1000000n).toString(),
|
|
4820
|
+
end_time: (BigInt(params.endVoting.getTime()) * 1000000n).toString()
|
|
4821
|
+
}
|
|
4822
|
+
}
|
|
4823
|
+
};
|
|
4824
|
+
const executeMsg = {
|
|
4825
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4826
|
+
value: {
|
|
4827
|
+
sender: address,
|
|
4828
|
+
contract: this.registryAddress,
|
|
4829
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4830
|
+
funds: [{ denom: FEE_DENOM, amount: DEFAULT_BASE_FEE }]
|
|
4831
|
+
}
|
|
4832
|
+
};
|
|
4833
|
+
const fee = await resolveFee(signingClient, address, [executeMsg], params.fee ?? "auto");
|
|
4834
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], fee);
|
|
4835
|
+
return { txHash };
|
|
4836
|
+
});
|
|
4793
4837
|
}
|
|
4794
4838
|
async setApiSaasMaciRoundInfo({
|
|
4795
4839
|
signer,
|
|
@@ -4800,74 +4844,29 @@ var Contract = class {
|
|
|
4800
4844
|
gasStation = false,
|
|
4801
4845
|
fee = 1.8
|
|
4802
4846
|
}) {
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
wallet: signer,
|
|
4806
|
-
contractAddress: this.apiSaasAddress
|
|
4807
|
-
});
|
|
4808
|
-
const roundInfo = {
|
|
4809
|
-
title,
|
|
4810
|
-
description,
|
|
4811
|
-
link
|
|
4812
|
-
};
|
|
4813
|
-
if (gasStation && typeof fee !== "object") {
|
|
4847
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4848
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
4814
4849
|
const [{ address }] = await signer.getAccounts();
|
|
4815
|
-
const contractClient = await this.contractClient({ signer });
|
|
4816
4850
|
const msg = {
|
|
4817
4851
|
set_round_info: {
|
|
4818
4852
|
contract_addr: contractAddress,
|
|
4819
|
-
round_info:
|
|
4853
|
+
round_info: { title, description, link }
|
|
4820
4854
|
}
|
|
4821
4855
|
};
|
|
4822
|
-
const
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
4831
|
-
}
|
|
4832
|
-
}
|
|
4833
|
-
],
|
|
4834
|
-
""
|
|
4835
|
-
);
|
|
4836
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
4837
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
4838
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
4839
|
-
const grantFee = {
|
|
4840
|
-
amount: calculatedFee.amount,
|
|
4841
|
-
gas: calculatedFee.gas,
|
|
4842
|
-
granter: this.apiSaasAddress
|
|
4843
|
-
};
|
|
4844
|
-
return client.setRoundInfo(
|
|
4845
|
-
{
|
|
4846
|
-
contractAddr: contractAddress,
|
|
4847
|
-
roundInfo
|
|
4848
|
-
},
|
|
4849
|
-
grantFee
|
|
4850
|
-
);
|
|
4851
|
-
} else if (gasStation && typeof fee === "object") {
|
|
4852
|
-
const grantFee = {
|
|
4853
|
-
...fee,
|
|
4854
|
-
granter: this.apiSaasAddress
|
|
4856
|
+
const executeMsg = {
|
|
4857
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4858
|
+
value: {
|
|
4859
|
+
sender: address,
|
|
4860
|
+
contract: this.apiSaasAddress,
|
|
4861
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4862
|
+
funds: []
|
|
4863
|
+
}
|
|
4855
4864
|
};
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
grantFee
|
|
4862
|
-
);
|
|
4863
|
-
}
|
|
4864
|
-
return client.setRoundInfo(
|
|
4865
|
-
{
|
|
4866
|
-
contractAddr: contractAddress,
|
|
4867
|
-
roundInfo
|
|
4868
|
-
},
|
|
4869
|
-
fee
|
|
4870
|
-
);
|
|
4865
|
+
const granter = gasStation ? this.apiSaasAddress : void 0;
|
|
4866
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
4867
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
4868
|
+
return { txHash };
|
|
4869
|
+
});
|
|
4871
4870
|
}
|
|
4872
4871
|
async setApiSaasMaciRoundVoteOptions({
|
|
4873
4872
|
signer,
|
|
@@ -4876,69 +4875,29 @@ var Contract = class {
|
|
|
4876
4875
|
gasStation = false,
|
|
4877
4876
|
fee = 1.8
|
|
4878
4877
|
}) {
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
wallet: signer,
|
|
4882
|
-
contractAddress: this.apiSaasAddress
|
|
4883
|
-
});
|
|
4884
|
-
if (gasStation && typeof fee !== "object") {
|
|
4878
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4879
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
4885
4880
|
const [{ address }] = await signer.getAccounts();
|
|
4886
|
-
const contractClient = await this.contractClient({ signer });
|
|
4887
4881
|
const msg = {
|
|
4888
4882
|
set_vote_options_map: {
|
|
4889
4883
|
contract_addr: contractAddress,
|
|
4890
4884
|
vote_option_map: voteOptionMap
|
|
4891
4885
|
}
|
|
4892
4886
|
};
|
|
4893
|
-
const
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
4902
|
-
}
|
|
4903
|
-
}
|
|
4904
|
-
],
|
|
4905
|
-
""
|
|
4906
|
-
);
|
|
4907
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
4908
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
4909
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
4910
|
-
const grantFee = {
|
|
4911
|
-
amount: calculatedFee.amount,
|
|
4912
|
-
gas: calculatedFee.gas,
|
|
4913
|
-
granter: this.apiSaasAddress
|
|
4914
|
-
};
|
|
4915
|
-
return client.setVoteOptionsMap(
|
|
4916
|
-
{
|
|
4917
|
-
contractAddr: contractAddress,
|
|
4918
|
-
voteOptionMap
|
|
4919
|
-
},
|
|
4920
|
-
grantFee
|
|
4921
|
-
);
|
|
4922
|
-
} else if (gasStation && typeof fee === "object") {
|
|
4923
|
-
const grantFee = {
|
|
4924
|
-
...fee,
|
|
4925
|
-
granter: this.apiSaasAddress
|
|
4887
|
+
const executeMsg = {
|
|
4888
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4889
|
+
value: {
|
|
4890
|
+
sender: address,
|
|
4891
|
+
contract: this.apiSaasAddress,
|
|
4892
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4893
|
+
funds: []
|
|
4894
|
+
}
|
|
4926
4895
|
};
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
grantFee
|
|
4933
|
-
);
|
|
4934
|
-
}
|
|
4935
|
-
return client.setVoteOptionsMap(
|
|
4936
|
-
{
|
|
4937
|
-
contractAddr: contractAddress,
|
|
4938
|
-
voteOptionMap
|
|
4939
|
-
},
|
|
4940
|
-
fee
|
|
4941
|
-
);
|
|
4896
|
+
const granter = gasStation ? this.apiSaasAddress : void 0;
|
|
4897
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
4898
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
4899
|
+
return { txHash };
|
|
4900
|
+
});
|
|
4942
4901
|
}
|
|
4943
4902
|
async addApiSaasOperator({
|
|
4944
4903
|
signer,
|
|
@@ -4946,50 +4905,24 @@ var Contract = class {
|
|
|
4946
4905
|
gasStation = false,
|
|
4947
4906
|
fee = 1.8
|
|
4948
4907
|
}) {
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
wallet: signer,
|
|
4952
|
-
contractAddress: this.apiSaasAddress
|
|
4953
|
-
});
|
|
4954
|
-
if (gasStation && typeof fee !== "object") {
|
|
4908
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4909
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
4955
4910
|
const [{ address }] = await signer.getAccounts();
|
|
4956
|
-
const
|
|
4957
|
-
const
|
|
4958
|
-
|
|
4959
|
-
|
|
4911
|
+
const msg = { add_operator: { operator } };
|
|
4912
|
+
const executeMsg = {
|
|
4913
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4914
|
+
value: {
|
|
4915
|
+
sender: address,
|
|
4916
|
+
contract: this.apiSaasAddress,
|
|
4917
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4918
|
+
funds: []
|
|
4960
4919
|
}
|
|
4961
4920
|
};
|
|
4962
|
-
const
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
value: {
|
|
4968
|
-
sender: address,
|
|
4969
|
-
contract: this.apiSaasAddress,
|
|
4970
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
4971
|
-
}
|
|
4972
|
-
}
|
|
4973
|
-
],
|
|
4974
|
-
""
|
|
4975
|
-
);
|
|
4976
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
4977
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
4978
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
4979
|
-
const grantFee = {
|
|
4980
|
-
amount: calculatedFee.amount,
|
|
4981
|
-
gas: calculatedFee.gas,
|
|
4982
|
-
granter: this.apiSaasAddress
|
|
4983
|
-
};
|
|
4984
|
-
return client.addOperator({ operator }, grantFee);
|
|
4985
|
-
} else if (gasStation && typeof fee === "object") {
|
|
4986
|
-
const grantFee = {
|
|
4987
|
-
...fee,
|
|
4988
|
-
granter: this.apiSaasAddress
|
|
4989
|
-
};
|
|
4990
|
-
return client.addOperator({ operator }, grantFee);
|
|
4991
|
-
}
|
|
4992
|
-
return client.addOperator({ operator }, fee);
|
|
4921
|
+
const granter = gasStation ? this.apiSaasAddress : void 0;
|
|
4922
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
4923
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
4924
|
+
return { txHash };
|
|
4925
|
+
});
|
|
4993
4926
|
}
|
|
4994
4927
|
async removeApiSaasOperator({
|
|
4995
4928
|
signer,
|
|
@@ -4997,169 +4930,70 @@ var Contract = class {
|
|
|
4997
4930
|
gasStation = false,
|
|
4998
4931
|
fee = 1.8
|
|
4999
4932
|
}) {
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
wallet: signer,
|
|
5003
|
-
contractAddress: this.apiSaasAddress
|
|
5004
|
-
});
|
|
5005
|
-
if (gasStation && typeof fee !== "object") {
|
|
4933
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4934
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5006
4935
|
const [{ address }] = await signer.getAccounts();
|
|
5007
|
-
const
|
|
5008
|
-
const
|
|
5009
|
-
|
|
5010
|
-
|
|
4936
|
+
const msg = { remove_operator: { operator } };
|
|
4937
|
+
const executeMsg = {
|
|
4938
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4939
|
+
value: {
|
|
4940
|
+
sender: address,
|
|
4941
|
+
contract: this.apiSaasAddress,
|
|
4942
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4943
|
+
funds: []
|
|
5011
4944
|
}
|
|
5012
4945
|
};
|
|
5013
|
-
const
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5018
|
-
value: {
|
|
5019
|
-
sender: address,
|
|
5020
|
-
contract: this.apiSaasAddress,
|
|
5021
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5022
|
-
}
|
|
5023
|
-
}
|
|
5024
|
-
],
|
|
5025
|
-
""
|
|
5026
|
-
);
|
|
5027
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5028
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5029
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5030
|
-
const grantFee = {
|
|
5031
|
-
amount: calculatedFee.amount,
|
|
5032
|
-
gas: calculatedFee.gas,
|
|
5033
|
-
granter: this.apiSaasAddress
|
|
5034
|
-
};
|
|
5035
|
-
return client.removeOperator({ operator }, grantFee);
|
|
5036
|
-
} else if (gasStation && typeof fee === "object") {
|
|
5037
|
-
const grantFee = {
|
|
5038
|
-
...fee,
|
|
5039
|
-
granter: this.apiSaasAddress
|
|
5040
|
-
};
|
|
5041
|
-
return client.removeOperator({ operator }, grantFee);
|
|
5042
|
-
}
|
|
5043
|
-
return client.removeOperator({ operator }, fee);
|
|
5044
|
-
}
|
|
5045
|
-
async isApiSaasOperator({ signer, operator }) {
|
|
5046
|
-
const client = await createApiSaasClientBy({
|
|
5047
|
-
rpcEndpoint: this.rpcEndpoint,
|
|
5048
|
-
wallet: signer,
|
|
5049
|
-
contractAddress: this.apiSaasAddress
|
|
4946
|
+
const granter = gasStation ? this.apiSaasAddress : void 0;
|
|
4947
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
4948
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
4949
|
+
return { txHash };
|
|
5050
4950
|
});
|
|
5051
|
-
return client.isOperator({ address: operator });
|
|
5052
4951
|
}
|
|
5053
4952
|
async createApiSaasAmaciRound(params) {
|
|
5054
4953
|
const { signer } = params;
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
description: params.description ?? "",
|
|
5058
|
-
link: params.link ?? ""
|
|
5059
|
-
};
|
|
5060
|
-
const votingTime = {
|
|
5061
|
-
start_time: (BigInt(params.startVoting.getTime()) * 1000000n).toString(),
|
|
5062
|
-
end_time: (BigInt(params.endVoting.getTime()) * 1000000n).toString()
|
|
5063
|
-
};
|
|
5064
|
-
const circuitType = params.circuitType.toString();
|
|
5065
|
-
const client = await createApiSaasClientBy({
|
|
5066
|
-
rpcEndpoint: this.rpcEndpoint,
|
|
5067
|
-
wallet: signer,
|
|
5068
|
-
contractAddress: this.apiSaasAddress
|
|
5069
|
-
});
|
|
5070
|
-
const roundParams = {
|
|
5071
|
-
certificationSystem: params.certificationSystem ?? "0",
|
|
5072
|
-
circuitType,
|
|
5073
|
-
deactivateEnabled: params.deactivateEnabled,
|
|
5074
|
-
operator: params.operator,
|
|
5075
|
-
registrationMode: params.registrationMode,
|
|
5076
|
-
roundInfo,
|
|
5077
|
-
voiceCreditMode: params.voiceCreditMode,
|
|
5078
|
-
voteOptionMap: params.voteOptionMap,
|
|
5079
|
-
votingTime
|
|
5080
|
-
};
|
|
5081
|
-
const gasStation = params.gasStation ?? false;
|
|
5082
|
-
const fee = params.fee ?? 1.8;
|
|
5083
|
-
let createResponse;
|
|
5084
|
-
if (gasStation && typeof fee !== "object") {
|
|
4954
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
4955
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5085
4956
|
const [{ address }] = await signer.getAccounts();
|
|
5086
|
-
const contractClient = await this.contractClient({ signer });
|
|
5087
4957
|
const msg = {
|
|
5088
4958
|
create_amaci_round: {
|
|
5089
|
-
certification_system:
|
|
5090
|
-
circuit_type:
|
|
5091
|
-
deactivate_enabled:
|
|
5092
|
-
operator:
|
|
5093
|
-
registration_mode:
|
|
5094
|
-
round_info:
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
4959
|
+
certification_system: params.certificationSystem ?? "0",
|
|
4960
|
+
circuit_type: params.circuitType.toString(),
|
|
4961
|
+
deactivate_enabled: params.deactivateEnabled,
|
|
4962
|
+
operator: params.operator,
|
|
4963
|
+
registration_mode: params.registrationMode,
|
|
4964
|
+
round_info: {
|
|
4965
|
+
title: params.title,
|
|
4966
|
+
description: params.description ?? "",
|
|
4967
|
+
link: params.link ?? ""
|
|
4968
|
+
},
|
|
4969
|
+
voice_credit_mode: params.voiceCreditMode,
|
|
4970
|
+
vote_option_map: params.voteOptionMap,
|
|
4971
|
+
voting_time: {
|
|
4972
|
+
start_time: (BigInt(params.startVoting.getTime()) * 1000000n).toString(),
|
|
4973
|
+
end_time: (BigInt(params.endVoting.getTime()) * 1000000n).toString()
|
|
4974
|
+
}
|
|
4975
|
+
}
|
|
4976
|
+
};
|
|
4977
|
+
const executeMsg = {
|
|
4978
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
4979
|
+
value: {
|
|
4980
|
+
sender: address,
|
|
4981
|
+
contract: this.apiSaasAddress,
|
|
4982
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
4983
|
+
funds: []
|
|
5098
4984
|
}
|
|
5099
4985
|
};
|
|
5100
|
-
const
|
|
4986
|
+
const granter = params.gasStation ?? false ? this.apiSaasAddress : void 0;
|
|
4987
|
+
const stdFee = await resolveFee(
|
|
4988
|
+
signingClient,
|
|
5101
4989
|
address,
|
|
5102
|
-
[
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
value: {
|
|
5106
|
-
sender: address,
|
|
5107
|
-
contract: this.apiSaasAddress,
|
|
5108
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5109
|
-
}
|
|
5110
|
-
}
|
|
5111
|
-
],
|
|
5112
|
-
""
|
|
4990
|
+
[executeMsg],
|
|
4991
|
+
params.fee ?? 1.8,
|
|
4992
|
+
granter
|
|
5113
4993
|
);
|
|
5114
|
-
const
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
const grantFee = {
|
|
5118
|
-
amount: calculatedFee.amount,
|
|
5119
|
-
gas: calculatedFee.gas,
|
|
5120
|
-
granter: this.apiSaasAddress
|
|
5121
|
-
};
|
|
5122
|
-
createResponse = await client.createAmaciRound(roundParams, grantFee);
|
|
5123
|
-
} else if (gasStation && typeof fee === "object") {
|
|
5124
|
-
const grantFee = {
|
|
5125
|
-
...fee,
|
|
5126
|
-
granter: this.apiSaasAddress
|
|
5127
|
-
};
|
|
5128
|
-
createResponse = await client.createAmaciRound(roundParams, grantFee);
|
|
5129
|
-
} else {
|
|
5130
|
-
createResponse = await client.createAmaciRound(roundParams, fee);
|
|
5131
|
-
}
|
|
5132
|
-
let contractAddress = "";
|
|
5133
|
-
let pollId = "";
|
|
5134
|
-
for (const event of createResponse.events) {
|
|
5135
|
-
if (event.type === "wasm") {
|
|
5136
|
-
const actionEvent = event.attributes.find(
|
|
5137
|
-
(attr) => attr.key === "action"
|
|
5138
|
-
);
|
|
5139
|
-
if (actionEvent && actionEvent.value === "created_round") {
|
|
5140
|
-
const roundAddrEvent = event.attributes.find(
|
|
5141
|
-
(attr) => attr.key === "round_addr"
|
|
5142
|
-
);
|
|
5143
|
-
const pollIdEvent = event.attributes.find(
|
|
5144
|
-
(attr) => attr.key === "poll_id"
|
|
5145
|
-
);
|
|
5146
|
-
if (roundAddrEvent) {
|
|
5147
|
-
contractAddress = roundAddrEvent.value.toString();
|
|
5148
|
-
}
|
|
5149
|
-
if (pollIdEvent) {
|
|
5150
|
-
pollId = pollIdEvent.value.toString();
|
|
5151
|
-
}
|
|
5152
|
-
if (contractAddress) {
|
|
5153
|
-
break;
|
|
5154
|
-
}
|
|
5155
|
-
}
|
|
5156
|
-
}
|
|
5157
|
-
}
|
|
5158
|
-
return {
|
|
5159
|
-
...createResponse,
|
|
5160
|
-
contractAddress,
|
|
5161
|
-
pollId
|
|
5162
|
-
};
|
|
4994
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
4995
|
+
return { txHash };
|
|
4996
|
+
});
|
|
5163
4997
|
}
|
|
5164
4998
|
async signupViaSaas({
|
|
5165
4999
|
signer,
|
|
@@ -5170,21 +5004,9 @@ var Contract = class {
|
|
|
5170
5004
|
granter,
|
|
5171
5005
|
fee = 1.8
|
|
5172
5006
|
}) {
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
wallet: signer,
|
|
5176
|
-
contractAddress: this.apiSaasAddress
|
|
5177
|
-
});
|
|
5178
|
-
const saasGranter = granter || this.apiSaasAddress;
|
|
5179
|
-
const signUpParams = {
|
|
5180
|
-
contractAddr: contractAddress,
|
|
5181
|
-
pubkey,
|
|
5182
|
-
certificate,
|
|
5183
|
-
amount
|
|
5184
|
-
};
|
|
5185
|
-
if (typeof fee !== "object") {
|
|
5007
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5008
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5186
5009
|
const [{ address }] = await signer.getAccounts();
|
|
5187
|
-
const contractClient = await this.contractClient({ signer });
|
|
5188
5010
|
const msg = {
|
|
5189
5011
|
sign_up: {
|
|
5190
5012
|
contract_addr: contractAddress,
|
|
@@ -5193,35 +5015,20 @@ var Contract = class {
|
|
|
5193
5015
|
amount: amount ?? null
|
|
5194
5016
|
}
|
|
5195
5017
|
};
|
|
5196
|
-
const
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5205
|
-
}
|
|
5206
|
-
}
|
|
5207
|
-
],
|
|
5208
|
-
""
|
|
5209
|
-
);
|
|
5210
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5211
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5212
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5213
|
-
const grantFee2 = {
|
|
5214
|
-
amount: calculatedFee.amount,
|
|
5215
|
-
gas: calculatedFee.gas,
|
|
5216
|
-
granter: saasGranter
|
|
5018
|
+
const executeMsg = {
|
|
5019
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5020
|
+
value: {
|
|
5021
|
+
sender: address,
|
|
5022
|
+
contract: this.apiSaasAddress,
|
|
5023
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5024
|
+
funds: []
|
|
5025
|
+
}
|
|
5217
5026
|
};
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
};
|
|
5224
|
-
return client.signUp(signUpParams, grantFee);
|
|
5027
|
+
const saasGranter = granter ?? this.apiSaasAddress;
|
|
5028
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, saasGranter);
|
|
5029
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5030
|
+
return { txHash };
|
|
5031
|
+
});
|
|
5225
5032
|
}
|
|
5226
5033
|
async preAddNewKeyViaSaas({
|
|
5227
5034
|
signer,
|
|
@@ -5233,22 +5040,9 @@ var Contract = class {
|
|
|
5233
5040
|
granter,
|
|
5234
5041
|
fee = 1.8
|
|
5235
5042
|
}) {
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
wallet: signer,
|
|
5239
|
-
contractAddress: this.apiSaasAddress
|
|
5240
|
-
});
|
|
5241
|
-
const saasGranter = granter || this.apiSaasAddress;
|
|
5242
|
-
const keyParams = {
|
|
5243
|
-
contractAddr: contractAddress,
|
|
5244
|
-
pubkey,
|
|
5245
|
-
nullifier,
|
|
5246
|
-
d,
|
|
5247
|
-
groth16Proof
|
|
5248
|
-
};
|
|
5249
|
-
if (typeof fee !== "object") {
|
|
5043
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5044
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5250
5045
|
const [{ address }] = await signer.getAccounts();
|
|
5251
|
-
const contractClient = await this.contractClient({ signer });
|
|
5252
5046
|
const msg = {
|
|
5253
5047
|
pre_add_new_key: {
|
|
5254
5048
|
contract_addr: contractAddress,
|
|
@@ -5258,37 +5052,22 @@ var Contract = class {
|
|
|
5258
5052
|
groth16_proof: groth16Proof
|
|
5259
5053
|
}
|
|
5260
5054
|
};
|
|
5261
|
-
const
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5270
|
-
}
|
|
5271
|
-
}
|
|
5272
|
-
],
|
|
5273
|
-
""
|
|
5274
|
-
);
|
|
5275
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5276
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5277
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5278
|
-
const grantFee2 = {
|
|
5279
|
-
amount: calculatedFee.amount,
|
|
5280
|
-
gas: calculatedFee.gas,
|
|
5281
|
-
granter: saasGranter
|
|
5055
|
+
const executeMsg = {
|
|
5056
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5057
|
+
value: {
|
|
5058
|
+
sender: address,
|
|
5059
|
+
contract: this.apiSaasAddress,
|
|
5060
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5061
|
+
funds: []
|
|
5062
|
+
}
|
|
5282
5063
|
};
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
};
|
|
5289
|
-
return client.preAddNewKey(keyParams, grantFee);
|
|
5064
|
+
const saasGranter = granter ?? this.apiSaasAddress;
|
|
5065
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, saasGranter);
|
|
5066
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5067
|
+
return { txHash };
|
|
5068
|
+
});
|
|
5290
5069
|
}
|
|
5291
|
-
async
|
|
5070
|
+
async preAddNewKey({
|
|
5292
5071
|
signer,
|
|
5293
5072
|
contractAddress,
|
|
5294
5073
|
pubkey,
|
|
@@ -5296,24 +5075,47 @@ var Contract = class {
|
|
|
5296
5075
|
d,
|
|
5297
5076
|
groth16Proof,
|
|
5298
5077
|
granter,
|
|
5299
|
-
|
|
5078
|
+
funds = [],
|
|
5079
|
+
fee = "auto"
|
|
5300
5080
|
}) {
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5081
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5082
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5083
|
+
const [{ address }] = await signer.getAccounts();
|
|
5084
|
+
const msg = {
|
|
5085
|
+
pre_add_new_key: {
|
|
5086
|
+
d,
|
|
5087
|
+
groth16_proof: groth16Proof,
|
|
5088
|
+
nullifier,
|
|
5089
|
+
pubkey
|
|
5090
|
+
}
|
|
5091
|
+
};
|
|
5092
|
+
const executeMsg = {
|
|
5093
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5094
|
+
value: {
|
|
5095
|
+
sender: address,
|
|
5096
|
+
contract: contractAddress,
|
|
5097
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5098
|
+
funds
|
|
5099
|
+
}
|
|
5100
|
+
};
|
|
5101
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
5102
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5103
|
+
return { txHash };
|
|
5104
|
+
});
|
|
5105
|
+
}
|
|
5106
|
+
async addNewKeyViaSaas({
|
|
5107
|
+
signer,
|
|
5108
|
+
contractAddress,
|
|
5109
|
+
pubkey,
|
|
5110
|
+
nullifier,
|
|
5111
|
+
d,
|
|
5112
|
+
groth16Proof,
|
|
5113
|
+
granter,
|
|
5114
|
+
fee = 1.8
|
|
5115
|
+
}) {
|
|
5116
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5117
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5315
5118
|
const [{ address }] = await signer.getAccounts();
|
|
5316
|
-
const contractClient = await this.contractClient({ signer });
|
|
5317
5119
|
const msg = {
|
|
5318
5120
|
add_new_key: {
|
|
5319
5121
|
contract_addr: contractAddress,
|
|
@@ -5323,35 +5125,20 @@ var Contract = class {
|
|
|
5323
5125
|
groth16_proof: groth16Proof
|
|
5324
5126
|
}
|
|
5325
5127
|
};
|
|
5326
|
-
const
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5335
|
-
}
|
|
5336
|
-
}
|
|
5337
|
-
],
|
|
5338
|
-
""
|
|
5339
|
-
);
|
|
5340
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5341
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5342
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5343
|
-
const grantFee2 = {
|
|
5344
|
-
amount: calculatedFee.amount,
|
|
5345
|
-
gas: calculatedFee.gas,
|
|
5346
|
-
granter: saasGranter
|
|
5128
|
+
const executeMsg = {
|
|
5129
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5130
|
+
value: {
|
|
5131
|
+
sender: address,
|
|
5132
|
+
contract: this.apiSaasAddress,
|
|
5133
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5134
|
+
funds: []
|
|
5135
|
+
}
|
|
5347
5136
|
};
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
};
|
|
5354
|
-
return client.addNewKey(keyParams, grantFee);
|
|
5137
|
+
const saasGranter = granter ?? this.apiSaasAddress;
|
|
5138
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, saasGranter);
|
|
5139
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5140
|
+
return { txHash };
|
|
5141
|
+
});
|
|
5355
5142
|
}
|
|
5356
5143
|
async publishMessageViaSaas({
|
|
5357
5144
|
signer,
|
|
@@ -5361,15 +5148,9 @@ var Contract = class {
|
|
|
5361
5148
|
granter,
|
|
5362
5149
|
fee = 1.8
|
|
5363
5150
|
}) {
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
wallet: signer,
|
|
5367
|
-
contractAddress: this.apiSaasAddress
|
|
5368
|
-
});
|
|
5369
|
-
const saasGranter = granter || this.apiSaasAddress;
|
|
5370
|
-
if (typeof fee !== "object") {
|
|
5151
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5152
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5371
5153
|
const [{ address }] = await signer.getAccounts();
|
|
5372
|
-
const contractClient = await this.contractClient({ signer });
|
|
5373
5154
|
const msg = {
|
|
5374
5155
|
publish_message: {
|
|
5375
5156
|
contract_addr: contractAddress,
|
|
@@ -5377,36 +5158,20 @@ var Contract = class {
|
|
|
5377
5158
|
messages
|
|
5378
5159
|
}
|
|
5379
5160
|
};
|
|
5380
|
-
const
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5389
|
-
}
|
|
5390
|
-
}
|
|
5391
|
-
],
|
|
5392
|
-
""
|
|
5393
|
-
);
|
|
5394
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5395
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5396
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5397
|
-
const grantFee = {
|
|
5398
|
-
amount: calculatedFee.amount,
|
|
5399
|
-
gas: calculatedFee.gas,
|
|
5400
|
-
granter: saasGranter
|
|
5401
|
-
};
|
|
5402
|
-
return client.publishMessage({ contractAddr: contractAddress, encPubKeys, messages }, grantFee);
|
|
5403
|
-
} else {
|
|
5404
|
-
const grantFee = {
|
|
5405
|
-
...fee,
|
|
5406
|
-
granter: saasGranter
|
|
5161
|
+
const executeMsg = {
|
|
5162
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5163
|
+
value: {
|
|
5164
|
+
sender: address,
|
|
5165
|
+
contract: this.apiSaasAddress,
|
|
5166
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5167
|
+
funds: []
|
|
5168
|
+
}
|
|
5407
5169
|
};
|
|
5408
|
-
|
|
5409
|
-
|
|
5170
|
+
const saasGranter = granter ?? this.apiSaasAddress;
|
|
5171
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, saasGranter);
|
|
5172
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5173
|
+
return { txHash };
|
|
5174
|
+
});
|
|
5410
5175
|
}
|
|
5411
5176
|
async publishDeactivateMessageViaSaas({
|
|
5412
5177
|
signer,
|
|
@@ -5416,15 +5181,9 @@ var Contract = class {
|
|
|
5416
5181
|
granter,
|
|
5417
5182
|
fee = 1.8
|
|
5418
5183
|
}) {
|
|
5419
|
-
|
|
5420
|
-
|
|
5421
|
-
wallet: signer,
|
|
5422
|
-
contractAddress: this.apiSaasAddress
|
|
5423
|
-
});
|
|
5424
|
-
const saasGranter = granter || this.apiSaasAddress;
|
|
5425
|
-
if (typeof fee !== "object") {
|
|
5184
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5185
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5426
5186
|
const [{ address }] = await signer.getAccounts();
|
|
5427
|
-
const contractClient = await this.contractClient({ signer });
|
|
5428
5187
|
const msg = {
|
|
5429
5188
|
publish_deactivate_message: {
|
|
5430
5189
|
contract_addr: contractAddress,
|
|
@@ -5432,42 +5191,196 @@ var Contract = class {
|
|
|
5432
5191
|
message
|
|
5433
5192
|
}
|
|
5434
5193
|
};
|
|
5435
|
-
const
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5444
|
-
}
|
|
5445
|
-
}
|
|
5446
|
-
],
|
|
5447
|
-
""
|
|
5448
|
-
);
|
|
5449
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5450
|
-
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5451
|
-
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5452
|
-
const grantFee = {
|
|
5453
|
-
amount: calculatedFee.amount,
|
|
5454
|
-
gas: calculatedFee.gas,
|
|
5455
|
-
granter: saasGranter
|
|
5194
|
+
const executeMsg = {
|
|
5195
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5196
|
+
value: {
|
|
5197
|
+
sender: address,
|
|
5198
|
+
contract: this.apiSaasAddress,
|
|
5199
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5200
|
+
funds: []
|
|
5201
|
+
}
|
|
5456
5202
|
};
|
|
5457
|
-
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
}
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5203
|
+
const saasGranter = granter ?? this.apiSaasAddress;
|
|
5204
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, saasGranter);
|
|
5205
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5206
|
+
return { txHash };
|
|
5207
|
+
});
|
|
5208
|
+
}
|
|
5209
|
+
// ── Direct (non-SAAS) write methods ──────────────────────────────────────
|
|
5210
|
+
async signup({
|
|
5211
|
+
signer,
|
|
5212
|
+
contractAddress,
|
|
5213
|
+
pubkey,
|
|
5214
|
+
amount = "0",
|
|
5215
|
+
certificate = "",
|
|
5216
|
+
granter,
|
|
5217
|
+
funds = [],
|
|
5218
|
+
fee = "auto"
|
|
5219
|
+
}) {
|
|
5220
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5221
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5222
|
+
const [{ address }] = await signer.getAccounts();
|
|
5223
|
+
const msg = {
|
|
5224
|
+
sign_up: {
|
|
5225
|
+
pubkey,
|
|
5226
|
+
amount,
|
|
5227
|
+
certificate
|
|
5228
|
+
}
|
|
5465
5229
|
};
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5230
|
+
const executeMsg = {
|
|
5231
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5232
|
+
value: {
|
|
5233
|
+
sender: address,
|
|
5234
|
+
contract: contractAddress,
|
|
5235
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5236
|
+
funds
|
|
5237
|
+
}
|
|
5238
|
+
};
|
|
5239
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
5240
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5241
|
+
return { txHash };
|
|
5242
|
+
});
|
|
5243
|
+
}
|
|
5244
|
+
async addNewKey({
|
|
5245
|
+
signer,
|
|
5246
|
+
contractAddress,
|
|
5247
|
+
pubkey,
|
|
5248
|
+
nullifier,
|
|
5249
|
+
d,
|
|
5250
|
+
groth16Proof,
|
|
5251
|
+
granter,
|
|
5252
|
+
funds = [],
|
|
5253
|
+
fee = "auto"
|
|
5254
|
+
}) {
|
|
5255
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5256
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5257
|
+
const [{ address }] = await signer.getAccounts();
|
|
5258
|
+
const msg = {
|
|
5259
|
+
add_new_key: {
|
|
5260
|
+
d,
|
|
5261
|
+
groth16_proof: groth16Proof,
|
|
5262
|
+
nullifier,
|
|
5263
|
+
pubkey
|
|
5264
|
+
}
|
|
5265
|
+
};
|
|
5266
|
+
const executeMsg = {
|
|
5267
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5268
|
+
value: {
|
|
5269
|
+
sender: address,
|
|
5270
|
+
contract: contractAddress,
|
|
5271
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5272
|
+
funds
|
|
5273
|
+
}
|
|
5274
|
+
};
|
|
5275
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
5276
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5277
|
+
return { txHash };
|
|
5278
|
+
});
|
|
5279
|
+
}
|
|
5280
|
+
async publishMessage({
|
|
5281
|
+
signer,
|
|
5282
|
+
contractAddress,
|
|
5283
|
+
encPubKeys,
|
|
5284
|
+
messages,
|
|
5285
|
+
granter,
|
|
5286
|
+
funds = [],
|
|
5287
|
+
fee = "auto"
|
|
5288
|
+
}) {
|
|
5289
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5290
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5291
|
+
const [{ address }] = await signer.getAccounts();
|
|
5292
|
+
const msg = {
|
|
5293
|
+
publish_message: {
|
|
5294
|
+
enc_pub_keys: encPubKeys,
|
|
5295
|
+
messages
|
|
5296
|
+
}
|
|
5297
|
+
};
|
|
5298
|
+
const executeMsg = {
|
|
5299
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5300
|
+
value: {
|
|
5301
|
+
sender: address,
|
|
5302
|
+
contract: contractAddress,
|
|
5303
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5304
|
+
funds
|
|
5305
|
+
}
|
|
5306
|
+
};
|
|
5307
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
5308
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5309
|
+
return { txHash };
|
|
5310
|
+
});
|
|
5311
|
+
}
|
|
5312
|
+
/**
|
|
5313
|
+
* Generic execute with retry – used for the legacy publish_message_batch format
|
|
5314
|
+
* where the caller pre-builds the EncodeObject (e.g. with stringizing).
|
|
5315
|
+
*/
|
|
5316
|
+
async executeWithRetry({
|
|
5317
|
+
signer,
|
|
5318
|
+
address,
|
|
5319
|
+
msgs,
|
|
5320
|
+
granter,
|
|
5321
|
+
fee = "auto"
|
|
5322
|
+
}) {
|
|
5323
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5324
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5325
|
+
const stdFee = await resolveFee(signingClient, address, msgs, fee, granter);
|
|
5326
|
+
const txHash = await signingClient.signAndBroadcastSync(address, msgs, stdFee);
|
|
5327
|
+
return { txHash };
|
|
5328
|
+
});
|
|
5329
|
+
}
|
|
5330
|
+
async publishDeactivateMessage({
|
|
5331
|
+
signer,
|
|
5332
|
+
contractAddress,
|
|
5333
|
+
encPubKey,
|
|
5334
|
+
message,
|
|
5335
|
+
granter,
|
|
5336
|
+
funds = [],
|
|
5337
|
+
fee = "auto"
|
|
5338
|
+
}) {
|
|
5339
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5340
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5341
|
+
const [{ address }] = await signer.getAccounts();
|
|
5342
|
+
const msg = {
|
|
5343
|
+
publish_deactivate_message: {
|
|
5344
|
+
enc_pub_key: encPubKey,
|
|
5345
|
+
message
|
|
5346
|
+
}
|
|
5347
|
+
};
|
|
5348
|
+
const executeMsg = {
|
|
5349
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5350
|
+
value: {
|
|
5351
|
+
sender: address,
|
|
5352
|
+
contract: contractAddress,
|
|
5353
|
+
msg: toUtf8(JSON.stringify(msg)),
|
|
5354
|
+
funds
|
|
5355
|
+
}
|
|
5356
|
+
};
|
|
5357
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, granter);
|
|
5358
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5359
|
+
return { txHash };
|
|
5360
|
+
});
|
|
5361
|
+
}
|
|
5362
|
+
async claim({
|
|
5363
|
+
signer,
|
|
5364
|
+
contractAddress,
|
|
5365
|
+
funds = [],
|
|
5366
|
+
fee = "auto"
|
|
5367
|
+
}) {
|
|
5368
|
+
return this.withRetry(async (rpcEndpoint) => {
|
|
5369
|
+
const signingClient = await createContractClientByWallet(rpcEndpoint, signer);
|
|
5370
|
+
const [{ address }] = await signer.getAccounts();
|
|
5371
|
+
const executeMsg = {
|
|
5372
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5373
|
+
value: {
|
|
5374
|
+
sender: address,
|
|
5375
|
+
contract: contractAddress,
|
|
5376
|
+
msg: toUtf8(JSON.stringify({ claim: {} })),
|
|
5377
|
+
funds
|
|
5378
|
+
}
|
|
5379
|
+
};
|
|
5380
|
+
const stdFee = await resolveFee(signingClient, address, [executeMsg], fee, void 0);
|
|
5381
|
+
const txHash = await signingClient.signAndBroadcastSync(address, [executeMsg], stdFee);
|
|
5382
|
+
return { txHash };
|
|
5383
|
+
});
|
|
5471
5384
|
}
|
|
5472
5385
|
};
|
|
5473
5386
|
|
|
@@ -5566,7 +5479,6 @@ var OracleCertificate = class {
|
|
|
5566
5479
|
};
|
|
5567
5480
|
|
|
5568
5481
|
// src/libs/maci/maci.ts
|
|
5569
|
-
var import_stargate3 = require("@cosmjs/stargate");
|
|
5570
5482
|
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx.js");
|
|
5571
5483
|
function isErrorResponse(response) {
|
|
5572
5484
|
return typeof response === "object" && response !== null && "error" in response && typeof response.error === "object" && "message" in response.error;
|
|
@@ -5813,7 +5725,6 @@ var MACI = class {
|
|
|
5813
5725
|
}
|
|
5814
5726
|
async signup({
|
|
5815
5727
|
signer,
|
|
5816
|
-
address,
|
|
5817
5728
|
contractAddress,
|
|
5818
5729
|
maciKeypair,
|
|
5819
5730
|
oracleCertificate,
|
|
@@ -5821,66 +5732,30 @@ var MACI = class {
|
|
|
5821
5732
|
fee
|
|
5822
5733
|
}) {
|
|
5823
5734
|
try {
|
|
5824
|
-
if (!address) {
|
|
5825
|
-
address = (await signer.getAccounts())[0].address;
|
|
5826
|
-
}
|
|
5827
5735
|
if (maciKeypair === void 0) {
|
|
5828
5736
|
maciKeypair = this.maciKeypair;
|
|
5829
5737
|
}
|
|
5830
|
-
const client = await this.contract.contractClient({
|
|
5831
|
-
signer
|
|
5832
|
-
});
|
|
5833
|
-
const msg = {
|
|
5834
|
-
sign_up: {
|
|
5835
|
-
pubkey: {
|
|
5836
|
-
x: maciKeypair.pubKey[0].toString(),
|
|
5837
|
-
y: maciKeypair.pubKey[1].toString()
|
|
5838
|
-
},
|
|
5839
|
-
amount: oracleCertificate?.amount || "0",
|
|
5840
|
-
certificate: oracleCertificate?.signature || ""
|
|
5841
|
-
}
|
|
5842
|
-
};
|
|
5843
5738
|
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
5844
|
-
|
|
5845
|
-
|
|
5846
|
-
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
""
|
|
5859
|
-
);
|
|
5860
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5861
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
5862
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5863
|
-
const grantFee = {
|
|
5864
|
-
amount: calculatedFee.amount,
|
|
5865
|
-
gas: calculatedFee.gas,
|
|
5866
|
-
granter: contractAddress
|
|
5867
|
-
};
|
|
5868
|
-
return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
|
|
5869
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
5870
|
-
const grantFee = {
|
|
5871
|
-
...fee,
|
|
5872
|
-
granter: contractAddress
|
|
5873
|
-
};
|
|
5874
|
-
return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
|
|
5875
|
-
}
|
|
5876
|
-
return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
|
|
5739
|
+
const granter = gasStation ? contractAddress : void 0;
|
|
5740
|
+
return await this.contract.signup({
|
|
5741
|
+
signer,
|
|
5742
|
+
contractAddress,
|
|
5743
|
+
pubkey: {
|
|
5744
|
+
x: maciKeypair.pubKey[0].toString(),
|
|
5745
|
+
y: maciKeypair.pubKey[1].toString()
|
|
5746
|
+
},
|
|
5747
|
+
amount: oracleCertificate?.amount ?? "0",
|
|
5748
|
+
certificate: oracleCertificate?.signature ?? "",
|
|
5749
|
+
granter,
|
|
5750
|
+
funds: signupFunds,
|
|
5751
|
+
fee: fee ?? "auto"
|
|
5752
|
+
});
|
|
5877
5753
|
} catch (error) {
|
|
5878
5754
|
throw Error(`Signup failed! ${error}`);
|
|
5879
5755
|
}
|
|
5880
5756
|
}
|
|
5881
5757
|
async rawSignup({
|
|
5882
5758
|
signer,
|
|
5883
|
-
address,
|
|
5884
5759
|
contractAddress,
|
|
5885
5760
|
pubKey,
|
|
5886
5761
|
oracleCertificate,
|
|
@@ -5888,73 +5763,35 @@ var MACI = class {
|
|
|
5888
5763
|
granter,
|
|
5889
5764
|
fee
|
|
5890
5765
|
}) {
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5766
|
+
const pubkey = {
|
|
5767
|
+
x: pubKey[0].toString(),
|
|
5768
|
+
y: pubKey[1].toString()
|
|
5769
|
+
};
|
|
5770
|
+
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
5771
|
+
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
5772
|
+
console.log("[rawSignup] path: viaSaas (gasStation=true, granter=apiSaasAddress)");
|
|
5773
|
+
return this.contract.signupViaSaas({
|
|
5774
|
+
signer,
|
|
5775
|
+
contractAddress,
|
|
5776
|
+
pubkey,
|
|
5777
|
+
certificate: oracleCertificate?.signature,
|
|
5778
|
+
amount: oracleCertificate?.amount,
|
|
5779
|
+
granter,
|
|
5780
|
+
fee
|
|
5897
5781
|
});
|
|
5898
|
-
const msg = {
|
|
5899
|
-
sign_up: {
|
|
5900
|
-
pubkey: {
|
|
5901
|
-
x: pubKey[0].toString(),
|
|
5902
|
-
y: pubKey[1].toString()
|
|
5903
|
-
},
|
|
5904
|
-
amount: oracleCertificate?.amount || "0",
|
|
5905
|
-
certificate: oracleCertificate?.signature || ""
|
|
5906
|
-
}
|
|
5907
|
-
};
|
|
5908
|
-
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
5909
|
-
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
5910
|
-
return this.contract.signupViaSaas({
|
|
5911
|
-
signer,
|
|
5912
|
-
contractAddress,
|
|
5913
|
-
pubkey: {
|
|
5914
|
-
x: pubKey[0].toString(),
|
|
5915
|
-
y: pubKey[1].toString()
|
|
5916
|
-
},
|
|
5917
|
-
certificate: oracleCertificate?.signature,
|
|
5918
|
-
amount: oracleCertificate?.amount,
|
|
5919
|
-
granter,
|
|
5920
|
-
fee
|
|
5921
|
-
});
|
|
5922
|
-
} else if (gasStation === true && typeof fee !== "object") {
|
|
5923
|
-
const gasEstimation = await client.simulate(
|
|
5924
|
-
address,
|
|
5925
|
-
[
|
|
5926
|
-
{
|
|
5927
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5928
|
-
value: {
|
|
5929
|
-
sender: address,
|
|
5930
|
-
contract: contractAddress,
|
|
5931
|
-
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
5932
|
-
funds: signupFunds
|
|
5933
|
-
}
|
|
5934
|
-
}
|
|
5935
|
-
],
|
|
5936
|
-
""
|
|
5937
|
-
);
|
|
5938
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5939
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
5940
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5941
|
-
const grantFee = {
|
|
5942
|
-
amount: calculatedFee.amount,
|
|
5943
|
-
gas: calculatedFee.gas,
|
|
5944
|
-
granter: granter || contractAddress
|
|
5945
|
-
};
|
|
5946
|
-
return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
|
|
5947
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
5948
|
-
const grantFee = {
|
|
5949
|
-
...fee,
|
|
5950
|
-
granter: granter || contractAddress
|
|
5951
|
-
};
|
|
5952
|
-
return client.execute(address, contractAddress, msg, grantFee, void 0, signupFunds);
|
|
5953
|
-
}
|
|
5954
|
-
return client.execute(address, contractAddress, msg, fee || "auto", void 0, signupFunds);
|
|
5955
|
-
} catch (error) {
|
|
5956
|
-
throw Error(`Signup failed! ${error}`);
|
|
5957
5782
|
}
|
|
5783
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
5784
|
+
console.log(`[rawSignup] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`);
|
|
5785
|
+
return this.contract.signup({
|
|
5786
|
+
signer,
|
|
5787
|
+
contractAddress,
|
|
5788
|
+
pubkey,
|
|
5789
|
+
amount: oracleCertificate?.amount ?? "0",
|
|
5790
|
+
certificate: oracleCertificate?.signature ?? "",
|
|
5791
|
+
granter: effectiveGranter,
|
|
5792
|
+
funds: signupFunds,
|
|
5793
|
+
fee: fee ?? "auto"
|
|
5794
|
+
});
|
|
5958
5795
|
}
|
|
5959
5796
|
async processVoteOptions({
|
|
5960
5797
|
selectedOptions,
|
|
@@ -6053,15 +5890,34 @@ var MACI = class {
|
|
|
6053
5890
|
fee
|
|
6054
5891
|
});
|
|
6055
5892
|
}
|
|
6056
|
-
|
|
6057
|
-
signer
|
|
6058
|
-
}
|
|
6059
|
-
|
|
6060
|
-
|
|
5893
|
+
if (!address) {
|
|
5894
|
+
address = (await signer.getAccounts())[0].address;
|
|
5895
|
+
}
|
|
5896
|
+
const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
|
|
5897
|
+
const legacyMsgs = payload.map(({ msg, encPubkeys }) => ({
|
|
5898
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5899
|
+
value: import_tx.MsgExecuteContract.fromPartial({
|
|
5900
|
+
sender: address,
|
|
5901
|
+
contract: contractAddress,
|
|
5902
|
+
msg: new TextEncoder().encode(
|
|
5903
|
+
JSON.stringify(
|
|
5904
|
+
stringizing({
|
|
5905
|
+
publish_message: {
|
|
5906
|
+
messages: [{ data: msg }],
|
|
5907
|
+
enc_pub_keys: [{ x: encPubkeys[0], y: encPubkeys[1] }]
|
|
5908
|
+
}
|
|
5909
|
+
})
|
|
5910
|
+
)
|
|
5911
|
+
),
|
|
5912
|
+
funds: [{ denom: FEE_DENOM, amount: this.feeConfig.messageFee }]
|
|
5913
|
+
})
|
|
5914
|
+
}));
|
|
5915
|
+
const granter = gasStation ? contractAddress : void 0;
|
|
5916
|
+
return await this.contract.executeWithRetry({
|
|
5917
|
+
signer,
|
|
6061
5918
|
address,
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
gasStation,
|
|
5919
|
+
msgs: legacyMsgs,
|
|
5920
|
+
granter,
|
|
6065
5921
|
fee
|
|
6066
5922
|
});
|
|
6067
5923
|
} catch (error) {
|
|
@@ -6107,7 +5963,7 @@ var MACI = class {
|
|
|
6107
5963
|
}
|
|
6108
5964
|
}
|
|
6109
5965
|
async publishMessage({
|
|
6110
|
-
|
|
5966
|
+
signer,
|
|
6111
5967
|
address,
|
|
6112
5968
|
payload,
|
|
6113
5969
|
contractAddress,
|
|
@@ -6115,7 +5971,10 @@ var MACI = class {
|
|
|
6115
5971
|
granter,
|
|
6116
5972
|
fee = 1.8
|
|
6117
5973
|
}) {
|
|
6118
|
-
|
|
5974
|
+
if (!address) {
|
|
5975
|
+
address = (await signer.getAccounts())[0].address;
|
|
5976
|
+
}
|
|
5977
|
+
const legacyMsgs = payload.map(({ msg, encPubkeys }) => ({
|
|
6119
5978
|
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6120
5979
|
value: import_tx.MsgExecuteContract.fromPartial({
|
|
6121
5980
|
sender: address,
|
|
@@ -6133,25 +5992,8 @@ var MACI = class {
|
|
|
6133
5992
|
funds: [{ denom: FEE_DENOM, amount: this.feeConfig.messageFee }]
|
|
6134
5993
|
})
|
|
6135
5994
|
}));
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6139
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6140
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6141
|
-
const grantFee = {
|
|
6142
|
-
amount: calculatedFee.amount,
|
|
6143
|
-
gas: calculatedFee.gas,
|
|
6144
|
-
granter: granter || contractAddress
|
|
6145
|
-
};
|
|
6146
|
-
return client.signAndBroadcast(address, msgs, grantFee);
|
|
6147
|
-
} else if (gasStation && typeof fee === "object") {
|
|
6148
|
-
const grantFee = {
|
|
6149
|
-
...fee,
|
|
6150
|
-
granter: granter || contractAddress
|
|
6151
|
-
};
|
|
6152
|
-
return client.signAndBroadcast(address, msgs, grantFee);
|
|
6153
|
-
}
|
|
6154
|
-
return client.signAndBroadcast(address, msgs, fee);
|
|
5995
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
5996
|
+
return this.contract.executeWithRetry({ signer, address, msgs: legacyMsgs, granter: effectiveGranter, fee });
|
|
6155
5997
|
}
|
|
6156
5998
|
async publishMessageBatch({
|
|
6157
5999
|
signer,
|
|
@@ -6165,10 +6007,6 @@ var MACI = class {
|
|
|
6165
6007
|
if (!address) {
|
|
6166
6008
|
address = (await signer.getAccounts())[0].address;
|
|
6167
6009
|
}
|
|
6168
|
-
const amaciClient = await this.contract.amaciClient({
|
|
6169
|
-
signer,
|
|
6170
|
-
contractAddress
|
|
6171
|
-
});
|
|
6172
6010
|
const messages = payload.map((p) => ({
|
|
6173
6011
|
data: p.msg.map((m) => m.toString())
|
|
6174
6012
|
}));
|
|
@@ -6179,6 +6017,7 @@ var MACI = class {
|
|
|
6179
6017
|
const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
|
|
6180
6018
|
const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
|
|
6181
6019
|
if (gasStation && granter === this.contract.apiSaasAddress) {
|
|
6020
|
+
console.log("[publishMessageBatch] path: viaSaas (gasStation=true, granter=apiSaasAddress)");
|
|
6182
6021
|
return this.contract.publishMessageViaSaas({
|
|
6183
6022
|
signer,
|
|
6184
6023
|
contractAddress,
|
|
@@ -6187,37 +6026,20 @@ var MACI = class {
|
|
|
6187
6026
|
granter,
|
|
6188
6027
|
fee
|
|
6189
6028
|
});
|
|
6190
|
-
} else if (gasStation && typeof fee !== "object") {
|
|
6191
|
-
const client = await this.contract.contractClient({ signer });
|
|
6192
|
-
const msgForSimulate = {
|
|
6193
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6194
|
-
value: import_tx.MsgExecuteContract.fromPartial({
|
|
6195
|
-
sender: address,
|
|
6196
|
-
contract: contractAddress,
|
|
6197
|
-
msg: new TextEncoder().encode(
|
|
6198
|
-
JSON.stringify({ publish_message: { enc_pub_keys: encPubKeys, messages } })
|
|
6199
|
-
),
|
|
6200
|
-
funds: batchFunds
|
|
6201
|
-
})
|
|
6202
|
-
};
|
|
6203
|
-
const gasEstimation = await client.simulate(address, [msgForSimulate], "");
|
|
6204
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6205
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6206
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6207
|
-
const grantFee = {
|
|
6208
|
-
amount: calculatedFee.amount,
|
|
6209
|
-
gas: calculatedFee.gas,
|
|
6210
|
-
granter: granter || contractAddress
|
|
6211
|
-
};
|
|
6212
|
-
return amaciClient.publishMessage({ encPubKeys, messages }, grantFee, void 0, batchFunds);
|
|
6213
|
-
} else if (gasStation && typeof fee === "object") {
|
|
6214
|
-
const grantFee = {
|
|
6215
|
-
...fee,
|
|
6216
|
-
granter: granter || contractAddress
|
|
6217
|
-
};
|
|
6218
|
-
return amaciClient.publishMessage({ encPubKeys, messages }, grantFee, void 0, batchFunds);
|
|
6219
6029
|
}
|
|
6220
|
-
|
|
6030
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
6031
|
+
console.log(
|
|
6032
|
+
`[publishMessageBatch] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`
|
|
6033
|
+
);
|
|
6034
|
+
return this.contract.publishMessage({
|
|
6035
|
+
signer,
|
|
6036
|
+
contractAddress,
|
|
6037
|
+
encPubKeys,
|
|
6038
|
+
messages,
|
|
6039
|
+
granter: effectiveGranter,
|
|
6040
|
+
funds: batchFunds,
|
|
6041
|
+
fee
|
|
6042
|
+
});
|
|
6221
6043
|
}
|
|
6222
6044
|
async publishMessageBatchLegacy({
|
|
6223
6045
|
signer,
|
|
@@ -6231,7 +6053,6 @@ var MACI = class {
|
|
|
6231
6053
|
if (!address) {
|
|
6232
6054
|
address = (await signer.getAccounts())[0].address;
|
|
6233
6055
|
}
|
|
6234
|
-
const client = await this.contract.contractClient({ signer });
|
|
6235
6056
|
const messages = payload.map((p) => ({
|
|
6236
6057
|
data: p.msg
|
|
6237
6058
|
}));
|
|
@@ -6241,7 +6062,7 @@ var MACI = class {
|
|
|
6241
6062
|
}));
|
|
6242
6063
|
const totalFee = (BigInt(this.feeConfig.messageFee) * BigInt(payload.length)).toString();
|
|
6243
6064
|
const batchFunds = [{ denom: FEE_DENOM, amount: totalFee }];
|
|
6244
|
-
const
|
|
6065
|
+
const legacyMsg = {
|
|
6245
6066
|
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6246
6067
|
value: import_tx.MsgExecuteContract.fromPartial({
|
|
6247
6068
|
sender: address,
|
|
@@ -6259,25 +6080,17 @@ var MACI = class {
|
|
|
6259
6080
|
funds: batchFunds
|
|
6260
6081
|
})
|
|
6261
6082
|
};
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
} else if (gasStation && typeof fee === "object") {
|
|
6274
|
-
const grantFee = {
|
|
6275
|
-
...fee,
|
|
6276
|
-
granter: granter || contractAddress
|
|
6277
|
-
};
|
|
6278
|
-
return client.signAndBroadcast(address, [msg], grantFee);
|
|
6279
|
-
}
|
|
6280
|
-
return client.signAndBroadcast(address, [msg], fee);
|
|
6083
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
6084
|
+
console.log(
|
|
6085
|
+
`[publishMessageBatchLegacy] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`
|
|
6086
|
+
);
|
|
6087
|
+
return this.contract.executeWithRetry({
|
|
6088
|
+
signer,
|
|
6089
|
+
address,
|
|
6090
|
+
msgs: [legacyMsg],
|
|
6091
|
+
granter: effectiveGranter,
|
|
6092
|
+
fee
|
|
6093
|
+
});
|
|
6281
6094
|
}
|
|
6282
6095
|
async deactivate({
|
|
6283
6096
|
signer,
|
|
@@ -6292,9 +6105,6 @@ var MACI = class {
|
|
|
6292
6105
|
if (maciKeypair === void 0) {
|
|
6293
6106
|
maciKeypair = this.maciKeypair;
|
|
6294
6107
|
}
|
|
6295
|
-
const client = await this.contract.contractClient({
|
|
6296
|
-
signer
|
|
6297
|
-
});
|
|
6298
6108
|
const stateIdx = await this.getStateIdxInc({
|
|
6299
6109
|
address,
|
|
6300
6110
|
contractAddress
|
|
@@ -6313,132 +6123,61 @@ var MACI = class {
|
|
|
6313
6123
|
[[0, 0]],
|
|
6314
6124
|
Number(pollId)
|
|
6315
6125
|
);
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
},
|
|
6323
|
-
message: {
|
|
6324
|
-
data: msg
|
|
6325
|
-
}
|
|
6326
|
-
}
|
|
6126
|
+
return await this.rawDeactivate({
|
|
6127
|
+
signer,
|
|
6128
|
+
contractAddress,
|
|
6129
|
+
payload: payload[0],
|
|
6130
|
+
gasStation,
|
|
6131
|
+
fee
|
|
6327
6132
|
});
|
|
6328
|
-
const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
|
|
6329
|
-
if (gasStation === true && typeof fee !== "object") {
|
|
6330
|
-
const gasEstimation = await client.simulate(
|
|
6331
|
-
address,
|
|
6332
|
-
[
|
|
6333
|
-
{
|
|
6334
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6335
|
-
value: import_tx.MsgExecuteContract.fromPartial({
|
|
6336
|
-
sender: address,
|
|
6337
|
-
contract: contractAddress,
|
|
6338
|
-
msg: new TextEncoder().encode(JSON.stringify(deactivateMsg)),
|
|
6339
|
-
funds: deactivateFunds
|
|
6340
|
-
})
|
|
6341
|
-
}
|
|
6342
|
-
],
|
|
6343
|
-
""
|
|
6344
|
-
);
|
|
6345
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6346
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6347
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6348
|
-
const grantFee = {
|
|
6349
|
-
amount: calculatedFee.amount,
|
|
6350
|
-
gas: calculatedFee.gas,
|
|
6351
|
-
granter: contractAddress
|
|
6352
|
-
};
|
|
6353
|
-
return client.execute(address, contractAddress, deactivateMsg, grantFee, void 0, deactivateFunds);
|
|
6354
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
6355
|
-
const grantFee = {
|
|
6356
|
-
...fee,
|
|
6357
|
-
granter: contractAddress
|
|
6358
|
-
};
|
|
6359
|
-
return client.execute(address, contractAddress, deactivateMsg, grantFee, void 0, deactivateFunds);
|
|
6360
|
-
}
|
|
6361
|
-
return client.execute(address, contractAddress, deactivateMsg, fee, void 0, deactivateFunds);
|
|
6362
6133
|
} catch (error) {
|
|
6363
6134
|
throw Error(`Submit deactivate failed! ${error}`);
|
|
6364
6135
|
}
|
|
6365
6136
|
}
|
|
6366
6137
|
async rawDeactivate({
|
|
6367
6138
|
signer,
|
|
6368
|
-
address,
|
|
6369
6139
|
contractAddress,
|
|
6370
6140
|
payload,
|
|
6371
6141
|
gasStation = false,
|
|
6372
6142
|
granter,
|
|
6373
6143
|
fee = 1.8
|
|
6374
6144
|
}) {
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
fee
|
|
6391
|
-
});
|
|
6392
|
-
}
|
|
6393
|
-
const client = await this.contract.contractClient({ signer });
|
|
6394
|
-
const deactivateMsg = stringizing({
|
|
6395
|
-
publish_deactivate_message: {
|
|
6396
|
-
enc_pub_key: {
|
|
6397
|
-
x: encPubkeys[0],
|
|
6398
|
-
y: encPubkeys[1]
|
|
6399
|
-
},
|
|
6400
|
-
message: {
|
|
6401
|
-
data: msg
|
|
6402
|
-
}
|
|
6403
|
-
}
|
|
6145
|
+
const { msg, encPubkeys } = payload;
|
|
6146
|
+
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
6147
|
+
console.log("[rawDeactivate] path: viaSaas (gasStation=true, granter=apiSaasAddress)");
|
|
6148
|
+
return this.contract.publishDeactivateMessageViaSaas({
|
|
6149
|
+
signer,
|
|
6150
|
+
contractAddress,
|
|
6151
|
+
encPubKey: {
|
|
6152
|
+
x: encPubkeys[0].toString(),
|
|
6153
|
+
y: encPubkeys[1].toString()
|
|
6154
|
+
},
|
|
6155
|
+
message: {
|
|
6156
|
+
data: msg.map((m) => m.toString())
|
|
6157
|
+
},
|
|
6158
|
+
granter,
|
|
6159
|
+
fee
|
|
6404
6160
|
});
|
|
6405
|
-
const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
|
|
6406
|
-
if (gasStation === true && typeof fee !== "object") {
|
|
6407
|
-
const gasEstimation = await client.simulate(
|
|
6408
|
-
address,
|
|
6409
|
-
[
|
|
6410
|
-
{
|
|
6411
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6412
|
-
value: import_tx.MsgExecuteContract.fromPartial({
|
|
6413
|
-
sender: address,
|
|
6414
|
-
contract: contractAddress,
|
|
6415
|
-
msg: new TextEncoder().encode(JSON.stringify(deactivateMsg)),
|
|
6416
|
-
funds: deactivateFunds
|
|
6417
|
-
})
|
|
6418
|
-
}
|
|
6419
|
-
],
|
|
6420
|
-
""
|
|
6421
|
-
);
|
|
6422
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6423
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6424
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6425
|
-
const grantFee = {
|
|
6426
|
-
amount: calculatedFee.amount,
|
|
6427
|
-
gas: calculatedFee.gas,
|
|
6428
|
-
granter: granter || contractAddress
|
|
6429
|
-
};
|
|
6430
|
-
return client.execute(address, contractAddress, deactivateMsg, grantFee, void 0, deactivateFunds);
|
|
6431
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
6432
|
-
const grantFee = {
|
|
6433
|
-
...fee,
|
|
6434
|
-
granter: granter || contractAddress
|
|
6435
|
-
};
|
|
6436
|
-
return client.execute(address, contractAddress, deactivateMsg, grantFee, void 0, deactivateFunds);
|
|
6437
|
-
}
|
|
6438
|
-
return client.execute(address, contractAddress, deactivateMsg, fee, void 0, deactivateFunds);
|
|
6439
|
-
} catch (error) {
|
|
6440
|
-
throw Error(`Submit deactivate failed! ${error}`);
|
|
6441
6161
|
}
|
|
6162
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
6163
|
+
console.log(
|
|
6164
|
+
`[rawDeactivate] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`
|
|
6165
|
+
);
|
|
6166
|
+
const deactivateFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.deactivateFee }];
|
|
6167
|
+
return this.contract.publishDeactivateMessage({
|
|
6168
|
+
signer,
|
|
6169
|
+
contractAddress,
|
|
6170
|
+
encPubKey: {
|
|
6171
|
+
x: encPubkeys[0].toString(),
|
|
6172
|
+
y: encPubkeys[1].toString()
|
|
6173
|
+
},
|
|
6174
|
+
message: {
|
|
6175
|
+
data: msg.map((m) => m.toString())
|
|
6176
|
+
},
|
|
6177
|
+
granter: effectiveGranter,
|
|
6178
|
+
funds: deactivateFunds,
|
|
6179
|
+
fee
|
|
6180
|
+
});
|
|
6442
6181
|
}
|
|
6443
6182
|
async fetchAllDeactivateLogs({ contractAddress }) {
|
|
6444
6183
|
const deactivates = await this.indexer.fetchAllDeactivateLogs(contractAddress);
|
|
@@ -6476,25 +6215,15 @@ var MACI = class {
|
|
|
6476
6215
|
newMaciKeypair,
|
|
6477
6216
|
fee = "auto"
|
|
6478
6217
|
}) {
|
|
6479
|
-
|
|
6218
|
+
return this.rawAddNewKey({
|
|
6480
6219
|
signer,
|
|
6481
|
-
contractAddress
|
|
6220
|
+
contractAddress,
|
|
6221
|
+
d,
|
|
6222
|
+
proof,
|
|
6223
|
+
nullifier,
|
|
6224
|
+
newPubkey: newMaciKeypair.pubKey,
|
|
6225
|
+
fee
|
|
6482
6226
|
});
|
|
6483
|
-
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
6484
|
-
return await client.addNewKey(
|
|
6485
|
-
{
|
|
6486
|
-
d,
|
|
6487
|
-
groth16Proof: proof,
|
|
6488
|
-
nullifier: nullifier.toString(),
|
|
6489
|
-
pubkey: {
|
|
6490
|
-
x: newMaciKeypair.pubKey[0].toString(),
|
|
6491
|
-
y: newMaciKeypair.pubKey[1].toString()
|
|
6492
|
-
}
|
|
6493
|
-
},
|
|
6494
|
-
fee,
|
|
6495
|
-
void 0,
|
|
6496
|
-
signupFunds
|
|
6497
|
-
);
|
|
6498
6227
|
}
|
|
6499
6228
|
async rawAddNewKey({
|
|
6500
6229
|
signer,
|
|
@@ -6507,77 +6236,40 @@ var MACI = class {
|
|
|
6507
6236
|
granter,
|
|
6508
6237
|
fee = "auto"
|
|
6509
6238
|
}) {
|
|
6510
|
-
const client = await this.contract.amaciClient({
|
|
6511
|
-
signer,
|
|
6512
|
-
contractAddress
|
|
6513
|
-
});
|
|
6514
6239
|
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
6515
|
-
const
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
nullifier: nullifier.toString(),
|
|
6519
|
-
pubkey: {
|
|
6520
|
-
x: newPubkey[0].toString(),
|
|
6521
|
-
y: newPubkey[1].toString()
|
|
6522
|
-
}
|
|
6240
|
+
const pubkey = {
|
|
6241
|
+
x: newPubkey[0].toString(),
|
|
6242
|
+
y: newPubkey[1].toString()
|
|
6523
6243
|
};
|
|
6244
|
+
const nullifierStr = nullifier.toString();
|
|
6524
6245
|
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
6246
|
+
console.log("[rawAddNewKey] path: viaSaas (gasStation=true, granter=apiSaasAddress)");
|
|
6525
6247
|
return this.contract.addNewKeyViaSaas({
|
|
6526
6248
|
signer,
|
|
6527
6249
|
contractAddress,
|
|
6528
|
-
pubkey
|
|
6529
|
-
nullifier:
|
|
6250
|
+
pubkey,
|
|
6251
|
+
nullifier: nullifierStr,
|
|
6530
6252
|
d,
|
|
6531
6253
|
groth16Proof: proof,
|
|
6532
6254
|
granter,
|
|
6533
6255
|
fee
|
|
6534
6256
|
});
|
|
6535
|
-
} else if (gasStation === true && typeof fee !== "object") {
|
|
6536
|
-
const [{ address }] = await signer.getAccounts();
|
|
6537
|
-
const contractClient = await this.contract.contractClient({ signer });
|
|
6538
|
-
const msg = {
|
|
6539
|
-
add_new_key: {
|
|
6540
|
-
d,
|
|
6541
|
-
groth16_proof: proof,
|
|
6542
|
-
nullifier: nullifier.toString(),
|
|
6543
|
-
pubkey: {
|
|
6544
|
-
x: newPubkey[0].toString(),
|
|
6545
|
-
y: newPubkey[1].toString()
|
|
6546
|
-
}
|
|
6547
|
-
}
|
|
6548
|
-
};
|
|
6549
|
-
const gasEstimation = await contractClient.simulate(
|
|
6550
|
-
address,
|
|
6551
|
-
[
|
|
6552
|
-
{
|
|
6553
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6554
|
-
value: {
|
|
6555
|
-
sender: address,
|
|
6556
|
-
contract: contractAddress,
|
|
6557
|
-
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
6558
|
-
funds: signupFunds
|
|
6559
|
-
}
|
|
6560
|
-
}
|
|
6561
|
-
],
|
|
6562
|
-
""
|
|
6563
|
-
);
|
|
6564
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6565
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6566
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6567
|
-
const grantFee = {
|
|
6568
|
-
amount: calculatedFee.amount,
|
|
6569
|
-
gas: calculatedFee.gas,
|
|
6570
|
-
granter: granter || contractAddress
|
|
6571
|
-
};
|
|
6572
|
-
return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
|
|
6573
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
6574
|
-
const grantFee = {
|
|
6575
|
-
...fee,
|
|
6576
|
-
granter: granter || contractAddress
|
|
6577
|
-
};
|
|
6578
|
-
return await client.addNewKey(keyParams, grantFee, void 0, signupFunds);
|
|
6579
6257
|
}
|
|
6580
|
-
|
|
6258
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
6259
|
+
console.log(
|
|
6260
|
+
`[rawAddNewKey] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`
|
|
6261
|
+
);
|
|
6262
|
+
return this.contract.addNewKey({
|
|
6263
|
+
signer,
|
|
6264
|
+
contractAddress,
|
|
6265
|
+
pubkey,
|
|
6266
|
+
nullifier: nullifierStr,
|
|
6267
|
+
d,
|
|
6268
|
+
groth16Proof: proof,
|
|
6269
|
+
granter: effectiveGranter,
|
|
6270
|
+
funds: signupFunds,
|
|
6271
|
+
fee
|
|
6272
|
+
});
|
|
6581
6273
|
}
|
|
6582
6274
|
async rawPreAddNewKey({
|
|
6583
6275
|
signer,
|
|
@@ -6590,88 +6282,47 @@ var MACI = class {
|
|
|
6590
6282
|
granter,
|
|
6591
6283
|
fee = "auto"
|
|
6592
6284
|
}) {
|
|
6593
|
-
const client = await this.contract.amaciClient({
|
|
6594
|
-
signer,
|
|
6595
|
-
contractAddress
|
|
6596
|
-
});
|
|
6597
6285
|
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
6598
|
-
const
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
nullifier: nullifier.toString(),
|
|
6602
|
-
pubkey: {
|
|
6603
|
-
x: newPubkey[0].toString(),
|
|
6604
|
-
y: newPubkey[1].toString()
|
|
6605
|
-
}
|
|
6286
|
+
const pubkey = {
|
|
6287
|
+
x: newPubkey[0].toString(),
|
|
6288
|
+
y: newPubkey[1].toString()
|
|
6606
6289
|
};
|
|
6290
|
+
const nullifierStr = nullifier.toString();
|
|
6607
6291
|
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
6292
|
+
console.log("[rawPreAddNewKey] path: viaSaas (gasStation=true, granter=apiSaasAddress)");
|
|
6608
6293
|
return this.contract.preAddNewKeyViaSaas({
|
|
6609
6294
|
signer,
|
|
6610
6295
|
contractAddress,
|
|
6611
|
-
pubkey
|
|
6612
|
-
nullifier:
|
|
6296
|
+
pubkey,
|
|
6297
|
+
nullifier: nullifierStr,
|
|
6613
6298
|
d,
|
|
6614
6299
|
groth16Proof: proof,
|
|
6615
6300
|
granter,
|
|
6616
6301
|
fee
|
|
6617
6302
|
});
|
|
6618
|
-
} else if (gasStation === true && typeof fee !== "object") {
|
|
6619
|
-
const [{ address }] = await signer.getAccounts();
|
|
6620
|
-
const contractClient = await this.contract.contractClient({ signer });
|
|
6621
|
-
const msg = {
|
|
6622
|
-
pre_add_new_key: {
|
|
6623
|
-
d,
|
|
6624
|
-
groth16_proof: proof,
|
|
6625
|
-
nullifier: nullifier.toString(),
|
|
6626
|
-
pubkey: {
|
|
6627
|
-
x: newPubkey[0].toString(),
|
|
6628
|
-
y: newPubkey[1].toString()
|
|
6629
|
-
}
|
|
6630
|
-
}
|
|
6631
|
-
};
|
|
6632
|
-
const gasEstimation = await contractClient.simulate(
|
|
6633
|
-
address,
|
|
6634
|
-
[
|
|
6635
|
-
{
|
|
6636
|
-
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
6637
|
-
value: {
|
|
6638
|
-
sender: address,
|
|
6639
|
-
contract: contractAddress,
|
|
6640
|
-
msg: new TextEncoder().encode(JSON.stringify(msg)),
|
|
6641
|
-
funds: signupFunds
|
|
6642
|
-
}
|
|
6643
|
-
}
|
|
6644
|
-
],
|
|
6645
|
-
""
|
|
6646
|
-
);
|
|
6647
|
-
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
6648
|
-
const gasPrice = import_stargate3.GasPrice.fromString("10000000000peaka");
|
|
6649
|
-
const calculatedFee = (0, import_stargate3.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
6650
|
-
const grantFee = {
|
|
6651
|
-
amount: calculatedFee.amount,
|
|
6652
|
-
gas: calculatedFee.gas,
|
|
6653
|
-
granter: granter || contractAddress
|
|
6654
|
-
};
|
|
6655
|
-
return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
|
|
6656
|
-
} else if (gasStation === true && typeof fee === "object") {
|
|
6657
|
-
const grantFee = {
|
|
6658
|
-
...fee,
|
|
6659
|
-
granter: granter || contractAddress
|
|
6660
|
-
};
|
|
6661
|
-
return await client.preAddNewKey(keyParams, grantFee, void 0, signupFunds);
|
|
6662
6303
|
}
|
|
6663
|
-
|
|
6304
|
+
const effectiveGranter = gasStation ? granter ?? contractAddress : void 0;
|
|
6305
|
+
console.log(
|
|
6306
|
+
`[rawPreAddNewKey] path: direct (gasStation=${gasStation}, granter=${effectiveGranter ?? "none"})`
|
|
6307
|
+
);
|
|
6308
|
+
return this.contract.preAddNewKey({
|
|
6309
|
+
signer,
|
|
6310
|
+
contractAddress,
|
|
6311
|
+
pubkey,
|
|
6312
|
+
nullifier: nullifierStr,
|
|
6313
|
+
d,
|
|
6314
|
+
groth16Proof: proof,
|
|
6315
|
+
granter: effectiveGranter,
|
|
6316
|
+
funds: signupFunds,
|
|
6317
|
+
fee
|
|
6318
|
+
});
|
|
6664
6319
|
}
|
|
6665
6320
|
async claimAMaciRound({
|
|
6666
6321
|
signer,
|
|
6667
6322
|
contractAddress,
|
|
6668
6323
|
fee = "auto"
|
|
6669
6324
|
}) {
|
|
6670
|
-
|
|
6671
|
-
signer,
|
|
6672
|
-
contractAddress
|
|
6673
|
-
});
|
|
6674
|
-
return client.claim(fee);
|
|
6325
|
+
return this.contract.claim({ signer, contractAddress, fee });
|
|
6675
6326
|
}
|
|
6676
6327
|
async getOracleCertificateConfig() {
|
|
6677
6328
|
const ecosystems = await this.oracleCertificate.listEcosystems();
|
|
@@ -6692,9 +6343,6 @@ var MACI = class {
|
|
|
6692
6343
|
amount,
|
|
6693
6344
|
fee = "auto"
|
|
6694
6345
|
}) {
|
|
6695
|
-
const client = await this.contract.contractClient({
|
|
6696
|
-
signer
|
|
6697
|
-
});
|
|
6698
6346
|
if (!address) {
|
|
6699
6347
|
address = (await signer.getAccounts())[0].address;
|
|
6700
6348
|
}
|
|
@@ -6736,12 +6384,7 @@ var MACI = class {
|
|
|
6736
6384
|
})
|
|
6737
6385
|
}
|
|
6738
6386
|
];
|
|
6739
|
-
|
|
6740
|
-
const result = await client.signAndBroadcast(address, msgs, fee);
|
|
6741
|
-
return result;
|
|
6742
|
-
} catch (err) {
|
|
6743
|
-
throw err;
|
|
6744
|
-
}
|
|
6387
|
+
return this.contract.executeWithRetry({ signer, address, msgs, fee });
|
|
6745
6388
|
}
|
|
6746
6389
|
/**
|
|
6747
6390
|
* Batch revoke with withdraw (for maci)
|
|
@@ -6756,9 +6399,6 @@ var MACI = class {
|
|
|
6756
6399
|
address,
|
|
6757
6400
|
fee = "auto"
|
|
6758
6401
|
}) {
|
|
6759
|
-
const client = await this.contract.contractClient({
|
|
6760
|
-
signer
|
|
6761
|
-
});
|
|
6762
6402
|
if (!address) {
|
|
6763
6403
|
address = (await signer.getAccounts())[0].address;
|
|
6764
6404
|
}
|
|
@@ -6792,12 +6432,7 @@ var MACI = class {
|
|
|
6792
6432
|
})
|
|
6793
6433
|
}
|
|
6794
6434
|
];
|
|
6795
|
-
|
|
6796
|
-
const result = await client.signAndBroadcast(address, msgs, fee);
|
|
6797
|
-
return result;
|
|
6798
|
-
} catch (err) {
|
|
6799
|
-
throw err;
|
|
6800
|
-
}
|
|
6435
|
+
return this.contract.executeWithRetry({ signer, address, msgs, fee });
|
|
6801
6436
|
}
|
|
6802
6437
|
};
|
|
6803
6438
|
|
|
@@ -7081,14 +6716,6 @@ var MaciApiClient = class {
|
|
|
7081
6716
|
});
|
|
7082
6717
|
}
|
|
7083
6718
|
// ==================== Pre-deactivate APIs ====================
|
|
7084
|
-
/**
|
|
7085
|
-
* Get pre-deactivate data by contract address
|
|
7086
|
-
*/
|
|
7087
|
-
async getPreDeactivate(params) {
|
|
7088
|
-
return this.fetch(`/v1/pre-deactivate/${params.contractAddress}`, {
|
|
7089
|
-
method: "GET"
|
|
7090
|
-
});
|
|
7091
|
-
}
|
|
7092
6719
|
/**
|
|
7093
6720
|
* Get coordinator public key, deactivate root, and voter scale for a round.
|
|
7094
6721
|
* Lighter alternative to the full data endpoint when only circuit inputs are needed.
|
|
@@ -7146,8 +6773,8 @@ var MaciClient = class {
|
|
|
7146
6773
|
constructor({
|
|
7147
6774
|
signer,
|
|
7148
6775
|
network,
|
|
7149
|
-
|
|
7150
|
-
|
|
6776
|
+
rpcEndpoints,
|
|
6777
|
+
restEndpoints,
|
|
7151
6778
|
apiEndpoint,
|
|
7152
6779
|
saasApiEndpoint,
|
|
7153
6780
|
saasApiKey,
|
|
@@ -7161,13 +6788,17 @@ var MaciClient = class {
|
|
|
7161
6788
|
feegrantOperator,
|
|
7162
6789
|
whitelistBackendPubkey,
|
|
7163
6790
|
certificateApiEndpoint,
|
|
7164
|
-
maciKeypair
|
|
6791
|
+
maciKeypair,
|
|
6792
|
+
retries,
|
|
6793
|
+
retryDelay
|
|
7165
6794
|
}) {
|
|
7166
6795
|
this.signer = signer;
|
|
7167
6796
|
this.network = network;
|
|
7168
6797
|
const defaultParams = getDefaultParams(network);
|
|
7169
|
-
|
|
7170
|
-
|
|
6798
|
+
const rpcUrls = rpcEndpoints ?? defaultParams.rpcEndpoints;
|
|
6799
|
+
const restUrls = restEndpoints ?? defaultParams.restEndpoints;
|
|
6800
|
+
this.rpcEndpoints = rpcUrls;
|
|
6801
|
+
this.restEndpoints = restUrls;
|
|
7171
6802
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
7172
6803
|
this.saasApiEndpoint = saasApiEndpoint || defaultParams.saasApiEndpoint;
|
|
7173
6804
|
this.certificateApiEndpoint = certificateApiEndpoint || defaultParams.certificateApiEndpoint;
|
|
@@ -7179,9 +6810,9 @@ var MaciClient = class {
|
|
|
7179
6810
|
this.feegrantOperator = feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
7180
6811
|
this.whitelistBackendPubkey = whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
|
|
7181
6812
|
this.maciKeypair = maciKeypair ?? genKeypair();
|
|
7182
|
-
this.http = new Http(this.apiEndpoint,
|
|
6813
|
+
this.http = new Http(this.apiEndpoint, restUrls, customFetch, defaultOptions, retries, retryDelay);
|
|
7183
6814
|
this.indexer = new Indexer({
|
|
7184
|
-
restEndpoint:
|
|
6815
|
+
restEndpoint: restUrls[0],
|
|
7185
6816
|
apiEndpoint: this.apiEndpoint,
|
|
7186
6817
|
// Indexer GraphQL API
|
|
7187
6818
|
registryAddress: this.registryAddress,
|
|
@@ -7189,14 +6820,16 @@ var MaciClient = class {
|
|
|
7189
6820
|
});
|
|
7190
6821
|
this.contract = new Contract({
|
|
7191
6822
|
network: this.network,
|
|
7192
|
-
|
|
6823
|
+
rpcEndpoints: rpcUrls,
|
|
7193
6824
|
registryAddress: this.registryAddress,
|
|
7194
6825
|
saasAddress: this.saasAddress,
|
|
7195
6826
|
apiSaasAddress: this.apiSaasAddress,
|
|
7196
6827
|
maciCodeId: this.maciCodeId,
|
|
7197
6828
|
oracleCodeId: this.oracleCodeId,
|
|
7198
6829
|
feegrantOperator: this.feegrantOperator,
|
|
7199
|
-
whitelistBackendPubkey: this.whitelistBackendPubkey
|
|
6830
|
+
whitelistBackendPubkey: this.whitelistBackendPubkey,
|
|
6831
|
+
retries,
|
|
6832
|
+
retryDelay
|
|
7200
6833
|
});
|
|
7201
6834
|
this.oracleCertificate = new OracleCertificate({
|
|
7202
6835
|
certificateApiEndpoint: this.certificateApiEndpoint,
|
|
@@ -8250,23 +7883,28 @@ var VoterClient = class _VoterClient {
|
|
|
8250
7883
|
mnemonic,
|
|
8251
7884
|
secretKey,
|
|
8252
7885
|
apiEndpoint,
|
|
8253
|
-
|
|
7886
|
+
rpcEndpoints,
|
|
7887
|
+
restEndpoints,
|
|
8254
7888
|
saasApiEndpoint,
|
|
8255
7889
|
saasApiKey,
|
|
8256
7890
|
registryAddress,
|
|
8257
7891
|
customFetch,
|
|
8258
|
-
defaultOptions
|
|
7892
|
+
defaultOptions,
|
|
7893
|
+
retries,
|
|
7894
|
+
retryDelay
|
|
8259
7895
|
}) {
|
|
8260
7896
|
this.network = network;
|
|
8261
7897
|
this.accountManager = new MaciAccount({ mnemonic, secretKey });
|
|
8262
7898
|
const defaultParams = getDefaultParams(network);
|
|
8263
|
-
|
|
7899
|
+
const rpcUrls = rpcEndpoints ?? defaultParams.rpcEndpoints;
|
|
7900
|
+
const restUrls = restEndpoints ?? defaultParams.restEndpoints;
|
|
7901
|
+
this.restEndpoints = restUrls;
|
|
8264
7902
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
8265
7903
|
this.saasApiEndpoint = saasApiEndpoint || defaultParams.saasApiEndpoint;
|
|
8266
7904
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
8267
|
-
this.http = new Http(this.apiEndpoint,
|
|
7905
|
+
this.http = new Http(this.apiEndpoint, restUrls, customFetch, defaultOptions, retries, retryDelay);
|
|
8268
7906
|
this.indexer = new Indexer({
|
|
8269
|
-
restEndpoint:
|
|
7907
|
+
restEndpoint: restUrls[0],
|
|
8270
7908
|
apiEndpoint: this.apiEndpoint,
|
|
8271
7909
|
// Indexer GraphQL API
|
|
8272
7910
|
registryAddress: this.registryAddress,
|
|
@@ -8279,14 +7917,16 @@ var VoterClient = class _VoterClient {
|
|
|
8279
7917
|
});
|
|
8280
7918
|
this.contract = new Contract({
|
|
8281
7919
|
network: this.network,
|
|
8282
|
-
|
|
7920
|
+
rpcEndpoints: rpcUrls,
|
|
8283
7921
|
registryAddress: this.registryAddress,
|
|
8284
7922
|
saasAddress: defaultParams.saasAddress,
|
|
8285
7923
|
apiSaasAddress: defaultParams.apiSaasAddress,
|
|
8286
7924
|
maciCodeId: defaultParams.maciCodeId,
|
|
8287
7925
|
oracleCodeId: defaultParams.oracleCodeId,
|
|
8288
7926
|
feegrantOperator: defaultParams.oracleFeegrantOperator,
|
|
8289
|
-
whitelistBackendPubkey: defaultParams.oracleWhitelistBackendPubkey
|
|
7927
|
+
whitelistBackendPubkey: defaultParams.oracleWhitelistBackendPubkey,
|
|
7928
|
+
retries,
|
|
7929
|
+
retryDelay
|
|
8290
7930
|
});
|
|
8291
7931
|
}
|
|
8292
7932
|
/**
|
|
@@ -9056,16 +8696,6 @@ var VoterClient = class _VoterClient {
|
|
|
9056
8696
|
}
|
|
9057
8697
|
return await this.saasApiClient.createAmaciRound(params);
|
|
9058
8698
|
}
|
|
9059
|
-
/**
|
|
9060
|
-
* Get pre-deactivate data via SaaS API
|
|
9061
|
-
* @param contractAddress - Contract address
|
|
9062
|
-
*/
|
|
9063
|
-
async saasGetPreDeactivate(contractAddress) {
|
|
9064
|
-
if (!this.saasApiClient) {
|
|
9065
|
-
throw new Error("SaaS API client not initialized");
|
|
9066
|
-
}
|
|
9067
|
-
return await this.saasApiClient.getPreDeactivate({ contractAddress });
|
|
9068
|
-
}
|
|
9069
8699
|
/**
|
|
9070
8700
|
* Signup via SaaS API
|
|
9071
8701
|
* @param params - Signup parameters (including ticket)
|
|
@@ -9126,10 +8756,14 @@ var VoterClient = class _VoterClient {
|
|
|
9126
8756
|
* Poll the chain REST endpoint until the given transaction is committed on-chain,
|
|
9127
8757
|
* then return its `tx_response` object with an added `status` field.
|
|
9128
8758
|
*
|
|
8759
|
+
* The underlying REST client automatically rotates through all configured
|
|
8760
|
+
* `restEndpoints` on failure, so a single unavailable node will not block polling.
|
|
8761
|
+
*
|
|
9129
8762
|
* @param txHash - On-chain transaction hash to wait for.
|
|
9130
8763
|
* @param options.timeout - Max wait time in milliseconds (default: 60 000 ms).
|
|
9131
8764
|
* @param options.interval - Polling interval in milliseconds (default: 2 000 ms).
|
|
9132
8765
|
* @returns The Cosmos `tx_response` record plus `status`: `'success'` when `code === 0`, `'failed'` otherwise.
|
|
8766
|
+
* The `events` array can be parsed with helpers such as `parseCreatedRoundEvent`.
|
|
9133
8767
|
* @throws If the transaction is not found within the timeout period.
|
|
9134
8768
|
*/
|
|
9135
8769
|
async waitForTransaction(txHash, options = {}) {
|
|
@@ -9182,7 +8816,7 @@ var VoterClient = class _VoterClient {
|
|
|
9182
8816
|
}) {
|
|
9183
8817
|
const newVoterClient = new _VoterClient({
|
|
9184
8818
|
network: this.network,
|
|
9185
|
-
|
|
8819
|
+
restEndpoints: this.restEndpoints,
|
|
9186
8820
|
apiEndpoint: this.apiEndpoint,
|
|
9187
8821
|
saasApiEndpoint: this.saasApiEndpoint,
|
|
9188
8822
|
registryAddress: this.registryAddress
|
|
@@ -9289,10 +8923,12 @@ var OperatorClient = class {
|
|
|
9289
8923
|
mnemonic,
|
|
9290
8924
|
secretKey,
|
|
9291
8925
|
apiEndpoint,
|
|
9292
|
-
|
|
8926
|
+
restEndpoints,
|
|
9293
8927
|
registryAddress,
|
|
9294
8928
|
customFetch,
|
|
9295
|
-
defaultOptions
|
|
8929
|
+
defaultOptions,
|
|
8930
|
+
retries,
|
|
8931
|
+
retryDelay
|
|
9296
8932
|
}) {
|
|
9297
8933
|
// State
|
|
9298
8934
|
this.deactivateSize = 0;
|
|
@@ -9314,12 +8950,13 @@ var OperatorClient = class {
|
|
|
9314
8950
|
this.network = network;
|
|
9315
8951
|
this.accountManager = new MaciAccount({ mnemonic, secretKey });
|
|
9316
8952
|
const defaultParams = getDefaultParams(network);
|
|
9317
|
-
|
|
8953
|
+
const restUrls = restEndpoints ?? defaultParams.restEndpoints;
|
|
8954
|
+
this.restEndpoints = restUrls;
|
|
9318
8955
|
this.apiEndpoint = apiEndpoint || defaultParams.apiEndpoint;
|
|
9319
8956
|
this.registryAddress = registryAddress || defaultParams.registryAddress;
|
|
9320
|
-
this.http = new Http(this.apiEndpoint,
|
|
8957
|
+
this.http = new Http(this.apiEndpoint, restUrls, customFetch, defaultOptions, retries, retryDelay);
|
|
9321
8958
|
this.indexer = new Indexer({
|
|
9322
|
-
restEndpoint:
|
|
8959
|
+
restEndpoint: restUrls[0],
|
|
9323
8960
|
apiEndpoint: this.apiEndpoint,
|
|
9324
8961
|
// Indexer GraphQL API
|
|
9325
8962
|
registryAddress: this.registryAddress,
|
|
@@ -9327,14 +8964,16 @@ var OperatorClient = class {
|
|
|
9327
8964
|
});
|
|
9328
8965
|
this.contract = new Contract({
|
|
9329
8966
|
network: this.network,
|
|
9330
|
-
|
|
8967
|
+
rpcEndpoints: defaultParams.rpcEndpoints,
|
|
9331
8968
|
registryAddress: this.registryAddress,
|
|
9332
8969
|
saasAddress: defaultParams.saasAddress,
|
|
9333
8970
|
apiSaasAddress: defaultParams.apiSaasAddress,
|
|
9334
8971
|
maciCodeId: defaultParams.maciCodeId,
|
|
9335
8972
|
oracleCodeId: defaultParams.oracleCodeId,
|
|
9336
8973
|
feegrantOperator: defaultParams.oracleFeegrantOperator,
|
|
9337
|
-
whitelistBackendPubkey: defaultParams.oracleWhitelistBackendPubkey
|
|
8974
|
+
whitelistBackendPubkey: defaultParams.oracleWhitelistBackendPubkey,
|
|
8975
|
+
retries,
|
|
8976
|
+
retryDelay
|
|
9338
8977
|
});
|
|
9339
8978
|
}
|
|
9340
8979
|
/**
|