import { Address } from '../../crypto' ; import AbiInfo from '../../smartcontract/abi/abiInfo' ; import { Parameter , ParameterType } from '../../smartcontract/abi/parameter' ; import { makeInvokeTransaction } from '../../transaction/transactionBuilder' ; import { reverseHex , str2hexstr } from '../../utils' ; import { Transaction } from './../../transaction/transaction' ; import abiJson from '../data/attestClaim' ; const abiInfo = AbiInfo . parseJson ( JSON . stringify ( abiJson ) ) ; const contractHash = abiInfo . getHash ( ) . replace ( '0x' , '' ) ; const contractAddress = new Address ( reverseHex ( contractHash ) ) ; param claimId param issuer param subject param gasPrice param gasLimit param payer export function buildCommitRecordTx ( claimId , issuer , subject , gasPrice , gasLimit , payer ) { const f = abiInfo . getFunction ( 'Commit' ) ; if ( issuer . substr ( 0 , 3 ) === 'did' ) { issuer = str2hexstr ( issuer ) ; } if ( subject . substr ( 0 , 3 ) === 'did' ) { subject = str2hexstr ( issuer ) ; } const p1 = new Parameter ( f . parameters [ 0 ] . getName ( ) , ParameterType . ByteArray , str2hexstr ( claimId ) ) ; const p2 = new Parameter ( f . parameters [ 1 ] . getName ( ) , ParameterType . ByteArray , issuer ) ; const p3 = new Parameter ( f . parameters [ 2 ] . getName ( ) , ParameterType . ByteArray , subject ) ; let tx = new Transaction ( ) ; tx = makeInvokeTransaction ( f . name , [ p1 , p2 , p3 ] , contractAddress , gasPrice , gasLimit , payer ) ; return tx ; } param claimId param revokerOntid param gasPrice param gasLimit param payer export function buildRevokeRecordTx ( claimId , revokerOntid , gasPrice , gasLimit , payer ) { const f = abiInfo . getFunction ( 'Revoke' ) ; const name1 = f . parameters [ 0 ] . getName ( ) ; const type1 = ParameterType . ByteArray ; if ( revokerOntid . substr ( 0 , 3 ) === 'did' ) { revokerOntid = str2hexstr ( revokerOntid ) ; } const p1 = new Parameter ( name1 , type1 , str2hexstr ( claimId ) ) ; const p2 = new Parameter ( f . parameters [ 1 ] . getName ( ) , ParameterType . ByteArray , revokerOntid ) ; return makeInvokeTransaction ( f . name , [ p1 , p2 ] , contractAddress , gasPrice , gasLimit , payer ) ; } param claimId export function buildGetRecordStatusTx ( claimId ) { const f = abiInfo . getFunction ( 'GetStatus' ) ; const p1 = new Parameter ( f . parameters [ 0 ] . getName ( ) , ParameterType . ByteArray , str2hexstr ( claimId ) ) ; const tx = makeInvokeTransaction ( f . name , [ p1 ] , contractAddress ) ; return tx ; }