-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
2235ac7
to
c7ea4ab
Compare
// 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) |
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.
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 { |
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.
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.
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.