src/action.js
/**
     * Run a smart contract work flow.
     * - use waitBalanceChange() instead of callback to check if tx is finalised, as tx callback function won't response in time.
     */
Run a smart contract work flow.
- use waitBalanceChange() instead of callback to check if tx is finalised, as tx callback function won't response in time.
Run a smart contract work flow . - use waitBalanceChange () instead of callback to check if tx is finalised as tx callback function won ' t response in time .
async _playSmartContract(){
        let retMsg = this.resultMsg
        const contractWasmFilePath = __dirname + '/../files/spin2win.wasm'
        const contractJsonFilePath = __dirname + '/../files/spin2win.json'
        const currContractHash = '0x1adcb2e5becd80a4250534bd43e4f172a33ffcac5590e9777665677ebfc58285'
        const seqNo = 10000000 + this.iterationNum
        const issuerSeed = `${addressListFrom[this.userId]}_${seqNo}`
        const destSeed =  `${addressListTo[this.userId]}_${seqNo}`
        const gasLimit = '50000'
        const endowment = '10000000000000000000'
        const transferValue = '1'
        let   txSucc = null
        this.transaction_start('transfer_topup')
        const seedFrom = endowedSeedLst[topupIndex++ % endowedSeedLst.length]
        const topupAmt = '20000000000000000000'
        let transferResult =  transfer( seedFrom, issuerSeed, topupAmt, true);
        await waitBalanceChange(issuerSeed)
        this.transaction_end('transfer_topup', true)
        this.transaction_start('putCode')
        txSucc = smc.putCode(issuerSeed, gasLimit, contractWasmFilePath)
        await waitBalanceChange(issuerSeed)
        this.transaction_end('putCode', true)
        this.transaction_start('createContract')
        smc.createContract(issuerSeed, endowment, gasLimit, currContractHash, contractJsonFilePath)
        await waitBalanceChange(issuerSeed)
        this.transaction_end('createContract', true)
        this.transaction_start('callContract')
        smc.callContract(issuerSeed, destSeed, transferValue, gasLimit)
        await waitBalanceChange(destSeed)
        this.transaction_end('callContract', true)
        return retMsg
    }
async _playSmartContract ( ) { let retMsg = this . resultMsg const contractWasmFilePath = __dirname + '/../files/spin2win.wasm' const contractJsonFilePath = __dirname + '/../files/spin2win.json' const currContractHash = '0x1adcb2e5becd80a4250534bd43e4f172a33ffcac5590e9777665677ebfc58285' const seqNo = 10000000 + this . iterationNum const issuerSeed = ` ${ addressListFrom [ this . userId ] } ${ seqNo } ` const destSeed = ` ${ addressListTo [ this . userId ] } ${ seqNo } ` const gasLimit = '50000' const endowment = '10000000000000000000' const transferValue = '1' let txSucc = null this . transaction_start ( 'transfer_topup' ) const seedFrom = endowedSeedLst [ topupIndex ++ % endowedSeedLst . length ] const topupAmt = '20000000000000000000' let transferResult = transfer ( seedFrom , issuerSeed , topupAmt , true ) ; await waitBalanceChange ( issuerSeed ) this . transaction_end ( 'transfer_topup' , true ) this . transaction_start ( 'putCode' ) txSucc = smc . putCode ( issuerSeed , gasLimit , contractWasmFilePath ) await waitBalanceChange ( issuerSeed ) this . transaction_end ( 'putCode' , true ) this . transaction_start ( 'createContract' ) smc . createContract ( issuerSeed , endowment , gasLimit , currContractHash , contractJsonFilePath ) await waitBalanceChange ( issuerSeed ) this . transaction_end ( 'createContract' , true ) this . transaction_start ( 'callContract' ) smc . callContract ( issuerSeed , destSeed , transferValue , gasLimit ) await waitBalanceChange ( destSeed ) this . transaction_end ( 'callContract' , true ) return retMsg }
Run a smart contract work flow.
Run a smart contract work flow .
// generate seed. For each iteration, contract needs different issuer to prevent dupliate error. // let   currContractHash = '' /**
         * Step - 0: Topup issuer account
         */ // if ( !transferResult.bSucc ){ //     this.transaction_end('transfer_topup', false) //     retMsg.bSucc = false //     retMsg.message = `Top up from [${seedFrom}] to [${issuerSeed}] with amount [${endowment}] failed: ${transferResult.message}` //     return retMsg // } /**
         * Step - 1: Deploy contract
         */ // if ( currContractHash.length <= 0 ){ //     this.transaction_end('putCode', false) //     retMsg.bSucc = false //     retMsg.message = 'Smart contract putCode() failed.' //     return retMsg // } /**
         * Step - 2: Create contract instance
         */ // if ( txSucc == false ){ //     retMsg.bSucc = false //     retMsg.message = 'Smart contract createContract() failed.' //     return retMsg // } /**
         * Step - 3: Call contract
         */ // if ( txSucc == false ){ //     retMsg.bSucc = false //     retMsg.message = 'Smart contract callContract() failed.' //     return retMsg // }