-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
src/loadContract.js
Outdated
} | ||
] | ||
|
||
if (rest.length > 0) { |
There was a problem hiding this comment.
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.
src/loadContract.js
Outdated
|
||
if (rest.length > 0) { | ||
for (let i = 0; i < rest.length; i += 2) { | ||
const chunk = rest.slice(i, i + 2) |
There was a problem hiding this comment.
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)
src/loadContract.js
Outdated
const Contract = new web3.eth.Contract(contract.abi, contract.address) | ||
let contractName = path.basename(contract.abiPath).split('.')[0] | ||
|
||
if (rplContext[contractName]) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
No description provided.