Skip to content

Commit

Permalink
Feature: Add support loadLogic for *.teal program and SCParam (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeena840 authored Oct 3, 2022
1 parent 66e7f1f commit 842f94c
Show file tree
Hide file tree
Showing 6 changed files with 581 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Features, Bug Fixes, API Breaking, Deprecated, Infrastructure, Template Updates
- Changed default sample project license to ISC
- Fix `txn AssetSender` should return zero address by default.
- Add unit tests for all transaction types in runtime executeTx.
- Add support loadLogic for *.teal program and SCParam.

#### Examples

Expand Down
11 changes: 7 additions & 4 deletions packages/runtime/src/lib/load-program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { ASSETS_DIR, PyCompileOp, pyExt, tealExt } from "./pycompile-op";
/**
* returns program TEAL code.
* @param fileName filename in /assets. Must end with .teal OR .py
* @param scInitParam smart contract template parameters, used to set hardcoded values in .py smart contract.
* (used only when compiling PyTEAL to TEAL)
* @param scInitParam smart contract template parameters, used to set hardcoded values
* in .py or .teal smart contract.
* @param logs only show logs on console when set as true. By default this value is true
*/
export function getProgram(fileName: string, scInitParam?: SCParams, logs = true): string {
Expand All @@ -19,9 +19,12 @@ export function getProgram(fileName: string, scInitParam?: SCParams, logs = true
throw new Error(`filename "${fileName}" must end with "${tealExt}" or "${pyExt}"`);
}

const pyOp = new PyCompileOp();
if (fileName.endsWith(pyExt)) {
const pyOp = new PyCompileOp();
return pyOp.ensurePyTEALCompiled(fileName, scInitParam, logs);
} else {
// teal
const [replaceParams] = pyOp.parseScTmplParam(scInitParam, logs);
return pyOp.replaceTempValues(program, replaceParams);
}
return program;
}
Loading

0 comments on commit 842f94c

Please sign in to comment.