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