PR feedback: Use request
This commit is contained in:
parent
6038da4339
commit
d9ae5cbfc7
|
@ -108,9 +108,10 @@ 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';
|
||||
|
||||
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) {
|
||||
|
@ -123,6 +124,7 @@ class ContractsManager {
|
|||
res.send({result: e.message});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -137,20 +139,23 @@ 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);
|
||||
|
||||
self.events.request("blockchain:contract:create", {abi: contract.abiDefinition}, async (contractObj) => {
|
||||
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});
|
||||
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