Skip to content

Make PromiseIndex type to avoid misuse of promise indices #118

@austinabell

Description

@austinabell

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions