Skip to content

Commit

Permalink
Merge pull request #34 from algorandfoundation/fix/is-arc4
Browse files Browse the repository at this point in the history
fix: throw error if the param being passed to ctx.contract.create function is not detected to be a contract
  • Loading branch information
boblat authored Jan 16, 2025
2 parents 84fee20 + 3793c4f commit 777faa0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/subcontexts/contract-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,20 @@ export class ContractContext {
}

private isArc4<T extends BaseContract>(type: IConstructor<T>): boolean {
// TODO: uncomment the following line once version puya-ts 1.0.0 is released
// return (type as DeliberateAny as typeof BaseContract).isArc4 ?? false

const result = (type as DeliberateAny as typeof BaseContract).isArc4
if (result !== undefined && result !== null) {
return result
}
// TODO: uncomment the following line once version puya-ts 1.0.0 is released and delete the rest of the function
// throw new internal.errors.CodeError('Cannot create a contract for class as it does not extend Contract or BaseContract')

const proto = Object.getPrototypeOf(type)
if (proto === BaseContract) {
return false
} else if (proto === Contract) {
return true
} else if (proto === null) {
return false
} else if (proto === Object || proto === null) {
throw new internal.errors.CodeError('Cannot create a contract for class as it does not extend Contract or BaseContract')
}
return this.isArc4(proto)
}
Expand Down

0 comments on commit 777faa0

Please sign in to comment.