Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Validate client's Ethereum address options #223

Merged
merged 5 commits into from
Mar 15, 2021
Merged

Conversation

teogeb
Copy link
Contributor

@teogeb teogeb commented Mar 15, 2021

If user overrides some option in StreamrClientOptions, we validate that value already in the constructor. Using the option is therefore easier in the code, as we know that the value is always valid.

In this PR we validate all overriden Ethereum addresses. Open question: Should we validate also other overriden fields this way? E.g. restUrl, maxPublishQueueSize...

@teogeb teogeb requested a review from timoxley March 15, 2021 12:37
Copy link
Contributor

@timoxley timoxley left a comment

Choose a reason for hiding this comment

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

Made a recommendation to use lodash/* instead of lodash.* here: #225,
and added a few comments, but otherwise lgtm 👍 great.

test/unit/Config.test.ts Show resolved Hide resolved
test/unit/Config.test.ts Outdated Show resolved Hide resolved
if (await mainnetProvider.getCode(this.factoryMainnetAddress) === '0x') {
throw new Error(
`Data union factory contract not found at ${this.factoryMainnetAddress}, check StreamrClient.options.dataUnion.factoryMainnetAddress!`
)
}

const factoryMainnet = new Contract(this.factoryMainnetAddress!, factoryMainnetABI, mainnetWallet)
const factoryMainnet = new Contract(this.factoryMainnetAddress, factoryMainnetABI, mainnetWallet)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

src/StreamrClient.ts Show resolved Hide resolved
'dataUnion.factoryMainnetAddress',
'dataUnion.factorySidechainAddress',
'dataUnion.templateMainnetAddress',
'dataUnion.templateSidechainAddress'
Copy link
Contributor

Choose a reason for hiding this comment

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

Neat, as-is this is an improvement, but note this will silently stop working if a config is renamed or if new EthereumAddress config items are added. Developer always needs to remember to update this list of paths. A shame since we do already have the type information.

I wonder if we should do something like I described in slack, where we have an unsafe type at API boundaries, then a safe type internally and the only way to get from unsafe to safe type is to pass through the isAddress validator.

@teogeb teogeb merged commit 567d1cb into master Mar 15, 2021
@teogeb teogeb deleted the validate-ethereum-config branch March 15, 2021 17:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants