import { smartwalletallowance } from "@koinosbox/contracts"; import { authority, System, Protobuf, StringBytes } from "@koinos/sdk-as"; export class SmartWalletAllowance { _contractId: Uint8Array; /** * Create an instance of a SmartWalletAllowance contract * @example * ```ts * const contract = new SmartWalletAllowance(Base58.decode("1DQzuCcTKacbs9GGScFTU1Hc8BsyARTPqe")); * ``` */ constructor(contractId: Uint8Array) { this._contractId = contractId; } /** * Set an allowance in user's contract * @external */ set_allowance(args: smartwalletallowance.allowance): void { const argsBuffer = Protobuf.encode(args, smartwalletallowance.allowance.encode); const callRes = System.call(this._contractId, 0xb1569611, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'SmartWalletAllowance.set_allowance': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } return; } /** * Authorize function * @external */ authorize(args: authority.authorize_arguments): authority.authorize_result { const argsBuffer = Protobuf.encode(args, authority.authorize_arguments.encode); const callRes = System.call(this._contractId, 0x4a2dbd90, argsBuffer); if (callRes.code != 0) { const errorMessage = `failed to call 'SmartWalletAllowance.authorize': ${callRes.res.error && callRes.res.error!.message ? callRes.res.error!.message : "unknown error"}`; System.exit(callRes.code, StringBytes.stringToBytes(errorMessage)); } if (!callRes.res.object) return new authority.authorize_result(); return Protobuf.decode(callRes.res.object, authority.authorize_result.decode); } }