optimizing contract
This commit is contained in:
parent
e42e79eff3
commit
74dab76fb4
@ -78,11 +78,9 @@ function buy (const parameter : buy; const storage : storage) : list(operation)
|
||||
profile = profile ;
|
||||
];
|
||||
identities[new_id] := new_id_details;
|
||||
end with ((nil : list(operation)), record [
|
||||
end with ((nil : list(operation)), storage with record [
|
||||
identities = identities;
|
||||
next_id = new_id + 1;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
])
|
||||
|
||||
function update_owner (const parameter : update_owner; const storage : storage) :
|
||||
@ -102,18 +100,12 @@ function update_owner (const parameter : update_owner; const storage : storage)
|
||||
Some(id_details) -> id_details
|
||||
| None -> (failwith("This ID does not exist."): id_details)
|
||||
end;
|
||||
var is_allowed : bool := False;
|
||||
if sender = id_details.owner
|
||||
then is_allowed := True
|
||||
then skip;
|
||||
else failwith("You are not the owner of this ID.");
|
||||
id_details.owner := new_owner;
|
||||
identities[id] := id_details;
|
||||
end with ((nil: list(operation)), record [
|
||||
identities = identities;
|
||||
next_id = storage.next_id;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
])
|
||||
end with ((nil: list(operation)), storage with record [ identities = identities; ])
|
||||
|
||||
function update_details (const parameter : update_details; const storage : storage ) :
|
||||
list(operation) * storage is
|
||||
@ -130,9 +122,8 @@ function update_details (const parameter : update_details; const storage : stora
|
||||
Some(id_details) -> id_details
|
||||
| None -> (failwith("This ID does not exist."): id_details)
|
||||
end;
|
||||
var is_allowed : bool := False;
|
||||
if (sender = id_details.controller) or (sender = id_details.owner)
|
||||
then is_allowed := True
|
||||
then skip;
|
||||
else failwith("You are not the owner or controller of this ID.");
|
||||
const owner: address = id_details.owner;
|
||||
const profile: bytes =
|
||||
@ -149,12 +140,7 @@ function update_details (const parameter : update_details; const storage : stora
|
||||
id_details.controller := controller;
|
||||
id_details.profile := profile;
|
||||
identities[id] := id_details;
|
||||
end with ((nil: list(operation)), record [
|
||||
identities = identities;
|
||||
next_id = storage.next_id;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
])
|
||||
end with ((nil: list(operation)), storage with record [ identities = identities; ])
|
||||
|
||||
(* Let someone skip the next identity so nobody has to take one that's undesirable *)
|
||||
function skip_ (const p: unit; const storage: storage) : list(operation) * storage is
|
||||
@ -162,12 +148,7 @@ function skip_ (const p: unit; const storage: storage) : list(operation) * stora
|
||||
if amount = storage.skip_price
|
||||
then skip
|
||||
else failwith("Incorrect amount paid.");
|
||||
end with ((nil: list(operation)), record [
|
||||
identities = storage.identities;
|
||||
next_id = storage.next_id + 1;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
])
|
||||
end with ((nil: list(operation)), storage with record [ next_id = storage.next_id + 1; ])
|
||||
|
||||
function main (const action : action; const storage : storage) : list(operation) * storage is
|
||||
case action of
|
||||
|
@ -78,10 +78,8 @@ let buy (parameter, storage: buy * storage) =
|
||||
let updated_identities : (id, id_details) big_map =
|
||||
Big_map.update new_id (Some new_id_details) identities
|
||||
in
|
||||
([]: operation list), {identities = updated_identities;
|
||||
([]: operation list), {storage with identities = updated_identities;
|
||||
next_id = new_id + 1;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
}
|
||||
|
||||
let update_owner (parameter, storage: update_owner * storage) =
|
||||
@ -96,10 +94,10 @@ let update_owner (parameter, storage: update_owner * storage) =
|
||||
| Some id_details -> id_details
|
||||
| None -> (failwith "This ID does not exist.": id_details)
|
||||
in
|
||||
let is_allowed: bool =
|
||||
let u : unit =
|
||||
if sender = current_id_details.owner
|
||||
then true
|
||||
else (failwith "You are not the owner of this ID.": bool)
|
||||
then ()
|
||||
else failwith "You are not the owner of this ID."
|
||||
in
|
||||
let updated_id_details: id_details = {
|
||||
owner = new_owner;
|
||||
@ -108,11 +106,7 @@ let update_owner (parameter, storage: update_owner * storage) =
|
||||
}
|
||||
in
|
||||
let updated_identities = Big_map.update id (Some updated_id_details) identities in
|
||||
([]: operation list), {identities = updated_identities;
|
||||
next_id = storage.next_id;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
}
|
||||
([]: operation list), {storage with identities = updated_identities}
|
||||
|
||||
let update_details (parameter, storage: update_details * storage) =
|
||||
if (amount <> 0mutez)
|
||||
@ -127,10 +121,10 @@ let update_details (parameter, storage: update_details * storage) =
|
||||
| Some id_details -> id_details
|
||||
| None -> (failwith "This ID does not exist.": id_details)
|
||||
in
|
||||
let is_allowed: bool =
|
||||
let u : unit =
|
||||
if (sender = current_id_details.controller) || (sender = current_id_details.owner)
|
||||
then true
|
||||
else (failwith ("You are not the owner or controller of this ID."): bool)
|
||||
then ()
|
||||
else failwith ("You are not the owner or controller of this ID.")
|
||||
in
|
||||
let owner: address = current_id_details.owner in
|
||||
let profile: bytes =
|
||||
@ -151,24 +145,16 @@ let update_details (parameter, storage: update_details * storage) =
|
||||
in
|
||||
let updated_identities: (id, id_details) big_map =
|
||||
Big_map.update id (Some updated_id_details) identities in
|
||||
([]: operation list), {identities = updated_identities;
|
||||
next_id = storage.next_id;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
}
|
||||
([]: operation list), {storage with identities = updated_identities}
|
||||
|
||||
(* 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
|
||||
then ()
|
||||
else (failwith "Incorrect amount paid.": unit)
|
||||
else failwith "Incorrect amount paid."
|
||||
in
|
||||
([]: operation list), {identities = storage.identities;
|
||||
next_id = storage.next_id + 1;
|
||||
name_price = storage.name_price;
|
||||
skip_price = storage.skip_price;
|
||||
}
|
||||
([]: operation list), {storage with next_id = storage.next_id + 1}
|
||||
|
||||
let main (action, storage : action * storage) : return =
|
||||
match action with
|
||||
|
@ -72,11 +72,9 @@ let buy = ((parameter, storage): (buy, storage)) : (list(operation), storage) =>
|
||||
};
|
||||
let updated_identities: big_map (id, id_details) =
|
||||
Big_map.update(new_id, Some(new_id_details), identities);
|
||||
(([]: list(operation)), {
|
||||
(([]: list(operation)), { ...storage,
|
||||
identities : updated_identities,
|
||||
next_id : new_id + 1,
|
||||
name_price : storage.name_price,
|
||||
skip_price : storage.skip_price,
|
||||
});
|
||||
};
|
||||
|
||||
@ -94,21 +92,16 @@ let update_owner = ((parameter, storage): (update_owner, storage)) : (list(opera
|
||||
| Some(id_details) => id_details
|
||||
| None => (failwith("This ID does not exist."): id_details)
|
||||
};
|
||||
let is_allowed: bool =
|
||||
if (sender == current_id_details.owner) { true; }
|
||||
else { (failwith("You are not the owner of this ID."): bool); };
|
||||
let u: unit =
|
||||
if (sender == current_id_details.owner) { (); }
|
||||
else { failwith("You are not the owner of this ID."); };
|
||||
let updated_id_details: id_details = {
|
||||
owner : new_owner,
|
||||
controller : current_id_details.controller,
|
||||
profile : current_id_details.profile,
|
||||
};
|
||||
let updated_identities = Big_map.update(id, (Some updated_id_details), identities);
|
||||
(([]: list(operation)), {
|
||||
identities : updated_identities,
|
||||
next_id : storage.next_id,
|
||||
name_price : storage.name_price,
|
||||
skip_price : storage.skip_price,
|
||||
});
|
||||
(([]: list(operation)), { ...storage, identities : updated_identities });
|
||||
};
|
||||
|
||||
let update_details = ((parameter, storage): (update_details, storage)) :
|
||||
@ -127,12 +120,12 @@ let update_details = ((parameter, storage): (update_details, storage)) :
|
||||
| Some(id_details) => id_details
|
||||
| None => (failwith("This ID does not exist."): id_details)
|
||||
};
|
||||
let is_allowed: bool =
|
||||
let u: unit =
|
||||
if ((sender != current_id_details.controller) &&
|
||||
(sender != current_id_details.owner)) {
|
||||
(failwith ("You are not the owner or controller of this ID."): bool)
|
||||
failwith ("You are not the owner or controller of this ID.")
|
||||
}
|
||||
else { true; };
|
||||
else { (); };
|
||||
let owner: address = current_id_details.owner;
|
||||
let profile: bytes =
|
||||
switch (new_profile) {
|
||||
@ -151,12 +144,7 @@ let update_details = ((parameter, storage): (update_details, storage)) :
|
||||
};
|
||||
let updated_identities: big_map (id, id_details) =
|
||||
Big_map.update(id, (Some updated_id_details), identities);
|
||||
(([]: list(operation)), {
|
||||
identities : updated_identities,
|
||||
next_id : storage.next_id,
|
||||
name_price : storage.name_price,
|
||||
skip_price : storage.skip_price,
|
||||
});
|
||||
(([]: list(operation)), { ...storage, identities : updated_identities });
|
||||
};
|
||||
|
||||
/* Let someone skip the next identity so nobody has to take one that's undesirable */
|
||||
@ -166,12 +154,7 @@ let skip = ((p,storage): (unit, storage)) => {
|
||||
failwith("Incorrect amount paid.");
|
||||
}
|
||||
else { (); };
|
||||
(([]: list(operation)), {
|
||||
identities : storage.identities,
|
||||
next_id : storage.next_id + 1,
|
||||
name_price : storage.name_price,
|
||||
skip_price : storage.skip_price,
|
||||
});
|
||||
(([]: list(operation)), { ...storage, next_id : storage.next_id + 1 });
|
||||
};
|
||||
|
||||
let main = ((action, storage): (action, storage)) : (list(operation), storage) => {
|
||||
|
Loading…
Reference in New Issue
Block a user