Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading more than one contract with load-contract #29

Merged
merged 4 commits into from
Sep 25, 2018

Conversation

lmcorbalan
Copy link
Contributor

No description provided.

@ghost ghost assigned lmcorbalan Sep 21, 2018
@ghost ghost added the in progress label Sep 21, 2018
}
]

if (rest.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not necessary: the for won't be entered if length is 0.


if (rest.length > 0) {
for (let i = 0; i < rest.length; i += 2) {
const chunk = rest.slice(i, i + 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

A slightly more readable version of this may be:

const [abiPath, address] = rest.slice(i, i + 2)

const Contract = new web3.eth.Contract(contract.abi, contract.address)
let contractName = path.basename(contract.abiPath).split('.')[0]

if (rplContext[contractName]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't work correctly in some veeery edge cases (for example: if you do eth lc ERC20.abi 0x ERC201.abi 0x ERC20.abi 0x, the suffix of the second ERC20 will be _2 instead of _1).

I don't think it's important enough to fix it: the worst case scenario is a wrong suffix in some very weird cases, but we may want to open an issue or put a comment for future reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think replacing return key.includes(contracName) with

const [noSuffixKey] = key.split('_')
const [noSuffixContract] = contractName.split('_')
return noSuffixKey === noSuffixContract

would cover that edge case and others like eth lc ERC20.abi 0x ERC20_1.abi 0x ERC20.abi 0x, although there will be more edge cases that won't be covered

@ghost ghost assigned fvictorio Sep 24, 2018
@fernandomg fernandomg merged commit 516f651 into protofire:master Sep 25, 2018
@ghost ghost removed the in progress label Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants