@broxus/js-core
Version:
MobX-based JavaScript Core library
85 lines (84 loc) • 3.84 kB
TypeScript
import { type Address, type FullContractState, type ProviderApiResponse, type ProviderRpcClient, type Subscriber } from 'everscale-inpage-provider';
import { AbstractStore } from '../AbstractStore';
import { type Forceable, type ObjectLiteral } from '../types';
export interface SmartContractModelData {
computedStorageData?: ProviderApiResponse<'computeStorageFee'>;
contractState?: FullContractState;
}
export interface SmartContractModelState {
isSyncing?: boolean;
syncedAt?: number;
}
export type SmartContractWatchCallback<T extends SmartContractModelData | ObjectLiteral = SmartContractModelData, U extends SmartContractModelState | ObjectLiteral = SmartContractModelState> = (data: SmartContractModelData & T, state: SmartContractModelState & U) => void;
interface SyncContractStateOptions extends Forceable {
ttl?: number;
}
export declare abstract class SmartContractModel<T extends SmartContractModelData | ObjectLiteral = SmartContractModelData, U extends SmartContractModelState | ObjectLiteral = SmartContractModelState> extends AbstractStore<SmartContractModelData & T, SmartContractModelState & U> {
protected readonly _connection: ProviderRpcClient;
private readonly _address;
protected contractSubscriber?: Subscriber;
/**
* @param {ProviderRpcClient} _connection
* Standalone RPC client that doesn't require connection to the TVM wallet provider
* @param {Address | string} address
* Contract address
* @protected
*/
protected constructor(_connection: ProviderRpcClient, address: Address | string);
get address(): Address;
get computedStorageData(): SmartContractModelData['computedStorageData'] | undefined;
/**
* **Get the full contract state.**
*
* This computed property returns the full contract state after synchronizing the contract state.
* @returns {SmartContractModelData["contractState"]}
*/
get contractState(): SmartContractModelData['contractState'];
get isSyncing(): SmartContractModelState['isSyncing'];
get syncedAt(): SmartContractModelState['syncedAt'];
/**
* **Check if the contract is deployed.**
*
* This computed property returns whether the contract is deployed on the blockchain.
* It checks the `isDeployed` property of the full contract state after synchronizing the contract state.
*
* @returns {boolean | undefined}
*/
get isDeployed(): FullContractState['isDeployed'] | undefined;
/**
* **Synchronize full contract state.**
*
* This method fetches the full contract state from the blockchain.
*
* @param {SyncContractStateOptions} options
* @returns {Promise<FullContractState | undefined>}
*/
syncContractState(options?: SyncContractStateOptions): Promise<FullContractState | undefined>;
/**
* **Synchronize computed storage data.**
*
* This method fetches the computed storage data for the contract.
*
* @returns {Promise<void>}
* @protected
*/
protected syncComputedStorageData(): Promise<void>;
/**
* **Watch contract state onchain changes.**
*
* This method is used to subscribe to the contract state changes.
*
* @template {SmartContractModelData} T
* @template {SmartContractModelState} U
* @param {((data?: T, state?: U) => void)} [callback]
* Callback function that will be called on state changes.
* It receives the current data and state as arguments.
*
* @returns {Promise<Subscriber>}
* Returns a promise that resolves to a Subscriber instance.
* The subscriber can be used to unsubscribe from the contract state changes.
*/
watch?(callback?: SmartContractWatchCallback<T, U>): Promise<Subscriber>;
unwatch?(): Promise<void>;
}
export {};