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

Allow to decode contract call without function name #297

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

davidyuk
Copy link
Member

@davidyuk davidyuk commented Nov 15, 2024

I feel missed the ability to decode contract call without knowing the function name using ACI. The requirement to provide function name looks unnecessary since the calldata already prefixed with the hash of that name.

To avoid ambiguity I propose to limit decoding only to the main contract (the last in ACI).

At last, I don't see a way for good naming without breaking changes.

This PR is supported by the Æternity Foundation

@davidyuk davidyuk requested a review from dincho November 15, 2024 15:31
@dincho
Copy link
Member

dincho commented Nov 18, 2024

I'm positive about adding a functionality to decode function id/names, but I definitely disagree with the proposed implementation, I'll comment the code for details.

* @param {string} data - Encoded calldata in canonical format.
* @returns {object} Decoded data
*/
decodeCallWithoutFunctionName(data) {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to have a single responsibility methods, thus something like decodeFunction without returning and decoding the actual data as it already exists as functionality

@@ -140,6 +142,18 @@ class AciTypeResolver extends TypeResolver {

return [typeDef, vars]
}

getContractAndFunctionNameById(functionId) {
Copy link
Member

Choose a reason for hiding this comment

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

getFunction should fit better, have a function name that includes all parameters and return structure properties makes no sense to me, see BytecodeTypeResolver for example

@davidyuk davidyuk force-pushed the decode-calldata-without-names branch from f22b742 to 696b968 Compare November 20, 2024 07:55
@davidyuk davidyuk requested a review from dincho November 20, 2024 07:56
@@ -39,7 +39,7 @@ class AciContractCallEncoder {
* const data = encoder.decodeCall('Test', 'test_string', 'cb_KxHwzCuVGyl3aG9vbHltb2x5zwMSnw==')
* console.log(`Decoded data: ${data}`)
* // Outputs:
* // Decoded data: ["whoolymoly"]
* // Decoded data: { functionId: "f0cc2b95", args: ["whoolymoly"] }
Copy link
Member

Choose a reason for hiding this comment

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

leftover ?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, this example is not correct. I see this format returned in tests:

test('Decode calldata', t => {
t.plan(1)
const decoded = encoder.decodeCall(
CONTRACT,
'test_template_maze',
'cb_KxGu5Sw8G6+CAAQBSzsrAgQGCK+EAAABAAIbFCg7KwIEBgj8xaf6',
)
t.deepEqual(
decoded,
{
functionId: 'aee52c3c',
args: [{
Any: [
{origin: {x: 1n, y: 2n}, a: 3n, b: 4n},
{Yep: [10n]},
20n,
{origin: {x: 1n, y: 2n}, a: 3n, b: 4n},
]
}]
}
)
})

@@ -72,20 +72,43 @@ class AciContractCallEncoder {
* const data = encoder.decodeCall('Test', 'test_string', 'cb_KxHwzCuVGyl3aG9vbHltb2x5zwMSnw==')
* console.log(`Decoded data: ${data}`)
* // Outputs:
* // Decoded data: ["whoolymoly"]
* // Decoded data: { functionId: "f0cc2b95", args: ["whoolymoly"] }
Copy link
Member

Choose a reason for hiding this comment

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

leftover?

dincho
dincho previously approved these changes Nov 28, 2024
Copy link
Member

@dincho dincho left a comment

Choose a reason for hiding this comment

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

thanks

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

Successfully merging this pull request may close these issues.

2 participants