Skip to content

Replace abi-decoder with ethers#9290

Merged
rekmarks merged 6 commits intodevelopfrom
replace-decode-abi
Aug 22, 2020
Merged

Replace abi-decoder with ethers#9290
rekmarks merged 6 commits intodevelopfrom
replace-decode-abi

Conversation

@rekmarks
Copy link
Copy Markdown
Member

@rekmarks rekmarks commented Aug 21, 2020

Replaces abi-decoder with the equivalent functionality in ethers.

This required significant changes to our unit tests, as the APIs and interfaces are quite different.

@rekmarks rekmarks requested a review from a team as a code owner August 21, 2020 16:29
@rekmarks rekmarks requested review from Gudahtt and whymarrh August 21, 2020 16:29
const { name } = (data && abiDecoder.decodeMethod(data)) || {}
let name
try {
name = data && hstInterface.parseTransaction({ data }).name
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ethers throws errors when invalid ABIs are passed to it whereas abi-decoder simply returns undefined.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that behavior is only relied on in transaction controller tests, but we don't need to investigate that further here.

const toAddressData = tokenParams.find((param) => param.name === '_to')
return toAddressData ? toAddressData.value : tokenParams[0].value
export function getTokenToAddress (tokenData = {}) {
return tokenData?.args?.['_to']?.toString().toLowerCase()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ethers uses checksummed addresses.

Comment on lines +50 to +56
if (test.tokenData) {
assert.equal(result.current.name, test.tokenData.name)
assert.equal(result.current.args[0].toLowerCase(), test.tokenData.args[0])
assert.ok(test.tokenData.args[1].eq(result.current.args[1]))
} else {
assert.equal(result.current, test.tokenData)
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The data returned by ethers includes a bunch of stuff that doesn't serialize well, so I decided to simply check some emblematic data that we use in practice. I'm pretty sure that the correctness of the data we check implies the correctness of everything else, should we ever want to use it.

Comment on lines +34 to +39
export function getTokenData (data) {
try {
return hstInterface.parseTransaction({ data })
} catch (_) {
return undefined
}
Copy link
Copy Markdown
Member Author

@rekmarks rekmarks Aug 21, 2020

Choose a reason for hiding this comment

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [d8c90d0]
Page Load Metrics (478 ± 68 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint278640167
domContentLoaded30867647614268
load31467747814268
domInteractive30867647514268

Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

It looks like there are still a few required changes as a result of the confirmTransaction.tokenData state. e.g there is a selector in ui/app/selectors/confirm-transaction.js that still references tokenData.params

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [b19f2ea]
Page Load Metrics (476 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint297837115
domContentLoaded30064347412460
load30164747612460
domInteractive29964247412459

@rekmarks rekmarks requested a review from Gudahtt August 21, 2020 23:03
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

I found one more remaining reference to the old tokenData structure in ui/app/pages/confirm-send-token/confirm-send-token.container.js. I think this is the last one?

@rekmarks
Copy link
Copy Markdown
Member Author

rekmarks commented Aug 22, 2020

@Gudahtt I addressed the tokenData usage in confirm-send-token in 939302c. In addition, I renamed getTokenToAddress and getTokenValue to getTokenAddressParam and getTokenValueParam, respectively, to better reflect what they're doing. In particuar, getTokenToAddress sometimes returns the "spender" address per the Human Standard Token ABI.

@rekmarks
Copy link
Copy Markdown
Member Author

After reviewing the Human Standard Token ABI (and our quite loose usage of the token param value getters), I restored their internal logic and added docstrings in 6279f39. In short, getTokenValueParam should only attempt to get the param named _value and getTokenAddressParam should default to the param named _to and then fallback to the first param.

@rekmarks rekmarks requested a review from Gudahtt August 22, 2020 02:10
Copy link
Copy Markdown
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [6279f39]
Page Load Metrics (422 ± 59 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint2910637168
domContentLoaded30862742012359
load31262942212359
domInteractive30762742012359

@rekmarks rekmarks merged commit 3aaa41e into develop Aug 22, 2020
@rekmarks rekmarks deleted the replace-decode-abi branch August 22, 2020 02:29
@MetaMask MetaMask locked as resolved and limited conversation to collaborators Jun 22, 2021
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.

3 participants