From 18b4805b22bcf003316a33053fc987f63a98c2b5 Mon Sep 17 00:00:00 2001 From: Artem Date: Tue, 9 Feb 2021 20:40:05 +0300 Subject: [PATCH] Fix: sapling in miguel and in schema --- internal/contractparser/meta/data.go | 6 ++++++ internal/contractparser/meta/data_test.go | 8 ++++++++ internal/contractparser/meta/parameter_builder.go | 2 +- internal/contractparser/newmiguel/literal.go | 8 +++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/internal/contractparser/meta/data.go b/internal/contractparser/meta/data.go index a52321ee7..d8988a75c 100644 --- a/internal/contractparser/meta/data.go +++ b/internal/contractparser/meta/data.go @@ -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) diff --git a/internal/contractparser/meta/data_test.go b/internal/contractparser/meta/data_test.go index d6091962a..1ac669d67 100644 --- a/internal/contractparser/meta/data_test.go +++ b/internal/contractparser/meta/data_test.go @@ -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 { diff --git a/internal/contractparser/meta/parameter_builder.go b/internal/contractparser/meta/parameter_builder.go index b14373a62..32631740c 100644 --- a/internal/contractparser/meta/parameter_builder.go +++ b/internal/contractparser/meta/parameter_builder.go @@ -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) { diff --git a/internal/contractparser/newmiguel/literal.go b/internal/contractparser/newmiguel/literal.go index cd8e2b8e7..b5e43e6d4 100644 --- a/internal/contractparser/newmiguel/literal.go +++ b/internal/contractparser/newmiguel/literal.go @@ -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()