Skip to content

Commit

Permalink
fix(drywrite): throw on bad drywrite and continue if successful
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Mar 25, 2024
1 parent 5f6e0a1 commit 5052c0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { ArconnectSigner, ArweaveSigner, DataItem } from 'arbundles';
import { InteractionResult, Transaction } from 'warp-contracts';
import { Transaction } from 'warp-contracts';

import {
ANTRecord,
Expand Down Expand Up @@ -98,7 +98,7 @@ export interface WriteContract {
inputs,
evaluationOptions,
}: EvaluationParameters<WriteParameters<Input>>): Promise<
Transaction | DataItem | InteractionResult<unknown, Input>
Transaction | DataItem
>;
}

Expand Down
13 changes: 8 additions & 5 deletions src/common/contracts/warp-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { DataItem, Signer } from 'arbundles';
import Arweave from 'arweave';
import {
Contract,
InteractionResult,
LoggerFactory,
Transaction,
Warp,
Expand Down Expand Up @@ -169,7 +168,7 @@ export class WarpContract<T>
inputs,
dryWrite = true,
}: EvaluationParameters<WriteParameters<Input>>): Promise<
Transaction | DataItem | InteractionResult<unknown, Input>
Transaction | DataItem
> {
try {
this.log.debug(`Write interaction: ${functionName}`, {
Expand All @@ -179,11 +178,15 @@ export class WarpContract<T>
await this.ensureContractInit();

if (dryWrite) {
// responsibility of the caller to handle the dry write result for control flows
return (await this.contract.dryWrite<Input>({
const { errorMessage, type } = await this.contract.dryWrite<Input>({
function: functionName,
...inputs,
})) as InteractionResult<unknown, Input>;
});
if (type !== 'ok') {
throw new Error(
`Failed to dry write contract interaction ${functionName}: ${errorMessage}`,
);
}
}

const writeResult = await this.contract.writeInteraction<Input>({
Expand Down

0 comments on commit 5052c0a

Please sign in to comment.