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

Make PromiseIndex type to avoid misuse of promise indices #118

Closed
austinabell opened this issue Jun 23, 2022 · 4 comments · Fixed by #260
Closed

Make PromiseIndex type to avoid misuse of promise indices #118

austinabell opened this issue Jun 23, 2022 · 4 comments · Fixed by #260
Assignees

Comments

@austinabell
Copy link
Contributor

austinabell commented Jun 23, 2022

Context: this is an optional and breaking suggestion

Currently, most APIs use BigInt or number | BigInt to represent the promise indices, which is very prone for misuse.

Take:

export function promiseBatchActionTransfer(promiseIndex: number | BigInt, amount: number | BigInt)

This function makes it very easy to swap the order of these and cause a bug at runtime either from unexpected behavior or a panic at runtime if the promise index does not exist.

There should be no way to manually construct a promise index, so it would be preferred if promiseCreate and other related functions returned a class/object that are only constructed by those functions. This would allow those bugs to be caught at compile time when using TS and runtime if using JS (but friendlier runtime error than if this wasn't done).

A lot of these APIs are way too easy to misuse, which will cause issues for people.

@austinabell austinabell added invalid This doesn't seem right Discussion and removed invalid This doesn't seem right labels Jun 23, 2022
@ailisp
Copy link
Member

ailisp commented Jul 22, 2022

Good idea, looks like this is also how rust sdk handles promise index

@ailisp
Copy link
Member

ailisp commented Sep 20, 2022

It's being addressed in part of #213

@exalate-issue-sync
Copy link

Jane Wang commented:

Looks like partially addressed by this PR #213

@exalate-issue-sync
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants