Skip to content

Commit

Permalink
Fix htlc example (#792)
Browse files Browse the repository at this point in the history
* fixed htlc eg
  • Loading branch information
Megha-Dev-19 authored Sep 28, 2022
1 parent 4894c7c commit 9efc8fe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion examples/htlc-pyteal-ts/scripts/withdraw/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getDeployerAccount(
return account;
}

export async function WithdrawExecuteTx(
export async function withdrawExecuteTx(
deployer: algob.types.Deployer,
txnParams: wtypes.ExecParams
): Promise<void> {
Expand All @@ -28,9 +28,11 @@ export async function WithdrawExecuteTx(
} catch (e) {
if (wtypes.isRequestError(e)) {
console.error("Transaction Failed", e?.response?.error);
throw e
}
if (e instanceof BuilderError) console.error("Transaction Failed", e.message);
console.error("An unexpected error occurred:", e);
throw e
}
}

Expand Down
18 changes: 13 additions & 5 deletions examples/htlc-pyteal-ts/scripts/withdraw/htlc-withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import * as algob from "@algo-builder/algob";
import { types as rtypes } from "@algo-builder/web";

import { prepareParameters, WithdrawExecuteTx } from "./common";
import { prepareParameters, withdrawExecuteTx } from "./common";

async function run(
runtimeEnv: algob.types.RuntimeEnv,
Expand All @@ -34,12 +34,20 @@ async function run(
args: [algob.convert.stringToBytes(wrongSecret)],
payFlags: { totalFee: 1000 },
};
// Transaction Fails : as wrong secret value is used
await WithdrawExecuteTx(deployer, txnParams);

// Transaction Passes : as right secret value is used
// Transaction Fails : as wrong secret value is used
await withdrawExecuteTx(deployer, txnParams)
.catch(error => {
console.log(error)
})

// Transaction Passes: as right secret value is used
txnParams.args = [algob.convert.stringToBytes(secret)];
await WithdrawExecuteTx(deployer, txnParams);
await withdrawExecuteTx(deployer, txnParams)
.catch(error => {
throw error
})

}

module.exports = { default: run };

0 comments on commit 9efc8fe

Please sign in to comment.