@algorandfoundation/algokit-utils 7.0.0-beta.8 → 7.0.0-beta.9

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.
@@ -52,6 +52,7 @@ class AppClient {
52
52
  this._appName = params.appName ?? this._appSpec.name;
53
53
  this._algorand = params.algorand;
54
54
  this._defaultSender = params.defaultSender;
55
+ this._defaultSigner = params.defaultSigner;
55
56
  this._approvalSourceMap = params.approvalSourceMap;
56
57
  this._clearSourceMap = params.clearSourceMap;
57
58
  this._localStateMethods = (address) => this.getStateMethods(() => this.getLocalState(address), () => this._appSpec.state.keys.local, () => this._appSpec.state.maps.local);
@@ -147,6 +148,10 @@ class AppClient {
147
148
  get appSpec() {
148
149
  return this._appSpec;
149
150
  }
151
+ /** A reference to the underlying `AlgorandClient` this app client is using. */
152
+ get algorand() {
153
+ return this._algorand;
154
+ }
150
155
  /** Get parameters to create transactions for the current app.
151
156
  *
152
157
  * A good mental model for this is that these parameters represent a deferred transaction creation.
@@ -340,11 +345,11 @@ class AppClient {
340
345
  */
341
346
  async compile(compilation) {
342
347
  const result = await AppClient.compile(this._appSpec, this._algorand.app, compilation);
343
- if (result.approvalProgramCompilationResult) {
344
- this._approvalSourceMap = result.approvalProgramCompilationResult.sourceMap;
348
+ if (result.compiledApproval) {
349
+ this._approvalSourceMap = result.compiledApproval.sourceMap;
345
350
  }
346
- if (result.clearStateProgramCompilationResult) {
347
- this._clearSourceMap = result.clearStateProgramCompilationResult.sourceMap;
351
+ if (result.compiledClear) {
352
+ this._clearSourceMap = result.compiledClear.sourceMap;
348
353
  }
349
354
  return result;
350
355
  }
@@ -400,25 +405,25 @@ class AppClient {
400
405
  };
401
406
  }
402
407
  const approvalTemplate = buffer.Buffer.from(appSpec.source.approval, 'base64').toString('utf-8');
403
- const approvalProgramCompilationResult = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
408
+ const compiledApproval = await appManager.compileTealTemplate(approvalTemplate, deployTimeParams, {
404
409
  updatable,
405
410
  deletable,
406
411
  });
407
412
  const clearTemplate = buffer.Buffer.from(appSpec.source.clear, 'base64').toString('utf-8');
408
- const clearStateProgramCompilationResult = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
413
+ const compiledClear = await appManager.compileTealTemplate(clearTemplate, deployTimeParams);
409
414
  if (config.Config.debug) {
410
415
  await config.Config.events.emitAsync(types_asyncEventEmitter.EventType.AppCompiled, {
411
416
  sources: [
412
- { compiledTeal: approvalProgramCompilationResult, appName: appSpec.name, fileName: 'approval' },
413
- { compiledTeal: clearStateProgramCompilationResult, appName: appSpec.name, fileName: 'clear' },
417
+ { compiledTeal: compiledApproval, appName: appSpec.name, fileName: 'approval' },
418
+ { compiledTeal: compiledClear, appName: appSpec.name, fileName: 'clear' },
414
419
  ],
415
420
  });
416
421
  }
417
422
  return {
418
- approvalProgram: approvalProgramCompilationResult.compiledBase64ToBytes,
419
- approvalProgramCompilationResult,
420
- clearStateProgram: clearStateProgramCompilationResult.compiledBase64ToBytes,
421
- clearStateProgramCompilationResult,
423
+ approvalProgram: compiledApproval.compiledBase64ToBytes,
424
+ compiledApproval,
425
+ clearStateProgram: compiledClear.compiledBase64ToBytes,
426
+ compiledClear,
422
427
  };
423
428
  }
424
429
  /**
@@ -543,10 +548,7 @@ class AppClient {
543
548
  const compiled = await this.compile(params);
544
549
  return {
545
550
  ...(await this.handleCallErrors(async () => this._algorand.send.appUpdate(await this.params.bare.update(params)))),
546
- ...{
547
- compiledApproval: compiled.approvalProgramCompilationResult,
548
- compiledClear: compiled.clearStateProgramCompilationResult,
549
- },
551
+ ...compiled,
550
552
  };
551
553
  },
552
554
  /** Signs and sends an opt-in call */
@@ -578,6 +580,7 @@ class AppClient {
578
580
  return {
579
581
  ...params,
580
582
  sender: this.getSender(params.sender),
583
+ signer: this.getSigner(params.sender, params.signer),
581
584
  receiver: this.appAddress,
582
585
  };
583
586
  },
@@ -619,10 +622,7 @@ class AppClient {
619
622
  const compiled = await this.compile(params);
620
623
  return {
621
624
  ...(await this.handleCallErrors(async () => this.processMethodCallReturn(this._algorand.send.appUpdateMethodCall(await this.params.update({ ...params })), types_appArc56.getArc56Method(params.method, this._appSpec)))),
622
- ...{
623
- compiledApproval: compiled.approvalProgramCompilationResult,
624
- compiledClear: compiled.clearStateProgramCompilationResult,
625
- },
625
+ ...compiled,
626
626
  };
627
627
  },
628
628
  /**
@@ -655,6 +655,8 @@ class AppClient {
655
655
  .addAppCallMethodCall(await this.params.call(params))
656
656
  .simulate({
657
657
  allowUnnamedResources: params.populateAppCallResources,
658
+ // Simulate calls for a readonly method shouldn't invoke signing
659
+ skipSignatures: true,
658
660
  });
659
661
  return this.processMethodCallReturn({
660
662
  ...result,
@@ -706,7 +708,7 @@ class AppClient {
706
708
  },
707
709
  };
708
710
  }
709
- /** Returns the sender for a call, using the `defaultSender`
711
+ /** Returns the sender for a call, using the provided sender or using the `defaultSender`
710
712
  * if none provided and throws an error if neither provided */
711
713
  getSender(sender) {
712
714
  if (!sender && !this._defaultSender) {
@@ -714,11 +716,18 @@ class AppClient {
714
716
  }
715
717
  return sender ?? this._defaultSender;
716
718
  }
719
+ /** Returns the signer for a call, using the provided signer or the `defaultSigner`
720
+ * if no signer was provided and the call will use default sender
721
+ * or `undefined` otherwise (so the signer is resolved from `AlgorandClient`) */
722
+ getSigner(sender, signer) {
723
+ return signer ?? (!sender ? this._defaultSigner : undefined);
724
+ }
717
725
  getBareParams(params, onComplete) {
718
726
  return {
719
727
  ...params,
720
728
  appId: this._appId,
721
729
  sender: this.getSender(params?.sender),
730
+ signer: this.getSigner(params?.sender, params?.signer),
722
731
  onComplete,
723
732
  };
724
733
  }
@@ -730,6 +739,7 @@ class AppClient {
730
739
  ...params,
731
740
  appId: this._appId,
732
741
  sender: sender,
742
+ signer: this.getSigner(params.sender, params.signer),
733
743
  method,
734
744
  onComplete,
735
745
  args,