Skip to content

Commit

Permalink
Fix: sapling in miguel and in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored and RomanSerikov committed Feb 9, 2021
1 parent a3ea01b commit 18b4805
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/contractparser/meta/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ func parseNodeMetadata(v gjson.Result, parent node.Node, path, inheritedName str
InternalArgs: args,
}
}
case n.Is(consts.SAPLINGSTATE) || n.Is(consts.SAPLINGTRANSACTION):
if len(arr) == 1 {
return internalNode{
Node: &n,
}
}
default:
for i := range arr {
argPath := fmt.Sprintf("%s/%d", path, i)
Expand Down
8 changes: 8 additions & 0 deletions internal/contractparser/meta/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func TestParseMetadata(t *testing.T) {
name: "Case: tzbtc upgrade",
v: `[{"prim": "or", "args": [{"prim":"pair","args":[{"prim":"string"},{"prim":"bytes"}],"annots":["%run"]},{"prim":"pair","args":[{"prim":"pair","args":[{"prim":"nat","annots":[":currentVersion"]},{"prim":"nat","annots":[":newVersion"]}]},{"prim":"pair","args":[{"prim":"lambda","args":[{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]},{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]}],"annots":[":migrationScript"]},{"prim":"pair","args":[{"prim":"option","args":[{"prim":"lambda","args":[{"prim":"pair","args":[{"prim":"pair","args":[{"prim":"string"},{"prim":"bytes"}]},{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]}]},{"prim":"pair","args":[{"prim":"list","args":[{"prim":"operation"}]},{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]}]}]}],"annots":[":newCode"]},{"prim":"option","args":[{"prim":"lambda","args":[{"prim":"pair","args":[{"prim":"unit"},{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]}]},{"prim":"pair","args":[{"prim":"list","args":[{"prim":"operation"}]},{"prim":"big_map","args":[{"prim":"bytes"},{"prim":"bytes"}]}]}]}],"annots":[":newPermCode"]}]}]}],"annots":["%upgrade"]}]}]`,
want: `{"0":{"prim":"or","args":["0/0","0/1"],"type":"namedunion"},"0/0":{"fieldname":"run","prim":"pair","args":["0/0/0","0/0/1"],"type":"tuple","name":"run"},"0/0/0":{"prim":"string","type":"string"},"0/0/1":{"prim":"bytes","type":"bytes"},"0/1":{"fieldname":"upgrade","prim":"pair","args":["0/1/0/0","0/1/0/1","0/1/1/0","0/1/1/1/0/o","0/1/1/1/1/o"],"type":"namedtuple","name":"upgrade"},"0/1/0":{"prim":"pair","type":"pair"},"0/1/0/0":{"typename":"currentVersion","prim":"nat","type":"nat","name":"currentVersion"},"0/1/0/1":{"typename":"newVersion","prim":"nat","type":"nat","name":"newVersion"},"0/1/1":{"prim":"pair","type":"pair"},"0/1/1/0":{"typename":"migrationScript","prim":"lambda","parameter":"{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}","return_value":"{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}","type":"lambda","name":"migrationScript"},"0/1/1/1":{"prim":"pair","type":"pair"},"0/1/1/1/0":{"typename":"newCode","prim":"option","type":"option"},"0/1/1/1/0/o":{"prim":"lambda","parameter":"{\"prim\":\"pair\",\"args\":[{\"prim\":\"pair\",\"args\":[{\"prim\":\"string\"},{\"prim\":\"bytes\"}]},{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}]}","return_value":"{\"prim\":\"pair\",\"args\":[{\"prim\":\"list\",\"args\":[{\"prim\":\"operation\"}]},{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}]}","type":"lambda","name":"newCode"},"0/1/1/1/1":{"typename":"newPermCode","prim":"option","type":"option"},"0/1/1/1/1/o":{"prim":"lambda","parameter":"{\"prim\":\"pair\",\"args\":[{\"prim\":\"unit\"},{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}]}","return_value":"{\"prim\":\"pair\",\"args\":[{\"prim\":\"list\",\"args\":[{\"prim\":\"operation\"}]},{\"prim\":\"big_map\",\"args\":[{\"prim\":\"bytes\"},{\"prim\":\"bytes\"}]}]}","type":"lambda","name":"newPermCode"}}`,
}, {
name: "Case: KT1P7WdaJCnyyz83oBrHrFUPsxeVawGy4TSB",
v: `[{"prim":"pair","args":[{"prim":"sapling_state","args":[{"int":"8"}],"annots":[":left"]},{"prim":"sapling_state","args":[{"int":"8"}],"annots":[":right"]}]}]}]`,
want: `{"0":{"prim":"pair","args":["0/0","0/1"],"type":"namedtuple"},"0/0":{"typename":"left","prim":"sapling_state","type":"sapling_state","name":"left"},"0/1":{"typename":"right","prim":"sapling_state","type":"sapling_state","name":"right"}}`,
}, {
name: "Case KT1XpFASuiYhShqteQ4QjSfR21ERq2R3ZfrH",
v: `[{"prim":"option","args":[{"prim":"sapling_transaction","args":[{"int":"8"}]}]}]}]`,
want: `{"0":{"prim":"option","type":"option"},"0/o":{"prim":"sapling_transaction","type":"sapling_transaction"}}`,
},
}
for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion internal/contractparser/meta/parameter_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (b defaultParameterBuilder) Build(node *NodeMetadata, path string, data map
switch node.Prim {
case consts.STRING, consts.KEYHASH, consts.KEY, consts.ADDRESS, consts.CHAINID, consts.SIGNATURE, consts.CONTRACT:
return fmt.Sprintf(`{"string": %s}`, strconv.Quote(value.(string))), nil
case consts.BYTES:
case consts.BYTES, consts.SAPLINGTRANSACTION:
return fmt.Sprintf(`{"bytes": "%s"}`, strings.TrimPrefix(value.(string), "0x")), nil
case consts.INT, consts.NAT, consts.MUTEZ:
switch t := value.(type) {
Expand Down
8 changes: 7 additions & 1 deletion internal/contractparser/newmiguel/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ func (l *literalDecoder) Decode(jsonData gjson.Result, path string, nm *meta.Nod
return &node, nil
}
switch nm.Type {
case consts.MUTEZ, consts.NAT, consts.STRING, consts.INT, consts.SAPLINGSTATE:
case consts.MUTEZ, consts.NAT, consts.STRING, consts.INT:
data, err := l.simple.Decode(jsonData, path, nm, metadata, false)
if err != nil {
return nil, err
}
node.Value = data
case consts.SAPLINGSTATE:
data, err := l.simple.Decode(jsonData, path+".args.0", nm, metadata, false)
if err != nil {
return nil, err
}
node.Value = data
case consts.BLS12381FR, consts.BLS12381G1, consts.BLS12381G2:
if jsonData.Get(consts.BYTES).Exists() {
s := jsonData.Get(consts.BYTES).String()
Expand Down

0 comments on commit 18b4805

Please sign in to comment.