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

Better types for opcodes #1966

Open
vostrnad opened this issue Aug 6, 2023 · 3 comments
Open

Better types for opcodes #1966

vostrnad opened this issue Aug 6, 2023 · 3 comments
Milestone

Comments

@vostrnad
Copy link

vostrnad commented Aug 6, 2023

ops.ts exports the list of opcodes as:

const OPS: { [key: string]: number }

That's not a very safe type, as it permits access with any string key. It also doesn't work with code completion.

Can this type be made more specific? It would technically be a breaking change for anyone using this in an unsafe manner, but I believe it's worth it. I'm happy to work on this.

@junderw
Copy link
Member

junderw commented Aug 7, 2023

OPS is pretty straightforward, (just as as const at the end) but REVERSE_OPS might be tricky to get to only respond to specific number keys...

Admittedly, when I migrated this library to TypeScript I was a TS beginner, and only feel like I now have a semi-intermediate grasp on it...

PRs are welcome, but I think this won't land until the next major version whenever that is.

@junderw junderw added this to the 7.0.0 milestone Sep 14, 2023
@ChrisCho-H
Copy link
Contributor

How about using enum as bitcoin core does?
https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L72

@ChrisCho-H
Copy link
Contributor

Made PR for this #2028.
Any review or commit would be grateful!

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

No branches or pull requests

3 participants