From 87b370aff9a8c0b540fbb3e2ecfd4b05ea11a51c Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Tue, 4 Oct 2022 22:57:26 +0530 Subject: [PATCH 01/18] added throw error --- examples/asa/scripts/0-gold-asa.js | 8 +- examples/asa/scripts/1-tesla-asa.js | 8 +- examples/asa/scripts/2-gold-asc.js | 48 +++++++----- examples/asa/scripts/3-contract-owned-asa.js | 54 ++++++++------ examples/asa/scripts/transfer/common.js | 4 +- .../change-contract-owner.js | 6 +- .../contract-owned-asa/contract-to-alice.js | 11 +-- .../contract-owned-asa/contract-to-bob.js | 8 +- .../asa/scripts/transfer/gold-contract-sc.js | 12 ++- .../scripts/transfer/gold-delegated-lsig.js | 18 ++++- examples/asa/scripts/transfer/gold-to-john.js | 3 +- .../asa/scripts/transfer/master-fund-john.js | 4 +- .../asa/scripts/transfer/tesla-to-john.js | 3 +- examples/bond/scripts/deploy.js | 62 +++++++++------- examples/bond/scripts/run/common/common.js | 15 +++- examples/bond/scripts/run/createBuyback.js | 10 ++- examples/bond/scripts/run/createDex.js | 15 +++- examples/bond/scripts/run/epoch0.js | 18 +++-- examples/bond/scripts/run/epoch1.js | 14 +++- examples/bond/scripts/run/exit.js | 14 ++-- examples/bond/scripts/run/issue.js | 4 +- examples/bond/scripts/run/redeem.js | 12 ++- .../crowdfunding/scripts/common/common.js | 13 ++++ examples/crowdfunding/scripts/createApp.js | 73 +++++++++++-------- .../crowdfunding/scripts/transfer/claim.js | 5 +- .../crowdfunding/scripts/transfer/delete.js | 5 +- .../crowdfunding/scripts/transfer/donate.js | 5 +- .../crowdfunding/scripts/transfer/reclaim.js | 5 +- examples/dao/scripts/deploy.js | 72 +++++++++++------- examples/dao/scripts/run/add_proposal.js | 2 +- examples/dao/scripts/run/close_proposal.js | 2 +- examples/dao/scripts/run/common/common.js | 7 +- .../dao/scripts/run/withdraw_from_proposal.js | 4 +- .../dao/scripts/run/withdraw_vote_deposit.js | 4 +- examples/htlc-pyteal-ts/scripts/deploy.ts | 10 ++- .../htlc-pyteal-ts/scripts/withdraw/common.ts | 31 ++++---- .../scripts/withdraw/htlc-withdraw.ts | 10 +-- .../scripts/common/common.js | 13 ++++ .../inner-tx-create-assets/scripts/deploy.js | 35 +++++---- .../scripts/run/useGroupTxn.js | 3 +- .../scripts/run/useInnerTxn.js | 3 +- examples/multisig/scripts/common/common.js | 5 +- examples/multisig/scripts/multisig_goal_sc.js | 2 +- examples/multisig/scripts/multisig_sdk_sc.js | 2 +- examples/nft/scripts/deploy-nft.js | 33 +++++---- examples/nft/scripts/transfer/common.js | 4 +- .../scripts/transfer/create-transfer-nft.js | 6 +- .../scripts/0-createAppAsset.js | 43 ++++++----- .../scripts/1-assetConfig.js | 11 ++- .../scripts/common/common.js | 13 ++++ .../scripts/transfer/set-clear-level.js | 5 +- .../scripts/transfer/transfer-asset.js | 8 +- .../scripts/1-setup-controller.js | 36 +++++---- .../scripts/2-asset-clawback.js | 10 ++- .../scripts/3-setup-permissions.js | 64 ++++++++-------- .../scripts/4-setup-new-permissions-app.js | 32 ++++---- .../permissioned-token/scripts/admin/cease.js | 4 +- .../scripts/admin/force-transfer.js | 8 +- .../permissioned-token/scripts/admin/kill.js | 2 +- .../scripts/admin/update-reserve.js | 3 +- .../scripts/common/common.js | 5 +- .../permissions/change-perm-manager.js | 4 +- .../permissions/set-permission-appid.js | 34 ++++----- .../scripts/permissions/whitelist.js | 4 +- .../scripts/user/opt-out.js | 4 +- .../scripts/user/transfer.js | 4 +- .../scripts/vote/common.js | 1 + .../permissioned-voting/scripts/vote/vote.js | 12 ++- .../permissioned-voting/scripts/voting.js | 47 +++++++----- .../ref-templates/scripts/common/common.js | 14 +--- examples/ref-templates/scripts/dynamic-fee.js | 26 +++++-- examples/ref-templates/scripts/htlc.js | 24 +++--- examples/signed-txn/scripts/transfer.js | 1 + .../stateful-counter/scripts/common/common.js | 9 +++ examples/stateful-counter/scripts/deploy.js | 39 ++++++---- .../scripts/interaction/call_application.js | 3 +- .../scripts/interaction/delete_application.js | 3 +- .../scripts/interaction/update_application.js | 28 ++++--- examples/trampoline/scripts/common/common.js | 9 +++ examples/trampoline/scripts/deployApp.js | 37 ++++++---- .../trampoline/scripts/run/create-fund-app.js | 11 ++- .../unique-nft-asa/scripts/0-deploy-app.js | 45 +++++++----- .../scripts/run/common/common.js | 3 +- 83 files changed, 795 insertions(+), 516 deletions(-) create mode 100644 examples/crowdfunding/scripts/common/common.js create mode 100644 examples/inner-tx-create-assets/scripts/common/common.js create mode 100644 examples/permissioned-token-freezing/scripts/common/common.js create mode 100644 examples/stateful-counter/scripts/common/common.js create mode 100644 examples/trampoline/scripts/common/common.js diff --git a/examples/asa/scripts/0-gold-asa.js b/examples/asa/scripts/0-gold-asa.js index e86d70e8f..7c79e02f9 100644 --- a/examples/asa/scripts/0-gold-asa.js +++ b/examples/asa/scripts/0-gold-asa.js @@ -1,7 +1,7 @@ const crypto = require("crypto"); const { balanceOf } = require("@algo-builder/algob"); -const { mkParam } = require("./transfer/common"); +const { mkParam, tryExecuteTx } = require("./transfer/common"); /* Create "gold" Algorand Standard Asset (ASA). Accounts are loaded from config. @@ -24,9 +24,9 @@ async function run(runtimeEnv, deployer) { // let note = new TextEncoder().encode(message); // note must be Uint8Array const promises = [ - deployer.executeTx(mkParam(masterAccount, goldOwner.addr, 5e6, { note: message })), - deployer.executeTx(mkParam(masterAccount, john.addr, 5e6, { note: message })), - deployer.executeTx(mkParam(masterAccount, bob.addr, 1e6, { note: message })), + tryExecuteTx(deployer, mkParam(masterAccount, goldOwner.addr, 5e6, { note: message })), + tryExecuteTx(deployer, mkParam(masterAccount, john.addr, 5e6, { note: message })), + tryExecuteTx(deployer, mkParam(masterAccount, bob.addr, 1e6, { note: message })), ]; await Promise.all(promises); diff --git a/examples/asa/scripts/1-tesla-asa.js b/examples/asa/scripts/1-tesla-asa.js index efbf57b71..60efc3020 100644 --- a/examples/asa/scripts/1-tesla-asa.js +++ b/examples/asa/scripts/1-tesla-asa.js @@ -1,5 +1,5 @@ const { balanceOf } = require("@algo-builder/algob"); -const { mkParam } = require("./transfer/common"); +const { mkParam, tryExecuteTx } = require("./transfer/common"); /* Create "tesla" Algorand Standard Asset (ASA) @@ -15,10 +15,12 @@ async function run(runtimeEnv, deployer) { const john = deployer.accountsByName.get("john"); // activate elon account - await deployer.executeTx( + await tryExecuteTx( + deployer, mkParam(masterAccount, elon.addr, 40e6, { note: "funding account" }) ); - await deployer.executeTx( + await tryExecuteTx( + deployer, mkParam(masterAccount, john.addr, 40e6, { note: "funding account" }) ); diff --git a/examples/asa/scripts/2-gold-asc.js b/examples/asa/scripts/2-gold-asc.js index bf2ecdd96..b81abbcf4 100644 --- a/examples/asa/scripts/2-gold-asc.js +++ b/examples/asa/scripts/2-gold-asc.js @@ -1,35 +1,41 @@ const { balanceOf, signTransactions } = require("@algo-builder/algob"); const { types, getSuggestedParams } = require("@algo-builder/web"); -const { mkParam } = require("./transfer/common"); +const { mkParam, tryExecuteTx } = require("./transfer/common"); const { makeAssetTransferTxnWithSuggestedParams } = require("algosdk"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const goldOwner = deployer.accountsByName.get("alice"); - await deployer.executeTx( + await tryExecuteTx( + deployer, mkParam(masterAccount, goldOwner.addr, 200e6, { note: "funding account" }) ); // save Smart Signature by name & fund the account - const ascInfoContract = await deployer.mkContractLsig( - "Gold_C_Lsig", - "2-gold-contract-asc.teal", - {} - ); + const ascInfoContract = await deployer + .mkContractLsig("Gold_C_Lsig", "2-gold-contract-asc.teal", {}) + .catch((error) => { + throw error; + }); console.log(ascInfoContract); - await deployer.fundLsig("Gold_C_Lsig", { funder: goldOwner, fundingMicroAlgo: 1e6 }, {}); // funding with 1 Algo + // funding with 1 Algo + await deployer + .fundLsig("Gold_C_Lsig", { funder: goldOwner, fundingMicroAlgo: 1e6 }, {}) + .catch((error) => { + throw error; + }); - const ascInfoAlgoDelegated = await deployer.mkDelegatedLsig( - "Gold_D_Lsig", - "3-gold-delegated-asc.teal", - goldOwner - ); - const ascInfoGoldDelegated = await deployer.mkDelegatedLsig( - "Gold_d_asa_lsig", - "4-gold-asa.teal", - goldOwner - ); + const ascInfoAlgoDelegated = await deployer + .mkDelegatedLsig("Gold_D_Lsig", "3-gold-delegated-asc.teal", goldOwner) + .catch((error) => { + throw error; + }); + const ascInfoGoldDelegated = await deployer + .mkDelegatedLsig("Gold_d_asa_lsig", "4-gold-asa.teal", goldOwner) + .catch((error) => { + throw error; + }); console.log(ascInfoAlgoDelegated); console.log(ascInfoGoldDelegated); @@ -38,7 +44,9 @@ async function run(runtimeEnv, deployer) { const lsig = await deployer.getLsig("Gold_C_Lsig"); const goldAsset = deployer.asa.get("gold"); const goldAssetID = goldAsset.assetIndex; - await deployer.optInLsigToASA(goldAssetID, lsig, { totalFee: 1000 }); + await deployer.optInLsigToASA(goldAssetID, lsig, { totalFee: 1000 }).catch((error) => { + throw error; + }); console.log("Balance: ", await balanceOf(deployer, lsig.address(), goldAssetID)); console.log(`Funding contract ${lsig.address()} with ASA gold`); @@ -57,7 +65,7 @@ async function run(runtimeEnv, deployer) { fromAccount: goldOwner, }; - await deployer.executeTx([{ transaction: tx, sign: sign }]); + await tryExecuteTx(deployer, [{ transaction: tx, sign: sign }]); await balanceOf(deployer, lsig.address(), goldAssetID); // To get raw signed transaction you may use `signTransactions` function diff --git a/examples/asa/scripts/3-contract-owned-asa.js b/examples/asa/scripts/3-contract-owned-asa.js index 1331c9951..b1d8347a0 100644 --- a/examples/asa/scripts/3-contract-owned-asa.js +++ b/examples/asa/scripts/3-contract-owned-asa.js @@ -7,44 +7,54 @@ * - Create contract account (with app_id embedded/passed as a template param) * - Deploy ASA using both contracts */ -const { mkParam } = require("./transfer/common"); +const { mkParam, tryExecuteTx } = require("./transfer/common"); const { types } = require("@algo-builder/web"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const alice = deployer.accountsByName.get("alice"); - await deployer.executeTx( + await tryExecuteTx( + deployer, mkParam(masterAccount, alice.addr, 200e6, { note: "funding account" }) ); // Create Application // Note: An Account can have maximum of 10 Applications. - const appInfo = await deployer.deployApp( - alice, - { - appName: "StatefulASA_App", - metaType: types.MetaType.FILE, - approvalProgramFilename: "5-contract-asa-stateful.py", // approval program - clearProgramFilename: "5-clear.py", // clear program - localInts: 1, - localBytes: 1, - globalInts: 1, - globalBytes: 1, - }, - {} - ); + const appInfo = await deployer + .deployApp( + alice, + { + appName: "StatefulASA_App", + metaType: types.MetaType.FILE, + approvalProgramFilename: "5-contract-asa-stateful.py", // approval program + clearProgramFilename: "5-clear.py", // clear program + localInts: 1, + localBytes: 1, + globalInts: 1, + globalBytes: 1, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(appInfo); // Get Statless Account Address - await deployer.mkContractLsig("StateLessASALsig", "5-contract-asa-stateless.py", { - APP_ID: appInfo.appID, - }); + await deployer + .mkContractLsig("StateLessASALsig", "5-contract-asa-stateless.py", { + APP_ID: appInfo.appID, + }) + .catch((error) => { + throw error; + }); const statelessAccount = deployer.getLsig("StateLessASALsig"); console.log("stateless Account Address:", statelessAccount.address()); - await deployer.executeTx( + await tryExecuteTx( + deployer, mkParam(masterAccount, statelessAccount.address(), 200e6, { note: "funding account" }) ); @@ -77,12 +87,12 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); // This should fail because maximum number of asa creation limit is set to 1 try { txGroup[1].asaName = "alu"; - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); } catch (e) { console.log(e.response?.error); } diff --git a/examples/asa/scripts/transfer/common.js b/examples/asa/scripts/transfer/common.js index 323f6bc53..d6f1031f6 100644 --- a/examples/asa/scripts/transfer/common.js +++ b/examples/asa/scripts/transfer/common.js @@ -2,9 +2,11 @@ const { types } = require("@algo-builder/web"); exports.tryExecuteTx = async function (deployer, txnParams) { try { - await deployer.executeTx(txnParams); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } }; diff --git a/examples/asa/scripts/transfer/contract-owned-asa/change-contract-owner.js b/examples/asa/scripts/transfer/contract-owned-asa/change-contract-owner.js index 20132e147..b49d55e5b 100644 --- a/examples/asa/scripts/transfer/contract-owned-asa/change-contract-owner.js +++ b/examples/asa/scripts/transfer/contract-owned-asa/change-contract-owner.js @@ -5,14 +5,14 @@ */ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); -const { mkParam } = require("../common"); +const { mkParam, tryExecuteTx } = require("../common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const alice = deployer.accountsByName.get("alice"); const bob = deployer.accountsByName.get("bob"); - await deployer.executeTx(mkParam(masterAccount, alice.addr, 5e6, { note: "Funding" })); + await tryExecuteTx(deployer, mkParam(masterAccount, alice.addr, 5e6, { note: "Funding" })); // Get AppInfo from checkpoint. const appInfo = deployer.getApp("StatefulASA_App"); @@ -31,7 +31,7 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(tx); + await tryExecuteTx(deployer, tx); } module.exports = { default: run }; diff --git a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js index 4d31dc9cd..54a846093 100644 --- a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js +++ b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js @@ -9,14 +9,14 @@ */ const { types } = require("@algo-builder/web"); const { balanceOf } = require("@algo-builder/algob"); -const { executeTx, mkParam } = require("../common"); +const { mkParam, tryExecuteTx } = require("../common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const alice = deployer.accountsByName.get("alice"); const bob = deployer.accountsByName.get("bob"); - await deployer.executeTx(mkParam(masterAccount, alice.addr, 5e6, { note: "Funding" })); + await tryExecuteTx(deployer, mkParam(masterAccount, alice.addr, 5e6, { note: "Funding" })); // Get AppInfo and AssetID from checkpoints. const appInfo = deployer.getApp("StatefulASA_App"); @@ -49,21 +49,22 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(txGroup); + await tryExecuteTx(txGroup); + // print assetHolding of alice console.log("Alice assetHolding balance: ", await balanceOf(deployer, alice.addr, assetID)); try { // tx FAIL: trying to receive asset from another account txGroup[0].fromAccount = bob; - await deployer.executeTx(txGroup); + await tryExecuteTx(txGroup); } catch (e) { console.error(e); } try { // tx FAIL: trying to send asset directly without calling stateful smart contract - await deployer.executeTx([ + await tryExecuteTx(deployer, [ { type: types.TransactionType.TransferAsset, sign: types.SignType.LogicSignature, diff --git a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js index ea261a773..e7abd065d 100644 --- a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js +++ b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js @@ -6,14 +6,14 @@ */ const { types } = require("@algo-builder/web"); const { balanceOf } = require("@algo-builder/algob"); -const { executeTx, mkParam } = require("../common"); +const { tryExecuteTx, mkParam } = require("../common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const alice = deployer.accountsByName.get("alice"); const bob = deployer.accountsByName.get("bob"); - await deployer.executeTx(mkParam(masterAccount, bob.addr, 5e6, { note: "Funding" })); + await tryExecuteTx(deployer, mkParam(masterAccount, bob.addr, 5e6, { note: "Funding" })); // Get AppInfo and AssetID from checkpoints. const appInfo = deployer.getApp("StatefulASA_App"); const lsig = deployer.getLsig("StateLessASALsig"); @@ -44,14 +44,14 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); // print assetHolding of alice console.log("Alice assetHolding balance: ", await balanceOf(deployer, alice.addr, assetID)); try { // tx FAIL: trying to receive asset from initial owner account txGroup[0].fromAccount = alice; - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); } catch (e) { console.error(e); } diff --git a/examples/asa/scripts/transfer/gold-contract-sc.js b/examples/asa/scripts/transfer/gold-contract-sc.js index f55f9b321..6d690399e 100644 --- a/examples/asa/scripts/transfer/gold-contract-sc.js +++ b/examples/asa/scripts/transfer/gold-contract-sc.js @@ -35,7 +35,11 @@ async function run(runtimeEnv, deployer) { // Transaction FAIL - Gets rejected by logic - As according to .teal logic, amount should be <= 100 const invalidParams = Object.assign({}, algoTxParam); invalidParams.amountMicroAlgos = 200; - await tryExecuteTx(deployer, invalidParams); + try { + await tryExecuteTx(deployer, invalidParams); + } catch (e) { + console.error(e); + } /* Transfer ASA 'gold' from contract account to user account */ const assetID = deployer.asa.get("gold").assetIndex; @@ -58,7 +62,11 @@ async function run(runtimeEnv, deployer) { // Transaction FAIL - Gets rejected by logic - As according to .teal logic, amount should be <= 100 const invalidTxParams = Object.assign({}, assetTxParam); invalidTxParams.amount = 500; - await tryExecuteTx(deployer, invalidTxParams); + try { + await tryExecuteTx(deployer, invalidTxParams); + } catch (e) { + console.error(e); + } } module.exports = { default: run }; diff --git a/examples/asa/scripts/transfer/gold-delegated-lsig.js b/examples/asa/scripts/transfer/gold-delegated-lsig.js index 41d6b1c95..b1c6c45c7 100644 --- a/examples/asa/scripts/transfer/gold-delegated-lsig.js +++ b/examples/asa/scripts/transfer/gold-delegated-lsig.js @@ -29,13 +29,21 @@ async function run(runtimeEnv, deployer) { // Transaction FAIL - rejected by lsig because amount is not <= 1000 txnParam.amount = 1500; - await tryExecuteTx(deployer, txnParam); + try { + await tryExecuteTx(deployer, txnParam); + } catch (e) { + console.error(e); + } // Transaction FAIL - rejected by lsig because sender must be the delegator i.e // account which signed the lsig (goldOwner in this case) txnParam.amount = 100; txnParam.fromAccountAddr = bob.addr; - await tryExecuteTx(deployer, txnParam); + try { + await tryExecuteTx(deployer, txnParam); + } catch (e) { + console.error(e); + } // Transaction for ALGO - Contract : '3-gold-delegated-asc.teal' (Delegated Approval Mode) const logicSignature = deployer.getLsig("Gold_D_Lsig"); @@ -54,7 +62,11 @@ async function run(runtimeEnv, deployer) { // Transaction FAIL - rejected by lsig because amount is not <= 100 txnParam.amountMicroAlgos = 580; - await tryExecuteTx(deployer, txnParam); + try { + await tryExecuteTx(deployer, txnParam); + } catch (e) { + console.error(e); + } } module.exports = { default: run }; diff --git a/examples/asa/scripts/transfer/gold-to-john.js b/examples/asa/scripts/transfer/gold-to-john.js index 334b0dc72..68385e2c2 100644 --- a/examples/asa/scripts/transfer/gold-to-john.js +++ b/examples/asa/scripts/transfer/gold-to-john.js @@ -5,6 +5,7 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common"); async function run(runtimeEnv, deployer) { // query gold ASA from deployer (using checkpoint information), @@ -19,7 +20,7 @@ async function run(runtimeEnv, deployer) { const goldOwner = deployer.accountsByName.get("alice"); // execute asset transfer transaction - await deployer.executeTx([ + await tryExecuteTx(deployer, [ { type: types.TransactionType.TransferAsset, sign: types.SignType.SecretKey, diff --git a/examples/asa/scripts/transfer/master-fund-john.js b/examples/asa/scripts/transfer/master-fund-john.js index dd1c5783c..bd98a5f2c 100644 --- a/examples/asa/scripts/transfer/master-fund-john.js +++ b/examples/asa/scripts/transfer/master-fund-john.js @@ -1,11 +1,11 @@ -const { mkParam } = require("./common"); +const { mkParam, tryExecuteTx } = require("./common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const john = deployer.accountsByName.get("john"); // fund John account with 1 Algo - await deployer.executeTx(mkParam(masterAccount, john.addr, 1e6, { note: "ALGO PAID" })); + await tryExecuteTx(deployer, mkParam(masterAccount, john.addr, 1e6, { note: "ALGO PAID" })); } module.exports = { default: run }; diff --git a/examples/asa/scripts/transfer/tesla-to-john.js b/examples/asa/scripts/transfer/tesla-to-john.js index 47e047c91..2f12d4de2 100644 --- a/examples/asa/scripts/transfer/tesla-to-john.js +++ b/examples/asa/scripts/transfer/tesla-to-john.js @@ -1,5 +1,6 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common"); async function run(runtimeEnv, deployer) { const teslaAssetID = deployer.asa.get("tesla").assetIndex; @@ -7,7 +8,7 @@ async function run(runtimeEnv, deployer) { const john = deployer.accountsByName.get("john"); const elon = deployer.accountsByName.get("elon-musk"); - await deployer.executeTx([ + await tryExecuteTx(deployer, [ { type: types.TransactionType.TransferAsset, sign: types.SignType.SecretKey, diff --git a/examples/bond/scripts/deploy.js b/examples/bond/scripts/deploy.js index f8bbfc093..6af7e9a9c 100644 --- a/examples/bond/scripts/deploy.js +++ b/examples/bond/scripts/deploy.js @@ -1,6 +1,6 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); -const { optInTx } = require("./run/common/common.js"); +const { optInTx, tryExecuteTx } = require("./run/common/common.js"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -12,17 +12,21 @@ async function run(runtimeEnv, deployer) { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, - toAccountAddr: managerAcc.addr, + toAccountAddr: managerAcc, amountMicroAlgos: 10e6, payFlags: {}, }, ]; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); algoTxnParams[0].toAccountAddr = creatorAccount.addr; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); // Create B_0 - Bond Token - const asaInfo = await deployer.deployASA("bond-token-0", { creator: creatorAccount }); + const asaInfo = await deployer + .deployASA("bond-token-0", { creator: creatorAccount }) + .catch((error) => { + throw error; + }); console.log(asaInfo); // Bond-Dapp initialization parameters @@ -30,7 +34,9 @@ async function run(runtimeEnv, deployer) { const issuePrice = "int:1000"; const couponValue = "int:20"; const currentBond = convert.uint64ToBigEndian(asaInfo.assetIndex); - const asset = await deployer.getAssetByID(asaInfo.assetIndex); + const asset = await deployer.getAssetByID(asaInfo.assetIndex).catch((error) => { + throw error; + }); const maxIssuance = convert.uint64ToBigEndian(asset.params.total); const creator = convert.addressToPk(creatorAccount.addr); @@ -40,22 +46,26 @@ async function run(runtimeEnv, deployer) { TMPL_MATURITY_DATE: Math.round(new Date().getTime() / 1000) + 240, }; // Create Application - const bondAppInfo = await deployer.deployApp( - managerAcc, - { - appName: "BondApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "bond-dapp-stateful.py", - clearProgramFilename: "bond-dapp-clear.py", - localInts: 1, - localBytes: 1, - globalInts: 8, - globalBytes: 15, - appArgs: appArgs, - }, - {}, - placeholderParam - ); + const bondAppInfo = await deployer + .deployApp( + managerAcc, + { + appName: "BondApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "bond-dapp-stateful.py", + clearProgramFilename: "bond-dapp-clear.py", + localInts: 1, + localBytes: 1, + globalInts: 8, + globalBytes: 15, + appArgs: appArgs, + }, + {}, + placeholderParam + ) + .catch((error) => { + throw error; + }); console.log(bondAppInfo); // Initialize issuer lsig with bond-app ID @@ -65,11 +75,13 @@ async function run(runtimeEnv, deployer) { TMPL_APP_MANAGER: managerAcc.addr, }; - await deployer.mkContractLsig("IssuerLsig", "issuer-lsig.py", scInitParam); + await deployer.mkContractLsig("IssuerLsig", "issuer-lsig.py", scInitParam).catch((error) => { + throw error; + }); const issuerLsig = deployer.getLsig("IssuerLsig"); algoTxnParams[0].toAccountAddr = issuerLsig.address(); - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); // Only app manager can opt-in issueer lsig to ASA await optInTx(deployer, managerAcc, issuerLsig, asaInfo.assetIndex); @@ -87,7 +99,7 @@ async function run(runtimeEnv, deployer) { appArgs: appArgs, }, ]; - await deployer.executeTx(appCallParams); + await tryExecuteTx(deployer, appCallParams); console.log("Issuer address updated!"); } diff --git a/examples/bond/scripts/run/common/common.js b/examples/bond/scripts/run/common/common.js index c4981bb2a..98dc6c129 100644 --- a/examples/bond/scripts/run/common/common.js +++ b/examples/bond/scripts/run/common/common.js @@ -21,6 +21,16 @@ const asaDef = { const tokenMap = new Map(); +async function tryExecuteTx(deployer, txnParams) { + try { + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +} + /** * returns asset id for a given asset name * @param name asset name @@ -41,7 +51,7 @@ async function fundAccount(deployer, accountAddress) { amountMicroAlgos: 200e6, payFlags: {}, }; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); } /** @@ -72,7 +82,7 @@ async function optInTx(deployer, managerAcc, lsig, assetIndex) { payFlags: {}, }, ]; - await deployer.executeTx(optInTx); + await tryExecuteTx(deployer, optInTx); } /** @@ -336,4 +346,5 @@ module.exports = { redeemCouponTx, buyTxNode, buyTxRuntime, + tryExecuteTx, }; diff --git a/examples/bond/scripts/run/createBuyback.js b/examples/bond/scripts/run/createBuyback.js index 36275f822..33a483833 100644 --- a/examples/bond/scripts/run/createBuyback.js +++ b/examples/bond/scripts/run/createBuyback.js @@ -1,6 +1,6 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); -const { tokenMap, optInTx, fundAccount } = require("./common/common"); +const { tokenMap, optInTx, fundAccount, tryExecuteTx } = require("./common/common"); /** * This function creates buyback lsig and store it's address in bond-dapp(stateful contract) @@ -17,7 +17,11 @@ exports.createBuyback = async function (deployer, managerAcc, n) { TMPL_APP_MANAGER: managerAcc.addr, TMPL_BOND: bondToken, }; - const buybackLsig = await deployer.loadLogicByFile("buyback-lsig.py", scInitParam); + const buybackLsig = await deployer + .loadLogicByFile("buyback-lsig.py", scInitParam) + .catch((error) => { + throw error; + }); await fundAccount(deployer, buybackLsig.address()); const buybackTx = [ @@ -35,6 +39,6 @@ exports.createBuyback = async function (deployer, managerAcc, n) { await optInTx(deployer, managerAcc, buybackLsig, bondToken); console.log("Setting buyback address!"); - await deployer.executeTx(buybackTx); + await tryExecuteTx(deployer, buybackTx); console.log("Buyback address set successfully!"); }; diff --git a/examples/bond/scripts/run/createDex.js b/examples/bond/scripts/run/createDex.js index 9929763f8..a0b467daf 100644 --- a/examples/bond/scripts/run/createDex.js +++ b/examples/bond/scripts/run/createDex.js @@ -6,6 +6,7 @@ const { optInTx, couponValue, createDexTx, + tryExecuteTx, } = require("./common/common.js"); const { types } = require("@algo-builder/web"); @@ -39,7 +40,7 @@ exports.createDex = async function (deployer, creatorAccount, managerAcc, i) { }, ]; // Create B_[i+1] - const newAsaInfo = (await deployer.executeTx(deployTx))[0]; + const newAsaInfo = (await tryExecuteTx(deployer, deployTx))[0]; console.log(newAsaInfo); const newIndex = newAsaInfo["asset-index"]; tokenMap.set(newBondToken, newIndex); @@ -54,14 +55,20 @@ exports.createDex = async function (deployer, creatorAccount, managerAcc, i) { TMPL_APPLICATION_ID: appInfo.appID, TMPL_APP_MANAGER: managerAcc.addr, }; - const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", lsigParams); + const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", lsigParams).catch((error) => { + throw error; + }); await fundAccount(deployer, dexLsig.address()); await optInTx(deployer, managerAcc, dexLsig, newIndex); await optInTx(deployer, managerAcc, dexLsig, oldBond); - const globalState = await readAppGlobalState(deployer, managerAcc.addr, appInfo.appID); + const globalState = await readAppGlobalState(deployer, managerAcc.addr, appInfo.appID).catch( + (error) => { + throw error; + } + ); const total = globalState.get("total") ?? 0; console.log("Total issued: ", total); @@ -82,7 +89,7 @@ exports.createDex = async function (deployer, creatorAccount, managerAcc, i) { ); console.log(`* Creating dex ${i}! *`); - await deployer.executeTx(groupTx); + await tryExecuteTx(deployer, groupTx); console.log("Dex created!"); return newIndex; }; diff --git a/examples/bond/scripts/run/epoch0.js b/examples/bond/scripts/run/epoch0.js index 54aea92fe..009733335 100644 --- a/examples/bond/scripts/run/epoch0.js +++ b/examples/bond/scripts/run/epoch0.js @@ -1,6 +1,6 @@ const { types } = require("@algo-builder/web"); const { accounts } = require("./common/accounts.js"); -const { issuePrice, buyTxNode } = require("./common/common.js"); +const { issuePrice, buyTxNode, tryExecuteTx } = require("./common/common.js"); /** * In this function: Elon buys 10 bonds and @@ -12,8 +12,16 @@ exports.epoch0 = async function (deployer) { const appInfo = deployer.getApp("BondApp"); const issuerLsig = deployer.getLsig("IssuerLsig"); const asaInfo = deployer.getASAInfo("bond-token-0"); - await deployer.optInAccountToASA(asaInfo.assetIndex, "bob", { totalFee: 1000 }); - await deployer.optInAccountToASA(asaInfo.assetIndex, "elon-musk", { totalFee: 1000 }); + await deployer + .optInAccountToASA(asaInfo.assetIndex, "bob", { totalFee: 1000 }) + .catch((error) => { + throw error; + }); + await deployer + .optInAccountToASA(asaInfo.assetIndex, "elon-musk", { totalFee: 1000 }) + .catch((error) => { + throw error; + }); // elon buys 10 bonds const algoAmount = 10 * issuePrice; @@ -28,7 +36,7 @@ exports.epoch0 = async function (deployer) { ); console.log("Elon buying 10 bonds!"); - await deployer.executeTx(groupTx); + await tryExecuteTx(deployer, groupTx); console.log("Elon bought 10 bonds!"); // elon sells 2 bonds to bob for 2020 Algo @@ -51,6 +59,6 @@ exports.epoch0 = async function (deployer) { payFlags: { totalFee: 1000 }, }, ]; - await deployer.executeTx(sellTx); + await tryExecuteTx(deployer, sellTx); console.log("2 bonds sold to bob from elon!"); }; diff --git a/examples/bond/scripts/run/epoch1.js b/examples/bond/scripts/run/epoch1.js index 40a32022d..13300ec1d 100644 --- a/examples/bond/scripts/run/epoch1.js +++ b/examples/bond/scripts/run/epoch1.js @@ -1,5 +1,5 @@ const { accounts } = require("./common/accounts.js"); -const { issuePrice, tokenMap, buyTxNode } = require("./common/common.js"); +const { issuePrice, tokenMap, buyTxNode, tryExecuteTx } = require("./common/common.js"); const { redeem } = require("./redeem.js"); /** @@ -17,8 +17,14 @@ exports.epoch1 = async function (deployer) { const appInfo = deployer.getApp("BondApp"); const issuerLsig = deployer.getLsig("IssuerLsig"); const bondToken = tokenMap.get("bond-token-1"); - await deployer.optInAccountToASA(bondToken, "bob", { totalFee: 1000 }); - await deployer.optInAccountToASA(bondToken, "elon-musk", { totalFee: 1000 }); + await deployer.optInAccountToASA(bondToken, "bob", { totalFee: 1000 }).catch((error) => { + throw error; + }); + await deployer + .optInAccountToASA(bondToken, "elon-musk", { totalFee: 1000 }) + .catch((error) => { + throw error; + }); // elon buys 4 bonds const algoAmount = 4 * issuePrice; @@ -33,6 +39,6 @@ exports.epoch1 = async function (deployer) { ); console.log("Elon buying 4 more bonds!"); - await deployer.executeTx(groupTx); + await tryExecuteTx(deployer, groupTx); console.log("Elon bought 4 more bonds!"); }; diff --git a/examples/bond/scripts/run/exit.js b/examples/bond/scripts/run/exit.js index 1988f9ce9..7788c9af8 100644 --- a/examples/bond/scripts/run/exit.js +++ b/examples/bond/scripts/run/exit.js @@ -1,5 +1,5 @@ const { types } = require("@algo-builder/web"); -const { tokenMap, nominalPrice } = require("./common/common"); +const { tokenMap, nominalPrice, tryExecuteTx } = require("./common/common"); /** * In this function buyer exits from all their bonds in exchange of algos @@ -17,7 +17,11 @@ exports.exitBuyer = async function (deployer, managerAcc, buyerAccount, n, amoun TMPL_APP_MANAGER: managerAcc.addr, TMPL_BOND: bondToken, }; - const buybackLsig = await deployer.loadLogicByFile("buyback-lsig.py", scInitParam); + const buybackLsig = await deployer + .loadLogicByFile("buyback-lsig.py", scInitParam) + .catch((error) => { + throw error; + }); const exitAmount = Number(amount) * Number(nominalPrice); const exitTx = [ // Bond token transfer to buyback address @@ -52,10 +56,6 @@ exports.exitBuyer = async function (deployer, managerAcc, buyerAccount, n, amoun ]; console.log("Exiting"); - try { - await deployer.executeTx(exitTx); - } catch (error) { - console.log(error.response?.error); - } + await tryExecuteTx(deployer, exitTx); console.log("Exited"); }; diff --git a/examples/bond/scripts/run/issue.js b/examples/bond/scripts/run/issue.js index b02d7d7ae..4aeeef5ed 100644 --- a/examples/bond/scripts/run/issue.js +++ b/examples/bond/scripts/run/issue.js @@ -1,4 +1,4 @@ -const { issueTx } = require("./common/common"); +const { issueTx, tryExecuteTx } = require("./common/common"); /** * In this function tokens are issued to issuer from token creator. * @param deployer deployer @@ -11,6 +11,6 @@ exports.issue = async function (deployer) { const groupTx = issueTx(creatorAccount, issuerLsig, appInfo.appID, asaInfo.assetIndex); console.log("Issuing tokens!"); - await deployer.executeTx(groupTx); + await tryExecuteTx(deployer, groupTx); console.log("Tokens issued to issuer"); }; diff --git a/examples/bond/scripts/run/redeem.js b/examples/bond/scripts/run/redeem.js index 1cfd53519..ba0aef6c7 100644 --- a/examples/bond/scripts/run/redeem.js +++ b/examples/bond/scripts/run/redeem.js @@ -1,4 +1,4 @@ -const { tokenMap, couponValue, redeemCouponTx } = require("./common/common.js"); +const { tokenMap, couponValue, redeemCouponTx, tryExecuteTx } = require("./common/common.js"); /** * Redeem old tokens, get coupon_value + new bond tokens @@ -19,8 +19,12 @@ exports.redeem = async function (deployer, buyerAccount, managerAcc, dex, amount TMPL_APPLICATION_ID: appInfo.appID, TMPL_APP_MANAGER: managerAcc.addr, }; - const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", scInitParam); - await deployer.optInAccountToASA(newBond, buyerAccount.name, {}); + const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", scInitParam).catch((error) => { + throw error; + }); + await deployer.optInAccountToASA(newBond, buyerAccount.name, {}).catch((error) => { + throw error; + }); const groupTx = redeemCouponTx( buyerAccount, dexLsig, @@ -32,6 +36,6 @@ exports.redeem = async function (deployer, buyerAccount, managerAcc, dex, amount ); console.log(`* Redeeming ${amount} tokens for ${buyerAccount.name} from Dex: ${dex}!`); - await deployer.executeTx(groupTx); + await tryExecuteTx(deployer, groupTx); console.log("Tokens redeemed!"); }; diff --git a/examples/crowdfunding/scripts/common/common.js b/examples/crowdfunding/scripts/common/common.js new file mode 100644 index 000000000..3596e26c1 --- /dev/null +++ b/examples/crowdfunding/scripts/common/common.js @@ -0,0 +1,13 @@ +async function tryExecuteTx(deployer, txnParams) { + try { + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +} + +module.exports = { + tryExecuteTx, +}; diff --git a/examples/crowdfunding/scripts/createApp.js b/examples/crowdfunding/scripts/createApp.js index bb628baa9..abb89cbd9 100644 --- a/examples/crowdfunding/scripts/createApp.js +++ b/examples/crowdfunding/scripts/createApp.js @@ -1,5 +1,6 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -14,9 +15,9 @@ async function run(runtimeEnv, deployer) { amountMicroAlgos: 200000000, payFlags: {}, }; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); algoTxnParams.toAccountAddr = donorAccount.addr; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); // Get begin date to pass in const beginDate = Math.round(new Date().getTime() / 1000); @@ -36,26 +37,34 @@ async function run(runtimeEnv, deployer) { // Create Application // Note: An Account can have maximum of 10 Applications. - const appInfo = await deployer.deployApp( - creatorAccount, - { - appName: "CrowdfundingApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "crowdFundApproval.teal", // approval program - clearProgramFilename: "crowdFundClear.teal", // clear program - localInts: 1, - localBytes: 0, - globalInts: 5, - globalBytes: 3, - appArgs: appArgs, - }, - {} - ); + const appInfo = await deployer + .deployApp( + creatorAccount, + { + appName: "CrowdfundingApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "crowdFundApproval.teal", // approval program + clearProgramFilename: "crowdFundClear.teal", // clear program + localInts: 1, + localBytes: 0, + globalInts: 5, + globalBytes: 3, + appArgs: appArgs, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(appInfo); // save lsig in checkpoint - await deployer.mkContractLsig("escrow", "crowdFundEscrow.py", { APP_ID: appInfo.appID }); + await deployer + .mkContractLsig("escrow", "crowdFundEscrow.py", { APP_ID: appInfo.appID }) + .catch((error) => { + throw error; + }); // Get Escrow Account Address const escrowAccount = await deployer.getLsig("escrow"); @@ -68,18 +77,22 @@ async function run(runtimeEnv, deployer) { appArgs = [convert.addressToPk(escrowAccount.address())]; - const updatedRes = await deployer.updateApp( - "CrowdfundingApp", - creatorAccount, - {}, // pay flags - applicationID, - { - metaType: types.MetaType.FILE, - approvalProgramFilename: "crowdFundApproval.teal", - clearProgramFilename: "crowdFundClear.teal", - }, - { appArgs: appArgs } - ); + const updatedRes = await deployer + .updateApp( + "CrowdfundingApp", + creatorAccount, + {}, // pay flags + applicationID, + { + metaType: types.MetaType.FILE, + approvalProgramFilename: "crowdFundApproval.teal", + clearProgramFilename: "crowdFundClear.teal", + }, + { appArgs: appArgs } + ) + .catch((error) => { + throw error; + }); console.log("Application Updated: ", updatedRes); console.log("Opting-In for Creator and Donor."); diff --git a/examples/crowdfunding/scripts/transfer/claim.js b/examples/crowdfunding/scripts/transfer/claim.js index 02ea52009..f8e3ad456 100644 --- a/examples/crowdfunding/scripts/transfer/claim.js +++ b/examples/crowdfunding/scripts/transfer/claim.js @@ -1,11 +1,12 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const creatorAccount = deployer.accountsByName.get("alice"); - await deployer.executeTx({ + await tryExecuteTx(deployer, { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, @@ -40,7 +41,7 @@ async function run(runtimeEnv, deployer) { ]; console.log("Claim transaction in process"); - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); console.log("Claimed!"); } diff --git a/examples/crowdfunding/scripts/transfer/delete.js b/examples/crowdfunding/scripts/transfer/delete.js index d2bf70b6e..f49d008f7 100644 --- a/examples/crowdfunding/scripts/transfer/delete.js +++ b/examples/crowdfunding/scripts/transfer/delete.js @@ -1,10 +1,11 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const creatorAccount = deployer.accountsByName.get("alice"); - await deployer.executeTx({ + await tryExecuteTx(deployer, { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, @@ -40,7 +41,7 @@ async function run(runtimeEnv, deployer) { ]; console.log("Deleting Application transaction in process"); - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); console.log("Application Deleted and Fund transferred to creator account"); } diff --git a/examples/crowdfunding/scripts/transfer/donate.js b/examples/crowdfunding/scripts/transfer/donate.js index ec69fd551..af2dad733 100644 --- a/examples/crowdfunding/scripts/transfer/donate.js +++ b/examples/crowdfunding/scripts/transfer/donate.js @@ -1,11 +1,12 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const donorAccount = deployer.accountsByName.get("john"); - await deployer.executeTx({ + await tryExecuteTx(deployer, { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, @@ -44,7 +45,7 @@ async function run(runtimeEnv, deployer) { ]; console.log("Donation transaction in process"); - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); console.log("Donated!"); } diff --git a/examples/crowdfunding/scripts/transfer/reclaim.js b/examples/crowdfunding/scripts/transfer/reclaim.js index 35e1810fb..56aa8f6c0 100644 --- a/examples/crowdfunding/scripts/transfer/reclaim.js +++ b/examples/crowdfunding/scripts/transfer/reclaim.js @@ -1,11 +1,12 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); const donorAccount = deployer.accountsByName.get("john"); - await deployer.executeTx({ + await tryExecuteTx(deployer, { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, @@ -46,7 +47,7 @@ async function run(runtimeEnv, deployer) { ]; console.log("Reclaim transaction in process"); - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); console.log("Reclaimed by ", donorAccount.addr); } diff --git a/examples/dao/scripts/deploy.js b/examples/dao/scripts/deploy.js index f96b11de2..f11b999ee 100644 --- a/examples/dao/scripts/deploy.js +++ b/examples/dao/scripts/deploy.js @@ -11,7 +11,11 @@ async function run(runtimeEnv, deployer) { await fundAccount(deployer, [creator, proposer, voterA, voterB]); // Create DAO Gov Token - const govToken = await deployer.deployASA("gov-token", { creator: creator }); + const govToken = await deployer + .deployASA("gov-token", { creator: creator }) + .catch((error) => { + throw error; + }); console.log(govToken); // DAO App initialization parameters @@ -32,22 +36,26 @@ async function run(runtimeEnv, deployer) { `int:${govToken.assetIndex}`, ]; // Create Application - const daoAppInfo = await deployer.deployApp( - creator, - { - appName: "DAOApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "dao-app-approval.py", - clearProgramFilename: "dao-app-clear.py", - localInts: 9, - localBytes: 7, - globalInts: 5, - globalBytes: 2, - appArgs: appArgs, - foreignAssets: [govToken.assetIndex], - }, - {} - ); + const daoAppInfo = await deployer + .deployApp( + creator, + { + appName: "DAOApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "dao-app-approval.py", + clearProgramFilename: "dao-app-clear.py", + localInts: 9, + localBytes: 7, + globalInts: 5, + globalBytes: 2, + appArgs: appArgs, + foreignAssets: [govToken.assetIndex], + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(daoAppInfo); // Fund application account with some ALGO(5) @@ -76,15 +84,23 @@ async function run(runtimeEnv, deployer) { await tryExecuteTx(deployer, optInToGovASAParam); // save lsig's (by name in checkpoint) - await deployer.mkContractLsig("daoFundLsig", "dao-fund-lsig.py", { - ARG_GOV_TOKEN: govToken.assetIndex, - ARG_DAO_APP_ID: daoAppInfo.appID, - }); - - await deployer.mkContractLsig("proposalLsig", "proposal-lsig.py", { - ARG_OWNER: proposer.addr, - ARG_DAO_APP_ID: daoAppInfo.appID, - }); + await deployer + .mkContractLsig("daoFundLsig", "dao-fund-lsig.py", { + ARG_GOV_TOKEN: govToken.assetIndex, + ARG_DAO_APP_ID: daoAppInfo.appID, + }) + .catch((error) => { + throw error; + }); + + await deployer + .mkContractLsig("proposalLsig", "proposal-lsig.py", { + ARG_OWNER: proposer.addr, + ARG_DAO_APP_ID: daoAppInfo.appID, + }) + .catch((error) => { + throw error; + }); // fund lsig's await Promise.all([ @@ -108,7 +124,9 @@ async function run(runtimeEnv, deployer) { deployer.optInAccountToASA(govToken.assetIndex, proposer.name, {}), deployer.optInAccountToASA(govToken.assetIndex, voterA.name, {}), deployer.optInAccountToASA(govToken.assetIndex, voterB.name, {}), - ]); + ]).catch((error) => { + throw error; + }); const distributeGovTokenParams = { type: types.TransactionType.TransferAsset, diff --git a/examples/dao/scripts/run/add_proposal.js b/examples/dao/scripts/run/add_proposal.js index f35159aba..2ed8789df 100644 --- a/examples/dao/scripts/run/add_proposal.js +++ b/examples/dao/scripts/run/add_proposal.js @@ -29,7 +29,7 @@ async function addProposal(runtimeEnv, deployer) { ); // Transaction FAIL (asset_transfer amount is less than min_deposit) - await tryExecuteTx(deployer, addProposalTx); + await tryExecuteTx(deployer, addProposalTx).catch((error) => console.log(error)); // Transaction PASS addProposalTx[1].amount = 15; // deposit is set as 15 in DAO App diff --git a/examples/dao/scripts/run/close_proposal.js b/examples/dao/scripts/run/close_proposal.js index 2b70fcb1b..54b4eacf5 100644 --- a/examples/dao/scripts/run/close_proposal.js +++ b/examples/dao/scripts/run/close_proposal.js @@ -45,7 +45,7 @@ async function run(runtimeEnv, deployer) { await tryExecuteTx(deployer, optInTx); // Transaction will FAIL: deposit amount is not the same as app.global("deposit") - await closeProposal(deployer, proposalLsig, 7); + await closeProposal(deployer, proposalLsig, 7).catch((error) => console.log(error)); // Transaction will SUCCEED await closeProposal(deployer, proposalLsig, 15); diff --git a/examples/dao/scripts/run/common/common.js b/examples/dao/scripts/run/common/common.js index 2f9bb1764..166d91e34 100644 --- a/examples/dao/scripts/run/common/common.js +++ b/examples/dao/scripts/run/common/common.js @@ -6,6 +6,7 @@ async function tryExecuteTx(deployer, txnParams) { return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.body : e); + throw e; } } @@ -32,11 +33,7 @@ async function fundAccount(deployer, accounts) { }); } - try { - await deployer.executeTx(params); - } catch (e) { - console.error("Transaction Failed", e.response ? e.response.error.text : e); - } + await tryExecuteTx(deployer, params); } const ProposalType = { diff --git a/examples/dao/scripts/run/withdraw_from_proposal.js b/examples/dao/scripts/run/withdraw_from_proposal.js index 417908f0a..6bebd1b9e 100644 --- a/examples/dao/scripts/run/withdraw_from_proposal.js +++ b/examples/dao/scripts/run/withdraw_from_proposal.js @@ -16,7 +16,9 @@ async function withdrawFromProposal(deployer, proposalLsig, proposer, voterA) { console.log( `* Withdrawing from proposalLsig ${proposalLsig.address()} to non-owner account *` ); //Should fail - await tryExecuteTx(deployer, withdrawTxFail); + await tryExecuteTx(deployer, withdrawTxFail).catch((error) => { + console.log(error); + }); } async function run(runtimeEnv, deployer) { diff --git a/examples/dao/scripts/run/withdraw_vote_deposit.js b/examples/dao/scripts/run/withdraw_vote_deposit.js index ba23832a9..9154d4023 100644 --- a/examples/dao/scripts/run/withdraw_vote_deposit.js +++ b/examples/dao/scripts/run/withdraw_vote_deposit.js @@ -24,7 +24,9 @@ async function run(runtimeEnv, deployer) { await withdrawVoteDeposit(deployer, voterB, 8); // Transaction FAIL: withdrawing votes again would result in negative no. - await withdrawVoteDeposit(deployer, voterA, 6); + await withdrawVoteDeposit(deployer, voterA, 6).catch((error) => { + console.log(error); + }); } module.exports = { default: run }; diff --git a/examples/htlc-pyteal-ts/scripts/deploy.ts b/examples/htlc-pyteal-ts/scripts/deploy.ts index 263323cda..eedd06001 100644 --- a/examples/htlc-pyteal-ts/scripts/deploy.ts +++ b/examples/htlc-pyteal-ts/scripts/deploy.ts @@ -5,7 +5,7 @@ import * as algob from "@algo-builder/algob"; import { types as rtypes } from "@algo-builder/web"; -import { getDeployerAccount, prepareParameters } from "./withdraw/common"; +import { getDeployerAccount, prepareParameters, tryExecuteTx } from "./withdraw/common"; async function run( runtimeEnv: algob.types.RuntimeEnv, @@ -27,15 +27,17 @@ async function run( const aliceFunding = Object.assign({}, bobFunding); aliceFunding.toAccountAddr = alice.addr; aliceFunding.amountMicroAlgos = 0.1e6; // 0.1 Algo - await Promise.all([deployer.executeTx([bobFunding]), deployer.executeTx([aliceFunding])]); + await Promise.all([tryExecuteTx(deployer, [bobFunding]), tryExecuteTx(deployer, [aliceFunding])]); /** ** now bob creates and deploys the escrow account ****/ console.log("hash of the secret:", scTmplParams.hash_image); // hash: QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc= - await deployer.mkContractLsig("HTLC_Lsig", "htlc.py", scTmplParams); + await deployer.mkContractLsig("HTLC_Lsig", "htlc.py", scTmplParams).catch((error) => { + throw error; + }); - await deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 2e6 }, {}); + deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 2e6 }, {}) // Add user checkpoint deployer.addCheckpointKV("User Checkpoint", "Fund Contract Account"); diff --git a/examples/htlc-pyteal-ts/scripts/withdraw/common.ts b/examples/htlc-pyteal-ts/scripts/withdraw/common.ts index 51e6cd921..91ff7829e 100644 --- a/examples/htlc-pyteal-ts/scripts/withdraw/common.ts +++ b/examples/htlc-pyteal-ts/scripts/withdraw/common.ts @@ -3,6 +3,20 @@ import { types as rtypes } from "@algo-builder/runtime"; import { BuilderError, types as wtypes } from "@algo-builder/web"; import { sha256 } from "js-sha256"; +export async function tryExecuteTx(deployer: algob.types.Deployer, txnParams: wtypes.ExecParams[]) { + try { + await deployer.executeTx(txnParams); + } 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 + } +} + /** * Returns account from algob config (by name) * @param deployer Deployer @@ -19,23 +33,6 @@ export function getDeployerAccount( return account; } -export async function withdrawExecuteTx( - deployer: algob.types.Deployer, - txnParams: wtypes.ExecParams -): Promise { - try { - await deployer.executeTx([txnParams]); - } 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 - } -} - /** * Prepares parameters for htlc run and deploy tasks * - alice account diff --git a/examples/htlc-pyteal-ts/scripts/withdraw/htlc-withdraw.ts b/examples/htlc-pyteal-ts/scripts/withdraw/htlc-withdraw.ts index c25836063..f3738b6e0 100644 --- a/examples/htlc-pyteal-ts/scripts/withdraw/htlc-withdraw.ts +++ b/examples/htlc-pyteal-ts/scripts/withdraw/htlc-withdraw.ts @@ -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, tryExecuteTx } from "./common"; async function run( runtimeEnv: algob.types.RuntimeEnv, @@ -36,18 +36,14 @@ async function run( }; // Transaction Fails : as wrong secret value is used - await withdrawExecuteTx(deployer, txnParams) + await tryExecuteTx(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) - .catch(error => { - throw error - }) - + await tryExecuteTx(deployer, [txnParams]) } module.exports = { default: run }; diff --git a/examples/inner-tx-create-assets/scripts/common/common.js b/examples/inner-tx-create-assets/scripts/common/common.js new file mode 100644 index 000000000..3596e26c1 --- /dev/null +++ b/examples/inner-tx-create-assets/scripts/common/common.js @@ -0,0 +1,13 @@ +async function tryExecuteTx(deployer, txnParams) { + try { + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +} + +module.exports = { + tryExecuteTx, +}; diff --git a/examples/inner-tx-create-assets/scripts/deploy.js b/examples/inner-tx-create-assets/scripts/deploy.js index 2ce6324a7..34701d607 100644 --- a/examples/inner-tx-create-assets/scripts/deploy.js +++ b/examples/inner-tx-create-assets/scripts/deploy.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common/common"); const { accounts } = require("./utils"); const min_balance = 3000000; @@ -8,20 +9,24 @@ async function run(runtimeEnv, deployer) { const { creator } = accounts(deployer); // Create Application - const appInfo = await deployer.deployApp( - creator, - { - appName: "coordinator", - metaType: types.MetaType.FILE, - approvalProgramFilename: "coordinator.py", - clearProgramFilename: "clear.teal", - localInts: 0, - localBytes: 0, - globalInts: 0, - globalBytes: 0, - }, - {} - ); + const appInfo = await deployer + .deployApp( + creator, + { + appName: "coordinator", + metaType: types.MetaType.FILE, + approvalProgramFilename: "coordinator.py", + clearProgramFilename: "clear.teal", + localInts: 0, + localBytes: 0, + globalInts: 0, + globalBytes: 0, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(appInfo); console.log("Contracts deployed successfully!"); @@ -35,7 +40,7 @@ async function run(runtimeEnv, deployer) { amountMicroAlgos: min_balance, payFlags: {}, }; - await deployer.executeTx(paymentTxnParam); + await tryExecuteTx(deployer, [paymentTxnParam]); } module.exports = { default: run }; diff --git a/examples/inner-tx-create-assets/scripts/run/useGroupTxn.js b/examples/inner-tx-create-assets/scripts/run/useGroupTxn.js index aa3ef60b1..04adda534 100644 --- a/examples/inner-tx-create-assets/scripts/run/useGroupTxn.js +++ b/examples/inner-tx-create-assets/scripts/run/useGroupTxn.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); const { accounts, decodeValue } = require("../utils"); // Deploy new application @@ -53,7 +54,7 @@ async function run(runtimeEnv, deployer) { }, }; - const receiptsTx = await deployer.executeTx([ + const receiptsTx = await tryExecuteTx(deployer, [ createAppTxnParam, createASATxnParam, masterTxnParam, diff --git a/examples/inner-tx-create-assets/scripts/run/useInnerTxn.js b/examples/inner-tx-create-assets/scripts/run/useInnerTxn.js index ed9147741..85846134c 100644 --- a/examples/inner-tx-create-assets/scripts/run/useInnerTxn.js +++ b/examples/inner-tx-create-assets/scripts/run/useInnerTxn.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); const { accounts, decodeValue } = require("../utils"); // Deploy new application @@ -19,7 +20,7 @@ async function run(runtimeEnv, deployer) { }, }; - const txReceipt = await deployer.executeTx([masterTxnParam]); + const txReceipt = await tryExecuteTx(deployer, [masterTxnParam]); // get logs from transaction const logs = txReceipt[0].logs; diff --git a/examples/multisig/scripts/common/common.js b/examples/multisig/scripts/common/common.js index 041503c09..6f727ff47 100644 --- a/examples/multisig/scripts/common/common.js +++ b/examples/multisig/scripts/common/common.js @@ -1,8 +1,9 @@ exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } }; diff --git a/examples/multisig/scripts/multisig_goal_sc.js b/examples/multisig/scripts/multisig_goal_sc.js index b694651ec..8be5e3ec0 100644 --- a/examples/multisig/scripts/multisig_goal_sc.js +++ b/examples/multisig/scripts/multisig_goal_sc.js @@ -58,7 +58,7 @@ async function run(runtimeEnv, deployer) { // Transaction FAIL - according to teal logic, amount should be <= 100 txnParams.amountMicroAlgos = 200; - await tryExecuteTx(deployer, txnParams); + await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); } module.exports = { default: run }; diff --git a/examples/multisig/scripts/multisig_sdk_sc.js b/examples/multisig/scripts/multisig_sdk_sc.js index 035425ad2..1e809d788 100644 --- a/examples/multisig/scripts/multisig_sdk_sc.js +++ b/examples/multisig/scripts/multisig_sdk_sc.js @@ -52,7 +52,7 @@ async function run(runtimeEnv, deployer) { txnParams.amountMicroAlgos = 580; // Transaction FAIL - according to sample-asc.teal logic, amount should be <= 100 - await tryExecuteTx(deployer, txnParams); + await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); } module.exports = { default: run }; diff --git a/examples/nft/scripts/deploy-nft.js b/examples/nft/scripts/deploy-nft.js index 541d8d078..753d59484 100644 --- a/examples/nft/scripts/deploy-nft.js +++ b/examples/nft/scripts/deploy-nft.js @@ -3,6 +3,7 @@ * This file deploys the stateful smart contract to create and transfer NFT */ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./transfer/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -19,21 +20,25 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(algoTxnParams); // fund john + await tryExecuteTx(deployer, algoTxnParams); // fund john - await deployer.deployApp( - masterAccount, - { - appName: "nft", - metaType: types.MetaType.FILE, - approvalProgramFilename: "nft_approval.py", - clearProgramFilename: "nft_clear_state.py", - localInts: 16, - globalInts: 1, - globalBytes: 63, - }, - {} - ); + await deployer + .deployApp( + masterAccount, + { + appName: "nft", + metaType: types.MetaType.FILE, + approvalProgramFilename: "nft_approval.py", + clearProgramFilename: "nft_clear_state.py", + localInts: 16, + globalInts: 1, + globalBytes: 63, + }, + {} + ) + .catch((error) => { + throw error; + }); const appInfo = await deployer.getApp("nft"); const appID = appInfo.appID; diff --git a/examples/nft/scripts/transfer/common.js b/examples/nft/scripts/transfer/common.js index 78d319ce0..8c63b7a41 100644 --- a/examples/nft/scripts/transfer/common.js +++ b/examples/nft/scripts/transfer/common.js @@ -3,9 +3,11 @@ const { default: algosdk } = require("algosdk"); exports.tryExecuteTx = async function (deployer, txnParams) { try { - await deployer.executeTx(deployer, txnParams); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } }; diff --git a/examples/nft/scripts/transfer/create-transfer-nft.js b/examples/nft/scripts/transfer/create-transfer-nft.js index 5c4adce3f..7050c9d68 100644 --- a/examples/nft/scripts/transfer/create-transfer-nft.js +++ b/examples/nft/scripts/transfer/create-transfer-nft.js @@ -2,7 +2,7 @@ * Description: * This file creates a new NFT and transfers 1 NFT from A to B */ -const { printGlobalNFT, printLocalNFT } = require("./common"); +const { printGlobalNFT, printLocalNFT, tryExecuteTx } = require("./common"); const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); @@ -31,7 +31,7 @@ async function run(runtimeEnv, deployer) { appArgs, }, ]; - await deployer.executeTx(txnParam); // creates new nft (with id = 1) + await tryExecuteTx(deployer, txnParam); // creates new nft (with id = 1) // print Global Count after creation await printGlobalNFT(deployer, masterAccount.addr, appID); @@ -60,7 +60,7 @@ async function run(runtimeEnv, deployer) { appArgs, }, ]; - await deployer.executeTx(txnParam); + await tryExecuteTx(deployer, txnParam); await printLocalNFT(deployer, masterAccount.addr, appID); await printLocalNFT(deployer, john.addr, appID); diff --git a/examples/permissioned-token-freezing/scripts/0-createAppAsset.js b/examples/permissioned-token-freezing/scripts/0-createAppAsset.js index ed5300752..17c7d5ae6 100644 --- a/examples/permissioned-token-freezing/scripts/0-createAppAsset.js +++ b/examples/permissioned-token-freezing/scripts/0-createAppAsset.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common/common"); async function run(runtimeEnv, deployer) { const master = deployer.accountsByName.get("master-account"); @@ -14,11 +15,13 @@ async function run(runtimeEnv, deployer) { amountMicroAlgos: 200e6, payFlags: {}, }; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); algoTxnParams.toAccountAddr = bob.addr; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); - const asaInfo = await deployer.deployASA("gold", { creator: creator }); + const asaInfo = await deployer.deployASA("gold", { creator: creator }).catch((error) => { + throw error; + }); await deployer.optInAccountToASA("gold", "bob", {}); // asa optIn for bob console.log(asaInfo); @@ -29,21 +32,25 @@ async function run(runtimeEnv, deployer) { "int:2", // set min user level(2) for asset transfer ("Accred-level") ]; - const sscInfo = await deployer.deployApp( - creator, - { - appName: "PermissionedTokenApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "poi-approval.teal", // approval program - clearProgramFilename: "poi-clear.teal", // clear program - localInts: 1, // to store level of asset for account - localBytes: 0, - globalInts: 2, // 1 to store assetId, 1 for min asset level required to transfer asset - globalBytes: 1, // to store creator address - appArgs: appArgs, - }, - {} - ); + const sscInfo = await deployer + .deployApp( + creator, + { + appName: "PermissionedTokenApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "poi-approval.teal", // approval program + clearProgramFilename: "poi-clear.teal", // clear program + localInts: 1, // to store level of asset for account + localBytes: 0, + globalInts: 2, // 1 to store assetId, 1 for min asset level required to transfer asset + globalBytes: 1, // to store creator address + appArgs: appArgs, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(sscInfo); diff --git a/examples/permissioned-token-freezing/scripts/1-assetConfig.js b/examples/permissioned-token-freezing/scripts/1-assetConfig.js index b067635cd..943df06e0 100644 --- a/examples/permissioned-token-freezing/scripts/1-assetConfig.js +++ b/examples/permissioned-token-freezing/scripts/1-assetConfig.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common/common"); async function run(runtimeEnv, deployer) { const creator = deployer.accountsByName.get("alice"); @@ -12,7 +13,11 @@ async function run(runtimeEnv, deployer) { ASSET_ID: assetInfo.assetIndex, APP_ID: appInfo.appID, }; - await deployer.mkContractLsig("clawbackEscrow", "clawback-escrow.py", escrowParams); + await deployer + .mkContractLsig("clawbackEscrow", "clawback-escrow.py", escrowParams) + .catch((error) => { + throw error; + }); await deployer.fundLsig("clawbackEscrow", { funder: creator, fundingMicroAlgo: 1e6 }, {}); // sending 1 Algo @@ -29,7 +34,7 @@ async function run(runtimeEnv, deployer) { fields: { clawback: escrowAddress }, // only pass the field you want to update payFlags: { totalFee: 1000 }, }; - await deployer.executeTx([assetConfigParams]); + await tryExecuteTx(deployer, [assetConfigParams]); /** now lock the asset by clearing the manager and freeze account **/ console.log("* Locking the manager and freeze address *"); @@ -37,7 +42,7 @@ async function run(runtimeEnv, deployer) { ...assetConfigParams, fields: { manager: "", freeze: "" }, }; - await deployer.executeTx([assetLockParams]); + await tryExecuteTx(deployer, [assetLockParams]); } module.exports = { default: run }; diff --git a/examples/permissioned-token-freezing/scripts/common/common.js b/examples/permissioned-token-freezing/scripts/common/common.js new file mode 100644 index 000000000..3596e26c1 --- /dev/null +++ b/examples/permissioned-token-freezing/scripts/common/common.js @@ -0,0 +1,13 @@ +async function tryExecuteTx(deployer, txnParams) { + try { + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +} + +module.exports = { + tryExecuteTx, +}; diff --git a/examples/permissioned-token-freezing/scripts/transfer/set-clear-level.js b/examples/permissioned-token-freezing/scripts/transfer/set-clear-level.js index d0dbd4b12..fe8a34546 100644 --- a/examples/permissioned-token-freezing/scripts/transfer/set-clear-level.js +++ b/examples/permissioned-token-freezing/scripts/transfer/set-clear-level.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const creator = deployer.accountsByName.get("alice"); @@ -20,8 +21,8 @@ async function run(runtimeEnv, deployer) { }; console.log("* Setting level 2 for Alice and Bob *"); - await deployer.executeTx([setLevelParams]); - await deployer.executeTx([ + await tryExecuteTx(deployer, [setLevelParams]); + await tryExecuteTx(deployer, [ { ...setLevelParams, accounts: [bob.addr], diff --git a/examples/permissioned-token-freezing/scripts/transfer/transfer-asset.js b/examples/permissioned-token-freezing/scripts/transfer/transfer-asset.js index 4feefded1..68749a4e5 100644 --- a/examples/permissioned-token-freezing/scripts/transfer/transfer-asset.js +++ b/examples/permissioned-token-freezing/scripts/transfer/transfer-asset.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const creator = deployer.accountsByName.get("alice"); @@ -58,11 +59,8 @@ async function run(runtimeEnv, deployer) { ]; console.log("* Transferring 1000 Assets from Alice to Bob *"); - try { - await deployer.executeTx(txGroup); - } catch (error) { - console.log("Error Occurred: ", error.response.error); - } + + await tryExecuteTx(deployer, txGroup); } module.exports = { default: run }; diff --git a/examples/permissioned-token/scripts/1-setup-controller.js b/examples/permissioned-token/scripts/1-setup-controller.js index 849c877ee..119897642 100644 --- a/examples/permissioned-token/scripts/1-setup-controller.js +++ b/examples/permissioned-token/scripts/1-setup-controller.js @@ -20,22 +20,26 @@ async function setupControllerSSC(runtimeEnv, deployer) { }; console.log("\n** Deploying smart contract: controller **"); - const controllerAppInfo = await deployer.deployApp( - owner, - { - appName: "Controller", - metaType: types.MetaType.FILE, - approvalProgramFilename: "controller.py", // approval program - clearProgramFilename: "clear_state_program.py", // clear program - localInts: 0, - localBytes: 0, - globalInts: 2, // 1 to store kill_status, 1 for storing permissions_app_id - globalBytes: 0, - foreignAssets: [tesla.assetIndex], // pass token_id in foreign assets array - }, - {}, - templateParam - ); // pass token_id as a template paramenter + const controllerAppInfo = await deployer + .deployApp( + owner, + { + appName: "Controller", + metaType: types.MetaType.FILE, + approvalProgramFilename: "controller.py", // approval program + clearProgramFilename: "clear_state_program.py", // clear program + localInts: 0, + localBytes: 0, + globalInts: 2, // 1 to store kill_status, 1 for storing permissions_app_id + globalBytes: 0, + foreignAssets: [tesla.assetIndex], // pass token_id in foreign assets array + }, + {}, + templateParam + ) // pass token_id as a template paramenter + .catch((error) => { + throw error; + }); console.log(controllerAppInfo); // Use executeSignedTxnFromFile function to execute deployment transaction from a signed file: diff --git a/examples/permissioned-token/scripts/2-asset-clawback.js b/examples/permissioned-token/scripts/2-asset-clawback.js index c5a7a761b..f9a15902e 100644 --- a/examples/permissioned-token/scripts/2-asset-clawback.js +++ b/examples/permissioned-token/scripts/2-asset-clawback.js @@ -1,6 +1,6 @@ const { types } = require("@algo-builder/web"); const accounts = require("./common/accounts"); -const { getClawbackParams } = require("./common/common"); +const { getClawbackParams, tryExecuteTx } = require("./common/common"); /** * Compile and set clawback logic sig (escrow) with template parameters: @@ -16,7 +16,11 @@ async function setupClawback(runtimeEnv, deployer) { // NOTE: make sure to deploy ASA and controller before const tesla = deployer.asa.get("tesla"); const clawbackParams = getClawbackParams(deployer); - await deployer.mkContractLsig("ClawbackLsig", "clawback.py", clawbackParams); + await deployer + .mkContractLsig("ClawbackLsig", "clawback.py", clawbackParams) + .catch((error) => { + throw error; + }); const clawbackLsig = deployer.getLsig("ClawbackLsig"); const clawbackAddress = clawbackLsig.address(); @@ -44,7 +48,7 @@ async function setupClawback(runtimeEnv, deployer) { payFlags: { totalFee: 1000 }, }, ]; - await deployer.executeTx(assetConfigParams); + await tryExecuteTx(deployer, assetConfigParams); } module.exports = { default: setupClawback }; diff --git a/examples/permissioned-token/scripts/3-setup-permissions.js b/examples/permissioned-token/scripts/3-setup-permissions.js index 8e22e83aa..17acbcc4d 100644 --- a/examples/permissioned-token/scripts/3-setup-permissions.js +++ b/examples/permissioned-token/scripts/3-setup-permissions.js @@ -1,5 +1,6 @@ const { types } = require("@algo-builder/web"); const accounts = require("./common/accounts"); +const { tryExecuteTx } = require("./common/common"); /** * Deploy Permissions smart contract @@ -18,21 +19,25 @@ async function setupPermissionsApp(runtimeEnv, deployer) { /** Deploy Permissions(rules) smart contract **/ console.log("\n** Deploying smart contract: permissions **"); - const permissionAppInfo = await deployer.deployApp( - owner, - { - appName: "Permissions", - metaType: types.MetaType.FILE, - approvalProgramFilename: "permissions.py", // approval program - clearProgramFilename: "clear_state_program.py", // clear program - localInts: 1, // 1 to store whitelisted status in local state - localBytes: 0, - globalInts: 2, // 1 to store max_tokens, 1 for storing total whitelisted accounts - globalBytes: 1, // to store permissions manager - }, - {}, - templateParam - ); // pass perm_manager as a template param (to set during deploy) + const permissionAppInfo = await deployer + .deployApp( + owner, + { + appName: "Permissions", + metaType: types.MetaType.FILE, + approvalProgramFilename: "permissions.py", // approval program + clearProgramFilename: "clear_state_program.py", // clear program + localInts: 1, // 1 to store whitelisted status in local state + localBytes: 0, + globalInts: 2, // 1 to store max_tokens, 1 for storing total whitelisted accounts + globalBytes: 1, // to store permissions manager + }, + {}, + templateParam + ) // pass perm_manager as a template param (to set during deploy) + .catch((error) => { + throw error; + }); console.log(permissionAppInfo); /** @@ -46,23 +51,20 @@ async function setupPermissionsApp(runtimeEnv, deployer) { * + Currently only 1 permissions app is supported. */ console.log("\n** Linking permissions smart contract to the controller **"); - try { - const appArgs = ["str:set_permission", `int:${permissionAppInfo.appID}`]; - await deployer.executeTx([ - { - type: types.TransactionType.CallApp, - sign: types.SignType.SecretKey, - fromAccount: owner, // asa manager account - appID: controllerappID, - payFlags: { totalFee: 1000 }, - appArgs: appArgs, - foreignAssets: [tesla.assetIndex], // controller sc verifies if correct token is being used + asa.manager is correct one - }, - ]); - } catch (e) { - console.log("Error occurred", e.response.error); - } + const appArgs = ["str:set_permission", `int:${permissionAppInfo.appID}`]; + + await tryExecuteTx(deployer, [ + { + type: types.TransactionType.CallApp, + sign: types.SignType.SecretKey, + fromAccount: owner, // asa manager account + appID: controllerappID, + payFlags: { totalFee: 1000 }, + appArgs: appArgs, + foreignAssets: [tesla.assetIndex], // controller sc verifies if correct token is being used + asa.manager is correct one + }, + ]); } module.exports = { default: setupPermissionsApp }; diff --git a/examples/permissioned-token/scripts/4-setup-new-permissions-app.js b/examples/permissioned-token/scripts/4-setup-new-permissions-app.js index 0ba2b5d74..7038497f3 100644 --- a/examples/permissioned-token/scripts/4-setup-new-permissions-app.js +++ b/examples/permissioned-token/scripts/4-setup-new-permissions-app.js @@ -12,20 +12,24 @@ async function setupNewPermissionsApp(runtimeEnv, deployer) { await fundAccount(deployer, owner); // deploy new permissions smart contract - const newPermissionsAppInfo = await deployer.deployApp( - owner, - { - appName: "PermissionNewApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "permissions_new.teal", // new permissions contract - clearProgramFilename: "clear_state_program.py", - localInts: 0, - localBytes: 0, - globalInts: 0, - globalBytes: 0, - }, - {} - ); + const newPermissionsAppInfo = await deployer + .deployApp( + owner, + { + appName: "PermissionNewApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "permissions_new.teal", // new permissions contract + clearProgramFilename: "clear_state_program.py", + localInts: 0, + localBytes: 0, + globalInts: 0, + globalBytes: 0, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(newPermissionsAppInfo); } diff --git a/examples/permissioned-token/scripts/admin/cease.js b/examples/permissioned-token/scripts/admin/cease.js index 37d5ec8a5..905e5adc3 100644 --- a/examples/permissioned-token/scripts/admin/cease.js +++ b/examples/permissioned-token/scripts/admin/cease.js @@ -2,7 +2,7 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); -const { fundAccount, optInAccountToApp } = require("../common/common"); +const { fundAccount, optInAccountToApp, tryExecuteTx } = require("../common/common"); const { issue } = require("./issue"); const { whitelist } = require("../permissions/whitelist"); @@ -62,7 +62,7 @@ async function cease(deployer, address, amount) { ]; console.log(`* Ceasing ${amount} tokens from [${address}] *`); - await deployer.executeTx(ceaseTxGroup); + await tryExecuteTx(deployer, ceaseTxGroup); console.log(`* ${address} asset holding after cease: *`); console.log(await balanceOf(deployer, address, tesla.assetIndex)); diff --git a/examples/permissioned-token/scripts/admin/force-transfer.js b/examples/permissioned-token/scripts/admin/force-transfer.js index 2c9825d33..5dc573ea3 100644 --- a/examples/permissioned-token/scripts/admin/force-transfer.js +++ b/examples/permissioned-token/scripts/admin/force-transfer.js @@ -2,7 +2,7 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); -const { fundAccount, optInAccountToApp } = require("../common/common"); +const { fundAccount, optInAccountToApp, tryExecuteTx } = require("../common/common"); const { issue } = require("./issue"); const { whitelist } = require("../permissions/whitelist"); @@ -81,7 +81,7 @@ async function forceTransfer(deployer, fromAddr, toAddr, amount) { console.log(`* Transferring ${amount} tokens from [${fromAddr}] to [${toAddr}] *`); - await deployer.executeTx(forceTxGroup); + await tryExecuteTx(deployer, forceTxGroup); console.log(`* ${toAddr}(receiver) asset holding: *`); console.log(await balanceOf(deployer, toAddr, tesla.assetIndex)); @@ -110,7 +110,7 @@ async function run(runtimeEnv, deployer) { optInAccountToApp(deployer, elon, permissionsAppInfo.appID, {}, {}), optInAccountToApp(deployer, bob, permissionsAppInfo.appID, {}, {}), optInAccountToApp(deployer, john, permissionsAppInfo.appID, {}, {}), - ]); + ]).catch((error) => console.log(error)); /* * use below function to whitelist accounts @@ -127,7 +127,7 @@ async function run(runtimeEnv, deployer) { deployer.optInAccountToASA("tesla", elon.name, {}), deployer.optInAccountToASA("tesla", bob.name, {}), deployer.optInAccountToASA("tesla", john.name, {}), - ]); + ]).catch((error) => console.log(error)); // note: if reserve is multisig, then user will use executeSignedTxnFromFile function await issue(deployer, bob.addr, 200); // issue(mint) 100 tokens to bob from reserve diff --git a/examples/permissioned-token/scripts/admin/kill.js b/examples/permissioned-token/scripts/admin/kill.js index 8bc5f2b0a..0b6de7020 100644 --- a/examples/permissioned-token/scripts/admin/kill.js +++ b/examples/permissioned-token/scripts/admin/kill.js @@ -42,7 +42,7 @@ async function run(runtimeEnv, deployer) { await kill(deployer); // kill token 'tesla' // transaction FAIL: token is killed, we can't issue tokens - await issue(deployer, elon.addr, 15); + await issue(deployer, elon.addr, 15).catch((error) => console.log(error)); } module.exports = { default: run, kill: kill }; diff --git a/examples/permissioned-token/scripts/admin/update-reserve.js b/examples/permissioned-token/scripts/admin/update-reserve.js index 20e5b030d..dbf1b1c16 100644 --- a/examples/permissioned-token/scripts/admin/update-reserve.js +++ b/examples/permissioned-token/scripts/admin/update-reserve.js @@ -1,6 +1,7 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); +const { tryExecuteTx } = require("../common/common"); // here instead of updating the asset reserve by modifyAsset tx, // we use rekey transaction for the reserve account. @@ -100,7 +101,7 @@ async function updateReserveByAssetConfig(deployer, address) { ]; console.log(`* Updating reserve address to: ${address} *`); - await deployer.executeTx(updateReserveParams); + await tryExecuteTx(deployer, updateReserveParams); console.log("* Update Successful *"); console.log( diff --git a/examples/permissioned-token/scripts/common/common.js b/examples/permissioned-token/scripts/common/common.js index 758d58af7..e1c0e3593 100644 --- a/examples/permissioned-token/scripts/common/common.js +++ b/examples/permissioned-token/scripts/common/common.js @@ -3,10 +3,11 @@ const { types } = require("@algo-builder/web"); exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } }; diff --git a/examples/permissioned-token/scripts/permissions/change-perm-manager.js b/examples/permissioned-token/scripts/permissions/change-perm-manager.js index c3c7c297b..737b5791a 100644 --- a/examples/permissioned-token/scripts/permissions/change-perm-manager.js +++ b/examples/permissioned-token/scripts/permissions/change-perm-manager.js @@ -1,4 +1,4 @@ -const { fundAccount, optInAccountToApp } = require("../common/common"); +const { fundAccount, optInAccountToApp, tryExecuteTx } = require("../common/common"); const { whitelist } = require("./whitelist"); const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); @@ -24,7 +24,7 @@ async function changePermissionsManager(deployer, permissionsManager, address) { ]; console.log(`\n* Updating permissions manager to: ${address} *`); - await deployer.executeTx(changePerManagerParams); + await tryExecuteTx(deployer, changePerManagerParams); } async function run(runtimeEnv, deployer) { diff --git a/examples/permissioned-token/scripts/permissions/set-permission-appid.js b/examples/permissioned-token/scripts/permissions/set-permission-appid.js index 851f1ef8b..159a8780b 100644 --- a/examples/permissioned-token/scripts/permissions/set-permission-appid.js +++ b/examples/permissioned-token/scripts/permissions/set-permission-appid.js @@ -1,5 +1,6 @@ const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const controllerAppInfo = deployer.getApp("Controller"); @@ -13,25 +14,22 @@ async function run(runtimeEnv, deployer) { console.log( `\n** Setting new permissions smart contract(id = ${newPermissionsAppInfo.appID}) **` ); - try { - const appArgs = ["str:set_permission", `int:${newPermissionsAppInfo.appID}`]; - // set new permissions app id in controller smart contract - // note: in current version, this replaces the previous appID in controller - await deployer.executeTx([ - { - type: types.TransactionType.CallApp, - sign: types.SignType.SecretKey, - fromAccount: owner, // asa manager account - appID: controllerappID, - payFlags: { totalFee: 1000 }, - appArgs: appArgs, - foreignAssets: [tesla.assetIndex], // controller smart contract verifies if correct token is being used + asa.manager is correct one - }, - ]); - } catch (e) { - console.log("Error occurred", e.response.error); - } + const appArgs = ["str:set_permission", `int:${newPermissionsAppInfo.appID}`]; + + // set new permissions app id in controller smart contract + // note: in current version, this replaces the previous appID in controller + await tryExecuteTx(deployer, [ + { + type: types.TransactionType.CallApp, + sign: types.SignType.SecretKey, + fromAccount: owner, // asa manager account + appID: controllerappID, + payFlags: { totalFee: 1000 }, + appArgs: appArgs, + foreignAssets: [tesla.assetIndex], // controller smart contract verifies if correct token is being used + asa.manager is correct one + }, + ]); } module.exports = { default: run }; diff --git a/examples/permissioned-token/scripts/permissions/whitelist.js b/examples/permissioned-token/scripts/permissions/whitelist.js index 0894a13f5..2128c26a6 100644 --- a/examples/permissioned-token/scripts/permissions/whitelist.js +++ b/examples/permissioned-token/scripts/permissions/whitelist.js @@ -1,4 +1,4 @@ -const { fundAccount, optInAccountToApp } = require("../common/common"); +const { fundAccount, optInAccountToApp, tryExecuteTx } = require("../common/common"); const { types } = require("@algo-builder/web"); const accounts = require("../common/accounts"); @@ -32,7 +32,7 @@ async function whitelist(deployer, permissionsManager, address) { }, ]; console.log(`* Adding [${address}] to whitelisted accounts *`); - await deployer.executeTx(whiteListParams); + await tryExecuteTx(deployer, whiteListParams); } /** diff --git a/examples/permissioned-token/scripts/user/opt-out.js b/examples/permissioned-token/scripts/user/opt-out.js index 3b986325f..b3231eab3 100644 --- a/examples/permissioned-token/scripts/user/opt-out.js +++ b/examples/permissioned-token/scripts/user/opt-out.js @@ -1,7 +1,7 @@ const { balanceOf } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); const { issue } = require("../admin/issue"); -const { fundAccount } = require("../common/common"); +const { fundAccount, tryExecuteTx } = require("../common/common"); /** * To opt-out of the token, do an asset transfer transaction with @@ -30,7 +30,7 @@ async function optOut(deployer, account) { ]; console.log(`* Opting out [${account.name}:${account.addr}] from token 'tesla' *`); - await deployer.executeTx(optOutParams); + await tryExecuteTx(deployer, optOutParams); } async function run(runtimeEnv, deployer) { diff --git a/examples/permissioned-token/scripts/user/transfer.js b/examples/permissioned-token/scripts/user/transfer.js index 7385934ee..83d2bcb07 100644 --- a/examples/permissioned-token/scripts/user/transfer.js +++ b/examples/permissioned-token/scripts/user/transfer.js @@ -3,7 +3,7 @@ const { types } = require("@algo-builder/web"); const { issue } = require("../admin/issue"); const { whitelist } = require("../permissions/whitelist"); -const { fundAccount, optInAccountToApp } = require("../common/common"); +const { fundAccount, optInAccountToApp, tryExecuteTx } = require("../common/common"); /** * Transfer token between non-reserve accounts @@ -77,7 +77,7 @@ async function transfer(deployer, from, toAddr, amount) { console.log(`* Transferring ${amount} tokens from [${from.name}:${from.addr}] to [${toAddr}] *`); - await deployer.executeTx(txGroup); + await tryExecuteTx(deployer, txGroup); console.log(`* ${toAddr}(receiver) asset holding: *`); console.log("Balance: ", await balanceOf(deployer, toAddr, tesla.assetIndex)); diff --git a/examples/permissioned-voting/scripts/vote/common.js b/examples/permissioned-voting/scripts/vote/common.js index b1ec8c768..607f18415 100644 --- a/examples/permissioned-voting/scripts/vote/common.js +++ b/examples/permissioned-voting/scripts/vote/common.js @@ -4,5 +4,6 @@ exports.tryExecuteTx = async function (deployer, txnParams) { else await deployer.executeTx([txnParams]); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e.error); + throw e; } }; diff --git a/examples/permissioned-voting/scripts/vote/vote.js b/examples/permissioned-voting/scripts/vote/vote.js index 82cea866a..6353199ce 100644 --- a/examples/permissioned-voting/scripts/vote/vote.js +++ b/examples/permissioned-voting/scripts/vote/vote.js @@ -8,7 +8,7 @@ async function run(runtimeEnv, deployer) { const votingAdminAccount = deployer.accountsByName.get("john"); const bob = deployer.accountsByName.get("bob"); - await deployer.executeTx([ + await tryExecuteTx(deployer, [ { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, @@ -18,7 +18,7 @@ async function run(runtimeEnv, deployer) { payFlags: {}, }, ]); - await deployer.executeTx([ + await tryExecuteTx(deployer, [ { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, @@ -67,13 +67,17 @@ async function run(runtimeEnv, deployer) { // Transaction Fails because Alice can only vote once. console.log("Alice tries to cast vote again"); - await tryExecuteTx(deployer, transactions); + await tryExecuteTx(deployer, transactions).catch((error) => { + console.log(error); + }); // Transaction Fails because bob is not registered voter. console.log("Bob tries to cast vote"); transactions[0].fromAccount = bob; transactions[1].fromAccount = bob; - await tryExecuteTx(deployer, transactions); + await tryExecuteTx(deployer, transactions).catch((error) => { + console.log(error); + }); } module.exports = { default: run }; diff --git a/examples/permissioned-voting/scripts/voting.js b/examples/permissioned-voting/scripts/voting.js index 699273b30..417c98939 100644 --- a/examples/permissioned-voting/scripts/voting.js +++ b/examples/permissioned-voting/scripts/voting.js @@ -1,5 +1,6 @@ const { convert } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./vote/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -14,13 +15,17 @@ async function run(runtimeEnv, deployer) { amountMicroAlgos: 200000000, payFlags: {}, }; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); algoTxnParams.toAccountAddr = alice.addr; - await deployer.executeTx(algoTxnParams); + await tryExecuteTx(deployer, algoTxnParams); // Create ASA - Vote Token - const asaInfo = await deployer.deployASA("vote-token", { creator: votingAdminAccount }); + const asaInfo = await deployer + .deployASA("vote-token", { creator: votingAdminAccount }) + .catch((error) => { + throw error; + }); console.log(asaInfo); // Transfer 1 vote token to alice. @@ -33,7 +38,7 @@ async function run(runtimeEnv, deployer) { assetID: asaInfo.assetIndex, payFlags: { note: "Sending Vote Token" }, }; - await deployer.executeTx(txnParam); + await tryExecuteTx(deployer, txnParam); // Get last round and Initialize rounds const status = await deployer.algodClient.status().do(); @@ -51,21 +56,25 @@ async function run(runtimeEnv, deployer) { // Create Application // Note: An Account can have maximum of 10 Applications. - const res = await deployer.deployApp( - votingAdminAccount, - { - appName: "PermissionedVotingApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "permissioned-voting-approval.py", - clearProgramFilename: "permissioned-voting-clear.py", - localInts: 0, - localBytes: 1, - globalInts: 6, - globalBytes: 1, - appArgs: appArgs, - }, - {} - ); + const res = await deployer + .deployApp( + votingAdminAccount, + { + appName: "PermissionedVotingApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "permissioned-voting-approval.py", + clearProgramFilename: "permissioned-voting-clear.py", + localInts: 0, + localBytes: 1, + globalInts: 6, + globalBytes: 1, + appArgs: appArgs, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(res); diff --git a/examples/ref-templates/scripts/common/common.js b/examples/ref-templates/scripts/common/common.js index 88976fd1f..ee2487414 100644 --- a/examples/ref-templates/scripts/common/common.js +++ b/examples/ref-templates/scripts/common/common.js @@ -1,23 +1,13 @@ const { types } = require("@algo-builder/web"); require("dotenv").config(); -const showError = () => { - // show error if IGNORE_TX_FAIL = false - if (process.env.IGNORE_TX_FAIL) { - return process.env.IGNORE_TX_FAIL === "false"; - } - // default not show error - return true; -}; - exports.tryExecuteTx = async function (deployer, txnParams) { try { if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); else await deployer.executeTx([txnParams]); } catch (e) { - if (showError()) { - console.error("Transaction Failed", e.response ? e.response.error : e); - } + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } }; diff --git a/examples/ref-templates/scripts/dynamic-fee.js b/examples/ref-templates/scripts/dynamic-fee.js index 8d9dbd408..94a8ff841 100644 --- a/examples/ref-templates/scripts/dynamic-fee.js +++ b/examples/ref-templates/scripts/dynamic-fee.js @@ -15,17 +15,25 @@ async function run(runtimeEnv, deployer) { }; const contractName = "dynamic-fee.py"; // setup a contract account and send 1 ALGO from master - await deployer.fundLsigByFile( - contractName, - { funder: masterAccount, fundingMicroAlgo: 100000000 }, - { closeRemainderTo: masterAccount.addr }, - scInitParam - ); + await deployer + .fundLsigByFile( + contractName, + { funder: masterAccount, fundingMicroAlgo: 100000000 }, + { closeRemainderTo: masterAccount.addr }, + scInitParam + ) + .catch((error) => { + throw error; + }); const contract = await deployer.loadLogicByFile(contractName, scInitParam); const escrow = contract.address(); // contract account - await deployer.mkDelegatedLsig("dynamicFeeLsig", contractName, masterAccount, scInitParam); // sign contract + await deployer + .mkDelegatedLsig("dynamicFeeLsig", contractName, masterAccount, scInitParam) + .catch((error) => { + throw error; + }); // sign contract const signedContract = await deployer.getLsig("dynamicFeeLsig"); console.log("Smart Sign ", signedContract); @@ -38,7 +46,9 @@ async function run(runtimeEnv, deployer) { ]; // Group Transaction FAIL - Correct transaction Fee is used BUT closeRemainderTo is set to bob - await tryExecuteTx(deployer, transactions); + await tryExecuteTx(deployer, transactions).catch((error) => { + console.log(error); + }); transactions = [ mkTxnParams(masterAccount, escrow, 1000, signedContract, { totalFee: 1000 }), diff --git a/examples/ref-templates/scripts/htlc.js b/examples/ref-templates/scripts/htlc.js index 9000de827..4ce6c9905 100644 --- a/examples/ref-templates/scripts/htlc.js +++ b/examples/ref-templates/scripts/htlc.js @@ -18,14 +18,18 @@ async function run(runtimeEnv, deployer) { const wrongSecret = "hero wisdom red split loop element vote belt"; // setup a contract account and send 1 ALGO from master - await deployer.fundLsigByFile( - "htlc.py", - { - funder: masterAccount, - fundingMicroAlgo: 1e6, // 1 Algo - }, - { closeRemainderTo: john.addr } - ); + await deployer + .fundLsigByFile( + "htlc.py", + { + funder: masterAccount, + fundingMicroAlgo: 1e6, // 1 Algo + }, + { closeRemainderTo: john.addr } + ) + .catch((error) => { + throw error; + }); await deployer.addCheckpointKV("User Checkpoint", "Fund Contract Account"); @@ -41,7 +45,9 @@ async function run(runtimeEnv, deployer) { txnParams.payFlags = { totalFee: 1000, closeRemainderTo: john.addr }; // Fails because wrong secret is provided - await tryExecuteTx(deployer, txnParams); + await tryExecuteTx(deployer, txnParams).catch((error) => { + console.log(error); + }); // Passes because right secret is provided txnParams.args = [convert.stringToBytes(secret)]; diff --git a/examples/signed-txn/scripts/transfer.js b/examples/signed-txn/scripts/transfer.js index 0d1b1cad3..c02144bad 100644 --- a/examples/signed-txn/scripts/transfer.js +++ b/examples/signed-txn/scripts/transfer.js @@ -17,6 +17,7 @@ async function run(runtimeEnv, deployer) { await executeSignedTxnFromFile(deployer, "john-to-bob.txn"); } catch (e) { console.log(e.response ? e.response.error : e); + throw e; } } diff --git a/examples/stateful-counter/scripts/common/common.js b/examples/stateful-counter/scripts/common/common.js new file mode 100644 index 000000000..d07af1a61 --- /dev/null +++ b/examples/stateful-counter/scripts/common/common.js @@ -0,0 +1,9 @@ +exports.tryExecuteTx = async function (deployer, txnParams) { + try { + if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); + else await deployer.executeTx([txnParams]); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +}; diff --git a/examples/stateful-counter/scripts/deploy.js b/examples/stateful-counter/scripts/deploy.js index 7e15a1f7a..7f96697aa 100644 --- a/examples/stateful-counter/scripts/deploy.js +++ b/examples/stateful-counter/scripts/deploy.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("./common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -13,29 +14,35 @@ async function run(runtimeEnv, deployer) { payFlags: {}, }; // transfer some algos to creator account - await deployer.executeTx([algoTxnParams]); + await tryExecuteTx(deployer, [algoTxnParams]); // Create Application // Note: An Account can have maximum of 10 Applications. - const sscInfo = await deployer.deployApp( - creatorAccount, - { - appName: "CounterApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "approval_program.teal", // approval program - clearProgramFilename: "clear_program.teal", // clear program - localInts: 1, - localBytes: 1, - globalInts: 1, - globalBytes: 1, - }, - {} - ); + const sscInfo = await deployer + .deployApp( + creatorAccount, + { + appName: "CounterApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "approval_program.teal", // approval program + clearProgramFilename: "clear_program.teal", // clear program + localInts: 1, + localBytes: 1, + globalInts: 1, + globalBytes: 1, + }, + {} + ) + .catch((error) => { + throw error; + }); console.log(sscInfo); // Opt-In for creator - await deployer.optInAccountToApp(creatorAccount, sscInfo.appID, {}, {}); + await deployer.optInAccountToApp(creatorAccount, sscInfo.appID, {}, {}).catch((error) => { + throw error; + }); } module.exports = { default: run }; diff --git a/examples/stateful-counter/scripts/interaction/call_application.js b/examples/stateful-counter/scripts/interaction/call_application.js index 7f76fdc9a..e3457c56f 100644 --- a/examples/stateful-counter/scripts/interaction/call_application.js +++ b/examples/stateful-counter/scripts/interaction/call_application.js @@ -1,5 +1,6 @@ const { readAppGlobalState } = require("@algo-builder/algob"); const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const creatorAccount = deployer.accountsByName.get("alice"); @@ -21,7 +22,7 @@ async function run(runtimeEnv, deployer) { payFlags: {}, }; - await deployer.executeTx([tx]); + await tryExecuteTx(deployer, [tx]); /* Uncomment below code to start debugger */ // await new Tealdbg(deployer, tx) diff --git a/examples/stateful-counter/scripts/interaction/delete_application.js b/examples/stateful-counter/scripts/interaction/delete_application.js index 13c761309..43bd02e54 100644 --- a/examples/stateful-counter/scripts/interaction/delete_application.js +++ b/examples/stateful-counter/scripts/interaction/delete_application.js @@ -1,4 +1,5 @@ const { types } = require("@algo-builder/web"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const creatorAccount = deployer.accountsByName.get("alice"); @@ -17,7 +18,7 @@ async function run(runtimeEnv, deployer) { appArgs: [], }; - await deployer.executeTx([tx]); + await tryExecuteTx(deployer, [tx]); console.log("Application Deleted!!"); } diff --git a/examples/stateful-counter/scripts/interaction/update_application.js b/examples/stateful-counter/scripts/interaction/update_application.js index 3f618b66f..5366ea75c 100644 --- a/examples/stateful-counter/scripts/interaction/update_application.js +++ b/examples/stateful-counter/scripts/interaction/update_application.js @@ -8,18 +8,22 @@ async function run(runtimeEnv, deployer) { const applicationID = appInfo.appID; console.log("Application Id ", applicationID); - const updatedRes = await deployer.updateApp( - "CounterApp", - creatorAccount, - {}, // pay flags - applicationID, - { - metaType: types.MetaType.FILE, - approvalProgramFilename: "new_approval.teal", - clearProgramFilename: "new_clear.teal", - }, - {} - ); + const updatedRes = await deployer + .updateApp( + "CounterApp", + creatorAccount, + {}, // pay flags + applicationID, + { + metaType: types.MetaType.FILE, + approvalProgramFilename: "new_approval.teal", + clearProgramFilename: "new_clear.teal", + }, + {} + ) + .catch((error) => { + throw error; + }); console.log("Application Updated: ", updatedRes); } diff --git a/examples/trampoline/scripts/common/common.js b/examples/trampoline/scripts/common/common.js new file mode 100644 index 000000000..d07af1a61 --- /dev/null +++ b/examples/trampoline/scripts/common/common.js @@ -0,0 +1,9 @@ +exports.tryExecuteTx = async function (deployer, txnParams) { + try { + if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); + else await deployer.executeTx([txnParams]); + } catch (e) { + console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; + } +}; diff --git a/examples/trampoline/scripts/deployApp.js b/examples/trampoline/scripts/deployApp.js index a8bbfeb1c..68e0a6e7c 100644 --- a/examples/trampoline/scripts/deployApp.js +++ b/examples/trampoline/scripts/deployApp.js @@ -4,6 +4,7 @@ */ const { types } = require("@algo-builder/web"); const { balanceOf } = require("@algo-builder/algob"); +const { tryExecuteTx } = require("./common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -21,22 +22,26 @@ async function run(runtimeEnv, deployer) { }, ]; - await deployer.executeTx(algoTxnParams); // execute Create app transaction + await tryExecuteTx(deployer, algoTxnParams); // execute Create app transaction - await deployer.deployApp( - john, - { - appName: "proxy_trampoline", - metaType: types.MetaType.FILE, - approvalProgramFilename: "approval.teal", - clearProgramFilename: "clear.teal", - localInts: 0, - localBytes: 0, - globalInts: 0, - globalBytes: 0, - }, - {} - ); //execute create App Transction + await deployer + .deployApp( + john, + { + appName: "proxy_trampoline", + metaType: types.MetaType.FILE, + approvalProgramFilename: "approval.teal", + clearProgramFilename: "clear.teal", + localInts: 0, + localBytes: 0, + globalInts: 0, + globalBytes: 0, + }, + {} + ) // execute create App Transction + .catch((error) => { + throw error; + }); const appInfo = await deployer.getApp("proxy_trampoline"); const appID = appInfo.appID; @@ -53,7 +58,7 @@ async function run(runtimeEnv, deployer) { payFlags: { note: "funding application" }, }, ]; - await deployer.executeTx(algoTxnFundProxy); + await tryExecuteTx(deployer, algoTxnFundProxy); console.log( "Balance of application: ", await balanceOf(deployer, appInfo.applicationAccount) diff --git a/examples/trampoline/scripts/run/create-fund-app.js b/examples/trampoline/scripts/run/create-fund-app.js index 827b8e430..48f9ac660 100644 --- a/examples/trampoline/scripts/run/create-fund-app.js +++ b/examples/trampoline/scripts/run/create-fund-app.js @@ -8,6 +8,7 @@ const { types } = require("@algo-builder/web"); const { convert, balanceOf } = require("@algo-builder/algob"); const algosdk = require("algosdk"); +const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { const masterAccount = deployer.accountsByName.get("master-account"); @@ -37,7 +38,7 @@ async function run(runtimeEnv, deployer) { }, }; - //Transaction that will transfer money to the new application + // Transaction that will transfer money to the new application const fundAppTxtParam = { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, @@ -48,7 +49,7 @@ async function run(runtimeEnv, deployer) { totalFee: 2000, }, }; - //Transaction application call + // Transaction application call const callAppTxn = { type: types.TransactionType.CallApp, sign: types.SignType.SecretKey, @@ -60,7 +61,11 @@ async function run(runtimeEnv, deployer) { }, }; - const receiptsTx = await deployer.executeTx([createAppTxnParam, fundAppTxtParam, callAppTxn]); + const receiptsTx = await tryExecuteTx(deployer, [ + createAppTxnParam, + fundAppTxtParam, + callAppTxn, + ]); // log all transaction have been confirmed including application-index created console.log(receiptsTx); diff --git a/examples/unique-nft-asa/scripts/0-deploy-app.js b/examples/unique-nft-asa/scripts/0-deploy-app.js index 127992008..ce849097d 100644 --- a/examples/unique-nft-asa/scripts/0-deploy-app.js +++ b/examples/unique-nft-asa/scripts/0-deploy-app.js @@ -8,27 +8,36 @@ async function run(runtimeEnv, deployer) { await fundAccount(deployer, [creator]); // Create App - const nftAppInfo = await deployer.deployApp( - creator, - { - appName: "NftApp", - metaType: types.MetaType.FILE, - approvalProgramFilename: "nft-app-approval.py", - clearProgramFilename: "nft-app-clear.py", - localInts: 1, // p - localBytes: 1, // creator - }, - {} - ); + const nftAppInfo = await deployer + .deployApp( + creator, + { + appName: "NftApp", + metaType: types.MetaType.FILE, + approvalProgramFilename: "nft-app-approval.py", + clearProgramFilename: "nft-app-clear.py", + localInts: 1, // p + localBytes: 1, // creator + }, + {} + ) + .catch((error) => { + throw error; + }); + console.log(nftAppInfo); // fund C_p lsig - await deployer.fundLsigByFile( - "stateless.py", - { funder: creator, fundingMicroAlgo: 1e6 }, - {}, // 1 algo - { ARG_P: p, ARG_NFT_APP_ID: nftAppInfo.appID } - ); + await deployer + .fundLsigByFile( + "stateless.py", + { funder: creator, fundingMicroAlgo: 1e6 }, + {}, // 1 algo + { ARG_P: p, ARG_NFT_APP_ID: nftAppInfo.appID } + ) + .catch((error) => { + throw error; + }); console.log("Contracts deployed successfully!"); } diff --git a/examples/unique-nft-asa/scripts/run/common/common.js b/examples/unique-nft-asa/scripts/run/common/common.js index 749a57086..2a14cce36 100644 --- a/examples/unique-nft-asa/scripts/run/common/common.js +++ b/examples/unique-nft-asa/scripts/run/common/common.js @@ -6,6 +6,7 @@ async function tryExecuteTx(deployer, txnParams) { else await deployer.executeTx([txnParams]); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); + throw e; } } @@ -33,7 +34,7 @@ async function fundAccount(deployer, accounts) { } try { - await deployer.executeTx(params); + await tryExecuteTx(deployer, params); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error.text : e); } From 3990eeb43b9fc409f2aae755a55dce717ee93e26 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Tue, 4 Oct 2022 23:03:18 +0530 Subject: [PATCH 02/18] fixes --- examples/bond/scripts/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bond/scripts/deploy.js b/examples/bond/scripts/deploy.js index 6af7e9a9c..2a874b590 100644 --- a/examples/bond/scripts/deploy.js +++ b/examples/bond/scripts/deploy.js @@ -12,7 +12,7 @@ async function run(runtimeEnv, deployer) { type: types.TransactionType.TransferAlgo, sign: types.SignType.SecretKey, fromAccount: masterAccount, - toAccountAddr: managerAcc, + toAccountAddr: managerAcc.addr, amountMicroAlgos: 10e6, payFlags: {}, }, From 60fe0711c81cd3c3c3590fae3ba245a638607832 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:03:31 +0530 Subject: [PATCH 03/18] test fixes --- examples/bond/scripts/run/run.js | 7 ++++--- examples/permissioned-voting/scripts/vote/common.js | 4 ++-- examples/ref-templates/README.md | 10 ---------- examples/ref-templates/scripts/common/common.js | 6 +++--- examples/stateful-counter/scripts/common/common.js | 4 ++-- examples/trampoline/scripts/common/common.js | 4 ++-- examples/unique-nft-asa/scripts/run/common/common.js | 4 ++-- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/examples/bond/scripts/run/run.js b/examples/bond/scripts/run/run.js index 9efa6f4a7..6fe7f3886 100644 --- a/examples/bond/scripts/run/run.js +++ b/examples/bond/scripts/run/run.js @@ -60,9 +60,10 @@ async function run(runtimeEnv, deployer) { // exit buyer from bond, buyer can exit only if maturity period is over // currently set to 240 seconds - await exitBuyer(deployer, account.manager, account.elon, 2, 12); - - await exitBuyer(deployer, account.manager, account.bob, 2, 2); + setTimeout(async () => { + await exitBuyer(deployer, account.manager, account.elon, 2, 12); + await exitBuyer(deployer, account.manager, account.bob, 2, 2); + }, 240000); } module.exports = { default: run }; diff --git a/examples/permissioned-voting/scripts/vote/common.js b/examples/permissioned-voting/scripts/vote/common.js index 607f18415..d6427f0b2 100644 --- a/examples/permissioned-voting/scripts/vote/common.js +++ b/examples/permissioned-voting/scripts/vote/common.js @@ -1,7 +1,7 @@ exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e.error); throw e; diff --git a/examples/ref-templates/README.md b/examples/ref-templates/README.md index f5f397564..4fa618756 100644 --- a/examples/ref-templates/README.md +++ b/examples/ref-templates/README.md @@ -16,13 +16,3 @@ This example is using PyTEAL, so make sure to follow the Python3 setup described To run hash time lock contract or dynamic Fee use the deploy command: yarn run algob deploy - -## Notes - -Default we don't show error when transaction fail. You can change this config follow below command: - -```bash -echo "IGNORE_TX_FAIL=false" > .env -``` - -You can change the IGNORE_TX_FAIL to `true`, script will not show any error when execute a transaction fail. \ No newline at end of file diff --git a/examples/ref-templates/scripts/common/common.js b/examples/ref-templates/scripts/common/common.js index ee2487414..29ced51e7 100644 --- a/examples/ref-templates/scripts/common/common.js +++ b/examples/ref-templates/scripts/common/common.js @@ -3,10 +3,10 @@ require("dotenv").config(); exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { - console.error("Transaction Failed", e.response ? e.response.error : e); + // console.error("Transaction Failed", e.response ? e.response.error : e); throw e; } }; diff --git a/examples/stateful-counter/scripts/common/common.js b/examples/stateful-counter/scripts/common/common.js index d07af1a61..6f727ff47 100644 --- a/examples/stateful-counter/scripts/common/common.js +++ b/examples/stateful-counter/scripts/common/common.js @@ -1,7 +1,7 @@ exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); throw e; diff --git a/examples/trampoline/scripts/common/common.js b/examples/trampoline/scripts/common/common.js index d07af1a61..6f727ff47 100644 --- a/examples/trampoline/scripts/common/common.js +++ b/examples/trampoline/scripts/common/common.js @@ -1,7 +1,7 @@ exports.tryExecuteTx = async function (deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); throw e; diff --git a/examples/unique-nft-asa/scripts/run/common/common.js b/examples/unique-nft-asa/scripts/run/common/common.js index 2a14cce36..7f8edb668 100644 --- a/examples/unique-nft-asa/scripts/run/common/common.js +++ b/examples/unique-nft-asa/scripts/run/common/common.js @@ -2,8 +2,8 @@ const { types } = require("@algo-builder/web"); async function tryExecuteTx(deployer, txnParams) { try { - if (Array.isArray(txnParams)) await deployer.executeTx(txnParams); - else await deployer.executeTx([txnParams]); + const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; + return await deployer.executeTx(txnParameters); } catch (e) { console.error("Transaction Failed", e.response ? e.response.error : e); throw e; From 4e4aa32a618f6882f995397ad316e25d4a6e8442 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:25:49 +0530 Subject: [PATCH 04/18] lint fix --- examples/dao/scripts/run/withdraw_from_proposal.js | 1 - .../permissioned-voting/scripts/vote/result.js | 1 - examples/ref-templates/scripts/common/common.js | 14 +++++++++----- examples/trampoline/scripts/deployApp.js | 1 - examples/trampoline/scripts/run/create-fund-app.js | 1 - 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/dao/scripts/run/withdraw_from_proposal.js b/examples/dao/scripts/run/withdraw_from_proposal.js index 6bebd1b9e..68df865af 100644 --- a/examples/dao/scripts/run/withdraw_from_proposal.js +++ b/examples/dao/scripts/run/withdraw_from_proposal.js @@ -1,5 +1,4 @@ const { tryExecuteTx } = require("./common/common.js"); -const { types } = require("@algo-builder/web"); const { accounts } = require("./common/accounts.js"); const { mkWithdrawFromProposalTx } = require("./common/tx-params.js"); diff --git a/examples/permissioned-voting/scripts/vote/result.js b/examples/permissioned-voting/scripts/vote/result.js index 272f682c7..f2c182008 100644 --- a/examples/permissioned-voting/scripts/vote/result.js +++ b/examples/permissioned-voting/scripts/vote/result.js @@ -1,5 +1,4 @@ const { readAppGlobalState } = require("@algo-builder/algob"); -const { default: deploy } = require("@algo-builder/algob/build/builtin-tasks/deploy"); const { types } = require("@algo-builder/web"); const { tryExecuteTx } = require("./common"); diff --git a/examples/ref-templates/scripts/common/common.js b/examples/ref-templates/scripts/common/common.js index 29ced51e7..1619aef28 100644 --- a/examples/ref-templates/scripts/common/common.js +++ b/examples/ref-templates/scripts/common/common.js @@ -1,17 +1,16 @@ const { types } = require("@algo-builder/web"); -require("dotenv").config(); -exports.tryExecuteTx = async function (deployer, txnParams) { +async function tryExecuteTx(deployer, txnParams) { try { const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; return await deployer.executeTx(txnParameters); } catch (e) { - // console.error("Transaction Failed", e.response ? e.response.error : e); + console.error("Transaction Failed", e.response ? e.response.error : e); throw e; } -}; +} -exports.mkTxnParams = function (senderAccount, receiverAddr, amount, lsig, payFlags) { +function mkTxnParams(senderAccount, receiverAddr, amount, lsig, payFlags) { return { type: types.TransactionType.TransferAlgo, sign: types.SignType.LogicSignature, @@ -21,4 +20,9 @@ exports.mkTxnParams = function (senderAccount, receiverAddr, amount, lsig, payFl lsig: lsig, payFlags: payFlags, }; +} + +module.exports = { + tryExecuteTx, + mkTxnParams, }; diff --git a/examples/trampoline/scripts/deployApp.js b/examples/trampoline/scripts/deployApp.js index 68e0a6e7c..fa1bd7941 100644 --- a/examples/trampoline/scripts/deployApp.js +++ b/examples/trampoline/scripts/deployApp.js @@ -44,7 +44,6 @@ async function run(runtimeEnv, deployer) { }); const appInfo = await deployer.getApp("proxy_trampoline"); - const appID = appInfo.appID; console.log(appInfo); //transfer algo to app proxy diff --git a/examples/trampoline/scripts/run/create-fund-app.js b/examples/trampoline/scripts/run/create-fund-app.js index 48f9ac660..bee020602 100644 --- a/examples/trampoline/scripts/run/create-fund-app.js +++ b/examples/trampoline/scripts/run/create-fund-app.js @@ -11,7 +11,6 @@ const algosdk = require("algosdk"); const { tryExecuteTx } = require("../common/common"); async function run(runtimeEnv, deployer) { - const masterAccount = deployer.accountsByName.get("master-account"); const john = deployer.accountsByName.get("john"); //Get the app that have been created and funded it From 897814970849c75a9688764053cfdf3b18e68913 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:27:31 +0530 Subject: [PATCH 05/18] fund added --- examples/htlc-pyteal-ts/scripts/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/htlc-pyteal-ts/scripts/deploy.ts b/examples/htlc-pyteal-ts/scripts/deploy.ts index eedd06001..66a35e167 100644 --- a/examples/htlc-pyteal-ts/scripts/deploy.ts +++ b/examples/htlc-pyteal-ts/scripts/deploy.ts @@ -26,7 +26,7 @@ async function run( // We need to copy, because the executeTx is async const aliceFunding = Object.assign({}, bobFunding); aliceFunding.toAccountAddr = alice.addr; - aliceFunding.amountMicroAlgos = 0.1e6; // 0.1 Algo + aliceFunding.amountMicroAlgos = 5e6; // 5 Algo await Promise.all([tryExecuteTx(deployer, [bobFunding]), tryExecuteTx(deployer, [aliceFunding])]); /** ** now bob creates and deploys the escrow account ****/ From ce036f59316748a273b62a74628094c6de0fe4c8 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:52:58 +0530 Subject: [PATCH 06/18] funding increased --- examples/htlc-pyteal-ts/scripts/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/htlc-pyteal-ts/scripts/deploy.ts b/examples/htlc-pyteal-ts/scripts/deploy.ts index 66a35e167..b9d075691 100644 --- a/examples/htlc-pyteal-ts/scripts/deploy.ts +++ b/examples/htlc-pyteal-ts/scripts/deploy.ts @@ -37,7 +37,7 @@ async function run( throw error; }); - deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 2e6 }, {}) + deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 5e6 }, {}) // Add user checkpoint deployer.addCheckpointKV("User Checkpoint", "Fund Contract Account"); From 4a99b2630f80a24195f264d38289736aee6befa0 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 6 Oct 2022 16:32:26 +0530 Subject: [PATCH 07/18] fund update --- examples/htlc-pyteal-ts/scripts/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/htlc-pyteal-ts/scripts/deploy.ts b/examples/htlc-pyteal-ts/scripts/deploy.ts index b9d075691..ec8ee81c9 100644 --- a/examples/htlc-pyteal-ts/scripts/deploy.ts +++ b/examples/htlc-pyteal-ts/scripts/deploy.ts @@ -26,7 +26,7 @@ async function run( // We need to copy, because the executeTx is async const aliceFunding = Object.assign({}, bobFunding); aliceFunding.toAccountAddr = alice.addr; - aliceFunding.amountMicroAlgos = 5e6; // 5 Algo + aliceFunding.amountMicroAlgos = 2e6; // 5 Algo await Promise.all([tryExecuteTx(deployer, [bobFunding]), tryExecuteTx(deployer, [aliceFunding])]); /** ** now bob creates and deploys the escrow account ****/ From 4929571ae1c6546afdcc1778b1f5e816088305a9 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Mon, 10 Oct 2022 10:50:34 +0530 Subject: [PATCH 08/18] fix error in ref-templates --- examples/ref-templates/assets/htlc.py | 26 ++++++++++++++------------ examples/ref-templates/scripts/htlc.js | 2 +- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/examples/ref-templates/assets/htlc.py b/examples/ref-templates/assets/htlc.py index 342efd850..815cbdfe6 100644 --- a/examples/ref-templates/assets/htlc.py +++ b/examples/ref-templates/assets/htlc.py @@ -6,12 +6,13 @@ hash_image = "QzYhq9JlYbn2QdOMrhyxVlNtNjeyvyJc/I8d8VAGfGc=" timeout = 2000 + def htlc(ARG_RCV, - ARG_OWN, - ARG_FEE, - ARG_HASHIMG, - ARG_HASHFN, - ARG_TIMEOUT): + ARG_OWN, + ARG_FEE, + ARG_HASHIMG, + ARG_HASHFN, + ARG_TIMEOUT): """This contract implements a "hash time lock". The contract will approve transactions spending algos from itself under two circumstances: @@ -41,16 +42,16 @@ def htlc(ARG_RCV, # Next, check that the Receiver field for this transaction is empty # Because this contract can approve transactions that close out its entire balance, # it should never have a receiver. - rec_field_check = Txn.receiver() == Global.zero_address() + rec_field_check = Txn.receiver() == ARG_RCV # Next, check that the Amount of algos transferred is 0. This is for the same reason as # above: we only allow transactions that close out this account completely, which # having a non-zero-address CloseRemainderTo will handle for us. amount_check = Txn.amount() == Int(0) - # Always verify that the RekeyTo property of any transaction is set to the ZeroAddress + # Always verify that the RekeyTo property of any transaction is set to the receiver addr # unless the contract is specifically involved ina rekeying operation. - rekey_check = Txn.rekey_to() == Global.zero_address() + rekey_check = Txn.rekey_to() == Txn.receiver() # fold all the above checks into a single boolean. common_checks = And( @@ -73,10 +74,9 @@ def htlc(ARG_RCV, # Next, we will check that arg_0 is the correct preimage for ARG_HASHIMG under ARG_HASHFN. preimage_check = ARG_HASHFN(Arg(0)) == Bytes("base64", ARG_HASHIMG) - #Fold the "Scenario 1" checks into a single boolean. + # Fold the "Scenario 1" checks into a single boolean. scenario_1 = And(recv_field_check, preimage_check) - # Scenario 2: Contract has timed out # First, check that the CloseRemainderTo field is set to be the ARG_OWN address # (presumably initialized to be the original owner of the funds). @@ -85,7 +85,7 @@ def htlc(ARG_RCV, # Next, check that this transaction has only occurred after the ARG_TIMEOUT round. timeout_check = Txn.first_valid() > Int(ARG_TIMEOUT) - #Fold the "Scenario 2" checks into a single boolean. + # Fold the "Scenario 2" checks into a single boolean. scenario_2 = And(owner_field_check, timeout_check) # At this point in the program's execution, the stack has three values. At the base of the @@ -99,6 +99,8 @@ def htlc(ARG_RCV, # whether or not it has been approved by this contract. return And(Or(scenario_1, scenario_2), common_checks) + optimize_options = OptimizeOptions(scratch_slots=True) if __name__ == "__main__": - print(compileTeal(htlc(john, master, fee, hash_image, Sha256, timeout), Mode.Signature, version = 5, optimize=optimize_options)) + print(compileTeal(htlc(john, master, fee, hash_image, Sha256, timeout), + Mode.Signature, version=5, optimize=optimize_options)) diff --git a/examples/ref-templates/scripts/htlc.js b/examples/ref-templates/scripts/htlc.js index 4ce6c9905..cc670a344 100644 --- a/examples/ref-templates/scripts/htlc.js +++ b/examples/ref-templates/scripts/htlc.js @@ -39,7 +39,7 @@ async function run(runtimeEnv, deployer) { txnParams.fromAccountAddr = contractAddress; txnParams.sign = types.SignType.LogicSignature; txnParams.args = [convert.stringToBytes(wrongSecret)]; - txnParams.toAccountAddr = globalZeroAddress; + txnParams.toAccountAddr = john.addr; txnParams.amountMicroAlgos = 0; txnParams.lsig = contract; txnParams.payFlags = { totalFee: 1000, closeRemainderTo: john.addr }; From b6acd4f5e34da7b53ba168dc2a56e5a3ec1acfbd Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Mon, 17 Oct 2022 14:41:51 +0530 Subject: [PATCH 09/18] test fixes --- examples/htlc-pyteal-ts/scripts/deploy.ts | 2 +- examples/ref-templates/assets/htlc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/htlc-pyteal-ts/scripts/deploy.ts b/examples/htlc-pyteal-ts/scripts/deploy.ts index ec8ee81c9..7f74face4 100644 --- a/examples/htlc-pyteal-ts/scripts/deploy.ts +++ b/examples/htlc-pyteal-ts/scripts/deploy.ts @@ -37,7 +37,7 @@ async function run( throw error; }); - deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 5e6 }, {}) + await deployer.fundLsig("HTLC_Lsig", { funder: bob, fundingMicroAlgo: 5e6 }, {}) // Add user checkpoint deployer.addCheckpointKV("User Checkpoint", "Fund Contract Account"); diff --git a/examples/ref-templates/assets/htlc.py b/examples/ref-templates/assets/htlc.py index 815cbdfe6..886ef270a 100644 --- a/examples/ref-templates/assets/htlc.py +++ b/examples/ref-templates/assets/htlc.py @@ -51,7 +51,7 @@ def htlc(ARG_RCV, # Always verify that the RekeyTo property of any transaction is set to the receiver addr # unless the contract is specifically involved ina rekeying operation. - rekey_check = Txn.rekey_to() == Txn.receiver() + rekey_check = Txn.rekey_to() == Global.zero_address() # fold all the above checks into a single boolean. common_checks = And( From c4e616921fe43b13dc4ac68c07eefa62c57a5528 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:00:56 +0530 Subject: [PATCH 10/18] fix multisig test --- examples/multisig/scripts/multisig_goal_sc.js | 8 ++++---- examples/multisig/scripts/multisig_sdk_sc.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/multisig/scripts/multisig_goal_sc.js b/examples/multisig/scripts/multisig_goal_sc.js index 8be5e3ec0..3011cde3f 100644 --- a/examples/multisig/scripts/multisig_goal_sc.js +++ b/examples/multisig/scripts/multisig_goal_sc.js @@ -25,7 +25,7 @@ async function run(runtimeEnv, deployer) { fromAccount: masterAccount, toAccountAddr: multisigAddr, amountMicroAlgos: 10000000, - payFlags: { note: "Funding multisig account", totalFee: 500 }, // totalFee will be converted to 1000 as it is minimum required transaction fee + payFlags: { note: "Funding multisig account", totalFee: 1000 }, }; // Funding multisignature account @@ -56,9 +56,9 @@ async function run(runtimeEnv, deployer) { // Transaction PASSES await tryExecuteTx(deployer, txnParams); - // Transaction FAIL - according to teal logic, amount should be <= 100 - txnParams.amountMicroAlgos = 200; - await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); + // // Transaction FAIL - according to teal logic, amount should be <= 100 + // txnParams.amountMicroAlgos = 200; + // await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); } module.exports = { default: run }; diff --git a/examples/multisig/scripts/multisig_sdk_sc.js b/examples/multisig/scripts/multisig_sdk_sc.js index 1e809d788..9debd93df 100644 --- a/examples/multisig/scripts/multisig_sdk_sc.js +++ b/examples/multisig/scripts/multisig_sdk_sc.js @@ -38,7 +38,7 @@ async function run(runtimeEnv, deployer) { }; // Funding multisignature account await tryExecuteTx(deployer, txnParams); - txnParams = bob.addr; + txnParams.fromAccount = bob; await tryExecuteTx(deployer, txnParams); // fund bob await deployer.addCheckpointKV("User Checkpoint", "Fund Multisignature Account"); From 50d03ca075663902d9f516fefa1f626b6027e66d Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 20 Oct 2022 08:38:39 +0530 Subject: [PATCH 11/18] fixed multisi --- examples/multisig/scripts/multisig_goal_sc.js | 6 +++--- packages/algob/src/internal/deployer.ts | 7 ++++++- packages/algob/src/lib/tx.ts | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/multisig/scripts/multisig_goal_sc.js b/examples/multisig/scripts/multisig_goal_sc.js index 3011cde3f..85ce3eb79 100644 --- a/examples/multisig/scripts/multisig_goal_sc.js +++ b/examples/multisig/scripts/multisig_goal_sc.js @@ -56,9 +56,9 @@ async function run(runtimeEnv, deployer) { // Transaction PASSES await tryExecuteTx(deployer, txnParams); - // // Transaction FAIL - according to teal logic, amount should be <= 100 - // txnParams.amountMicroAlgos = 200; - // await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); + // Transaction FAIL - according to teal logic, amount should be <= 100 + txnParams.amountMicroAlgos = 200; + await tryExecuteTx(deployer, txnParams).catch((error) => console.log(error)); } module.exports = { default: run }; diff --git a/packages/algob/src/internal/deployer.ts b/packages/algob/src/internal/deployer.ts index 8404f17b4..7ce967b40 100644 --- a/packages/algob/src/internal/deployer.ts +++ b/packages/algob/src/internal/deployer.ts @@ -526,7 +526,12 @@ class DeployerBasicMode { break; } case wtypes.SignType.LogicSignature: { - signer.lsig.lsig.args = signer.args ?? []; + if (signer?.lsig?.lsig?.args) { + signer.lsig.lsig.args = signer.args ?? []; + } else { + (signer.lsig as any).args = signer.args ?? []; // args property didn't exist in earlier version of API (for reference: see the multisig example) + } + decodedResult = algosdk.signLogicSigTransactionObject(transaction, signer.lsig).blob; break; } diff --git a/packages/algob/src/lib/tx.ts b/packages/algob/src/lib/tx.ts index 1d0c8818a..b574c9811 100644 --- a/packages/algob/src/lib/tx.ts +++ b/packages/algob/src/lib/tx.ts @@ -100,7 +100,12 @@ function signTransaction(txn: Transaction, signer: wtypes.Sign): Uint8Array { return txn.signTxn(signer.fromAccount.sk); } case wtypes.SignType.LogicSignature: { - signer.lsig.lsig.args = signer.args ?? []; + if (signer?.lsig?.lsig?.args) { + signer.lsig.lsig.args = signer.args ?? []; + } else { + (signer.lsig as any).args = signer.args ?? []; // args property didn't exist in earlier version of API (for reference: see the multisig example) + } + return algosdk.signLogicSigTransactionObject(txn, signer.lsig).blob; } default: { From 66c5985111651a8600af0faf0fd8dc7959acc066 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 20 Oct 2022 08:59:58 +0530 Subject: [PATCH 12/18] fix permissioned token --- examples/permissioned-token/scripts/admin/kill.js | 5 +++-- examples/permissioned-token/scripts/user/opt-out.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/permissioned-token/scripts/admin/kill.js b/examples/permissioned-token/scripts/admin/kill.js index 0b6de7020..6d2ebafaf 100644 --- a/examples/permissioned-token/scripts/admin/kill.js +++ b/examples/permissioned-token/scripts/admin/kill.js @@ -35,9 +35,10 @@ async function run(runtimeEnv, deployer) { const elon = deployer.accountsByName.get("elon-musk"); await fundAccount(deployer, elon); // fund elon + // (in scripts flow we already issue the tokens before kill, so uncomment if another sequence is followed) // transaction pass (issue 15 tokens to elon) - await deployer.optInAccountToASA("tesla", elon.name, {}); - await issue(deployer, elon.addr, 15); + // await deployer.optInAccountToASA("tesla", elon.name, {}); + // await issue(deployer, elon.addr, 15); await kill(deployer); // kill token 'tesla' diff --git a/examples/permissioned-token/scripts/user/opt-out.js b/examples/permissioned-token/scripts/user/opt-out.js index b3231eab3..02af01219 100644 --- a/examples/permissioned-token/scripts/user/opt-out.js +++ b/examples/permissioned-token/scripts/user/opt-out.js @@ -43,8 +43,8 @@ async function run(runtimeEnv, deployer) { // opt in elon to tesla first await deployer.optInAccountToASA("tesla", elon.name, {}); - // first issue few tokens to elon - await issue(deployer, elon.addr, 15); // issue(mint) 15 tokens to elon from reserve + // first issue few tokens to elon (in scripts flow we already kill the tesla token before running opt-out, so uncomment if running it in another sequence) + // await issue(deployer, elon.addr, 15); // issue(mint) 15 tokens to elon from reserve /* * Use below function to opt-out elon from token tesla From 32fed8c1a11cdf7a99f7aeaeeb0ec093e9d65bb6 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 20 Oct 2022 09:07:14 +0530 Subject: [PATCH 13/18] lint fix --- examples/permissioned-token/scripts/user/opt-out.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/permissioned-token/scripts/user/opt-out.js b/examples/permissioned-token/scripts/user/opt-out.js index 02af01219..1b7c24f50 100644 --- a/examples/permissioned-token/scripts/user/opt-out.js +++ b/examples/permissioned-token/scripts/user/opt-out.js @@ -43,7 +43,9 @@ async function run(runtimeEnv, deployer) { // opt in elon to tesla first await deployer.optInAccountToASA("tesla", elon.name, {}); - // first issue few tokens to elon (in scripts flow we already kill the tesla token before running opt-out, so uncomment if running it in another sequence) + // in scripts flow we kill the tesla token before executing opt-out, + // uncomment if running it in another sequence + // first issue few tokens to elon // await issue(deployer, elon.addr, 15); // issue(mint) 15 tokens to elon from reserve /* From f574ccfd09abdbaca2cbfcfeeb842c56b4944057 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Wed, 26 Oct 2022 01:51:32 +0530 Subject: [PATCH 14/18] added description --- examples/bond/scripts/run/common/common.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/bond/scripts/run/common/common.js b/examples/bond/scripts/run/common/common.js index 98dc6c129..62dacb72a 100644 --- a/examples/bond/scripts/run/common/common.js +++ b/examples/bond/scripts/run/common/common.js @@ -21,6 +21,12 @@ const asaDef = { const tokenMap = new Map(); +/** + * Execute single transaction or group of transactions (atomic transaction) + * @param deployer deployer instance + * @param transactions transaction parameters, atomic transaction parameters + * @returns TxnReceipt which includes confirmed txn response along with txID + */ async function tryExecuteTx(deployer, txnParams) { try { const txnParameters = Array.isArray(txnParams) ? txnParams : [txnParams]; From 6d4011c115cd089eae786b95624eb9f00f4d8ffc Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 27 Oct 2022 20:34:40 +0530 Subject: [PATCH 15/18] remove catch --- examples/bond/scripts/run/createBuyback.js | 7 ++----- examples/bond/scripts/run/createDex.js | 4 +--- examples/bond/scripts/run/exit.js | 7 ++----- examples/bond/scripts/run/redeem.js | 4 +--- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/examples/bond/scripts/run/createBuyback.js b/examples/bond/scripts/run/createBuyback.js index 33a483833..dd6c33d80 100644 --- a/examples/bond/scripts/run/createBuyback.js +++ b/examples/bond/scripts/run/createBuyback.js @@ -17,11 +17,8 @@ exports.createBuyback = async function (deployer, managerAcc, n) { TMPL_APP_MANAGER: managerAcc.addr, TMPL_BOND: bondToken, }; - const buybackLsig = await deployer - .loadLogicByFile("buyback-lsig.py", scInitParam) - .catch((error) => { - throw error; - }); + const buybackLsig = await deployer.loadLogicByFile("buyback-lsig.py", scInitParam); + await fundAccount(deployer, buybackLsig.address()); const buybackTx = [ diff --git a/examples/bond/scripts/run/createDex.js b/examples/bond/scripts/run/createDex.js index a0b467daf..ce129a15c 100644 --- a/examples/bond/scripts/run/createDex.js +++ b/examples/bond/scripts/run/createDex.js @@ -55,9 +55,7 @@ exports.createDex = async function (deployer, creatorAccount, managerAcc, i) { TMPL_APPLICATION_ID: appInfo.appID, TMPL_APP_MANAGER: managerAcc.addr, }; - const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", lsigParams).catch((error) => { - throw error; - }); + const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", lsigParams); await fundAccount(deployer, dexLsig.address()); diff --git a/examples/bond/scripts/run/exit.js b/examples/bond/scripts/run/exit.js index 7788c9af8..9e0cdef3f 100644 --- a/examples/bond/scripts/run/exit.js +++ b/examples/bond/scripts/run/exit.js @@ -17,11 +17,8 @@ exports.exitBuyer = async function (deployer, managerAcc, buyerAccount, n, amoun TMPL_APP_MANAGER: managerAcc.addr, TMPL_BOND: bondToken, }; - const buybackLsig = await deployer - .loadLogicByFile("buyback-lsig.py", scInitParam) - .catch((error) => { - throw error; - }); + const buybackLsig = await deployer.loadLogicByFile("buyback-lsig.py", scInitParam); + const exitAmount = Number(amount) * Number(nominalPrice); const exitTx = [ // Bond token transfer to buyback address diff --git a/examples/bond/scripts/run/redeem.js b/examples/bond/scripts/run/redeem.js index ba0aef6c7..47fa383fc 100644 --- a/examples/bond/scripts/run/redeem.js +++ b/examples/bond/scripts/run/redeem.js @@ -19,9 +19,7 @@ exports.redeem = async function (deployer, buyerAccount, managerAcc, dex, amount TMPL_APPLICATION_ID: appInfo.appID, TMPL_APP_MANAGER: managerAcc.addr, }; - const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", scInitParam).catch((error) => { - throw error; - }); + const dexLsig = await deployer.loadLogicByFile("dex-lsig.py", scInitParam); await deployer.optInAccountToASA(newBond, buyerAccount.name, {}).catch((error) => { throw error; }); From 15e8adf785660aebb806728b8738360762a01060 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Thu, 27 Oct 2022 20:38:50 +0530 Subject: [PATCH 16/18] format fix --- examples/trampoline/scripts/deployApp.js | 3 +-- examples/unique-nft-asa/scripts/0-deploy-app.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/trampoline/scripts/deployApp.js b/examples/trampoline/scripts/deployApp.js index fa1bd7941..ffb15d038 100644 --- a/examples/trampoline/scripts/deployApp.js +++ b/examples/trampoline/scripts/deployApp.js @@ -24,8 +24,7 @@ async function run(runtimeEnv, deployer) { await tryExecuteTx(deployer, algoTxnParams); // execute Create app transaction - await deployer - .deployApp( + await deployer.deployApp( john, { appName: "proxy_trampoline", diff --git a/examples/unique-nft-asa/scripts/0-deploy-app.js b/examples/unique-nft-asa/scripts/0-deploy-app.js index ce849097d..2eecd71a4 100644 --- a/examples/unique-nft-asa/scripts/0-deploy-app.js +++ b/examples/unique-nft-asa/scripts/0-deploy-app.js @@ -8,8 +8,7 @@ async function run(runtimeEnv, deployer) { await fundAccount(deployer, [creator]); // Create App - const nftAppInfo = await deployer - .deployApp( + const nftAppInfo = await deployer.deployApp( creator, { appName: "NftApp", From b743971ae1e8eaf9360a3dd8d62544341f912b87 Mon Sep 17 00:00:00 2001 From: Megha-Dev-19 <100185149+Megha-Dev-19@users.noreply.github.com> Date: Fri, 28 Oct 2022 09:23:21 +0530 Subject: [PATCH 17/18] Update examples/asa/scripts/3-contract-owned-asa.js Co-authored-by: sczembor <43810037+sczembor@users.noreply.github.com> --- examples/asa/scripts/3-contract-owned-asa.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/asa/scripts/3-contract-owned-asa.js b/examples/asa/scripts/3-contract-owned-asa.js index b1d8347a0..febabc1eb 100644 --- a/examples/asa/scripts/3-contract-owned-asa.js +++ b/examples/asa/scripts/3-contract-owned-asa.js @@ -44,7 +44,7 @@ async function run(runtimeEnv, deployer) { // Get Statless Account Address await deployer - .mkContractLsig("StateLessASALsig", "5-contract-asa-stateless.py", { + .mkContractLsig("StatelessASALsig", "5-contract-asa-stateless.py", { APP_ID: appInfo.appID, }) .catch((error) => { From ea9af1837c6e658493fd2376faab73859071e669 Mon Sep 17 00:00:00 2001 From: MEGHA <100185149+Megha-Dev-19@users.noreply.github.com> Date: Fri, 28 Oct 2022 09:29:36 +0530 Subject: [PATCH 18/18] fix name --- examples/asa/scripts/3-contract-owned-asa.js | 4 ++-- .../scripts/transfer/contract-owned-asa/contract-to-alice.js | 2 +- .../scripts/transfer/contract-owned-asa/contract-to-bob.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/asa/scripts/3-contract-owned-asa.js b/examples/asa/scripts/3-contract-owned-asa.js index b1d8347a0..6a7145958 100644 --- a/examples/asa/scripts/3-contract-owned-asa.js +++ b/examples/asa/scripts/3-contract-owned-asa.js @@ -44,13 +44,13 @@ async function run(runtimeEnv, deployer) { // Get Statless Account Address await deployer - .mkContractLsig("StateLessASALsig", "5-contract-asa-stateless.py", { + .mkContractLsig("StatelessASALsig", "5-contract-asa-stateless.py", { APP_ID: appInfo.appID, }) .catch((error) => { throw error; }); - const statelessAccount = deployer.getLsig("StateLessASALsig"); + const statelessAccount = deployer.getLsig("StatelessASALsig"); console.log("stateless Account Address:", statelessAccount.address()); await tryExecuteTx( diff --git a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js index 54a846093..32727148f 100644 --- a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js +++ b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-alice.js @@ -20,7 +20,7 @@ async function run(runtimeEnv, deployer) { // Get AppInfo and AssetID from checkpoints. const appInfo = deployer.getApp("StatefulASA_App"); - const lsig = deployer.getLsig("StateLessASALsig"); + const lsig = deployer.getLsig("StatelessASALsig"); /* Transfer ASA 'gold' from contract account to user account */ const assetID = deployer.asa.get("platinum").assetIndex; diff --git a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js index e7abd065d..a1eeae1c5 100644 --- a/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js +++ b/examples/asa/scripts/transfer/contract-owned-asa/contract-to-bob.js @@ -16,7 +16,7 @@ async function run(runtimeEnv, deployer) { await tryExecuteTx(deployer, mkParam(masterAccount, bob.addr, 5e6, { note: "Funding" })); // Get AppInfo and AssetID from checkpoints. const appInfo = deployer.getApp("StatefulASA_App"); - const lsig = deployer.getLsig("StateLessASALsig"); + const lsig = deployer.getLsig("StatelessASALsig"); /* Transfer ASA 'gold' from contract account to user account */ const assetID = deployer.asa.get("platinum").assetIndex;