diff --git a/embark-ui/src/components/ContractFunctions.js b/embark-ui/src/components/ContractFunctions.js index 762ae6f3..27a700e8 100644 --- a/embark-ui/src/components/ContractFunctions.js +++ b/embark-ui/src/components/ContractFunctions.js @@ -18,7 +18,7 @@ const ContractFunction = ({method}) => ( {method.inputs.length > 0 && {method.inputs.map(input => ( - + ))} @@ -32,11 +32,15 @@ const ContractFunction = ({method}) => ( ); +ContractFunction.propTypes = { + method: PropTypes.object +}; + const ContractFunctions = ({contractProfile}) => ( {contractProfile.methods .filter(method => method.name !== 'constructor') - .map(method => )} + .map(method => )} ); diff --git a/embark-ui/src/containers/ContractContainer.js b/embark-ui/src/containers/ContractContainer.js index 3389abf8..5c8f516f 100644 --- a/embark-ui/src/containers/ContractContainer.js +++ b/embark-ui/src/containers/ContractContainer.js @@ -26,6 +26,7 @@ function mapStateToProps(state, props) { } ContractContainer.propTypes = { + match: PropTypes.object, contract: PropTypes.object, error: PropTypes.string }; diff --git a/embark-ui/src/containers/ContractsContainer.js b/embark-ui/src/containers/ContractsContainer.js index 94b0839f..1d769ede 100644 --- a/embark-ui/src/containers/ContractsContainer.js +++ b/embark-ui/src/containers/ContractsContainer.js @@ -27,7 +27,7 @@ function mapStateToProps(state) { ContractsContainer.propTypes = { contracts: PropTypes.array, - fetchContracts: PropTypes.func, + fetchContracts: PropTypes.func }; export default connect( diff --git a/lib/modules/contracts_manager/index.js b/lib/modules/contracts_manager/index.js index b944ef07..f4599547 100644 --- a/lib/modules/contracts_manager/index.js +++ b/lib/modules/contracts_manager/index.js @@ -1,3 +1,4 @@ +/*global web3*/ let toposort = require('toposort'); let async = require('async'); const cloneDeep = require('clone-deep'); @@ -91,6 +92,36 @@ class ContractsManager { } ); + plugin.registerAPICall( + 'get', + '/embark-api/contract/:contractName/function', + (req, res) => { + async.parallel({ + contract: (callback) => { + self.events.request('contracts:contract', req.params.contractName, (contract) => callback(null, contract)); + }, + account: (callback) => { + self.events.request("blockchain:defaultAccount:get", (account) => callback(null, account)); + } + }, function (err, result) { + if (err) { + return res.send({error: err.message}); + } + const {account, contract} = result; + const contractObj = new web3.eth.Contract(contract.abiDefinition, contract.deployedAddress); + const abi = contract.abiDefinition.find(definition => definition.name === req.query.method); + const funcCall = (abi.constant === true || abi.stateMutability === 'view' || abi.stateMutability === 'pure') ? 'call' : 'send'; + contractObj.methods[req.query.method].apply(this, req.query.inputs)[funcCall]({from: account}, (err, result) => { + if (err) { + return res.send({error: err.message}); + } + + res.send({result: result}); + }); + }); + } + ); + plugin.registerAPICall( 'get', '/embark-api/contracts', @@ -215,7 +246,10 @@ class ContractsManager { } if (parentContract === undefined) { - self.logger.error(__("{{className}}: couldn't find instanceOf contract {{parentContractName}}", {className: className, parentContractName: parentContractName})); + self.logger.error(__("{{className}}: couldn't find instanceOf contract {{parentContractName}}", { + className: className, + parentContractName: parentContractName + })); let suggestion = utils.proposeAlternative(parentContractName, dictionary, [className, parentContractName]); if (suggestion) { self.logger.warn(__('did you mean "%s"?', suggestion)); @@ -228,7 +262,10 @@ class ContractsManager { } if (contract.code !== undefined) { - self.logger.error(__("{{className}} has code associated to it but it's configured as an instanceOf {{parentContractName}}", {className: className, parentContractName: parentContractName})); + self.logger.error(__("{{className}} has code associated to it but it's configured as an instanceOf {{parentContractName}}", { + className: className, + parentContractName: parentContractName + })); } contract.code = parentContract.code; @@ -274,8 +311,8 @@ class ContractsManager { // look in code for dependencies let libMatches = (contract.code.match(/:(.*?)(?=_)/g) || []); for (let match of libMatches) { - self.contractDependencies[className] = self.contractDependencies[className] || []; - self.contractDependencies[className].push(match.substr(1)); + self.contractDependencies[className] = self.contractDependencies[className] || []; + self.contractDependencies[className].push(match.substr(1)); } // look in arguments for dependencies @@ -375,7 +412,7 @@ class ContractsManager { self.events.emit("status", __("Compile/Build error")); self.events.emit("outputError", __("Error building Dapp, please check console")); self.logger.error(__("Error Compiling/Building contracts: ") + err); - }else{ + } else { self.compileError = false; } self.logger.trace("finished".underline); @@ -415,8 +452,8 @@ class ContractsManager { let orderedDependencies; try { - orderedDependencies = toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse(); - } catch(e) { + orderedDependencies = toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse(); + } catch (e) { this.logger.error((__("Error: ") + e.message).red); this.logger.error(__("there are two or more contracts that depend on each other in a cyclic manner").bold.red); this.logger.error(__("Embark couldn't determine which one to deploy first").red);