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:
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

View File

@ -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) {