-
Notifications
You must be signed in to change notification settings - Fork 23
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
Added Human-Readable ABI format #557
Added Human-Readable ABI format #557
Conversation
✅ Deploy Preview for taco-nft-demo canceled.
|
✅ Deploy Preview for taco-demo canceled.
|
delete jsonAbi.constant; | ||
delete jsonAbi.payable; |
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.
Why do we delete these fields? Can we use destructuring and only pick relevant fields instead?
jsonAbi.inputs = jsonAbi.inputs.map((input: any) => ({ | ||
...input, | ||
internalType: input.type, | ||
})); | ||
jsonAbi.outputs = jsonAbi.outputs.map((output: any) => ({ | ||
...output, | ||
internalType: output.type, | ||
})); |
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.
Why do we need to map type
to internalType
? To be consistent with JSON ABI schema?
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.
Yes!
z | ||
.string() | ||
.refine( | ||
(abi) => { | ||
try { | ||
toJsonAbiFormat(abi); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
}, | ||
{ | ||
message: 'Invalid Human-Readable ABI format', | ||
}, | ||
) | ||
.transform(toJsonAbiFormat), |
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.
Let's move this variable into a separate declaration, just like functionAbiSchema
, humanReadableAbiSchema
?
interface ContractConditionHumanReadableAbi extends ContractConditionProps { | ||
functionAbi: string; | ||
} |
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.
Why not infer it using z.infer
?
constructor(value: OmitConditionType<ContractConditionHumanReadableAbi | ContractConditionProps>) { | ||
if (typeof value.functionAbi === 'string') { | ||
value.functionAbi = toJsonAbiFormat(value.functionAbi); | ||
} |
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.
Why do we need to update this constructor and add a type invariant? Can we update ContractConditionProps
(z.infer
) instead?
}); | ||
}); | ||
|
||
it('converts human-readable ABI to JSON ABI format', () => { |
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.
You can test the low-level behavior of humanReadableAbiSchema
here
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.
LGTM, thanks for contributing
37b0b86
to
b29b131
Compare
Type of PR:
Required reviews:
What this does:
Issues fixed/closed: