coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.61k stars 1.32k forks source link

ts: Automatically convert legacy IDLs #3238

Open ngundotra opened 1 month ago

ngundotra commented 1 month ago

That way explorers have easy access to same functionality as in #3009

acheroncrypto commented 1 month ago

Yep, we should do it. The Rust conversion should also work in WASM, so maybe we can use that instead rather than duplicating the logic.

ngundotra commented 1 month ago

I think I'd prefer vanilla TS so I don't have to think about where it runs.

Example port I wrote for TS: https://github.com/solana-labs/explorer/pull/374

acheroncrypto commented 1 month ago

https://github.com/solana-labs/explorer/pull/374 looks great! It would be helpful to support it from Anchor itself for other people to also benefit from it. Would you like to create a PR?

ngundotra commented 4 weeks ago

Yes I can create a PR. I will note that in order to get legacy IDLs supported, I had to prune unused types after formatting them to the new spec. Is this expected behavior? If I don't do this, an error is thrown in the construction of the Borsh coders.

https://github.com/solana-labs/explorer/pull/376#event-14250318111

acheroncrypto commented 3 weeks ago

I think it makes sense for it to error if a field references a type that's not included in the IDL (or a default type). Otherwise how can we de/serialize it correctly?

ngundotra commented 4 days ago

@acheroncrypto what if the type that's doing the dangling reference is never used?

In this case I think it should be fine to prune, right?

I think the old coder seemed to be fine loading this.

acheroncrypto commented 3 days ago

@acheroncrypto what if the type that's doing the dangling reference is never used?

In this case I think it should be fine to prune, right?

It should be fine to prune in that case.

I think the old coder seemed to be fine loading this.

I think that's because the old generation did not know whether a type was being used or not, so the old coder also had to be loose. In contrast, the new generation doesn't include unused types in the IDL.