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

feat: accept Uint8Arrays as inputs for Vecs, add docs for bytecode inputs #2018

Merged
merged 19 commits into from
Apr 10, 2024

Conversation

Dhaiwat10
Copy link
Member

@Dhaiwat10 Dhaiwat10 commented Apr 5, 2024

Summary

Before this PR, the VecCoder wasn't accepting input arrays of type Uint8Array. In some cases, like the compute_bytecode_root function from the bytecode Sway Lib, you need to pass in a Uint8Array to the Sway function.

I have tweaked the validation inside the VecCoder for the inputs, and also added some documentation around how to pass in bytecode to Sway functions.

You can pass in bytecode to any Sway function like so now:

import { arrayify } from 'fuels';

const { logs } = await contract.functions
  .compute_bytecode_root(arrayify(bytecodeFromFile))
  .call();

Closes #1950

This PR will unblock the Fuelnaut project, too.

@Dhaiwat10 Dhaiwat10 self-assigned this Apr 5, 2024
@Dhaiwat10 Dhaiwat10 added the feat Issue is a feature label Apr 5, 2024
@Dhaiwat10 Dhaiwat10 marked this pull request as ready for review April 5, 2024 19:55
@Dhaiwat10 Dhaiwat10 marked this pull request as draft April 5, 2024 19:55
@Dhaiwat10 Dhaiwat10 changed the title feat: accept Uint8Arrays as inputs for Vecs feat: accept Uint8Arrays as inputs for Vecs, add docs for bytecode inputs Apr 5, 2024
@Dhaiwat10 Dhaiwat10 marked this pull request as ready for review April 5, 2024 22:00
apps/docs-snippets/src/guide/types/vector.test.ts Outdated Show resolved Hide resolved
apps/docs/src/guide/types/vectors.md Outdated Show resolved Hide resolved
packages/abi-coder/src/encoding/coders/v0/VecCoder.ts Outdated Show resolved Hide resolved
apps/docs-snippets/src/guide/types/vector.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@danielbate danielbate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm IMO a Vec<u8> representing a byte array should actually be taking Bytes as the input? Which would then be picked up by the ByteCoder which accepts UInt8Array. Is this a sway built in function which accepts Vec<u8> when expecting bytes?

Co-authored-by: Peter Smith <[email protected]>
@Dhaiwat10
Copy link
Member Author

@danielbate yes that is the case. All the functions in this Sway library (which is officially maintained and supported by us) accept bytecode as Vec<u8>

Copy link
Contributor

@petertonysmith94 petertonysmith94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! One small nit.

Co-authored-by: Peter Smith <[email protected]>
Copy link
Contributor

@petertonysmith94 petertonysmith94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks great 😆

Copy link
Contributor

This PR is published in NPM with version 0.0.0-pr-2018-20240410113607

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
79.41%(+0%) 69.7%(+0.03%) 77.47%(+0.02%) 79.55%(+0%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 packages/abi-coder/src/utils/utilities.ts 98.24%
(+0.03%)
90%
(+0%)
100%
(+0%)
98.36%
(+0.06%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a helper for the conversion: bytecode file contents -> Vec<u8>
5 participants