Alpha: use 'Data_set' for storing the spendable flag
This commit is contained in:
parent
9ff3be14b6
commit
4c1e4bc6cd
@ -192,13 +192,8 @@ let create_base c contract
|
|||||||
Storage.Contract.Delegate.init c contract delegate >>=? fun c ->
|
Storage.Contract.Delegate.init c contract delegate >>=? fun c ->
|
||||||
link_delegate c contract delegate balance
|
link_delegate c contract delegate balance
|
||||||
end >>=? fun c ->
|
end >>=? fun c ->
|
||||||
Storage.Contract.Spendable.init c contract spendable >>=? fun c ->
|
Storage.Contract.Spendable.set c contract spendable >>= fun c ->
|
||||||
begin
|
Storage.Contract.Delegatable.set c contract delegatable >>= fun c ->
|
||||||
if delegatable then
|
|
||||||
Storage.Contract.Delegatable.add c contract
|
|
||||||
else
|
|
||||||
Lwt.return c
|
|
||||||
end >>= fun c ->
|
|
||||||
Storage.Contract.Counter.init c contract counter >>=? fun c ->
|
Storage.Contract.Counter.init c contract counter >>=? fun c ->
|
||||||
(match script with
|
(match script with
|
||||||
| Some ({ Script_repr.code ; storage }, (code_fees, storage_fees)) ->
|
| Some ({ Script_repr.code ; storage }, (code_fees, storage_fees)) ->
|
||||||
@ -225,7 +220,7 @@ let delete c contract =
|
|||||||
Storage.Contract.Balance.delete c contract >>=? fun c ->
|
Storage.Contract.Balance.delete c contract >>=? fun c ->
|
||||||
Storage.Contract.Manager.delete c contract >>=? fun c ->
|
Storage.Contract.Manager.delete c contract >>=? fun c ->
|
||||||
Storage.Contract.Delegate.remove c contract >>= fun c ->
|
Storage.Contract.Delegate.remove c contract >>= fun c ->
|
||||||
Storage.Contract.Spendable.delete c contract >>=? fun c ->
|
Storage.Contract.Spendable.del c contract >>= fun c ->
|
||||||
Storage.Contract.Delegatable.del c contract >>= fun c ->
|
Storage.Contract.Delegatable.del c contract >>= fun c ->
|
||||||
Storage.Contract.Counter.delete c contract >>=? fun c ->
|
Storage.Contract.Counter.delete c contract >>=? fun c ->
|
||||||
Storage.Contract.Code.remove c contract >>= fun c ->
|
Storage.Contract.Code.remove c contract >>= fun c ->
|
||||||
@ -332,13 +327,10 @@ let is_delegatable c contract =
|
|||||||
Storage.Contract.Delegatable.mem c contract >>= return
|
Storage.Contract.Delegatable.mem c contract >>= return
|
||||||
|
|
||||||
let is_spendable c contract =
|
let is_spendable c contract =
|
||||||
Storage.Contract.Spendable.get_option c contract >>=? function
|
|
||||||
| None -> begin
|
|
||||||
match Contract_repr.is_implicit contract with
|
match Contract_repr.is_implicit contract with
|
||||||
| Some _ -> return true
|
| Some _ -> return true
|
||||||
| None -> failwith "is_spendable"
|
| None ->
|
||||||
end
|
Storage.Contract.Spendable.mem c contract >>= return
|
||||||
| Some v -> return v
|
|
||||||
|
|
||||||
let set_delegate c contract delegate =
|
let set_delegate c contract delegate =
|
||||||
match delegate with
|
match delegate with
|
||||||
@ -442,7 +434,7 @@ let credit c contract amount =
|
|||||||
Roll_storage.Contract.add_amount c contract amount
|
Roll_storage.Contract.add_amount c contract amount
|
||||||
|
|
||||||
let spend c contract amount =
|
let spend c contract amount =
|
||||||
Storage.Contract.Spendable.get c contract >>=? fun spendable ->
|
is_spendable c contract >>=? fun spendable ->
|
||||||
if not spendable
|
if not spendable
|
||||||
then fail (Unspendable_contract contract)
|
then fail (Unspendable_contract contract)
|
||||||
else spend_from_script c contract amount
|
else spend_from_script c contract amount
|
||||||
|
@ -14,11 +14,6 @@ module Int32 = struct
|
|||||||
let encoding = Data_encoding.int32
|
let encoding = Data_encoding.int32
|
||||||
end
|
end
|
||||||
|
|
||||||
module Bool = struct
|
|
||||||
type t = bool
|
|
||||||
let encoding = Data_encoding.bool
|
|
||||||
end
|
|
||||||
|
|
||||||
module String_index = struct
|
module String_index = struct
|
||||||
type t = string
|
type t = string
|
||||||
let path_length = 1
|
let path_length = 1
|
||||||
@ -60,9 +55,8 @@ module Contract = struct
|
|||||||
(Make_value(Manager_repr))
|
(Make_value(Manager_repr))
|
||||||
|
|
||||||
module Spendable =
|
module Spendable =
|
||||||
Indexed_context.Make_map
|
Indexed_context.Make_set
|
||||||
(struct let name = ["spendable"] end)
|
(struct let name = ["spendable"] end)
|
||||||
(Make_value(Bool))
|
|
||||||
|
|
||||||
module Delegatable =
|
module Delegatable =
|
||||||
Indexed_context.Make_set
|
Indexed_context.Make_set
|
||||||
|
@ -112,9 +112,8 @@ module Contract : sig
|
|||||||
with type elt = Contract_hash.t
|
with type elt = Contract_hash.t
|
||||||
and type t = Raw_context.t * Contract_repr.t
|
and type t = Raw_context.t * Contract_repr.t
|
||||||
|
|
||||||
module Spendable : Indexed_data_storage
|
module Spendable : Data_set_storage
|
||||||
with type key = Contract_repr.t
|
with type elt = Contract_repr.t
|
||||||
and type value = bool
|
|
||||||
and type t := Raw_context.t
|
and type t := Raw_context.t
|
||||||
|
|
||||||
module Delegatable : Data_set_storage
|
module Delegatable : Data_set_storage
|
||||||
|
@ -139,6 +139,9 @@ module Make_data_set_storage (C : Raw_context.T) (I : INDEX)
|
|||||||
let del s i =
|
let del s i =
|
||||||
C.remove s (I.to_path i []) >>= fun t ->
|
C.remove s (I.to_path i []) >>= fun t ->
|
||||||
Lwt.return (C.project t)
|
Lwt.return (C.project t)
|
||||||
|
let set s i = function
|
||||||
|
| true -> add s i
|
||||||
|
| false -> del s i
|
||||||
let clear s =
|
let clear s =
|
||||||
C.remove_rec s [] >>= fun t ->
|
C.remove_rec s [] >>= fun t ->
|
||||||
Lwt.return (C.project t)
|
Lwt.return (C.project t)
|
||||||
@ -398,6 +401,9 @@ module Make_indexed_subcontext (C : Raw_context.T) (I : INDEX)
|
|||||||
let del s i =
|
let del s i =
|
||||||
Raw_context.remove (s, i) N.name >>= fun (s, _) ->
|
Raw_context.remove (s, i) N.name >>= fun (s, _) ->
|
||||||
Lwt.return (C.project s)
|
Lwt.return (C.project s)
|
||||||
|
let set s i = function
|
||||||
|
| true -> add s i
|
||||||
|
| false -> del s i
|
||||||
let clear s =
|
let clear s =
|
||||||
fold_keys s
|
fold_keys s
|
||||||
~init:s
|
~init:s
|
||||||
|
@ -178,6 +178,9 @@ module type Data_set_storage = sig
|
|||||||
(** Removes a elt of the set ; does nothing if not a member *)
|
(** Removes a elt of the set ; does nothing if not a member *)
|
||||||
val del: context -> elt -> Raw_context.t Lwt.t
|
val del: context -> elt -> Raw_context.t Lwt.t
|
||||||
|
|
||||||
|
(** Adds/Removes a elt of the set *)
|
||||||
|
val set: context -> elt -> bool -> Raw_context.t Lwt.t
|
||||||
|
|
||||||
(** Returns the elements of the set, deserialized in a list in no
|
(** Returns the elements of the set, deserialized in a list in no
|
||||||
particular order. *)
|
particular order. *)
|
||||||
val elements: context -> elt list Lwt.t
|
val elements: context -> elt list Lwt.t
|
||||||
|
Loading…
Reference in New Issue
Block a user