import Fixed64 from '../common/fixed64' ; import { NATIVE_INVOKE_NAME } from '../consts' ; import { Address } from '../crypto' ; import { num2hexstring , str2hexstr } from '../utils' ; import OPCODE from './opcode' ; import InvokeCode from './payload/invokeCode' ; import { pushHexString } from './program' ; import { pushInt } from './scriptBuilder' ; import { Transaction , TxType } from './transaction' ; import { Transfer } from './transfer' ; param funcName param params param contractAddr param gasPrice param gasLimit param payer export function makeNativeContractTx ( funcName , params , contractAddr , gasPrice ? , gasLimit ? , payer ? ) { let code = '' ; code += params ; code += pushHexString ( str2hexstr ( funcName ) ) ; code += pushHexString ( contractAddr . serialize ( ) ) ; code += pushInt ( 0 ) ; code += num2hexstring ( OPCODE . SYSCALL ) ; code += pushHexString ( str2hexstr ( NATIVE_INVOKE_NAME ) ) ; const payload = new InvokeCode ( ) ; payload . code = code ; let tx ; if ( [ 'transfer' , 'transferV2' , 'transferFrom' , 'transferFromV2' ] . includes ( funcName ) ) { tx = new Transfer ( ) ; } else { tx = new Transaction ( ) ; } tx . type = TxType . Invoke ; tx . payload = payload ; if ( gasLimit ) { tx . gasLimit = new Fixed64 ( gasLimit ) ; } if ( gasPrice ) { tx . gasPrice = new Fixed64 ( gasPrice ) ; } if ( payer ) { tx . payer = payer ; } return tx ; }