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

fix: Fix method BigmapDetection #16

Merged
merged 10 commits into from
Sep 9, 2024
Merged

Conversation

huancheng-trili
Copy link

@huancheng-trili huancheng-trili commented Sep 4, 2024

What

Fix the method BigmapDetection.

I never really understood the logic of the original stack method. I decided to simply read the primitives following the michelson grammar. This requires all storage values to have the original primitive information, which is why the RPC code is updated.

Why

Closes #15.

Test

Added test cases. Note that one new test case is commented out because it breaks the BigmapTypeDetection method. This will be fixed in #17.

@huancheng-trili huancheng-trili changed the title fix: Fix bigmap detection fix: Fix method BigmapDetection Sep 6, 2024
// GetContractScript returns the originated contract script in default data mode.
func (c *Client) GetContractScript(ctx context.Context, addr tezos.Address) (*micheline.Script, error) {
u := fmt.Sprintf("chains/main/blocks/head/context/contracts/%s/script", addr)
Copy link
Author

Choose a reason for hiding this comment

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

Storage values retrieved from /chains/main/blocks/head/context/contracts/%s/script are not in the original primitive form. Primitive type information is crucial, so I'm reading scripts from chains/main/blocks/head/context/contracts/%s where primitive information is returned.

// Flattens pair primitives. Basically the same as the UNPAIR michelson operation.
// For instance, `pair (pair (pair 1 2) 3) 4` becomes `pair 1 2 3 4`. Other container
// primitives like map and list remain untouched.
func flatten(p Prim) []Prim {
Copy link
Author

Choose a reason for hiding this comment

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

This is needed because storage values are not always in the same shape as the type definitions in the storage code, specifically for pairs. Nested pair definitions can actually accept flattened storage values (see contract KT1CSYNJ6dFcnsV4QJ6HnBFtdif8LJGPQiDM,) so I flatten all pairs here just for consistency. In function linkStorageTypeAndValue, because pair values are assumed to be flattened, pair primitives continue to use the same value queue, unlike maps and lists that unfold the value on the spot and proceed recursively with the new unfolded value queue.

@huancheng-trili huancheng-trili marked this pull request as ready for review September 6, 2024 09:11
@huancheng-trili huancheng-trili merged commit 9c08fd0 into master Sep 9, 2024
4 checks passed
@huancheng-trili huancheng-trili deleted the fix-bigmap-detection branch September 9, 2024 13:10
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.

Error parsing BigMapIds
1 participant