PR feedback: Use request
This commit is contained in:
parent
6038da4339
commit
d9ae5cbfc7
|
@ -108,20 +108,22 @@ class ContractsManager {
|
|||
return res.send({error: error.message});
|
||||
}
|
||||
const {account, contract} = result;
|
||||
const contractObj = new web3.eth.Contract(contract.abiDefinition, contract.deployedAddress);
|
||||
const abi = contract.abiDefinition.find(definition => definition.name === req.body.method);
|
||||
const funcCall = (abi.constant === true || abi.stateMutability === 'view' || abi.stateMutability === 'pure') ? 'call' : 'send';
|
||||
try {
|
||||
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account}, (error, result) => {
|
||||
if (error) {
|
||||
return res.send({result: error.message});
|
||||
}
|
||||
|
||||
res.send({result});
|
||||
});
|
||||
} catch (e) {
|
||||
res.send({result: e.message});
|
||||
}
|
||||
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition, address: contract.deployedAddress}, (contractObj) => {
|
||||
try {
|
||||
contractObj.methods[req.body.method].apply(this, req.body.inputs)[funcCall]({from: account}, (error, result) => {
|
||||
if (error) {
|
||||
return res.send({result: error.message});
|
||||
}
|
||||
|
||||
res.send({result});
|
||||
});
|
||||
} catch (e) {
|
||||
res.send({result: e.message});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -137,19 +139,22 @@ class ContractsManager {
|
|||
account: (callback) => {
|
||||
self.events.request("blockchain:defaultAccount:get", (account) => callback(null, account));
|
||||
}
|
||||
}, async (error, result) => {
|
||||
}, (error, result) => {
|
||||
if (error) {
|
||||
return res.send({error: error.message});
|
||||
}
|
||||
const {account, contract} = result;
|
||||
const contractObj = new web3.eth.Contract(contract.abiDefinition);
|
||||
try {
|
||||
let gas = await contractObj.deploy({data: `0x${contract.code}`, arguments: req.body.inputs}).estimateGas();
|
||||
let newContract = await contractObj.deploy({data: `0x${contract.code}`, arguments: req.body.inputs}).send({from: account, gas});
|
||||
res.send({result: newContract._address});
|
||||
} catch (e) {
|
||||
res.send({result: e.message});
|
||||
}
|
||||
|
||||
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition}, async (contractObj) => {
|
||||
try {
|
||||
const params = {data: `0x${contract.code}`, arguments: req.body.inputs};
|
||||
let gas = await contractObj.deploy(params).estimateGas();
|
||||
let newContract = await contractObj.deploy(params).send({from: account, gas});
|
||||
res.send({result: newContract._address});
|
||||
} catch (e) {
|
||||
res.send({result: e.message});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue