Skip to content

Commit

Permalink
Merge pull request #510 from algorandfoundation/feat/addr_tmpl
Browse files Browse the repository at this point in the history
feat: use addr for address template vars
  • Loading branch information
joe-p authored Jul 8, 2024
2 parents d8f63c1 + b4bf852 commit 3a6d5c9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 71 deletions.
2 changes: 1 addition & 1 deletion examples/reti/artifacts/StakingPool.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@ getFeeSink:

// examples/reti/stakingPool.algo.ts:956
// return this.feeSinkAddr;
pushbytes TMPL_feeSinkAddr
addr TMPL_feeSinkAddr
retsub

// algoSaturationLevel(): uint64
Expand Down
2 changes: 1 addition & 1 deletion examples/reti/artifacts/StakingPool.arc32.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/reti/artifacts/StakingPool.arc56_draft.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/lib/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5871,6 +5871,8 @@ export default class Compiler {
const { type, name } = this.templateVars[chain[0].getNameNode().getText()];
if (isNumeric(type)) {
this.push(chain[0], `pushint TMPL_${name}`, type);
} else if (type.kind === 'base' && type.type === 'address') {
this.push(chain[0], `addr TMPL_${name}`, type);
} else {
this.push(chain[0], `pushbytes TMPL_${name}`, type);
}
Expand Down Expand Up @@ -7320,17 +7322,17 @@ declare type AssetFreezeTxn = Required<AssetFreezeParams>;
.map((t) => t.teal)
.map((t) => {
// Replace template variables
if (t.match(/push(int|bytes) TMPL_/)) {
if (t.trim().match(/^push(int|bytes) TMPL_/) || t.trim().startsWith('addr TMPL_')) {
const [opcode, arg] = t.trim().split(' ');
if (opcode === 'pushint') return 'pushint 0';

const tVar = Object.values(this.templateVars).find((v) => v.name === arg.replace(/^TMPL_/, ''));

if (tVar === undefined) throw Error(`Could not find template variable ${arg}`);

if (this.isDynamicType(tVar.type)) return 'byte 0x';
if (this.isDynamicType(tVar.type)) return 'pushbytes 0x';

return `byte 0x${'00'.repeat(this.getTypeLength(tVar.type))}`;
return `pushbytes 0x${'00'.repeat(this.getTypeLength(tVar.type))}`;
}

// Remove comments to avoid taking up space in the request body
Expand Down
Loading

0 comments on commit 3a6d5c9

Please sign in to comment.