import { SmartContract } from "../../smart-contract/contract"; import { Core } from "../core/core"; import { ContractId } from "../core/types"; import { SupportedParamType, bsv } from "scryptlib"; /** A options can be used to subscribe */ export interface SubscribeOptions { /** Contract id */ id: ContractId; /** Contract typescript class */ clazz: new (...args: any) => T; /** Use `methodNames` to specify that only receive events when specific methods are called. The default is to notify when all methods are called */ methodNames?: Array; } /** SubScription can be used to unsubscribe */ export interface SubScription { unsubscribe: () => void; } /** * ContractCalledEvent is the relevant information when the contract is called, such as the public function name and function arguments when the call occurs. */ export interface ContractCalledEvent { /** * If a stateful contract is called, `nexts` contains the contract instance containing the new state generated by this call. * If a stateless contract is called, `nexts` is empty. */ nexts: Array; /** name of public function */ methodName: string; /** public function arguments */ args: SupportedParamType[]; /** transaction where contract is called */ tx: bsv.Transaction; } export declare class ContractApi { private readonly _core; constructor(_core: Core); /** @ignore */ syncHashedProps(instance: T): Promise; /** * Get a contract instance containing the latest state of the contract by the contract ID. * The obtained contract instance may also be obtained by other users at the same time. * If other users call this contract instance. Then the contract instance will be invalid. * At this time, calling the contract will cause a `txn-mempool-conflict` error (that is, UTXO double spending). * If this error occurs, you need to re-acquire the contract instance * @param clazz * @param contractId * @returns a contract instance contains latest state */ getLatestInstance(clazz: new (...args: any) => T, contractId: ContractId): Promise; /** * Subscribe to notifications of contract status changes by contract ID, * @param options SubscribeOptions * @param cb * @returns a SubScription, which can be used to unsubscribe */ subscribe(options: SubscribeOptions, cb: (e: ContractCalledEvent) => void): SubScription; }