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

Fix wrong transaction input for contract deployments #4052

Merged
merged 5 commits into from
Jan 6, 2017
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions js/src/api/contract/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,19 @@ export default class Contract {
}

_encodeOptions (func, options, values) {
options.data = this.getCallData(func, options, values);
return options;
const data = this.getCallData(func, options, values);
Copy link
Contributor

@jacogr jacogr Jan 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we fixed a bug, would love a testcase that reproduces it and verifies it fixed so it doesn't happen again. (In the case of fixing bugs, should get into that habit overall)


return {
...options,
data
};
}

_addOptionsTo (options = {}) {
return Object.assign({
to: this._address
}, options);
return {
to: this._address,
...options
};
}

_bindFunction = (func) => {
Expand Down
46 changes: 44 additions & 2 deletions js/src/views/WriteContract/writeContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,23 +458,65 @@ class WriteContract extends Component {
const { bytecode } = contract;
const abi = contract.interface;

const metadata = contract.metadata
? (
<Input
allowCopy
label='Metadata'
readOnly
value={ contract.metadata }
/>
)
: null;

return (
<div>
<Input
allowCopy
label='ABI Interface'
readOnly
value={ abi }
label='ABI Interface'
/>

<Input
allowCopy
label='Bytecode'
readOnly
value={ `0x${bytecode}` }
label='Bytecode'
/>

{ metadata }
{ this.renderSwarmHash(contract) }
</div>
);
}

renderSwarmHash (contract) {
if (!contract || !contract.metadata) {
return null;
}

const { bytecode } = contract;

// @see https://solidity.readthedocs.io/en/develop/miscellaneous.html#encoding-of-the-metadata-hash-in-the-bytecode
const hashRegex = /a165627a7a72305820([a-f0-9]{64})0029$/;

if (!hashRegex.test(bytecode)) {
return null;
}

const hash = hashRegex.exec(bytecode)[1];

return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

<Input
allowCopy
label='Swarm Metadata Hash'
readOnly
value={ `${hash}` }
/>
);
}

renderErrors () {
const { annotations } = this.store;

Expand Down