shazow / whatsabi

Extract the ABI (and resolve proxies, and get other metadata) from Ethereum bytecode, even without source code.
https://shazow.github.io/whatsabi/
MIT License
1.04k stars 71 forks source link

loaders: getContract returns non-nullable ContractResult #81

Closed shazow closed 8 months ago

shazow commented 8 months ago

Made ContractResult non-nullable (and renamed to be similar to AutoloadResult).

This way we can do more ergonomic

const { abi, name, ok } = await loader.getContract(address);
if (!ok) throw "failed"; // If we care, or skip this altogether if we don't
...

Rather than

const result = await loader.getContract(address);
if (result === null) throw "failed"; // Need this check either way, because it's nullable
const { abi, name } = result;
...

@SonOfMosiah what do you think?

SonOfMosiah commented 8 months ago

Looks great! I was thinking of a status or success variable and I ok does the trick.

shazow commented 8 months ago

I figure ok is a little closer to the Result-type that some other languages have. 🤷