|
| 1 | +import * as wasm from './wasm'; |
| 2 | +import { asJsonString } from './util'; |
| 3 | + |
| 4 | +export class ContractsFacade { |
| 5 | + private _sdk: wasm.WasmSdk; |
| 6 | + |
| 7 | + constructor(sdk: wasm.WasmSdk) { |
| 8 | + this._sdk = sdk; |
| 9 | + } |
| 10 | + |
| 11 | + fetch(contractId: string): Promise<wasm.DataContractWasm> { |
| 12 | + return wasm.data_contract_fetch(this._sdk, contractId); |
| 13 | + } |
| 14 | + |
| 15 | + fetchWithProof(contractId: string): Promise<any> { |
| 16 | + return wasm.data_contract_fetch_with_proof_info(this._sdk, contractId); |
| 17 | + } |
| 18 | + |
| 19 | + getHistory(args: { contractId: string; limit?: number; startAtMs?: number | bigint }): Promise<any> { |
| 20 | + const { contractId, limit, startAtMs } = args; |
| 21 | + return wasm.get_data_contract_history(this._sdk, contractId, limit ?? null, null, startAtMs ?? null); |
| 22 | + } |
| 23 | + |
| 24 | + getHistoryWithProof(args: { contractId: string; limit?: number; startAtMs?: number | bigint }): Promise<any> { |
| 25 | + const { contractId, limit, startAtMs } = args; |
| 26 | + return wasm.get_data_contract_history_with_proof_info(this._sdk, contractId, limit ?? null, null, startAtMs ?? null); |
| 27 | + } |
| 28 | + |
| 29 | + getMany(contractIds: string[]): Promise<any> { |
| 30 | + return wasm.get_data_contracts(this._sdk, contractIds); |
| 31 | + } |
| 32 | + |
| 33 | + getManyWithProof(contractIds: string[]): Promise<any> { |
| 34 | + return wasm.get_data_contracts_with_proof_info(this._sdk, contractIds); |
| 35 | + } |
| 36 | + |
| 37 | + create(args: { ownerId: string; definition: unknown; privateKeyWif: string; keyId?: number }): Promise<any> { |
| 38 | + const { ownerId, definition, privateKeyWif, keyId } = args; |
| 39 | + return this._sdk.contractCreate(ownerId, asJsonString(definition)!, privateKeyWif, keyId ?? null); |
| 40 | + } |
| 41 | + |
| 42 | + update(args: { contractId: string; ownerId: string; updates: unknown; privateKeyWif: string; keyId?: number }): Promise<any> { |
| 43 | + const { contractId, ownerId, updates, privateKeyWif, keyId } = args; |
| 44 | + return this._sdk.contractUpdate(contractId, ownerId, asJsonString(updates)!, privateKeyWif, keyId ?? null); |
| 45 | + } |
| 46 | +} |
0 commit comments