-
Notifications
You must be signed in to change notification settings - Fork 754
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: Implement Calldata Decoding to JSC Types #1018
base: develop
Are you sure you want to change the base?
feat: Implement Calldata Decoding to JSC Types #1018
Conversation
c238cfe
to
fe4fcfd
Compare
14ae463
to
055ed25
Compare
@tabaktoni @ivpavici |
Good point splitting it into two subtasks is more manageable. |
Are the current changes a step in the right direction? If so, then I'll start to work on the API encoder part as well :D |
In general, this is a good direction. I think you would focus for now only on this part of the task as there are multiple data types to support this flow. Priority is to have test type by type and mix types for this flow. |
Hi, sorry I was busy last week and couldn't get to this task, I'll quickly get to addressing these, and implementing the rest of the solution :) |
055ed25
to
e4a97ee
Compare
@tabaktoni I've written an initial test. Does this approach seem correct to you?
|
997f282
to
00e104c
Compare
Not sure what was the goal with Iterator, but in general I imagine test to be like: import contractX....
const data = {
list: [1, 3n],
balance: "0x34"
};
const cd = new CallData(contractX.abi);
const compiledCalldata = cd.compile('methodY', testData)
const decompiledCalldata = cd.decompile(compiledCalldata)
expect(data).toEqual(decompiledCalldata) You can use any of predefined contracts abi we already have in mocks for example: starknet.js/__tests__/cairo1v2.test.ts Line 560 in dceaf85
and use const contractCallData: CallData = new CallData(compiledComplexSierra.abi); |
00e104c
to
4b6c6e7
Compare
I am a bit in trouble to review this PR. For example, if I want to decode the encoded parameters of a function, I just write 4 lines : const encodedCalldata=["4674576345645645","2000","0"];
const fnName="transfer";
const myCallData=new CallData(abi);
const { inputs } = myCallData.parser.getLegacyFormat().find((abiItem:AbiEntry) => abiItem.name === fnName) as FunctionAbi;
const inputsTypes=inputs.map((inp:any)=>{return inp.type as string});
const result=myCallData.decodeParameters(inputsTypes,encodedCalldata);
console.log(result); |
Hey, @PhilippeR26, Can you share a link for this code? I'd love to take a look as well. As for the PR, from the issue, according to me, while you already have a great way to accomplish this, having a proper functionality setup within the repo itself would be both more user-friendly and also more sustainable. This will allow a seamless transition between the blockchain and JSC types without having to rely on external tools/write custom logic yourself for each new use case. Plus, it improves flexibility and customization for handling complex data structures. Additionally, it'll help in validation, error handling, and testing, enhancing the reliability and maintainability of the repo. |
And if you want to encode a function response, you can use the current code this way : const params = [cairo.tuple(300,new CairoOption<BigNumberish>(CairoOptionVariant.Some,50));];
const selectedType = "(core::felt252, core::option::Option::<core::integer::u8>)";
const iter = params[Symbol.iterator]();
const structs = CallData.getAbiStruct(abi);
const enums = CallData.getAbiEnum(abi);
const abiExtract = abi.find((abiItem) => abiItem.name === selectedType);
const inputAbi: AbiEntry = abiExtract ?
{ name: abiExtract.type, type: abiExtract.name } :
{ name: "literal", type: responseType };
const result = parseCalldataField(iter, inputAbi, structs, enums); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some guidelines:
- The response is only an object no need for an array.
- Cleanup
- re-enable lint src/
- resolve circle dependency
fb94876
to
764e316
Compare
Motivation and Resolution
Resolves #952
Currently involves calldata decoder, ie,
calldata -> JSC types
Checklist: