diff --git a/src/contract/HandlerBasedContract.ts b/src/contract/HandlerBasedContract.ts index 78c93110..95a1ed12 100644 --- a/src/contract/HandlerBasedContract.ts +++ b/src/contract/HandlerBasedContract.ts @@ -370,30 +370,8 @@ export class HandlerBasedContract implements Contract { reward?: string ) { if (this._evaluationOptions.internalWrites) { - // Call contract and verify if there are any internal writes: - // 1. Evaluate current contract state - // 2. Apply input as "dry-run" transaction - // 3. Verify the callStack and search for any "internalWrites" transactions - // 4. For each found "internalWrite" transaction - generate additional tag: - // {name: 'InternalWrite', value: callingContractTxId} - const handlerResult = await this.callContract(input, undefined, undefined, tags, transfer, strict, vrf); - - if (strict && handlerResult.type !== 'ok') { - throw Error(`Cannot create interaction: ${handlerResult.errorMessage}`); - } - const callStack: ContractCallRecord = this.getCallStack(); - const innerWrites = this._innerWritesEvaluator.eval(callStack); - this.logger.debug('Input', input); - this.logger.debug('Callstack', callStack.print()); - - innerWrites.forEach((contractTxId) => { - tags.push({ - name: SmartWeaveTags.INTERACT_WRITE, - value: contractTxId - }); - }); - - this.logger.debug('Tags with inner calls', tags); + // it modifies tags + await this.discoverInternalWrites(input, tags, transfer, strict, vrf); } if (vrf) { @@ -649,7 +627,8 @@ export class HandlerBasedContract implements Contract { tags: Tags = [], transfer: ArTransfer = emptyTransfer, strict = false, - vrf = false + vrf = false, + sign = true ): Promise> { this.logger.info('Call contract input', input); this.maybeResetRootContract(); @@ -692,7 +671,7 @@ export class HandlerBasedContract implements Contract { this.logger.debug('interaction', interaction); const tx = await createInteractionTx( arweave, - this.signature?.signer, + sign ? this.signature?.signer : undefined, this._contractTxId, input, tags, @@ -989,4 +968,37 @@ export class HandlerBasedContract implements Contract { return result as HandlerBasedContract; } + + // Call contract and verify if there are any internal writes: + // 1. Evaluate current contract state + // 2. Apply input as "dry-run" transaction + // 3. Verify the callStack and search for any "internalWrites" transactions + // 4. For each found "internalWrite" transaction - generate additional tag: + // {name: 'InternalWrite', value: callingContractTxId} + private async discoverInternalWrites( + input: Input, + tags: Tags, + transfer: ArTransfer, + strict: boolean, + vrf: boolean + ) { + const handlerResult = await this.callContract(input, undefined, undefined, tags, transfer, strict, vrf, false); + + if (strict && handlerResult.type !== 'ok') { + throw Error(`Cannot create interaction: ${handlerResult.errorMessage}`); + } + const callStack: ContractCallRecord = this.getCallStack(); + const innerWrites = this._innerWritesEvaluator.eval(callStack); + this.logger.debug('Input', input); + this.logger.debug('Callstack', callStack.print()); + + innerWrites.forEach((contractTxId) => { + tags.push({ + name: SmartWeaveTags.INTERACT_WRITE, + value: contractTxId + }); + }); + + this.logger.debug('Tags with inner calls', tags); + } }