Alpha: improve storage
This commit is contained in:
parent
1dc748ee47
commit
c656d54500
@ -159,11 +159,6 @@ module Contract = struct
|
|||||||
(struct let name = ["counter"] end)
|
(struct let name = ["counter"] end)
|
||||||
(Z)
|
(Z)
|
||||||
|
|
||||||
module Proposals =
|
|
||||||
Indexed_context.Make_map
|
|
||||||
(struct let name = ["proposals"] end)
|
|
||||||
(Int)
|
|
||||||
|
|
||||||
(* Consume gas for serilization and deserialization of expr in this
|
(* Consume gas for serilization and deserialization of expr in this
|
||||||
module *)
|
module *)
|
||||||
module Make_carbonated_map_expr (N : Storage_sigs.NAME) = struct
|
module Make_carbonated_map_expr (N : Storage_sigs.NAME) = struct
|
||||||
@ -531,6 +526,13 @@ module Vote = struct
|
|||||||
(Make_subcontext(Raw_context)(struct let name = ["proposals"] end))
|
(Make_subcontext(Raw_context)(struct let name = ["proposals"] end))
|
||||||
(Pair(Make_index(Protocol_hash))(Make_index(Signature.Public_key_hash)))
|
(Pair(Make_index(Protocol_hash))(Make_index(Signature.Public_key_hash)))
|
||||||
|
|
||||||
|
module Proposals_count =
|
||||||
|
Make_indexed_data_storage
|
||||||
|
(Make_subcontext(Raw_context)
|
||||||
|
(struct let name = ["proposals_count"] end))
|
||||||
|
(Make_index(Signature.Public_key_hash))
|
||||||
|
(Int)
|
||||||
|
|
||||||
module Ballots =
|
module Ballots =
|
||||||
Make_indexed_data_storage
|
Make_indexed_data_storage
|
||||||
(Make_subcontext(Raw_context)(struct let name = ["ballots"] end))
|
(Make_subcontext(Raw_context)(struct let name = ["ballots"] end))
|
||||||
|
@ -179,11 +179,6 @@ module Contract : sig
|
|||||||
and type value = Z.t
|
and type value = Z.t
|
||||||
and type t := Raw_context.t
|
and type t := Raw_context.t
|
||||||
|
|
||||||
module Proposals : Indexed_data_storage
|
|
||||||
with type key = Contract_repr.t
|
|
||||||
and type value = int
|
|
||||||
and type t := Raw_context.t
|
|
||||||
|
|
||||||
module Code : Non_iterable_indexed_carbonated_data_storage
|
module Code : Non_iterable_indexed_carbonated_data_storage
|
||||||
with type key = Contract_repr.t
|
with type key = Contract_repr.t
|
||||||
and type value = Script_repr.lazy_expr
|
and type value = Script_repr.lazy_expr
|
||||||
@ -260,6 +255,11 @@ module Vote : sig
|
|||||||
with type elt = Protocol_hash.t * Signature.Public_key_hash.t
|
with type elt = Protocol_hash.t * Signature.Public_key_hash.t
|
||||||
and type t := Raw_context.t
|
and type t := Raw_context.t
|
||||||
|
|
||||||
|
module Proposals_count : Indexed_data_storage
|
||||||
|
with type key = Signature.Public_key_hash.t
|
||||||
|
and type value = int
|
||||||
|
and type t := Raw_context.t
|
||||||
|
|
||||||
module Ballots : Indexed_data_storage
|
module Ballots : Indexed_data_storage
|
||||||
with type key = Signature.Public_key_hash.t
|
with type key = Signature.Public_key_hash.t
|
||||||
and type value = Vote_repr.ballot
|
and type value = Vote_repr.ballot
|
||||||
|
@ -24,15 +24,13 @@
|
|||||||
(*****************************************************************************)
|
(*****************************************************************************)
|
||||||
|
|
||||||
let recorded_proposal_count_for_delegate ctxt proposer =
|
let recorded_proposal_count_for_delegate ctxt proposer =
|
||||||
let delegate = Contract_repr.implicit_contract proposer in
|
Storage.Vote.Proposals_count.get_option ctxt proposer >>=? function
|
||||||
Storage.Contract.Proposals.get_option ctxt delegate >>=? function
|
|
||||||
| None -> return 0
|
| None -> return 0
|
||||||
| Some count -> return count
|
| Some count -> return count
|
||||||
|
|
||||||
let record_proposal ctxt proposal proposer =
|
let record_proposal ctxt proposal proposer =
|
||||||
recorded_proposal_count_for_delegate ctxt proposer >>=? fun count ->
|
recorded_proposal_count_for_delegate ctxt proposer >>=? fun count ->
|
||||||
let delegate = Contract_repr.implicit_contract proposer in
|
Storage.Vote.Proposals_count.init_set ctxt proposer (count + 1) >>= fun ctxt ->
|
||||||
Storage.Contract.Proposals.init_set ctxt delegate (count + 1) >>= fun ctxt ->
|
|
||||||
Storage.Vote.Proposals.add ctxt (proposal, proposer) >>= fun ctxt ->
|
Storage.Vote.Proposals.add ctxt (proposal, proposer) >>= fun ctxt ->
|
||||||
return ctxt
|
return ctxt
|
||||||
|
|
||||||
@ -52,10 +50,7 @@ let get_proposals ctxt =
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
let clear_proposals ctxt =
|
let clear_proposals ctxt =
|
||||||
Storage.Delegates.fold ctxt ~init:ctxt ~f:begin fun proposer ctxt ->
|
Storage.Vote.Proposals_count.clear ctxt >>= fun ctxt ->
|
||||||
let delegate = Contract_repr.implicit_contract proposer in
|
|
||||||
Storage.Contract.Proposals.remove ctxt delegate
|
|
||||||
end >>= fun ctxt ->
|
|
||||||
Storage.Vote.Proposals.clear ctxt
|
Storage.Vote.Proposals.clear ctxt
|
||||||
|
|
||||||
type ballots = {
|
type ballots = {
|
||||||
|
Loading…
Reference in New Issue
Block a user