-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add a helper for the conversion: bytecode file contents -> Vec<u8>
#1950
Comments
@Dhaiwat10 You mean the contract bytecode needs to be sent as an argument to another contract/function call? |
@arboleya precisely |
If we were to treat import { arrayify } from 'fuels';
const bytecodeFromFile = readFile(pathToBytecode); // string
await contract.functions.verify_bytecode(arrayify(bytecodeFromFile)); On first look, it seems to me that this wouldn't even require any change to the runtime behavior in pointer.dynamicData = {
0: concatWithDynamicData(Array.from(value).map((v) => this.coder.encode(v))),
};
Array.from(new Uint8Array([1,2,3]));
// Array(3) [1, 2, 3]
Array.from([1,2,3]);
// Array(3) [1, 2, 3] |
@sarahschwartz Could you try my proposal from above? You'd have to do something like this: await contract.functions.verify_bytecode(arrayify(bytecodeFromFile) as unknown as number[]); |
I tried this, but i get this error:
Here is my code for reference: Sway Contract: fn verify_bytecode_test(bytecode_input: Vec<u8>){
let mut bytecode = bytecode_input;
let root = compute_bytecode_root(bytecode);
log(root);
} Next.js app: // server side
const byteCodePath = join(
fuelnautPath,
`${levelKey}/out/debug/${levelKey}.bin`,
);
const bytecode = readFileSync(byteCodePath);
const base64Bytecode = bytecode.toString('base64');
// client side
const bytecodeBuffer = Buffer.from(base64Bytecode, 'base64');
const input = arrayify(bytecodeBuffer) as unknown as number[];
console.log("INPUT:", input)
await contract.functions
.verify_bytecode_test(input)
.txParams({ gasPrice: 1, gasLimit: 1_000_000 })
.call(); I can log the input though:
|
We need a helper function to read bytecode from a file and convert that to a bytearray that users can pass into our
sway-libs
functions related to bytecode: https://github.com/FuelLabs/sway-libs/tree/master/libs/bytecodeThis conversion is required because the bytecode from a file is a
string
, but the type that these Sway functions accept for the bytecode is aVec<u8>
- which in JavaScript-land is aVec<BigNumberish>
.This helper would convert the string to the proper type and ensure all the data is correctly packed.
Possible API
The Fuelnaut project is blocked for now until we figure this out.
The text was updated successfully, but these errors were encountered: