Skip to content

Commit

Permalink
update runtime.updateApp, deployer.updateApp, Changelog (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
ratik21 authored Dec 21, 2021
1 parent aca0901 commit 09844ac
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 23 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
const appID = receipt.appID;
```
+ `getProgram` is moved to `@algo-builder/runtime` from `@algo-builder/algob`.
+ `runtime.addAsset`, `runtime.addAssetDef` and `runtime.addApp` are deprecated.
+ `runtime.addAsset`, `runtime.addAssetDef` and `runtime.addApp` are deprecated.
Please use `runtime.deployASA`, `runtime.deployASADef` and `runtime.deployAdd` instead of the above functions.
+ Update `runtime.deloyApp` to be compatible with `deployer.deployApp`.
+ `balanceOf` in `@algo-builder/algob` package now return amount (number) of asset account holding and won't print them. If the account does not hold an asset it will return 0. To query asset holding, please use a new `@algo-builder/web.status.getAssetHolding` function.
+ Updated `deployer.deployApp` to pass `scTmplParams` (smart contract template parameters).
### Bug Fixes
+ Fix bug substring3 opcode pop wrong order [/#505](https://github.com/scale-it/algo-builder/pull/505), contribution: @vuvth.
Expand Down
12 changes: 9 additions & 3 deletions packages/algob/src/internal/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ export class DeployerDeployMode extends DeployerBasicMode implements Deployer {
* @param newApprovalProgram New Approval Program filename
* @param newClearProgram New Clear Program filename
* @param flags Optional parameters to SSC (accounts, args..)
* @param scTmplParams: scTmplParams: Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
* @param appName name of the app to deploy. This name (if passed) will be used as
* the checkpoint "key", and app information will be stored agaisnt this name
*/
Expand All @@ -700,6 +702,7 @@ export class DeployerDeployMode extends DeployerBasicMode implements Deployer {
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags,
scTmplParams?: SCParams,
appName?: string
): Promise<rtypes.SSCInfo> {
this.assertCPNotDeleted({
Expand All @@ -716,7 +719,7 @@ export class DeployerDeployMode extends DeployerBasicMode implements Deployer {
let sscInfo = {} as rtypes.SSCInfo;
try {
sscInfo = await this.algoOp.updateApp(sender, payFlags, appID,
newApprovalProgram, newClearProgram, flags, this.txWriter);
newApprovalProgram, newClearProgram, flags, this.txWriter, scTmplParams);
} catch (error) {
this.persistCP();

Expand Down Expand Up @@ -827,14 +830,17 @@ export class DeployerRunMode extends DeployerBasicMode implements Deployer {
* @param newApprovalProgram new approval program name
* @param newClearProgram new clear program name
* @param flags SSC optional flags
* @param scTmplParams: scTmplParams: Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
async updateApp (
sender: algosdk.Account,
payFlags: wtypes.TxParams,
appID: number,
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags
flags: rtypes.AppOptionalFlags,
scTmplParams?: SCParams
): Promise<rtypes.SSCInfo> {
this.assertCPNotDeleted({
type: wtypes.TransactionType.UpdateApp,
Expand All @@ -848,7 +854,7 @@ export class DeployerRunMode extends DeployerBasicMode implements Deployer {
return await this.algoOp.updateApp(
sender, payFlags, appID,
newApprovalProgram, newClearProgram,
flags, this.txWriter
flags, this.txWriter, scTmplParams
);
}
}
13 changes: 9 additions & 4 deletions packages/algob/src/lib/algo-operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export interface AlgoOperator {
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags,
txWriter: txWriter
txWriter: txWriter,
scTmplParams?: SCParams
) => Promise<rtypes.SSCInfo>
waitForConfirmation: (txId: string) => Promise<ConfirmedTxInfo>
getAssetByID: (assetIndex: number | bigint) => Promise<modelsv2.Asset>
Expand Down Expand Up @@ -372,6 +373,9 @@ export class AlgoOperatorImpl implements AlgoOperator {
* @param newApprovalProgram New Approval Program filename
* @param newClearProgram New Clear Program filename
* @param flags Optional parameters to SSC (accounts, args..)
* @param txWriter - transaction log writer
* @param scTmplParams: scTmplParams: Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
*/
async updateApp (
sender: algosdk.Account,
Expand All @@ -380,13 +384,14 @@ export class AlgoOperatorImpl implements AlgoOperator {
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags,
txWriter: txWriter
txWriter: txWriter,
scTmplParams?: SCParams
): Promise<rtypes.SSCInfo> {
const params = await mkTxParams(this.algodClient, payFlags);

const app = await this.ensureCompiled(newApprovalProgram, false);
const app = await this.ensureCompiled(newApprovalProgram, false, scTmplParams);
const approvalProg = new Uint8Array(Buffer.from(app.compiled, "base64"));
const clear = await this.ensureCompiled(newClearProgram, false);
const clear = await this.ensureCompiled(newClearProgram, false, scTmplParams);
const clearProg = new Uint8Array(Buffer.from(clear.compiled, "base64"));

const execParam: wtypes.ExecParams = {
Expand Down
3 changes: 3 additions & 0 deletions packages/algob/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ export interface Deployer {
* @param newApprovalProgram New Approval Program filename
* @param newClearProgram New Clear Program filename
* @param flags Optional parameters to SSC (accounts, args..)
* @param scTmplParams: scTmplParams: Smart contract template parameters
* (used only when compiling PyTEAL to TEAL)
* @param appName name of the app to deploy. This name (if passed) will be used as
* the checkpoint "key", and app information will be stored agaisnt this name
*/
Expand All @@ -561,6 +563,7 @@ export interface Deployer {
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags,
scTmplParams?: SCParams,
appName?: string
) => Promise<rtypes.SSCInfo>

Expand Down
2 changes: 1 addition & 1 deletion packages/algob/test/internal/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe("DeployerDeployMode", () => {
});

const updatedInfo = await deployer.updateApp(
deployer.accounts[0], {}, 33, "app", "clear", {}, "my-app");
deployer.accounts[0], {}, 33, "app", "clear", {}, {}, "my-app");
assert.deepEqual(updatedInfo,
{
creator: "addr-1-get-address-dry-run",
Expand Down
4 changes: 3 additions & 1 deletion packages/algob/test/mocks/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type {
Deployer,
FundASCFlags,
LogicSig,
LsigInfo
LsigInfo,
SCParams
} from "../../src/types";

export class FakeDeployer implements Deployer {
Expand Down Expand Up @@ -159,6 +160,7 @@ export class FakeDeployer implements Deployer {
newApprovalProgram: string,
newClearProgram: string,
flags: rtypes.AppOptionalFlags,
scTmplParams?: SCParams,
appName?: string
): Promise<rtypes.SSCInfo> {
throw new Error("Not implemented");
Expand Down
28 changes: 20 additions & 8 deletions packages/runtime/src/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,32 @@ export class Ctx implements Context {
/**
* Update application
* @param appID application Id
* @param approvalProgram new approval program
* @param clearProgram new clear program
* NOTE - approval and clear program must be the TEAL code as string
* @param approvalProgram new approval program (TEAL code or program filename)
* @param clearProgram new clear program (TEAL code or program filename)
* @param idx index of transaction in group
* @param scTmplParams Smart Contract template parameters
*/
updateApp (
appID: number,
approvalProgram: string,
clearProgram: string,
idx: number
idx: number,
scTmplParams?: SCParams
): TxReceipt {
if (approvalProgram === "") {
const approvalProgTEAL =
(approvalProgram.endsWith(tealExt) || approvalProgram.endsWith(pyExt))
? getProgram(approvalProgram, scTmplParams)
: approvalProgram;

const clearProgTEAL =
(clearProgram.endsWith(tealExt) || clearProgram.endsWith(pyExt))
? getProgram(clearProgram, scTmplParams)
: clearProgram;

if (approvalProgTEAL === "") {
throw new RuntimeError(RUNTIME_ERRORS.GENERAL.INVALID_APPROVAL_PROGRAM);
}
if (clearProgram === "") {
if (clearProgTEAL === "") {
throw new RuntimeError(RUNTIME_ERRORS.GENERAL.INVALID_CLEAR_PROGRAM);
}

Expand All @@ -558,8 +570,8 @@ export class Ctx implements Context {
this.runtime.run(appParams[APPROVAL_PROGRAM], ExecutionMode.APPLICATION, idx, this.debugStack);

const updatedApp = this.getApp(appID);
updatedApp[APPROVAL_PROGRAM] = approvalProgram;
updatedApp["clear-state-program"] = clearProgram;
updatedApp[APPROVAL_PROGRAM] = approvalProgTEAL;
updatedApp["clear-state-program"] = clearProgTEAL;
return txReceipt;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,13 +602,12 @@ export class Runtime {
* Update application
* @param senderAddr sender address
* @param appID application Id
* @param approvalProgram new approval program
* @param clearProgram new clear program
* @param approvalProgram new approval program (TEAL code or program filename)
* @param clearProgram new clear program (TEAL code or program filename)
* @param payFlags Transaction parameters
* @param flags Stateful smart contract transaction optional parameters (accounts, args..)
* @param debugStack: if passed then TEAL Stack is logged to console after
* each opcode execution (upto depth = debugStack)
* NOTE - approval and clear program must be the TEAL code as string
*/
updateApp (
senderAddr: string,
Expand All @@ -617,11 +616,12 @@ export class Runtime {
clearProgram: string,
payFlags: types.TxParams,
flags: AppOptionalFlags,
scTmplParams?: SCParams,
debugStack?: number
): TxReceipt {
this.addCtxAppUpdateTx(senderAddr, appID, payFlags, flags);
this.ctx.debugStack = debugStack;
const txReceipt = this.ctx.updateApp(appID, approvalProgram, clearProgram, 0);
const txReceipt = this.ctx.updateApp(appID, approvalProgram, clearProgram, 0, scTmplParams);

// If successful, Update programs and state
this.store = this.ctx.state;
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ export interface Context {
approvalProgram: string, clearProgram: string, idx: number, scTmplParams?: SCParams
) => DeployedAppTxReceipt
optInToApp: (accountAddr: string, appID: number, idx: number) => TxReceipt
updateApp: (appID: number, approvalProgram: string, clearProgram: string, idx: number) => TxReceipt
updateApp: (appID: number, approvalProgram: string,
clearProgram: string, idx: number, scTmplParams?: SCParams) => TxReceipt
}

// custom AssetHolding for AccountStore (using bigint in amount instead of number)
Expand Down

0 comments on commit 09844ac

Please sign in to comment.