@dorafactory/maci-sdk 0.0.53 → 0.0.55

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.
@@ -109,10 +109,9 @@ export declare class MACI {
109
109
  fee?: StdFee;
110
110
  }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
111
111
  private processVoteOptions;
112
- vote({ signer, address, stateIdx, contractAddress, selectedOptions, operatorCoordPubKey, maciKeypair, gasStation, }: {
112
+ vote({ signer, address, contractAddress, selectedOptions, operatorCoordPubKey, maciKeypair, gasStation, }: {
113
113
  signer: OfflineSigner;
114
114
  address?: string;
115
- stateIdx: number;
116
115
  contractAddress: string;
117
116
  selectedOptions: {
118
117
  idx: number;
package/dist/maci.d.ts CHANGED
@@ -76,9 +76,10 @@ export declare class MaciClient {
76
76
  address?: string;
77
77
  contractAddress: string;
78
78
  }): Promise<string>;
79
- getVoiceCreditBalance({ signer, stateIdx, contractAddress, }: {
79
+ getVoiceCreditBalance({ signer, stateIdx, maciKeypair, contractAddress, }: {
80
80
  signer?: OfflineSigner;
81
- stateIdx: number;
81
+ stateIdx?: number;
82
+ maciKeypair?: Keypair;
82
83
  contractAddress: string;
83
84
  }): Promise<string>;
84
85
  getStateIdxByPubKey({ contractAddress, pubKey, }: {
@@ -173,10 +174,9 @@ export declare class MaciClient {
173
174
  gasStation?: boolean;
174
175
  fee?: StdFee;
175
176
  }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
176
- vote({ signer, address, stateIdx, contractAddress, selectedOptions, operatorCoordPubKey, maciKeypair, gasStation, }: {
177
+ vote({ signer, address, contractAddress, selectedOptions, operatorCoordPubKey, maciKeypair, gasStation, }: {
177
178
  signer?: OfflineSigner;
178
179
  address?: string;
179
- stateIdx: number;
180
180
  contractAddress: string;
181
181
  selectedOptions: {
182
182
  idx: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.53",
3
+ "version": "0.0.55",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
@@ -554,7 +554,6 @@ export class MACI {
554
554
  async vote({
555
555
  signer,
556
556
  address,
557
- stateIdx,
558
557
  contractAddress,
559
558
  selectedOptions,
560
559
  operatorCoordPubKey,
@@ -563,7 +562,6 @@ export class MACI {
563
562
  }: {
564
563
  signer: OfflineSigner;
565
564
  address?: string;
566
- stateIdx: number;
567
565
  contractAddress: string;
568
566
  selectedOptions: {
569
567
  idx: number;
@@ -573,8 +571,19 @@ export class MACI {
573
571
  maciKeypair?: Keypair;
574
572
  gasStation?: boolean;
575
573
  }) {
574
+ if (maciKeypair === undefined) {
575
+ maciKeypair = this.maciKeypair;
576
+ }
577
+
578
+ const stateIdx = await this.getStateIdxByPubKey({
579
+ contractAddress,
580
+ pubKey: maciKeypair.pubKey,
581
+ });
582
+
576
583
  if (stateIdx === -1) {
577
- throw new Error('State index is not set, Please signup first');
584
+ throw new Error(
585
+ 'State index is not set, Please signup or addNewKey first'
586
+ );
578
587
  }
579
588
 
580
589
  try {
@@ -633,10 +642,6 @@ export class MACI {
633
642
  address = (await signer.getAccounts())[0].address;
634
643
  }
635
644
 
636
- if (maciKeypair === undefined) {
637
- maciKeypair = this.maciKeypair;
638
- }
639
-
640
645
  const plan = options.map((o) => {
641
646
  return [o.idx, o.vc] as [number, number];
642
647
  });
package/src/maci.ts CHANGED
@@ -249,12 +249,25 @@ export class MaciClient {
249
249
  async getVoiceCreditBalance({
250
250
  signer,
251
251
  stateIdx,
252
+ maciKeypair,
252
253
  contractAddress,
253
254
  }: {
254
255
  signer?: OfflineSigner;
255
- stateIdx: number;
256
+ stateIdx?: number;
257
+ maciKeypair?: Keypair;
256
258
  contractAddress: string;
257
259
  }) {
260
+ if (maciKeypair === undefined) {
261
+ maciKeypair = this.maciKeypair;
262
+ }
263
+
264
+ if (stateIdx === undefined) {
265
+ stateIdx = await this.getStateIdxByPubKey({
266
+ contractAddress,
267
+ pubKey: maciKeypair.pubKey,
268
+ });
269
+ }
270
+
258
271
  return await this.maci.getVoiceCreditBalance({
259
272
  signer: this.getSigner(signer),
260
273
  stateIdx,
@@ -489,7 +502,6 @@ export class MaciClient {
489
502
  async vote({
490
503
  signer,
491
504
  address,
492
- stateIdx,
493
505
  contractAddress,
494
506
  selectedOptions,
495
507
  operatorCoordPubKey,
@@ -498,7 +510,6 @@ export class MaciClient {
498
510
  }: {
499
511
  signer?: OfflineSigner;
500
512
  address?: string;
501
- stateIdx: number;
502
513
  contractAddress: string;
503
514
  selectedOptions: {
504
515
  idx: number;
@@ -511,7 +522,6 @@ export class MaciClient {
511
522
  return await this.maci.vote({
512
523
  signer: this.getSigner(signer),
513
524
  address,
514
- stateIdx,
515
525
  contractAddress,
516
526
  selectedOptions,
517
527
  operatorCoordPubKey,