import { createCodeParamsScript } from '../../transaction/scriptBuilder' ; import { Transaction } from '../../transaction/transaction' ; import { str2hexstr } from '../../utils' ; import { Address } from './../../crypto/address' ; import { makeInvokeTransaction } from './../../transaction/transactionBuilder' ; import { Parameter , ParameterType } from './../abi/parameter' ; export class Oep5Param { public toAcct : string ; public tokenId : string ; public constructor ( toAcct , tokenId ) { this . toAcct = toAcct . serialize ( ) ; this . tokenId = tokenId ; } } const FunctionNames = { Init : 'init' , Name : 'name' , Symbol : 'symbol' , TotalSupply : 'totalSupply' , BalanceOf : 'balanceOf' , OwnerOf : 'ownerOf' , Transfer : 'transfer' , TransferMulti : 'transferMulti' , Approve : 'approve' , ApproveMulti : 'approveMulti' , TakeOwnership : 'takeOwnership' , QueryTokenIDByIndex : 'queryTokenIDByIndex' , QueryTokenByID : 'queryTokenByID' , GetApproved : 'getApproved' , CreateMultiTokens : 'createMultiTokens' , CreateOneToken : 'createOneToken' } ; export class Oep5TxBuilder { contractAddr : Address ; constructor ( contractAddr ) { this . contractAddr = contractAddr ; } makeInitTx ( gasPrice , gasLimit , payer ) { const func = FunctionNames . Init ; return makeInvokeTransaction ( func , [ ] , this . contractAddr , gasPrice , gasLimit , payer ) ; } makeOwnerOfTx ( tokenId ) { const func = FunctionNames . OwnerOf ; const params = [ new Parameter ( 'tokenId' , ParameterType . ByteArray , tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr ) ; } param oep5Param param gasPrice param gasLimit param payer makeTransferTx ( oep5Param , gasPrice , gasLimit , payer ) { const func = FunctionNames . Transfer ; const params = [ new Parameter ( 'toAcct' , ParameterType . ByteArray , oep5Param . toAcct ) , new Parameter ( 'tokenId' , ParameterType . ByteArray , oep5Param . tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr , gasPrice , gasLimit , payer ) ; } /**
     * Transfer the control to multi people
     */ makeTransferMultiTx ( oep5Params , gasPrice , gasLimit , payer ) { const list = [ ] ; list . push ( str2hexstr ( FunctionNames . TransferMulti ) ) ; const temp = [ ] ; for ( const param of oep5Params ) { temp . push ( [ param . toAcct , param . tokenId ] ) ; } list . push ( temp ) ; const params = createCodeParamsScript ( list ) ; return makeInvokeTransaction ( '' , params , this . contractAddr , gasPrice , gasLimit , payer ) ; } param oep5Param param gasPrice param gasLimit param payer makeApproveTx ( oep5Param , gasPrice , gasLimit , payer ) { const func = FunctionNames . Approve ; const params = [ new Parameter ( 'toAcct' , ParameterType . ByteArray , oep5Param . toAcct ) , new Parameter ( 'tokenId' , ParameterType . ByteArray , oep5Param . tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr , gasPrice , gasLimit , payer ) ; } param oep5Param param gasPrice param gasLimit param payer makeTakeOwnershipTx ( oep5Param , gasPrice , gasLimit , payer ) { const func = FunctionNames . TakeOwnership ; const params = [ new Parameter ( 'toAcct' , ParameterType . ByteArray , oep5Param . toAcct ) , new Parameter ( 'tokenId' , ParameterType . ByteArray , oep5Param . tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr , gasPrice , gasLimit , payer ) ; } makeQueryBalanceOfTx ( addr ) { const func = FunctionNames . BalanceOf ; const params = [ new Parameter ( 'addr' , ParameterType . ByteArray , addr . serialize ( ) ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr ) ; } makeQueryTotalSupplyTx ( ) { const func = FunctionNames . TotalSupply ; return makeInvokeTransaction ( func , [ ] , this . contractAddr ) ; } makeQueryTokenIDByIndexTx ( index ) { const func = FunctionNames . QueryTokenIDByIndex ; const params = [ new Parameter ( 'index' , ParameterType . Long , index ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr ) ; } makeQueryTokenByIDTx ( tokenId ) { const func = FunctionNames . QueryTokenByID ; const params = [ new Parameter ( 'tokenId' , ParameterType . ByteArray , tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr ) ; } makeGetApprovedTx ( tokenId ) { const func = FunctionNames . GetApproved ; const params = [ new Parameter ( 'tokenId' , ParameterType . ByteArray , tokenId ) ] ; return makeInvokeTransaction ( func , params , this . contractAddr ) ; } makeQueryNameTx ( ) { const func = FunctionNames . Name ; return makeInvokeTransaction ( func , [ ] , this . contractAddr ) ; } makeQuerySymbolTx ( ) { const func = FunctionNames . Symbol ; return makeInvokeTransaction ( func , [ ] , this . contractAddr ) ; } }