add the ID Contract example for cameligo and reasonligo

This commit is contained in:
technomad21c 2020-05-22 14:23:39 -07:00 committed by Pierre-Emmanuel Wulfman
parent 5b398b47c2
commit f29cf5a612
2 changed files with 71 additions and 9 deletions

View File

@ -4,10 +4,41 @@
compile: compile:
entrypoint: main entrypoint: main
dryRun: 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: deploy:
evaluateValue: evaluateValue:
entrypoint: "" entrypoint: ""
evaluateFunction: 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 type id = int

View File

@ -1,16 +1,47 @@
(*_* /* (*_*
name: ID Contract (ReasonLIGO) name: ID Contract (ReasonLIGO)
language: reasonligo language: reasonligo
compile: compile:
entrypoint: main entrypoint: main
dryRun: 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: deploy:
entrypoint: main entrypoint: main
storage: 0 storage: 0
evaluateValue: evaluateValue:
entrypoint: "" entrypoint: ""
evaluateFunction: 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 type id = int
@ -42,8 +73,8 @@ type action =
| Update_details(update_details) | Update_details(update_details)
| Skip(unit) | Skip(unit)
(* The prices kept in storage can be changed by bakers, though they should only be /* The prices kept in storage can be changed by bakers, though they should only be
adjusted down over time, not up. *) adjusted down over time, not up. */
type storage = { type storage = {
identities: big_map (id, id_details), identities: big_map (id, id_details),
next_id: int, next_id: int,
@ -51,7 +82,7 @@ type storage = {
skip_price: tez, skip_price: tez,
} }
(** Preliminary thoughts on ids: /** Preliminary thoughts on ids:
I very much like the simplicity of http://gurno.com/adam/mne/. 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 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. 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 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. be to deter people from doing it just to chew up address space.
*) */
let buy = ((parameter, storage): (buy, storage)) : (list(operation), storage) => { let buy = ((parameter, storage): (buy, storage)) : (list(operation), storage) => {
let void: unit = let void: unit =
@ -150,12 +181,12 @@ let update_details = ((parameter, storage): (update_details, storage)) :
let owner: address = current_id_details.owner; let owner: address = current_id_details.owner;
let profile: bytes = let profile: bytes =
switch (new_profile) { switch (new_profile) {
| None => (* Default *) current_id_details.profile | None => /* Default */ current_id_details.profile
| Some(new_profile) => new_profile | Some(new_profile) => new_profile
}; };
let controller: address = let controller: address =
switch (new_controller) { switch (new_controller) {
| None => (* Default *) current_id_details.controller | None => /* Default */ current_id_details.controller
| Some new_controller => new_controller | Some new_controller => new_controller
}; };
let updated_id_details: id_details = { 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 skip = ((p,storage): (unit, storage)) => {
let void : unit = let void : unit =
if (amount != storage.skip_price) { if (amount != storage.skip_price) {