Payload requires 'contract' and 'address'
This commit is contained in:
parent
9badb2f3fe
commit
3d5739715b
|
@ -87,8 +87,9 @@ const msgObj = {
|
|||
powTime: 20,
|
||||
topic: "0x4964656e",
|
||||
payload: web3.utils.toHex({
|
||||
'address': "0x692a70d2e424a56d2c6c27aa97d1a86395877b3a",
|
||||
'encodedFunctionCall': funCall
|
||||
'contract': "0x692a70d2e424a56d2c6c27aa97d1a86395877b3a",
|
||||
'encodedFunctionCall': funCall,
|
||||
'address': web3.eth.defaultAccount
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class MessageProcessor {
|
|||
}
|
||||
|
||||
async _validateInput(message){
|
||||
console.info("Processing request to: %s, %s", message.input.address, message.input.functionName);
|
||||
console.info("Processing request to: %s, %s", message.input.contract, message.input.functionName);
|
||||
|
||||
const contract = this.settings.getContractByTopic(message.topic);
|
||||
|
||||
|
@ -37,24 +37,31 @@ class MessageProcessor {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Get code from address and compare it against the contract code
|
||||
// Get code from contract and compare it against the contract code
|
||||
if(!contract.isIdentity){
|
||||
const code = this.web3.utils.soliditySha3(await this.web3.eth.getCode(message.input.address));
|
||||
const code = this.web3.utils.soliditySha3(await this.web3.eth.getCode(message.input.contract));
|
||||
if(code != contract.code){
|
||||
this._reply('Invalid contract code', message);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!(/^0x[0-9a-f]{40}$/i).test(message.input.address)){
|
||||
this._reply('Invalid address', message);
|
||||
if(!(/^0x[0-9a-f]{40}$/i).test(message.input.contract)){
|
||||
this._reply('Invalid contract address', message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(message.input.address && !(/^0x[0-9a-f]{40}$/i).test(message.input.address)){
|
||||
this._reply('Invalid address', message);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_extractInput(message){
|
||||
let obj = {
|
||||
contract: null,
|
||||
address: null,
|
||||
functionName: null,
|
||||
functionParameters: null,
|
||||
|
@ -64,8 +71,8 @@ class MessageProcessor {
|
|||
try {
|
||||
const msg = this.web3.utils.toAscii(message.payload);
|
||||
let parsedObj = JSON.parse(msg);
|
||||
obj.contract = parsedObj.contract;
|
||||
obj.address = parsedObj.address;
|
||||
obj.wallet = parsedObj.wallet;
|
||||
obj.functionName = parsedObj.encodedFunctionCall.slice(0, 10);
|
||||
obj.functionParameters = "0x" + parsedObj.encodedFunctionCall.slice(10);
|
||||
obj.payload = parsedObj.encodedFunctionCall;
|
||||
|
@ -103,7 +110,7 @@ class MessageProcessor {
|
|||
|
||||
let p = {
|
||||
from: this.config.node.blockchain.account,
|
||||
to: message.input.address,
|
||||
to: message.input.contract,
|
||||
value: 0,
|
||||
data: message.input.payload,
|
||||
gasPrice: this.config.gasPrice
|
||||
|
|
|
@ -4,7 +4,7 @@ const erc20ABI = require('../../abi/ERC20Token.json');
|
|||
class IdentityStrategy extends Strategy {
|
||||
|
||||
async _validateInstance(message){
|
||||
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(message.input.address));
|
||||
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(message.input.contract));
|
||||
const kernelVerifSignature = this.web3.utils.soliditySha3(this.contract.kernelVerification).slice(0, 10);
|
||||
if(instanceCodeHash === null) return false;
|
||||
|
||||
|
@ -35,14 +35,14 @@ class IdentityStrategy extends Strategy {
|
|||
if(this.contract.allowedFunctions[message.input.functionName].isToken){
|
||||
const Token = new this.web3.eth.Contract(erc20ABI.abi);
|
||||
Token.options.address = params('_baseToken');
|
||||
const tokenBalance = new this.web3.utils.BN(await Token.methods.balanceOf(message.input.address).call());
|
||||
const tokenBalance = new this.web3.utils.BN(await Token.methods.balanceOf(message.input.contract).call());
|
||||
if(tokenBalance.lt(this.web3.utils.toBN(params('_value')))){
|
||||
return {success: false, message: "Identity has not enough balance for specified value"};
|
||||
}
|
||||
}
|
||||
|
||||
// gasPrice * limit calculation
|
||||
const balance = await this.getBalance(message.input.address, token);
|
||||
const balance = await this.getBalance(message.input.contract, token);
|
||||
if(balance.lt(this.web3.utils.toBN(gasPrice.mul(gasLimit)))) {
|
||||
return {success: false, message: "Identity has not enough tokens for gasPrice*gasLimit"};
|
||||
}
|
||||
|
|
|
@ -13,13 +13,13 @@ class SNTStrategy extends Strategy {
|
|||
const token = this.settings.getTokenBySymbol("SNT");
|
||||
if(token == undefined) return {success: false, message: "Token not allowed"};
|
||||
|
||||
const balance = await this.getBalance(message.input.wallet, token);
|
||||
const balance = await this.getBalance(message.input.address, token);
|
||||
|
||||
if(message.input.functionName == TransferSNT){
|
||||
const estimatedGas = await this.web3.eth.estimateGas({
|
||||
data: message.input.payload,
|
||||
from: this.config.node.blockchain.account,
|
||||
to: message.input.address
|
||||
to: message.input.contract
|
||||
});
|
||||
|
||||
const gas = this.web3.utils.toBN(estimatedGas);
|
||||
|
|
|
@ -126,8 +126,9 @@ class ApproveAndCallGasRelayed extends Component {
|
|||
topic: this.state.topic,
|
||||
symKeyID: skid,
|
||||
payload: web3.utils.toHex({
|
||||
'address': this.props.identityAddress,
|
||||
'encodedFunctionCall': funCall
|
||||
'contract': this.props.identityAddress,
|
||||
'encodedFunctionCall': funCall,
|
||||
'address': web3.eth.defaultAccount
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -128,8 +128,9 @@ class CallGasRelayed extends Component {
|
|||
topic: this.state.topic,
|
||||
symKeyID: skid,
|
||||
payload: web3.utils.toHex({
|
||||
'address': this.props.identityAddress,
|
||||
'encodedFunctionCall': funCall
|
||||
'contract': this.props.identityAddress,
|
||||
'encodedFunctionCall': funCall,
|
||||
'address': web3.eth.defaultAccount
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -131,8 +131,8 @@ class Execute extends Component {
|
|||
topic: this.state.topic,
|
||||
symKeyID: skid,
|
||||
payload: web3.utils.toHex({
|
||||
'address': SNTController.options.address,
|
||||
'wallet': accounts[2],
|
||||
'contract': SNTController.options.address,
|
||||
'address': accounts[2],
|
||||
'encodedFunctionCall': funCall
|
||||
})
|
||||
};
|
||||
|
|
|
@ -128,8 +128,8 @@ class TransferSNT extends Component {
|
|||
topic: this.state.topic,
|
||||
symKeyID: skid,
|
||||
payload: web3.utils.toHex({
|
||||
'address': SNTController.options.address,
|
||||
'wallet': accounts[2],
|
||||
'contract': SNTController.options.address,
|
||||
'address': accounts[2],
|
||||
'encodedFunctionCall': funCall
|
||||
})
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue