import { Web3Client } from './web3.client' ; import { EncodedTransaction , Account } from 'web3/types' ; /**
 *
 */ export default class Contract { protected contract : any ; param web3 param address param abi constructor ( private web3client , private web3 , private abi , private address ? ) { this . contract = new this . web3 . eth . Contract ( this . abi , this . address ) ; } param params async deploy ( params , account ) { const contract = new this . web3 . eth . Contract ( this . abi ) ; const deploy = contract . deploy ( { data : params . byteCode , arguments : params . constructorArguments } ) ; const txInput = { from : account . address , to : null , amount : '0' , gas : params . gas || ( await deploy . estimateGas ( ) + 300000 ) , gasPrice : params . gasPrice , data : deploy . encodeABI ( ) } ; return this . web3client . signTransactionByAccount ( txInput , account ) ; } param params async executeMethod ( params , account ) { const method = this . contract . methods [ params . methodName ] ( ... params . arguments ) ; const txInput = { from : account . address , to : this . address , amount : params . amount , gas : params . gas || ( await method . estimateGas ( { from : account . address } ) + 50000 ) , gasPrice : params . gasPrice , data : method . encodeABI ( ) } ; return this . web3client . signTransactionByAccount ( txInput , account ) ; } param params queryMethod ( params ) { const method = this . contract . methods [ params . methodName ] ( ... params . arguments ) ; return method . call ( ) ; } onEvent ( name ) { return this . contract . events [ name ] ( ) ; } } TODO export class DummyContract extends Contract { protected contract : any ; param web3 param address param abi constructor ( ) { super ( null , { eth : { Contract : function ( ) { } } } , null , '' ) ; } param params async deploy ( params , account ) { return { } as EncodedTransaction ; } param params async executeMethod ( params , account ) { return { } as EncodedTransaction ; } param params queryMethod ( params ) { return Promise . resolve ( { } ) ; } onEvent ( name ) { return Promise . resolve ( { } ) ; } }