import { Address } from '../../crypto' ; import { makeNativeContractTx } from '../../transaction/transactionUtils' ; import { hex2VarBytes , str2hexstr , varifyPositiveInt } from '../../utils' ; import { buildNativeCodeScript } from '../abi/nativeVmParamsBuilder' ; import Struct from '../abi/struct' ; import { Transaction } from './../../transaction/transaction' ; /**
 * Address of auth contract.
 */ export const AUTH_CONTRACT = '0000000000000000000000000000000000000006' ; const contractAddress = new Address ( AUTH_CONTRACT ) ; param adminOntId param payer param gasPrice param gasLimit export function makeInitContractAdminTx ( adminOntId , payer , gasPrice , gasLimit ) { if ( adminOntId . substr ( 0 , 3 ) === 'did' ) { adminOntId = str2hexstr ( adminOntId ) ; } const params = hex2VarBytes ( adminOntId ) ; const tx = makeNativeContractTx ( 'initContractAdmin' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param newAdminOntid param keyNo param payer param gasPrice param gasLimit export function makeTransferAuthTx ( contractAddr , newAdminOntid , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; if ( newAdminOntid . substr ( 0 , 3 ) === 'did' ) { newAdminOntid = str2hexstr ( newAdminOntid ) ; } const struct = new Struct ( ) ; struct . add ( contractAddress . serialize ( ) , newAdminOntid , keyNo ) ; const list = [ struct ] ; const params = buildNativeCodeScript ( list ) ; const tx = makeNativeContractTx ( 'transfer' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param callerOntId param funcName param keyNo param payer param gasPrice param gasLimit export function makeVerifyTokenTx ( contractAddr , callerOntId , funcName , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; if ( callerOntId . substr ( 0 , 3 ) === 'did' ) { callerOntId = str2hexstr ( callerOntId ) ; } const struct = new Struct ( ) ; struct . add ( contractAddr . serialize ( ) , callerOntId , str2hexstr ( funcName ) , keyNo ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( 'verifyToken' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param adminOntId param role param funcNames param keyNo param payer param gasPrice param gasLimit export function makeAssignFuncsToRoleTx ( contractAddr , adminOntId , role , funcNames , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; if ( adminOntId . substr ( 0 , 3 ) === 'did' ) { adminOntId = str2hexstr ( adminOntId ) ; } const struct = new Struct ( ) ; struct . add ( contractAddr . serialize ( ) , adminOntId , str2hexstr ( role ) , funcNames . length ) ; for ( const f of funcNames ) { struct . add ( str2hexstr ( f ) ) ; } struct . add ( keyNo ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( 'assignFuncsToRole' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param adminOntId param role param ontIds param keyNo param payer param gasPrice param gasLimit export function makeAssignOntIdsToRoleTx ( contractAddr , adminOntId , role , ontIds , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; if ( adminOntId . substr ( 0 , 3 ) === 'did' ) { adminOntId = str2hexstr ( adminOntId ) ; } const struct = new Struct ( ) ; struct . add ( contractAddr . serialize ( ) , adminOntId , str2hexstr ( role ) , ontIds . length ) ; for ( const i of ontIds ) { if ( i . substr ( 0 , 3 ) === 'did' ) { struct . add ( str2hexstr ( i ) ) ; } else { struct . add ( i ) ; } } struct . add ( keyNo ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( 'assignOntIDsToRole' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param from param to param role param period param level param keyNo param payer param gasPrice param gasLimit export function makeDelegateRoleTx ( contractAddr , from , to , role , period , level = 1 , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; varifyPositiveInt ( period ) ; if ( from . substr ( 0 , 3 ) === 'did' ) { from = str2hexstr ( from ) ; } if ( to . substr ( 0 , 3 ) === 'did' ) { to = str2hexstr ( to ) ; } const struct = new Struct ( ) ; struct . add ( contractAddr . serialize ( ) , from , to , str2hexstr ( role ) , period , level , keyNo ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( 'delegate' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param contractAddr param initiator param delegate param role param keyNo param payer param gasPrice param gasLimit export function makeWithdrawRoleTx ( contractAddr , initiator , delegate , role , keyNo , payer , gasPrice , gasLimit ) { varifyPositiveInt ( keyNo ) ; if ( initiator . substr ( 0 , 3 ) === 'did' ) { initiator = str2hexstr ( initiator ) ; } if ( delegate . substr ( 0 , 3 ) === 'did' ) { delegate = str2hexstr ( delegate ) ; } const struct = new Struct ( ) ; struct . add ( contractAddr . serialize ( ) , initiator , delegate , str2hexstr ( role ) , keyNo ) ; const params = buildNativeCodeScript ( [ struct ] ) ; const tx = makeNativeContractTx ( 'withdraw' , params , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; }