Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use addr for address template vars #510

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading