Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Better logic for contract deployments (#4821)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac authored and jacogr committed Mar 8, 2017
1 parent 94a3961 commit 02c51c8
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions js/src/ui/MethodDecoding/methodDecodingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,19 @@ export default class MethodDecodingStore {

// Contract deployment
if (!signature || signature === CONTRACT_CREATE || transaction.creates) {
return this.decodeContractCreation(result, contractAddress || transaction.creates);
const address = contractAddress || transaction.creates;

return this.isContractCreation(input, address)
.then((isContractCreation) => {
if (!isContractCreation) {
result.contract = false;
result.deploy = false;

return result;
}

return this.decodeContractCreation(result, address);
});
}

return this
Expand Down Expand Up @@ -204,7 +216,7 @@ export default class MethodDecodingStore {
const { input } = data;
const abi = this._contractsAbi[contractAddress];

if (!input || !abi || !abi.constructors || abi.constructors.length === 0) {
if (!abi || !abi.constructors || abi.constructors.length === 0) {
return Promise.resolve(result);
}

Expand Down Expand Up @@ -306,6 +318,30 @@ export default class MethodDecodingStore {
return Promise.resolve(this._isContract[contractAddress]);
}

/**
* Check if the input resulted in a contract creation
* by checking that the contract address code contains
* a part of the input, or vice-versa
*/
isContractCreation (input, contractAddress) {
return this.api.eth
.getCode(contractAddress)
.then((code) => {
if (/^(0x)?0*$/.test(code)) {
return false;
}

const strippedCode = code.replace(/^0x/, '');
const strippedInput = input.replace(/^0x/, '');

return strippedInput.indexOf(strippedInput) >= 0 || strippedCode.indexOf(strippedInput) >= 0;
})
.catch((error) => {
console.error(error);
return false;
});
}

getCode (contractAddress) {
// If zero address, resolve to '0x'
if (!contractAddress || /^(0x)?0*$/.test(contractAddress)) {
Expand Down

0 comments on commit 02c51c8

Please sign in to comment.