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

Why the args of transaction constructor are strictly required to be UInt8Array? #631

Open
HarmlessEvil opened this issue Aug 24, 2022 · 2 comments

Comments

@HarmlessEvil
Copy link

I noticed the following code in the transaction constructor:

txn.appArgs.forEach((arg) => {
    if (arg.constructor !== Uint8Array)
        throw Error('each element of AppArgs must be a Uint8Array.');
});

It forces the args to be of type Uint8Array, but ignores the inheritance tree. I stumbled upon this when tried to pass Buffer as transaction args, but received this error. My question is: is it intentional to force args to be strictly UInt8Array? Because I'd suggest to use instanceof here if it won't break anything.

@winder
Copy link
Contributor

winder commented Sep 29, 2022

@jasonpaulos do you know why this is?

@jasonpaulos
Copy link
Contributor

I believe this is because Uint8Array and Buffer have some differences, and we like to maintain consistency internally.

That being said, I think it'd be reasonable for the constructor to convert any Buffer arguments to Uint8Arrays instead of erroring.

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

No branches or pull requests

4 participants
@winder @jasonpaulos @HarmlessEvil and others