Skip to content

Commit

Permalink
Using hardcoded snippet temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya committed Apr 25, 2024
1 parent bad37a1 commit be3accd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion apps/docs/src/guide/types/vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,28 @@ Some Sway functions require you to pass in bytecode to the function. The type of

Take the `compute_bytecode_root` function from the [`bytecode` Sway library](https://github.com/FuelLabs/sway-libs/tree/master/libs/src/bytecode.sw), for example.

<<< @/../../docs-snippets/test/fixtures/forc-projects/bytecode-input/src/main.sw#vector-bytecode-input-sway{ts:line-numbers}
<!-- <<< @/../../docs-snippets/test/fixtures/forc-projects/bytecode-input/src/main.sw#vector-bytecode-input-sway{ts:line-numbers} -->

<!-- TODO: Uncomment swap hardcoded snippet -->

```rust
contract;

use bytecode::*;

abi MyContract {
fn compute_bytecode_root(bytecode_input: Vec<u8>) -> b256;
}

impl MyContract for Contract {
// #region vector-bytecode-input-sway
fn compute_bytecode_root(bytecode_input: Vec<u8>) -> bool {
let root = compute_bytecode_root(bytecode_input);
return root;
}
// #endregion vector-bytecode-input-sway
}
```

To pass bytecode to this function, you can make use of the `arrayify` function to convert the bytecode file contents into a `UInt8Array`, the TS compatible type for Sway's `Vec<u8>` type and pass it the function like so:

Expand Down

0 comments on commit be3accd

Please sign in to comment.