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

Added Human-Readable ABI format #557

Open
wants to merge 4 commits into
base: epic-humanreadableabi
Choose a base branch
from

Conversation

andresceballosm
Copy link

Type of PR:

  • Bugfix
  • Feature
  • Documentation
  • Other

Required reviews:

  • 1
  • 2
  • 3

What this does:

Added Human-Readable ABI format

Issues fixed/closed:

Copy link

netlify bot commented Jul 29, 2024

Deploy Preview for taco-nft-demo canceled.

Name Link
🔨 Latest commit b731bf2
🔍 Latest deploy log https://app.netlify.com/sites/taco-nft-demo/deploys/66a7f8cfe60e530008603b2b

Copy link

netlify bot commented Jul 29, 2024

Deploy Preview for taco-demo canceled.

Name Link
🔨 Latest commit b731bf2
🔍 Latest deploy log https://app.netlify.com/sites/taco-demo/deploys/66a7f8cfe60e530008603b29

Comment on lines 83 to 84
delete jsonAbi.constant;
delete jsonAbi.payable;
Copy link
Contributor

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?

Comment on lines 86 to 93
jsonAbi.inputs = jsonAbi.inputs.map((input: any) => ({
...input,
internalType: input.type,
}));
jsonAbi.outputs = jsonAbi.outputs.map((output: any) => ({
...output,
internalType: output.type,
}));
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

Yes!

Comment on lines 113 to 128
z
.string()
.refine(
(abi) => {
try {
toJsonAbiFormat(abi);
return true;
} catch (e) {
return false;
}
},
{
message: 'Invalid Human-Readable ABI format',
},
)
.transform(toJsonAbiFormat),
Copy link
Contributor

@piotr-roslaniec piotr-roslaniec Jul 29, 2024

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?

Comment on lines 146 to 148
interface ContractConditionHumanReadableAbi extends ContractConditionProps {
functionAbi: string;
}
Copy link
Contributor

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?

Comment on lines 151 to 156
constructor(value: OmitConditionType<ContractConditionHumanReadableAbi | ContractConditionProps>) {
if (typeof value.functionAbi === 'string') {
value.functionAbi = toJsonAbiFormat(value.functionAbi);
}
Copy link
Contributor

@piotr-roslaniec piotr-roslaniec Jul 29, 2024

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', () => {
Copy link
Contributor

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

Copy link
Contributor

@piotr-roslaniec piotr-roslaniec left a 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

@derekpierre derekpierre changed the base branch from main to epic-humanreadableabi July 31, 2024 12:06
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.

Support human-redeable ABI format in ContractCondition.functionAbi
4 participants