import { Method , Query , Receipt , Transaction } from "." ; import { Provider } from "./provider" ; import { Result } from "./result" ; import { CheckResult } from "./types" ; export class Client { name : string ; filePath : string ; provider : Provider ; constructor ( name , filePath , provider ) { this . name = name ; this . filePath = filePath ; this . provider = provider ; } checkContract = async ( ) : Promise < void > => { const checkResult = await this . provider . checkContract ( this . filePath ) ; if ( ! checkResult . success ) { throw new Error ( checkResult . error ) ; } } ; deployContract = async ( ) : Promise < Receipt > => { const receipt = await this . provider . launchContract ( this . name , this . filePath ) ; return receipt ; } ; createTransaction = ( params ? ) : Transaction => { const tx = new Transaction ( params && params . method ) ; return tx ; } ; submitTransaction = async ( tx ) : Promise < Receipt > => { if ( ! tx . sender ) { throw new Error ( "Transaction should have `sender` property" ) ; } if ( ! tx . method ) { throw new Error ( "Transaction should have `method` property" ) ; } let receipt ; try { receipt = await this . provider . execute ( this . name , tx . method . name , tx . sender , ... tx . method . args ) ; } catch ( error ) { receipt = { success : false , error : error } ; } return receipt ; } ; createQuery = ( params ) : Query => { const query = new Query ( params . method , params . atChaintip ) ; return query ; } ; submitQuery = async ( query ) : Promise < Receipt > => { if ( ! query . method ) { throw new Error ( "Query should target a method" ) ; } const res = await this . provider . eval ( this . name , `(${ query . method . name } ${ query . method . args . join ( " " ) })` , true , query . atChaintip ) ; return res ; } ; }