Add more builtin types

We probably should extract these from the standard library instead of
cherry picking the ones that are needed by the chain? e.g. Chain.tx
still doesn't work.
This commit is contained in:
Jarvis Carroll 2025-09-26 09:05:59 +10:00
parent 057861e9cf
commit 2abb15cceb

View File

@ -1549,15 +1549,47 @@ builtin_typedefs() ->
"hash" => {[], {bytes, [32]}}, "hash" => {[], {bytes, [32]}},
"option" => {["'T"], {variant, [{"None", []}, "option" => {["'T"], {variant, [{"None", []},
{"Some", [{var, "'T"}]}]}}, {"Some", [{var, "'T"}]}]}},
"Chain.ttl" => {[], {variant, [{"FixedTTL", [{list, [integer]}]}, "Chain.ttl" => {[], {variant, [{"FixedTTL", [integer]},
{"RelativeTTL", [{list, [integer]}]}]}}, {"RelativeTTL", [integer]}]}},
"AENS.pointee" => {[], {variant, [{"AccountPt", [{list, [address]}]}, "AENS.pointee" => {[], {variant, [{"AccountPt", [address]},
{"OraclePt", [{list, [address]}]}, {"OraclePt", [address]},
{"ContractPt", [{list, [address]}]}, {"ContractPt", [address]},
{"ChannelPt", [{list, [address]}]}]}}, {"ChannelPt", [address]}]}},
"AENS.name" => {[], {variant, [{"Name", [address, "AENS.name" => {[], {variant, [{"Name", [address,
"Chain.ttl", "Chain.ttl",
{map, [string, "AENS.pointee"]}]}]}} {map, [string, "AENS.pointee"]}]}]}},
"AENSv2.pointee" => {[], {variant, [{"AccountPt", [address]},
{"OraclePt", [address]},
{"ContractPt", [address]},
{"ChannelPt", [address]},
{"DataPt", [{bytes, [any]}]}]}},
"AENSv2.name" => {[], {variant, [{"Name", [address,
"Chain.ttl",
{map, [string, "AENSv2.pointee"]}]}]}},
"Chain.ga_meta_tx" => {[], {variant, [{"GAMetaTx", [address, integer]}]}},
"Chain.paying_for_tx" => {[], {variant, [{"PayingForTx", [address, integer]}]}},
"Chain.base_tx" => {[], {variant, [{"SpendTx", [address, integer, string]},
{"OracleRegisterTx", []},
{"OracleQueryTx", []},
{"OracleResponseTx", []},
{"OracleExtendTx", []},
{"NamePreclaimTx", []},
{"NameClaimTx", ["hash"]},
{"NameUpdateTx", [string]},
{"NameRevokeTx", ["hash"]},
{"NameTransferTx", [address, string]},
{"ChannelCreateTx", [address]},
{"ChannelDepositTx", [address, integer]},
{"ChannelWithdrawTx", [address, integer]},
{"ChannelForceProgressTx", [address]},
{"ChannelCloseMutualTx", [address]},
{"ChannelCloseSoloTx", [address]},
{"ChannelSlashTx", [address]},
{"ChannelSettleTx", [address]},
{"ChannelSnapshotSoloTx", [address]},
{"ContractCreateTx", [integer]},
{"ContractCallTx", [address, integer]},
{"GAAttachTx", []}]}}
}. }.
% Type preparation has two goals. First, we need a data structure that can be % Type preparation has two goals. First, we need a data structure that can be
@ -2693,8 +2725,22 @@ obscure_aaci_test() ->
entrypoint unit(): unit = () entrypoint unit(): unit = ()
entrypoint ttl(x): Chain.ttl = FixedTTL(x) entrypoint ttl(x): Chain.ttl = FixedTTL(x)
entrypoint paying_for(x, y): Chain.paying_for_tx = Chain.PayingForTx(x, y)
entrypoint ga_meta_tx(x, y): Chain.ga_meta_tx = Chain.GAMetaTx(x, y)
entrypoint base_tx(x, y, z): Chain.base_tx = Chain.SpendTx(x, y, z)
entrypoint tx(a, b, c, d, e, f): Chain.tx =
{paying_for = a,
ga_metas = b,
actor = c,
fee = d,
ttl = e,
tx = f}
entrypoint pointee(x): AENS.pointee = AENS.AccountPt(x) entrypoint pointee(x): AENS.pointee = AENS.AccountPt(x)
entrypoint name(x, y, z): AENS.name = AENS.Name(x, y, z) entrypoint name(x, y, z): AENS.name = AENS.Name(x, y, z)
entrypoint pointee2(x): AENSv2.pointee = AENSv2.DataPt(x)
entrypoint name2(x, y, z): AENSv2.name = AENSv2.Name(x, y, z)
", ",
{ok, AACI} = aaci_from_string(Contract), {ok, AACI} = aaci_from_string(Contract),
@ -2708,8 +2754,36 @@ obscure_aaci_test() ->
{ok, {[], {"unit", _, {tuple, []}}}} = aaci_lookup_spec(AACI, "unit"), {ok, {[], {"unit", _, {tuple, []}}}} = aaci_lookup_spec(AACI, "unit"),
{ok, {_, {"Chain.ttl", _, {variant, _}}}} = aaci_lookup_spec(AACI, "ttl"), {ok, {_, {"Chain.ttl", _, {variant, _}}}} = aaci_lookup_spec(AACI, "ttl"),
{ok, {_, {"Chain.paying_for_tx", _, {variant, _}}}} = aaci_lookup_spec(AACI, "paying_for"),
{ok, {_, {"Chain.ga_meta_tx", _, {variant, _}}}} = aaci_lookup_spec(AACI, "ga_meta_tx"),
{ok, {_, {"Chain.base_tx", _, {variant, _}}}} = aaci_lookup_spec(AACI, "base_tx"),
% Why do the other types here get hard coded in the compiler, but this one
% doesn't? Should we be getting stdlib types from includes?
%{ok, {_, {"Chain.tx", _, {variant, _}}}} = aaci_lookup_spec(AACI, "tx"),
{ok, {_, {"AENS.pointee", _, {variant, _}}}} = aaci_lookup_spec(AACI, "pointee"), {ok, {_, {"AENS.pointee", _, {variant, _}}}} = aaci_lookup_spec(AACI, "pointee"),
{ok, {_, {"AENS.name", _, {variant, _}}}} = aaci_lookup_spec(AACI, "name"), {ok, {_, {"AENS.name", _, {variant, _}}}} = aaci_lookup_spec(AACI, "name"),
{ok, {_, {"AENSv2.pointee", _, {variant, _}}}} = aaci_lookup_spec(AACI, "pointee2"),
{ok, {_, {"AENSv2.name", _, {variant, _}}}} = aaci_lookup_spec(AACI, "name2"),
ok. ok.
name_coerce_test() ->
AddrSoph = "ak_2FTnrGfV8qsfHpaSEHpBrziioCpwwzLqSevHqfxQY3PaAAdARx",
AddrFate = {address, <<164,136,155,90,124,22,40,206,255,76,213,56,238,123,
167,208,53,78,40,235,2,163,132,36,47,183,228,151,9,
210,39,214>>},
{ok, TTL} = annotate_type("Chain.ttl", builtin_typedefs()),
TTLSoph = {"FixedTTL", 0},
TTLFate = {variant, [1, 1], 0, {0}},
try_coerce(TTL, TTLSoph, TTLFate),
{ok, Pointee} = annotate_type("AENS.pointee", builtin_typedefs()),
PointeeSoph = {"AccountPt", AddrSoph},
PointeeFate = {variant, [1, 1, 1, 1], 0, {AddrFate}},
try_coerce(Pointee, PointeeSoph, PointeeFate),
{ok, Name} = annotate_type("AENS.name", builtin_typedefs()),
NameSoph = {"Name", AddrSoph, TTLSoph, #{"myname" => PointeeSoph}},
NameFate = {variant, [3], 0, {AddrFate, TTLFate, #{<<"myname">> => PointeeFate}}},
try_coerce(Name, NameSoph, NameFate).