From 93c5606f2ad3ef49060cd580a49358393e4291ac Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 28 Mar 2018 17:12:49 +0200 Subject: [PATCH 1/5] remove udapp argument and replace it by a needed callback "callbackDeployLibrary" --- remix-lib/src/execution/txFormat.js | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/remix-lib/src/execution/txFormat.js b/remix-lib/src/execution/txFormat.js index 7d6ee341c2..493e676ee8 100644 --- a/remix-lib/src/execution/txFormat.js +++ b/remix-lib/src/execution/txFormat.js @@ -40,11 +40,11 @@ module.exports = { * @param {Bool} isConstructor - isConstructor. * @param {Object} funAbi - abi definition of the function to call. null if building data for the ctor. * @param {Object} params - input paramater of the function to call - * @param {Object} udapp - udapp * @param {Function} callback - callback * @param {Function} callbackStep - callbackStep + * @param {Function} callbackDeployLibrary - callbackDeployLibrary */ - buildData: function (contractName, contract, contracts, isConstructor, funAbi, params, udapp, callback, callbackStep) { + buildData: function (contractName, contract, contracts, isConstructor, funAbi, params, callback, callbackStep, callbackDeployLibrary) { var funArgs = '' var data = '' var dataHex = '' @@ -83,7 +83,7 @@ module.exports = { contractBytecode = contract.evm.bytecode.object var bytecodeToDeploy = contract.evm.bytecode.object if (bytecodeToDeploy.indexOf('_') >= 0) { - this.linkBytecode(contract, contracts, udapp, (err, bytecode) => { + this.linkBytecode(contract, contracts, (err, bytecode) => { if (err) { callback('Error deploying required libraries: ' + err) } else { @@ -103,12 +103,12 @@ module.exports = { atAddress: function () {}, - linkBytecodeStandard: function (contract, contracts, udapp, callback, callbackStep) { + linkBytecodeStandard: function (contract, contracts, callback, callbackStep, callbackDeployLibrary) { asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences, (libs, file, cbFile) => { asyncJS.eachOfSeries(contract.evm.bytecode.linkReferences[file], (libRef, libName, cbLibDeployed) => { var library = contracts[file][libName] if (library) { - this.deployLibrary(file + ':' + libName, libName, library, contracts, udapp, (error, address) => { + this.deployLibrary(file + ':' + libName, libName, library, contracts, (error, address) => { if (error) { return cbLibDeployed(error) } @@ -118,7 +118,7 @@ module.exports = { } contract.evm.bytecode.object = this.linkLibraryStandard(libName, hexAddress, contract) cbLibDeployed() - }, callbackStep) + }, callbackStep, callbackDeployLibrary) } else { cbLibDeployed('Cannot find compilation data of library ' + libName) } @@ -133,7 +133,7 @@ module.exports = { }) }, - linkBytecodeLegacy: function (contract, contracts, udapp, callback, callbackStep) { + linkBytecodeLegacy: function (contract, contracts, callback, callbackStep, callbackDeployLibrary) { var libraryRefMatch = contract.evm.bytecode.object.match(/__([^_]{1,36})__/) if (!libraryRefMatch) { return callback('Invalid bytecode format.') @@ -152,7 +152,7 @@ module.exports = { if (!library) { return callback('Library ' + libraryName + ' not found.') } - this.deployLibrary(libraryName, libraryShortName, library, contracts, udapp, (err, address) => { + this.deployLibrary(libraryName, libraryShortName, library, contracts, (err, address) => { if (err) { return callback(err) } @@ -161,36 +161,36 @@ module.exports = { hexAddress = hexAddress.slice(2) } contract.evm.bytecode.object = this.linkLibrary(libraryName, hexAddress, contract.evm.bytecode.object) - this.linkBytecode(contract, contracts, udapp, callback, callbackStep) - }, callbackStep) + this.linkBytecode(contract, contracts, callback, callbackStep, callbackDeployLibrary) + }, callbackStep, callbackDeployLibrary) }, - linkBytecode: function (contract, contracts, udapp, callback, callbackStep) { + linkBytecode: function (contract, contracts, callback, callbackStep, callbackDeployLibrary) { if (contract.evm.bytecode.object.indexOf('_') < 0) { return callback(null, contract.evm.bytecode.object) } if (contract.evm.bytecode.linkReferences && Object.keys(contract.evm.bytecode.linkReferences).length) { - this.linkBytecodeStandard(contract, contracts, udapp, callback, callbackStep) + this.linkBytecodeStandard(contract, contracts, callback, callbackStep) } else { - this.linkBytecodeLegacy(contract, contracts, udapp, callback, callbackStep) + this.linkBytecodeLegacy(contract, contracts, callback, callbackStep) } }, - deployLibrary: function (libraryName, libraryShortName, library, contracts, udapp, callback, callbackStep) { + deployLibrary: function (libraryName, libraryShortName, library, contracts, callback, callbackStep, callbackDeployLibrary) { var address = library.address if (address) { return callback(null, address) } var bytecode = library.evm.bytecode.object if (bytecode.indexOf('_') >= 0) { - this.linkBytecode(library, contracts, udapp, (err, bytecode) => { + this.linkBytecode(library, contracts, (err, bytecode) => { if (err) callback(err) - else this.deployLibrary(libraryName, libraryShortName, library, contracts, udapp, callback, callbackStep) - }, callbackStep) + else this.deployLibrary(libraryName, libraryShortName, library, contracts, callback, callbackStep, callbackDeployLibrary) + }, callbackStep, callbackDeployLibrary) } else { callbackStep(`creation of library ${libraryName} pending...`) var data = {dataHex: bytecode, funAbi: {type: 'constructor'}, funArgs: [], contractBytecode: bytecode, contractName: libraryShortName} - udapp.runTx({ data: data, useCall: false }, (err, txResult) => { + callbackDeployLibrary({ data: data, useCall: false }, (err, txResult) => { if (err) { return callback(err) } From e969f57fb6fd1cff2ccfac0a6057a7154a64a354 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 28 Mar 2018 17:13:00 +0200 Subject: [PATCH 2/5] update test --- remix-lib/test/txFormat.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/remix-lib/test/txFormat.js b/remix-lib/test/txFormat.js index 35e9122804..2b1a9d9ea8 100644 --- a/remix-lib/test/txFormat.js +++ b/remix-lib/test/txFormat.js @@ -10,8 +10,7 @@ tape('ContractParameters - (TxFormat.buildData) - format input parameters', func var output = compiler.compileStandardWrapper(compilerInput(uintContract)) output = JSON.parse(output) var contract = output.contracts['test.sol']['uintContractTest'] - var udapp = { runTx: () => {} } // fake - context = { output, contract, udapp } + context = { output, contract } var bytecode = '6060604052341561000f57600080fd5b6101058061001e6000396000f300606060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680634b521953146044575b600080fd5b3415604e57600080fd5b608a600480803590602001909190803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050608c565b005b8260008190555081600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050505600a165627a7a72305820d05e3789952dfb3ba575bcb79da62b6e259adbf498ea909031a42b647f7bceb30029' t.test('(TxFormat.buildData)', function (st) { st.plan(3) @@ -23,12 +22,11 @@ tape('ContractParameters - (TxFormat.buildData) - format input parameters', func }) function testWithInput (st, params, expected) { - txFormat.buildData('uintContractTest', context.contract, context.output.contracts, true, context.contract.abi[0], params, context.udapp - , (error, data) => { - if (error) { return st.fails(error) } - console.log(data) - st.equal(data.dataHex, expected) - }, () => {}) + txFormat.buildData('uintContractTest', context.contract, context.output.contracts, true, context.contract.abi[0], params, (error, data) => { + if (error) { return st.fails(error) } + console.log(data) + st.equal(data.dataHex, expected) + }, () => {}, () => {}) } tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) { @@ -73,7 +71,7 @@ function testLinkLibrary (st, fakeDeployedContracts) { }, (msg) => { st.equal(msg, deployMsg[0]) deployMsg.shift() - }) + }, () => {}) } var uintContract = `contract uintContractTest { From 3b1d055b16566bd2d3e3c459e6329226c03fef86 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 28 Mar 2018 17:13:31 +0200 Subject: [PATCH 3/5] use txRunner instead of udapp --- remix-lib/src/execution/txExecution.js | 44 ++++++++++++++++++-------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/remix-lib/src/execution/txExecution.js b/remix-lib/src/execution/txExecution.js index 04ea13aea6..c80c09d192 100644 --- a/remix-lib/src/execution/txExecution.js +++ b/remix-lib/src/execution/txExecution.js @@ -4,30 +4,48 @@ module.exports = { /** * deploy the given contract * + * @param {String} from - sender address * @param {String} data - data to send with the transaction ( return of txFormat.buildData(...) ). - * @param {Object} udapp - udapp. - * @param {Function} callback - callback. + * @param {String} value - decimal representation of value. + * @param {String} gasLimit - decimal representation of gas limit. + * @param {Object} txRunner - TxRunner.js instance + * @param {Object} callbacks - { confirmationCb, gasEstimationForceSend, promptCb } + * [validate transaction] confirmationCb (network, tx, gasEstimation, continueTxExecution, cancelCb) + * [transaction failed, force send] gasEstimationForceSend (error, continueTxExecution, cancelCb) + * [personal mode enabled, need password to continue] promptCb (okCb, cancelCb) + * @param {Function} finalCallback - last callback. */ - createContract: function (data, udapp, callback) { - udapp.runTx({data: data, useCall: false}, (error, txResult) => { + createContract: function (from, data, value, gasLimit, txRunner, callbacks, finalCallback) { + if (!callbacks.confirmationCb || !callbacks.gasEstimationForceSend || !callbacks.promptCb) { + return finalCallback('all the callbacks must have been defined') + } + var tx = { from: from, to: null, data: data, useCall: false, value: value, gasLimit: gasLimit } + txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => { // see universaldapp.js line 660 => 700 to check possible values of txResult (error case) - callback(error, txResult) + finalCallback(error, txResult) }) }, /** - * call the current given contract + * call the current given contract ! that will create a transaction ! * - * @param {String} to - address of the contract to call. + * @param {String} from - sender address + * @param {String} to - recipient address * @param {String} data - data to send with the transaction ( return of txFormat.buildData(...) ). - * @param {Object} funAbi - abi definition of the function to call. - * @param {Object} udapp - udapp. - * @param {Function} callback - callback. + * @param {String} value - decimal representation of value. + * @param {String} gasLimit - decimal representation of gas limit. + * @param {Object} txRunner - TxRunner.js instance + * @param {Object} callbacks - { confirmationCb, gasEstimationForceSend, promptCb } + * [validate transaction] confirmationCb (network, tx, gasEstimation, continueTxExecution, cancelCb) + * [transaction failed, force send] gasEstimationForceSend (error, continueTxExecution, cancelCb) + * [personal mode enabled, need password to continue] promptCb (okCb, cancelCb) + * @param {Function} finalCallback - last callback. */ - callFunction: function (to, data, funAbi, udapp, callback) { - udapp.runTx({to: to, data: data, useCall: funAbi.constant}, (error, txResult) => { + callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) { + var tx = { from: from, to: to, data: data, useCall: false, value: value, gasLimit: gasLimit } + txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => { // see universaldapp.js line 660 => 700 to check possible values of txResult (error case) - callback(error, txResult) + finalCallback(error, txResult) }) }, From 97ee2523b76c0a962064acd20704d3c1323d3026 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 28 Mar 2018 17:19:00 +0200 Subject: [PATCH 4/5] fix test --- remix-lib/test/txFormat.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/remix-lib/test/txFormat.js b/remix-lib/test/txFormat.js index 2b1a9d9ea8..0f107e7999 100644 --- a/remix-lib/test/txFormat.js +++ b/remix-lib/test/txFormat.js @@ -56,22 +56,21 @@ tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) function testLinkLibrary (st, fakeDeployedContracts) { var deployMsg = ['creation of library test.sol:lib1 pending...', 'creation of library test.sol:lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2 pending...'] - txFormat.buildData('testContractLinkLibrary', context.contract, context.output.contracts, true, context.contract.abi[0], '', context.udapp - , (error, data) => { - if (error) { return st.fails(error) } - console.log(data) - var linkedbyteCode = data.dataHex - var libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib1'] - st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib1'].replace('0x', '')) - st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib1'].replace('0x', '')) + txFormat.buildData('testContractLinkLibrary', context.contract, context.output.contracts, true, context.contract.abi[0], '', (error, data) => { + if (error) { return st.fails(error) } + console.log(data) + var linkedbyteCode = data.dataHex + var libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib1'] + st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib1'].replace('0x', '')) + st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib1'].replace('0x', '')) - libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'] - st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', '')) - st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', '')) - }, (msg) => { - st.equal(msg, deployMsg[0]) - deployMsg.shift() - }, () => {}) + libReference = context.contract.evm.bytecode.linkReferences['test.sol']['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'] + st.equal(linkedbyteCode.substr(2 * libReference[0].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', '')) + st.equal(linkedbyteCode.substr(2 * libReference[1].start, 40), fakeDeployedContracts['lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2'].replace('0x', '')) + }, (msg) => { + st.equal(msg, deployMsg[0]) + deployMsg.shift() + }, () => {}) } var uintContract = `contract uintContractTest { From c2e117d0862b77db4a5fe372a33fa5a9b81dca36 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 28 Mar 2018 17:32:14 +0200 Subject: [PATCH 5/5] fix test --- remix-lib/src/execution/txFormat.js | 6 +++--- remix-lib/test/txFormat.js | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/remix-lib/src/execution/txFormat.js b/remix-lib/src/execution/txFormat.js index 493e676ee8..5928f6ff29 100644 --- a/remix-lib/src/execution/txFormat.js +++ b/remix-lib/src/execution/txFormat.js @@ -90,7 +90,7 @@ module.exports = { bytecodeToDeploy = bytecode + dataHex return callback(null, {dataHex: bytecodeToDeploy, funAbi, funArgs, contractBytecode, contractName: contractName}) } - }, callbackStep) + }, callbackStep, callbackDeployLibrary) return } else { dataHex = bytecodeToDeploy + dataHex @@ -170,9 +170,9 @@ module.exports = { return callback(null, contract.evm.bytecode.object) } if (contract.evm.bytecode.linkReferences && Object.keys(contract.evm.bytecode.linkReferences).length) { - this.linkBytecodeStandard(contract, contracts, callback, callbackStep) + this.linkBytecodeStandard(contract, contracts, callback, callbackStep, callbackDeployLibrary) } else { - this.linkBytecodeLegacy(contract, contracts, callback, callbackStep) + this.linkBytecodeLegacy(contract, contracts, callback, callbackStep, callbackDeployLibrary) } }, diff --git a/remix-lib/test/txFormat.js b/remix-lib/test/txFormat.js index 0f107e7999..736de57dcd 100644 --- a/remix-lib/test/txFormat.js +++ b/remix-lib/test/txFormat.js @@ -39,21 +39,21 @@ tape('ContractParameters - (TxFormat.buildData) - link Libraries', function (t) lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2: '0xf7a10e525d4b168f45f74db1b61f63d3e7619e33', testContractLinkLibrary: '0xf7a10e525d4b168f45f74db1b61f63d3e7619e22' } - var udapp = { runTx: (param, callback) => { + var callbackDeployLibraries = (param, callback) => { callback(null, { result: { createdAddress: fakeDeployedContracts[param.data.contractName] } }) - } } // fake - context = { output, contract, udapp } + } // fake + context = { output, contract } t.test('(TxFormat.buildData and link library (standard way))', function (st) { st.plan(6) - testLinkLibrary(st, fakeDeployedContracts) + testLinkLibrary(st, fakeDeployedContracts, callbackDeployLibraries) }) }) -function testLinkLibrary (st, fakeDeployedContracts) { +function testLinkLibrary (st, fakeDeployedContracts, callbackDeployLibraries) { var deployMsg = ['creation of library test.sol:lib1 pending...', 'creation of library test.sol:lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2_lib2 pending...'] txFormat.buildData('testContractLinkLibrary', context.contract, context.output.contracts, true, context.contract.abi[0], '', (error, data) => { @@ -70,7 +70,7 @@ function testLinkLibrary (st, fakeDeployedContracts) { }, (msg) => { st.equal(msg, deployMsg[0]) deployMsg.shift() - }, () => {}) + }, callbackDeployLibraries) } var uintContract = `contract uintContractTest {