Alpha: allow to iter on delegates

This commit is contained in:
Grégoire Henry 2018-02-23 10:29:12 -05:00 committed by Benjamin Canou
parent 54efe8fcd7
commit b63b333b1a
5 changed files with 31 additions and 0 deletions

View File

@ -471,6 +471,12 @@ module Delegate : sig
val set: val set:
context -> Contract.t -> public_key_hash option -> context tzresult Lwt.t context -> Contract.t -> public_key_hash option -> context tzresult Lwt.t
val fold:
context ->
init:'a -> f:(public_key_hash -> 'a -> 'a Lwt.t) -> 'a Lwt.t
val list: context -> public_key_hash list Lwt.t
end end
module Vote : sig module Vote : sig

View File

@ -111,8 +111,17 @@ let set c contract delegate =
unlink c contract balance >>=? fun c -> unlink c contract balance >>=? fun c ->
Storage.Contract.Delegate.init_set c contract delegate >>= fun c -> Storage.Contract.Delegate.init_set c contract delegate >>= fun c ->
link c contract delegate balance >>=? fun c -> link c contract delegate balance >>=? fun c ->
begin
if self_delegation then
Storage.Delegate.add c delegate
else
Lwt.return c
end >>= fun c ->
return c return c
let remove ctxt contract = let remove ctxt contract =
Storage.Contract.Balance.get ctxt contract >>=? fun balance -> Storage.Contract.Balance.get ctxt contract >>=? fun balance ->
unlink ctxt contract balance unlink ctxt contract balance
let fold = Storage.Delegate.fold
let list = Storage.Delegate.elements

View File

@ -26,3 +26,10 @@ val set:
Raw_context.t tzresult Lwt.t Raw_context.t tzresult Lwt.t
val remove: Raw_context.t -> Contract_repr.t -> Raw_context.t tzresult Lwt.t val remove: Raw_context.t -> Contract_repr.t -> Raw_context.t tzresult Lwt.t
val fold:
Raw_context.t ->
init:'a ->
f:(Ed25519.Public_key_hash.t -> 'a -> 'a Lwt.t) -> 'a Lwt.t
val list: Raw_context.t -> Ed25519.Public_key_hash.t list Lwt.t

View File

@ -129,6 +129,11 @@ module Contract = struct
end end
module Delegate =
Make_data_set_storage
(Make_subcontext(Raw_context)(struct let name = ["delegates"] end))
(Ed25519.Public_key_hash)
(** Rolls *) (** Rolls *)
module Cycle = struct module Cycle = struct

View File

@ -154,6 +154,10 @@ module Contract : sig
end end
module Delegate : Data_set_storage
with type t := Raw_context.t
and type elt = Ed25519.Public_key_hash.t
(** Votes *) (** Votes *)
module Vote : sig module Vote : sig