Skip to content

Commit

Permalink
Fix: entrypoint API
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jun 23, 2023
1 parent f132dd0 commit 224978f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/bcd/ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,10 @@ func TestTypedAst_GetEntrypointsDocs(t *testing.T) {
name: "ithacanet/KT1AJJLbnxLdwkzmjAdz3SJ64B2brYcjox5M/storage",
tree: `{"prim":"pair","args":[{"prim":"option","args":[{"prim":"ticket","args":[{"prim":"int"}]}],"annots":["%x"]},{"prim":"option","args":[{"prim":"ticket","args":[{"prim":"string"}]}],"annots":["%y"]}]}`,
result: `[{"name":"default","typedef":[{"name":"@pair_1","type":"pair","args":[{"key":"x","value":"option(ticket(int))"},{"key":"y","value":"option(ticket(string))"}]}]}]`,
}, {
name: "ghostnet/KT1SZUANBGK1dz1uuTyYqZPWMGzJ779JYB42",
tree: `{"prim":"or","args":[{"prim":"pair","args":[{"prim":"address","annots":["%contract"]},{"prim":"or","args":[{"prim":"map","args":[{"prim":"nat"},{"prim":"option","args":[{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%provider"]},{"prim":"nat","annots":["%token1_id"]},{"prim":"nat","annots":["%token2_id"]},{"prim":"bytes","annots":["%options"]}]}]}],"annots":["%updateDexes"]},{"prim":"or","args":[{"prim":"map","args":[{"prim":"nat"},{"prim":"option","args":[{"prim":"or","args":[{"prim":"or","args":[{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%decimals"]}],"annots":["%fa12"]},{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%fa2_id"]},{"prim":"nat","annots":["%decimals"]}],"annots":["%fa2"]}]},{"prim":"nat","annots":["%xtz"]}]}]}],"annots":["%updateTokens"]},{"prim":"or","args":[{"prim":"map","args":[{"prim":"nat"},{"prim":"option","args":[{"prim":"lambda","args":[{"prim":"pair","args":[{"prim":"pair","args":[{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%provider"]},{"prim":"nat","annots":["%token1_id"]},{"prim":"nat","annots":["%token2_id"]},{"prim":"bytes","annots":["%options"]}],"annots":["%dex"]},{"prim":"nat","annots":["%amount_in"]},{"prim":"bool","annots":["%is_sell"]},{"prim":"bytes","annots":["%params"]}]},{"prim":"big_map","args":[{"prim":"nat"},{"prim":"or","args":[{"prim":"or","args":[{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%decimals"]}],"annots":["%fa12"]},{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%fa2_id"]},{"prim":"nat","annots":["%decimals"]}],"annots":["%fa2"]}]},{"prim":"nat","annots":["%xtz"]}]}],"annots":["%tokens"]},{"prim":"big_map","args":[{"prim":"nat"},{"prim":"pair","args":[{"prim":"address","annots":["%contract_address"]},{"prim":"nat","annots":["%provider"]},{"prim":"nat","annots":["%token1_id"]},{"prim":"nat","annots":["%token2_id"]},{"prim":"bytes","annots":["%options"]}]}],"annots":["%dexes"]},{"prim":"address","annots":["%dex_referral"]}]},{"prim":"list","args":[{"prim":"operation"}]}]}]}],"annots":["%updateProviders"]},{"prim":"or","args":[{"prim":"option","args":[{"prim":"address"}],"annots":["%setAdmin"]},{"prim":"or","args":[{"prim":"bool","annots":["%setPaused"]},{"prim":"or","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"nat","annots":["%id"]},{"prim":"address","annots":["%spender_address"]},{"prim":"nat","annots":["%amount"]}]}],"annots":["%approveTokens"]},{"prim":"or","args":[{"prim":"pair","args":[{"prim":"list","args":[{"prim":"pair","args":[{"prim":"nat","annots":["%id"]},{"prim":"nat","annots":["%amount"]}]}],"annots":["%tokens"]},{"prim":"address","annots":["%out_address"]}],"annots":["%withdrawTokens"]},{"prim":"or","args":[{"prim":"pair","args":[{"prim":"option","args":[{"prim":"nat"}],"annots":["%value"]},{"prim":"option","args":[{"prim":"address"}],"annots":["%recipient"]}],"annots":["%updateFeeOptions"]},{"prim":"or","args":[{"prim":"address","annots":["%updateDexReferral"]},{"prim":"or","args":[{"prim":"address","annots":["%updateContract"]},{"prim":"unit","annots":["%confirmAdmin"]}]}]}]}]}]}]}]}]}]}],"annots":["%action"]}],"annots":["%execute"]},{"prim":"or","args":[{"prim":"map","args":[{"prim":"address"},{"prim":"option","args":[{"prim":"nat"}]}],"annots":["%updateAccounts"]},{"prim":"unit","annots":["%confirmAccount"]}]}]}`,
result: `[{"name":"execute","typedef":[{"name":"execute","type":"pair","args":[{"key":"contract","value":"address"},{"key":"action","value":"$action"}]},{"name":"action","type":"or","args":[{"key":"updateDexes","value":"map(nat, option($updateDexes_value))"},{"key":"updateTokens","value":"map(nat, option($updateTokens_value))"},{"key":"updateProviders","value":"map(nat, option($updateProviders_value))"},{"key":"setAdmin","value":"option(address)"},{"key":"setPaused","value":"bool"},{"key":"approveTokens","value":"list($approveTokens_item)"},{"key":"withdrawTokens","value":"$withdrawTokens"},{"key":"updateFeeOptions","value":"$updateFeeOptions"},{"key":"updateDexReferral","value":"address"},{"key":"updateContract","value":"address"},{"key":"confirmAdmin","value":"unit"}]},{"name":"@nat_6","type":"nat"},{"name":"updateDexes_value","type":"pair","args":[{"key":"contract_address","value":"address"},{"key":"provider","value":"nat"},{"key":"token1_id","value":"nat"},{"key":"token2_id","value":"nat"},{"key":"options","value":"bytes"}]},{"name":"@nat_19","type":"nat"},{"name":"fa12","type":"pair","args":[{"key":"contract_address","value":"address"},{"key":"decimals","value":"nat"}]},{"name":"fa2","type":"pair","args":[{"key":"contract_address","value":"address"},{"key":"fa2_id","value":"nat"},{"key":"decimals","value":"nat"}]},{"name":"@nat_34","type":"nat"},{"name":"updateProviders_value","type":"lambda","args":[{"key":"input","value":"pair (pair (pair %dex (address %contract_address) (pair (nat %provider) (pair (nat %token1_id) (pair (nat %token2_id) (bytes %options))))) (pair (nat %amount_in) (pair (bool %is_sell) (bytes %params)))) (pair (big_map %tokens nat (or (or (pair %fa12 (address %contract_address) (nat %decimals)) (pair %fa2 (address %contract_address) (pair (nat %fa2_id) (nat %decimals)))) (nat %xtz))) (pair (big_map %dexes nat (pair (address %contract_address) (pair (nat %provider) (pair (nat %token1_id) (pair (nat %token2_id) (bytes %options)))))) (address %dex_referral)))"},{"key":"return","value":"list operation"}]},{"name":"approveTokens_item","type":"pair","args":[{"key":"id","value":"nat"},{"key":"spender_address","value":"address"},{"key":"amount","value":"nat"}]},{"name":"withdrawTokens","type":"pair","args":[{"key":"tokens","value":"list($tokens_item)"},{"key":"out_address","value":"address"}]},{"name":"tokens_item","type":"pair","args":[{"key":"id","value":"nat"},{"key":"amount","value":"nat"}]},{"name":"updateFeeOptions","type":"pair","args":[{"key":"value","value":"option(nat)"},{"key":"recipient","value":"option(address)"}]}]},{"name":"updateAccounts","typedef":[{"name":"updateAccounts","type":"map(address, option(nat))","args":[{"key":"@address_114","value":"address"},{"value":"option(nat)"}]},{"name":"@address_114","type":"address"}]},{"name":"confirmAccount","typedef":[{"name":"confirmAccount","type":"unit"}]}]`,
},
}
for _, tt := range tests {
Expand Down
6 changes: 5 additions & 1 deletion internal/bcd/ast/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,11 @@ func (m *Map) Docs(inferredName string) ([]Typedef, string, error) {
if err != nil {
return nil, "", err
}
typedef.Args = append(typedef.Args, TypedefArg{Key: valDocs[0].Name, Value: valVarName})
if len(valDocs) > 0 {
typedef.Args = append(typedef.Args, TypedefArg{Key: valDocs[0].Name, Value: valVarName})
} else {
typedef.Args = append(typedef.Args, TypedefArg{Value: valVarName})
}

typedef.Type = fmt.Sprintf("map(%s, %s)", keyVarName, valVarName)
result := []Typedef{typedef}
Expand Down

0 comments on commit 224978f

Please sign in to comment.