author liangqin.fan gmail import { ReturnCode , seal_call } from "as-contract-runtime" ; import { ReadBuffer } from "../primitives/readbuffer" ; import { WriteBuffer } from "../primitives/writebuffer" ; import { UInt128 , UInt64 } from "as-scale-codec" ; import { u128 } from "as-bignum" ; export class Callable { private _callee : u8 [ ] | null = null ; private _gas : UInt64 | null = null ; private _value : UInt128 | null = null ; private _data : u8 [ ] | null = null ; private _outBuffer : ReadBuffer | null = null ; constructor ( callee ) { this . _callee = callee ; } gas ( g ) { this . _gas = new UInt64 ( g ) ; return this ; } value ( v ) { this . _value = new UInt128 ( v ) ; return this ; } data ( d ) { this . _data = d ; return this ; } callResult ( ) { if ( this . _outBuffer === null ) return [ ] ; return this . _outBuffer ! . valueBytes ; } call ( ) { assert ( this . _callee !== null , "callee not set" ) ; assert ( this . _gas !== null , "gas not set" ) ; const callee = new WriteBuffer ( this . _callee ! ) ; let value = null ; if ( this . _value === null ) { value = new WriteBuffer ( [ 0 ] ) ; } else { value = new WriteBuffer ( this . _value ! . toU8a ( ) ) ; } const data = new WriteBuffer ( this . _data ! ) ; this . _outBuffer = new ReadBuffer ( ) ; const ret = seal_call ( callee . buffer , callee . size , this . _gas ! . unwrap ( ) , value . buffer , value . size , data . buffer , data . size , this . _outBuffer ! . valueBuffer , this . _outBuffer ! . sizeBuffer ) ; return ret ; } }