mirror of https://github.com/embarklabs/embark.git
Call Function API
This commit is contained in:
parent
cdc7c107a6
commit
c234a850e3
|
@ -18,7 +18,7 @@ const ContractFunction = ({method}) => (
|
||||||
{method.inputs.length > 0 &&
|
{method.inputs.length > 0 &&
|
||||||
<Card.Body>
|
<Card.Body>
|
||||||
{method.inputs.map(input => (
|
{method.inputs.map(input => (
|
||||||
<Form.Group label={input.name}>
|
<Form.Group key={input.name} label={input.name}>
|
||||||
<Form.Input placeholder={input.type}/>
|
<Form.Input placeholder={input.type}/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
))}
|
))}
|
||||||
|
@ -32,11 +32,15 @@ const ContractFunction = ({method}) => (
|
||||||
</Grid.Row>
|
</Grid.Row>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ContractFunction.propTypes = {
|
||||||
|
method: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
const ContractFunctions = ({contractProfile}) => (
|
const ContractFunctions = ({contractProfile}) => (
|
||||||
<Page.Content title={contractProfile.name + ' Functions'}>
|
<Page.Content title={contractProfile.name + ' Functions'}>
|
||||||
{contractProfile.methods
|
{contractProfile.methods
|
||||||
.filter(method => method.name !== 'constructor')
|
.filter(method => method.name !== 'constructor')
|
||||||
.map(method => <ContractFunction method={method} />)}
|
.map(method => <ContractFunction key={method.name} method={method} />)}
|
||||||
</Page.Content>
|
</Page.Content>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ function mapStateToProps(state, props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ContractContainer.propTypes = {
|
ContractContainer.propTypes = {
|
||||||
|
match: PropTypes.object,
|
||||||
contract: PropTypes.object,
|
contract: PropTypes.object,
|
||||||
error: PropTypes.string
|
error: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ function mapStateToProps(state) {
|
||||||
|
|
||||||
ContractsContainer.propTypes = {
|
ContractsContainer.propTypes = {
|
||||||
contracts: PropTypes.array,
|
contracts: PropTypes.array,
|
||||||
fetchContracts: PropTypes.func,
|
fetchContracts: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/*global web3*/
|
||||||
let toposort = require('toposort');
|
let toposort = require('toposort');
|
||||||
let async = require('async');
|
let async = require('async');
|
||||||
const cloneDeep = require('clone-deep');
|
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(
|
plugin.registerAPICall(
|
||||||
'get',
|
'get',
|
||||||
'/embark-api/contracts',
|
'/embark-api/contracts',
|
||||||
|
@ -215,7 +246,10 @@ class ContractsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentContract === undefined) {
|
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]);
|
let suggestion = utils.proposeAlternative(parentContractName, dictionary, [className, parentContractName]);
|
||||||
if (suggestion) {
|
if (suggestion) {
|
||||||
self.logger.warn(__('did you mean "%s"?', suggestion));
|
self.logger.warn(__('did you mean "%s"?', suggestion));
|
||||||
|
@ -228,7 +262,10 @@ class ContractsManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contract.code !== undefined) {
|
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;
|
contract.code = parentContract.code;
|
||||||
|
@ -274,8 +311,8 @@ class ContractsManager {
|
||||||
// look in code for dependencies
|
// look in code for dependencies
|
||||||
let libMatches = (contract.code.match(/:(.*?)(?=_)/g) || []);
|
let libMatches = (contract.code.match(/:(.*?)(?=_)/g) || []);
|
||||||
for (let match of libMatches) {
|
for (let match of libMatches) {
|
||||||
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
self.contractDependencies[className] = self.contractDependencies[className] || [];
|
||||||
self.contractDependencies[className].push(match.substr(1));
|
self.contractDependencies[className].push(match.substr(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// look in arguments for dependencies
|
// look in arguments for dependencies
|
||||||
|
@ -375,7 +412,7 @@ class ContractsManager {
|
||||||
self.events.emit("status", __("Compile/Build error"));
|
self.events.emit("status", __("Compile/Build error"));
|
||||||
self.events.emit("outputError", __("Error building Dapp, please check console"));
|
self.events.emit("outputError", __("Error building Dapp, please check console"));
|
||||||
self.logger.error(__("Error Compiling/Building contracts: ") + err);
|
self.logger.error(__("Error Compiling/Building contracts: ") + err);
|
||||||
}else{
|
} else {
|
||||||
self.compileError = false;
|
self.compileError = false;
|
||||||
}
|
}
|
||||||
self.logger.trace("finished".underline);
|
self.logger.trace("finished".underline);
|
||||||
|
@ -415,8 +452,8 @@ class ContractsManager {
|
||||||
let orderedDependencies;
|
let orderedDependencies;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
orderedDependencies = toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse();
|
orderedDependencies = toposort(converted_dependencies.filter((x) => x[0] !== x[1])).reverse();
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
this.logger.error((__("Error: ") + e.message).red);
|
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(__("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);
|
this.logger.error(__("Embark couldn't determine which one to deploy first").red);
|
||||||
|
|
Loading…
Reference in New Issue