4.1 链下智能合约
智能合约采用sCrypt提供的比特币智能合约高级语言编写,以确保索引验证器在有限时间内完成执行。此外,支持包括Swap、Oracle和零知识证明在内的高级用例。
以下是一个简单的链下合约示例:
export class N20_Sample extends SmartContract {
@prop()
readonly tick: ByteString
@prop()
readonly max: bigint
@prop()
readonly lim: bigint
@prop()
readonly dec: bigint
constructor(tick: ByteString, max: bigint, lim: bigint, dec: bigint) {
super(...arguments)
this.tick = tick
this.max = max
this.lim = lim
this.dec = dec
}
@method()
public mint(tick: ByteString, amt: bigint) {
assert(tick == this.tick, 'Tick does not match')
assert(amt <= this.lim, 'Amount check failed')
}
@method()
public transfer(tick: ByteString, amt: bigint) {
assert(tick == this.tick, 'Tick does not match')
assert(amt <= this.lim, 'Amount check failed')
}
}