Skip to content

Commit

Permalink
fix: throw error if the param being passed to ctx.contract.create fun…
Browse files Browse the repository at this point in the history
…ction is not detected to be a contract
  • Loading branch information
boblat committed Jan 16, 2025
1 parent 84fee20 commit 3793c4f
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 3793c4f

Please sign in to comment.