Skip to content

Commit

Permalink
fix(signer): check that contract is connected before trying to write (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Mar 26, 2024
2 parents 0d313d9 + d352e9c commit 536a116
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/common/contracts/warp-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class WarpContract<T>
private cacheUrl: string | undefined;
private arweave: Arweave;
private log: Logger;
private signer: ContractSigner | undefined;

constructor({
contractTxId,
Expand All @@ -63,6 +64,7 @@ export class WarpContract<T>
},
true,
),
signer,
arweave = defaultArweave,
log = new DefaultLogger({
level: 'debug',
Expand All @@ -80,6 +82,9 @@ export class WarpContract<T>
this.cacheUrl = cacheUrl;
this.arweave = arweave;
this.log = log;
if (signer) {
this.connect(signer);
}
}

configuration(): { contractTxId: string; cacheUrl: string | undefined } {
Expand All @@ -92,6 +97,7 @@ export class WarpContract<T>
// base contract methods
connect(signer: ContractSigner) {
// TODO: Update type to use Signer interface
this.signer = signer;
this.contract = this.contract.connect(signer as Signer);
return this;
}
Expand Down Expand Up @@ -171,6 +177,11 @@ export class WarpContract<T>
Transaction | DataItem | InteractionResult<unknown, unknown>
> {
try {
if (!this.signer) {
throw new Error(
'Contract not connected - call .connect(signer) to connect a signer for write interactions ',
);
}
this.log.debug(`Write interaction: ${functionName}`, {
contractTxId: this.contractTxId,
});
Expand Down

0 comments on commit 536a116

Please sign in to comment.