@vocdoni/davinci-sdk 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/dist/contracts.d.ts +14 -3
- package/dist/index.d.ts +128 -3
- package/dist/index.js +170 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +170 -1
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1005,7 +1005,7 @@
|
|
|
1005
1005
|
return this.contract.stVerifier();
|
|
1006
1006
|
}
|
|
1007
1007
|
// ─── WRITES ────────────────────────────────────────────────────────
|
|
1008
|
-
newProcess(status, startTime, duration, ballotMode, census, metadata, encryptionKey, initStateRoot) {
|
|
1008
|
+
newProcess(status, startTime, duration, maxVoters, ballotMode, census, metadata, encryptionKey, initStateRoot) {
|
|
1009
1009
|
const contractCensus = {
|
|
1010
1010
|
censusOrigin: BigInt(census.censusOrigin),
|
|
1011
1011
|
censusRoot: census.censusRoot,
|
|
@@ -1016,6 +1016,7 @@
|
|
|
1016
1016
|
status,
|
|
1017
1017
|
startTime,
|
|
1018
1018
|
duration,
|
|
1019
|
+
maxVoters,
|
|
1019
1020
|
ballotMode,
|
|
1020
1021
|
contractCensus,
|
|
1021
1022
|
metadata,
|
|
@@ -1056,6 +1057,14 @@
|
|
|
1056
1057
|
async () => ({ success: true })
|
|
1057
1058
|
);
|
|
1058
1059
|
}
|
|
1060
|
+
setProcessMaxVoters(processID, maxVoters) {
|
|
1061
|
+
return this.sendTx(
|
|
1062
|
+
this.contract.setProcessMaxVoters(processID, maxVoters).catch((e) => {
|
|
1063
|
+
throw new ProcessDurationError(e.message, "setMaxVoters");
|
|
1064
|
+
}),
|
|
1065
|
+
async () => ({ success: true })
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1059
1068
|
/**
|
|
1060
1069
|
* Matches the on-chain `submitStateTransition(processId, proof, input)`
|
|
1061
1070
|
*/
|
|
@@ -1126,6 +1135,13 @@
|
|
|
1126
1135
|
cb
|
|
1127
1136
|
).catch((err) => console.error("Error setting up ProcessResultsSet listener:", err));
|
|
1128
1137
|
}
|
|
1138
|
+
onProcessMaxVotersChanged(cb) {
|
|
1139
|
+
this.setupEventListener(
|
|
1140
|
+
this.contract,
|
|
1141
|
+
this.contract.filters.ProcessMaxVotersChanged(),
|
|
1142
|
+
cb
|
|
1143
|
+
).catch((err) => console.error("Error setting up ProcessMaxVotersChanged listener:", err));
|
|
1144
|
+
}
|
|
1129
1145
|
removeAllListeners() {
|
|
1130
1146
|
this.contract.removeAllListeners();
|
|
1131
1147
|
this.clearPollingIntervals();
|
|
@@ -1231,6 +1247,7 @@
|
|
|
1231
1247
|
endDate: new Date(endTime * 1e3),
|
|
1232
1248
|
duration,
|
|
1233
1249
|
timeRemaining,
|
|
1250
|
+
maxVoters: Number(rawProcess.maxVoters),
|
|
1234
1251
|
result: rawProcess.result,
|
|
1235
1252
|
votersCount: Number(rawProcess.votersCount),
|
|
1236
1253
|
overwrittenVotesCount: Number(rawProcess.overwrittenVotesCount),
|
|
@@ -1285,6 +1302,7 @@
|
|
|
1285
1302
|
ProcessStatus.READY,
|
|
1286
1303
|
data.startTime,
|
|
1287
1304
|
data.duration,
|
|
1305
|
+
data.maxVoters,
|
|
1288
1306
|
data.ballotMode,
|
|
1289
1307
|
data.census,
|
|
1290
1308
|
data.metadataUri,
|
|
@@ -1372,6 +1390,7 @@
|
|
|
1372
1390
|
ballotMode,
|
|
1373
1391
|
signature
|
|
1374
1392
|
});
|
|
1393
|
+
const maxVoters = config.maxVoters ?? censusConfig.size;
|
|
1375
1394
|
const census = {
|
|
1376
1395
|
censusOrigin: censusConfig.type,
|
|
1377
1396
|
censusRoot,
|
|
@@ -1381,6 +1400,7 @@
|
|
|
1381
1400
|
processId,
|
|
1382
1401
|
startTime,
|
|
1383
1402
|
duration,
|
|
1403
|
+
maxVoters,
|
|
1384
1404
|
censusRoot,
|
|
1385
1405
|
ballotMode,
|
|
1386
1406
|
metadataUri,
|
|
@@ -1767,6 +1787,84 @@
|
|
|
1767
1787
|
}
|
|
1768
1788
|
throw new Error("Resume process stream ended unexpectedly");
|
|
1769
1789
|
}
|
|
1790
|
+
/**
|
|
1791
|
+
* Sets the maximum number of voters for a process.
|
|
1792
|
+
* Returns an async generator that yields transaction status events.
|
|
1793
|
+
*
|
|
1794
|
+
* @param processId - The process ID
|
|
1795
|
+
* @param maxVoters - The new maximum number of voters
|
|
1796
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
1797
|
+
*
|
|
1798
|
+
* @example
|
|
1799
|
+
* ```typescript
|
|
1800
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
1801
|
+
*
|
|
1802
|
+
* for await (const event of stream) {
|
|
1803
|
+
* switch (event.status) {
|
|
1804
|
+
* case "pending":
|
|
1805
|
+
* console.log("Transaction pending:", event.hash);
|
|
1806
|
+
* break;
|
|
1807
|
+
* case "completed":
|
|
1808
|
+
* console.log("MaxVoters updated successfully");
|
|
1809
|
+
* break;
|
|
1810
|
+
* case "failed":
|
|
1811
|
+
* console.error("Transaction failed:", event.error);
|
|
1812
|
+
* break;
|
|
1813
|
+
* case "reverted":
|
|
1814
|
+
* console.error("Transaction reverted:", event.reason);
|
|
1815
|
+
* break;
|
|
1816
|
+
* }
|
|
1817
|
+
* }
|
|
1818
|
+
* ```
|
|
1819
|
+
*/
|
|
1820
|
+
async *setProcessMaxVotersStream(processId, maxVoters) {
|
|
1821
|
+
const txStream = this.processRegistry.setProcessMaxVoters(processId, maxVoters);
|
|
1822
|
+
for await (const event of txStream) {
|
|
1823
|
+
if (event.status === TxStatus.Pending) {
|
|
1824
|
+
yield { status: TxStatus.Pending, hash: event.hash };
|
|
1825
|
+
} else if (event.status === TxStatus.Completed) {
|
|
1826
|
+
yield {
|
|
1827
|
+
status: TxStatus.Completed,
|
|
1828
|
+
response: { success: true }
|
|
1829
|
+
};
|
|
1830
|
+
break;
|
|
1831
|
+
} else if (event.status === TxStatus.Failed) {
|
|
1832
|
+
yield { status: TxStatus.Failed, error: event.error };
|
|
1833
|
+
break;
|
|
1834
|
+
} else if (event.status === TxStatus.Reverted) {
|
|
1835
|
+
yield { status: TxStatus.Reverted, reason: event.reason };
|
|
1836
|
+
break;
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Sets the maximum number of voters for a process.
|
|
1842
|
+
* This is a simplified method that waits for transaction completion.
|
|
1843
|
+
*
|
|
1844
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
1845
|
+
*
|
|
1846
|
+
* @param processId - The process ID
|
|
1847
|
+
* @param maxVoters - The new maximum number of voters
|
|
1848
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
1849
|
+
*
|
|
1850
|
+
* @example
|
|
1851
|
+
* ```typescript
|
|
1852
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
1853
|
+
* console.log("MaxVoters updated successfully");
|
|
1854
|
+
* ```
|
|
1855
|
+
*/
|
|
1856
|
+
async setProcessMaxVoters(processId, maxVoters) {
|
|
1857
|
+
for await (const event of this.setProcessMaxVotersStream(processId, maxVoters)) {
|
|
1858
|
+
if (event.status === "completed") {
|
|
1859
|
+
return;
|
|
1860
|
+
} else if (event.status === "failed") {
|
|
1861
|
+
throw event.error;
|
|
1862
|
+
} else if (event.status === "reverted") {
|
|
1863
|
+
throw new Error(`Transaction reverted: ${event.reason || "unknown reason"}`);
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
throw new Error("Set process maxVoters stream ended unexpectedly");
|
|
1867
|
+
}
|
|
1770
1868
|
}
|
|
1771
1869
|
|
|
1772
1870
|
class CircomProof {
|
|
@@ -3271,6 +3369,77 @@
|
|
|
3271
3369
|
this.ensureProvider();
|
|
3272
3370
|
return this.processOrchestrator.resumeProcess(processId);
|
|
3273
3371
|
}
|
|
3372
|
+
/**
|
|
3373
|
+
* Sets the maximum number of voters for a process and returns an async generator
|
|
3374
|
+
* that yields transaction status events. This allows you to change the voter limit
|
|
3375
|
+
* after process creation.
|
|
3376
|
+
*
|
|
3377
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
3378
|
+
*
|
|
3379
|
+
* @param processId - The process ID
|
|
3380
|
+
* @param maxVoters - The new maximum number of voters
|
|
3381
|
+
* @returns AsyncGenerator yielding transaction status events
|
|
3382
|
+
* @throws Error if signer does not have a provider
|
|
3383
|
+
*
|
|
3384
|
+
* @example
|
|
3385
|
+
* ```typescript
|
|
3386
|
+
* const stream = sdk.setProcessMaxVotersStream("0x1234567890abcdef...", 500);
|
|
3387
|
+
*
|
|
3388
|
+
* for await (const event of stream) {
|
|
3389
|
+
* switch (event.status) {
|
|
3390
|
+
* case TxStatus.Pending:
|
|
3391
|
+
* console.log("Transaction pending:", event.hash);
|
|
3392
|
+
* break;
|
|
3393
|
+
* case TxStatus.Completed:
|
|
3394
|
+
* console.log("MaxVoters updated successfully");
|
|
3395
|
+
* break;
|
|
3396
|
+
* case TxStatus.Failed:
|
|
3397
|
+
* console.error("Transaction failed:", event.error);
|
|
3398
|
+
* break;
|
|
3399
|
+
* case TxStatus.Reverted:
|
|
3400
|
+
* console.error("Transaction reverted:", event.reason);
|
|
3401
|
+
* break;
|
|
3402
|
+
* }
|
|
3403
|
+
* }
|
|
3404
|
+
* ```
|
|
3405
|
+
*/
|
|
3406
|
+
setProcessMaxVotersStream(processId, maxVoters) {
|
|
3407
|
+
if (!this.initialized) {
|
|
3408
|
+
throw new Error(
|
|
3409
|
+
"SDK must be initialized before setting process maxVoters. Call sdk.init() first."
|
|
3410
|
+
);
|
|
3411
|
+
}
|
|
3412
|
+
this.ensureProvider();
|
|
3413
|
+
return this.processOrchestrator.setProcessMaxVotersStream(processId, maxVoters);
|
|
3414
|
+
}
|
|
3415
|
+
/**
|
|
3416
|
+
* Sets the maximum number of voters for a process.
|
|
3417
|
+
* This is the simplified method that waits for transaction completion.
|
|
3418
|
+
*
|
|
3419
|
+
* For real-time transaction status updates, use setProcessMaxVotersStream() instead.
|
|
3420
|
+
*
|
|
3421
|
+
* Requires a signer with a provider for blockchain interactions.
|
|
3422
|
+
*
|
|
3423
|
+
* @param processId - The process ID
|
|
3424
|
+
* @param maxVoters - The new maximum number of voters
|
|
3425
|
+
* @returns Promise resolving when the maxVoters is updated
|
|
3426
|
+
* @throws Error if signer does not have a provider
|
|
3427
|
+
*
|
|
3428
|
+
* @example
|
|
3429
|
+
* ```typescript
|
|
3430
|
+
* await sdk.setProcessMaxVoters("0x1234567890abcdef...", 500);
|
|
3431
|
+
* console.log("MaxVoters updated successfully");
|
|
3432
|
+
* ```
|
|
3433
|
+
*/
|
|
3434
|
+
async setProcessMaxVoters(processId, maxVoters) {
|
|
3435
|
+
if (!this.initialized) {
|
|
3436
|
+
throw new Error(
|
|
3437
|
+
"SDK must be initialized before setting process maxVoters. Call sdk.init() first."
|
|
3438
|
+
);
|
|
3439
|
+
}
|
|
3440
|
+
this.ensureProvider();
|
|
3441
|
+
return this.processOrchestrator.setProcessMaxVoters(processId, maxVoters);
|
|
3442
|
+
}
|
|
3274
3443
|
/**
|
|
3275
3444
|
* Resolve contract address based on configuration priority:
|
|
3276
3445
|
* 1. Custom addresses from user config (if provided)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocdoni/davinci-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@ethereumjs/common": "^4.4.0",
|
|
75
|
-
"@vocdoni/davinci-contracts": "0.0.
|
|
75
|
+
"@vocdoni/davinci-contracts": "0.0.29",
|
|
76
76
|
"axios": "^1.8.4",
|
|
77
77
|
"ethers": "^6.7.1",
|
|
78
78
|
"snarkjs": "^0.7.5"
|