From f29cf5a61281e7297cfe5e135943b8d7b1059c8a Mon Sep 17 00:00:00 2001 From: technomad21c Date: Fri, 22 May 2020 14:23:39 -0700 Subject: [PATCH] add the ID Contract example for cameligo and reasonligo --- src/test/examples/cameligo/id.mligo | 31 ++++++++++++++++ src/test/examples/reasonligo/id.religo | 49 +++++++++++++++++++++----- 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/src/test/examples/cameligo/id.mligo b/src/test/examples/cameligo/id.mligo index 660c50616..8ae86b16d 100644 --- a/src/test/examples/cameligo/id.mligo +++ b/src/test/examples/cameligo/id.mligo @@ -4,10 +4,41 @@ compile: entrypoint: main dryRun: + entrypoint: main + parameters: | + Buy ( + { + profile=0x0501000000026869; + initial_controller=Some(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)) + } + ) + storage: | + { + identities=Big_map.literal[(1, {owner=("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); controller=("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address); profile=0x0501000000026869});]; + next_id=2; + name_price=0tez; + skip_price=333mutez + } + deploy: evaluateValue: entrypoint: "" evaluateFunction: + entrypoint: buy + parameters: | + { + profile=0x0501000000026869; + initial_controller=Some(("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address)) + }, + + { + identities=Big_map.literal[(1, {owner=("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address); + controller=("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address); + profile=0x0501000000026869});]; + next_id=2; + name_price=0tez; + skip_price=333mutez + } *_*) type id = int diff --git a/src/test/examples/reasonligo/id.religo b/src/test/examples/reasonligo/id.religo index 715aec10d..456439a0c 100644 --- a/src/test/examples/reasonligo/id.religo +++ b/src/test/examples/reasonligo/id.religo @@ -1,16 +1,47 @@ -(*_* +/* (*_* name: ID Contract (ReasonLIGO) language: reasonligo compile: entrypoint: main dryRun: + entrypoint: main + parameters: | + Buy ( + { + profile: 0x0501000000026869, initial_controller: Some(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)) + } + ) + storage: | + { + identities:Big_map.literal([(1, {owner:("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), + controller:("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), profile:0x0501000000026869})]), + next_id:2, + name_price:0tez, + skip_price:333mutez + } deploy: entrypoint: main storage: 0 evaluateValue: entrypoint: "" evaluateFunction: -*_*) + entrypoint: buy + parameters: | + ( + { + profile: 0x0501000000026869, + initial_controller: Some(("tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN" : address)) + }, + { + identities:Big_map.literal([(1, {owner:("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx" : address), + controller:("tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx": address), + profile:0x0501000000026869})]), + next_id:2, + name_price:0tez, + skip_price:333mutez + } + ) +*_*) */ type id = int @@ -42,8 +73,8 @@ type action = | Update_details(update_details) | Skip(unit) -(* The prices kept in storage can be changed by bakers, though they should only be - adjusted down over time, not up. *) +/* The prices kept in storage can be changed by bakers, though they should only be + adjusted down over time, not up. */ type storage = { identities: big_map (id, id_details), next_id: int, @@ -51,7 +82,7 @@ type storage = { skip_price: tez, } -(** Preliminary thoughts on ids: +/** Preliminary thoughts on ids: I very much like the simplicity of http://gurno.com/adam/mne/. 5 three letter words means you have a 15 character identity, not actually more @@ -64,7 +95,7 @@ something so people don't eat up the address space. 256 ^ 5 means you have a lot of address space, but if people troll by skipping a lot that could be eaten up. Should probably do some napkin calculations for how expensive skipping needs to be to deter people from doing it just to chew up address space. -*) +*/ let buy = ((parameter, storage): (buy, storage)) : (list(operation), storage) => { let void: unit = @@ -150,12 +181,12 @@ let update_details = ((parameter, storage): (update_details, storage)) : let owner: address = current_id_details.owner; let profile: bytes = switch (new_profile) { - | None => (* Default *) current_id_details.profile + | None => /* Default */ current_id_details.profile | Some(new_profile) => new_profile }; let controller: address = switch (new_controller) { - | None => (* Default *) current_id_details.controller + | None => /* Default */ current_id_details.controller | Some new_controller => new_controller }; let updated_id_details: id_details = { @@ -173,7 +204,7 @@ let update_details = ((parameter, storage): (update_details, storage)) : }); }; -(* Let someone skip the next identity so nobody has to take one that's undesirable *) +/* Let someone skip the next identity so nobody has to take one that's undesirable */ let skip = ((p,storage): (unit, storage)) => { let void : unit = if (amount != storage.skip_price) {