Alpha/RPC: export various delegate data

This commit is contained in:
Grégoire Henry 2018-04-20 12:07:46 +02:00 committed by Benjamin Canou
parent 991846e716
commit 7b758dbca8
11 changed files with 458 additions and 63 deletions

View File

@ -104,6 +104,8 @@ module Cycle : sig
val sub: cycle -> int -> cycle option val sub: cycle -> int -> cycle option
val to_int32: cycle -> int32 val to_int32: cycle -> int32
module Map : S.MAP with type key = cycle
end end
module Gas : sig module Gas : sig
@ -617,6 +619,9 @@ module Delegate : sig
context -> public_key_hash -> Cycle.t -> context -> public_key_hash -> Cycle.t ->
(context * Tez.t) tzresult Lwt.t (context * Tez.t) tzresult Lwt.t
val full_balance:
context -> public_key_hash -> Tez.t tzresult Lwt.t
val has_frozen_balance: val has_frozen_balance:
context -> public_key_hash -> Cycle.t -> context -> public_key_hash -> Cycle.t ->
bool tzresult Lwt.t bool tzresult Lwt.t
@ -624,17 +629,34 @@ module Delegate : sig
val frozen_balance: val frozen_balance:
context -> public_key_hash -> Tez.t tzresult Lwt.t context -> public_key_hash -> Tez.t tzresult Lwt.t
type frozen_balances = { type frozen_balance = {
deposit : Tez.t ; deposit : Tez.t ;
fees : Tez.t ; fees : Tez.t ;
rewards : Tez.t ; rewards : Tez.t ;
} }
val frozen_balances: val frozen_balance_encoding: frozen_balance Data_encoding.t
context -> public_key_hash -> frozen_balances tzresult Lwt.t val frozen_balances_encoding: frozen_balance Cycle.Map.t Data_encoding.t
val full_balance: val frozen_balances:
context -> public_key_hash -> Tez.t tzresult Lwt.t context -> Signature.Public_key_hash.t ->
frozen_balance Cycle.Map.t Lwt.t
val get_delegated_contracts:
context -> Signature.Public_key_hash.t ->
Contract_hash.t list Lwt.t
val delegated_balance:
context -> Signature.Public_key_hash.t ->
Tez.t tzresult Lwt.t
val deactivated:
context -> Signature.Public_key_hash.t ->
bool Lwt.t
val grace_period:
context -> Signature.Public_key_hash.t ->
Cycle.t tzresult Lwt.t
end end
@ -865,6 +887,11 @@ end
module Roll : sig module Roll : sig
type t = private int32
type roll = t
val encoding: roll Data_encoding.t
val snapshot_rolls: context -> context tzresult Lwt.t val snapshot_rolls: context -> context tzresult Lwt.t
val cycle_end: context -> Cycle.t -> context tzresult Lwt.t val cycle_end: context -> Cycle.t -> context tzresult Lwt.t
@ -877,6 +904,11 @@ module Roll : sig
val delegate_pubkey: val delegate_pubkey:
context -> public_key_hash -> public_key tzresult Lwt.t context -> public_key_hash -> public_key tzresult Lwt.t
val get_rolls:
context -> Signature.Public_key_hash.t -> roll list tzresult Lwt.t
val get_change:
context -> Signature.Public_key_hash.t -> Tez.t tzresult Lwt.t
end end
module Commitment : sig module Commitment : sig

View File

@ -28,6 +28,8 @@ let pp ppf cycle = Format.fprintf ppf "%ld" cycle
include (Compare.Int32 : Compare.S with type t := t) include (Compare.Int32 : Compare.S with type t := t)
module Map = Map.Make(Compare.Int32)
let root = 0l let root = 0l
let succ = Int32.succ let succ = Int32.succ
let pred = function let pred = function

View File

@ -23,6 +23,8 @@ val succ: cycle -> cycle
val to_int32: cycle -> int32 val to_int32: cycle -> int32
val of_int32_exn: int32 -> cycle val of_int32_exn: int32 -> cycle
module Map : S.MAP with type key = cycle
module Index : sig module Index : sig
(* Storage_functors.INDEX with type t = cycle *) (* Storage_functors.INDEX with type t = cycle *)
type t = cycle type t = cycle

View File

@ -16,6 +16,221 @@ let slots_range_encoding =
(opt "first_level" Raw_level.encoding) (opt "first_level" Raw_level.encoding)
(opt "last_level" Raw_level.encoding)) (opt "last_level" Raw_level.encoding))
type info = {
balance: Tez.t ;
frozen_balance: Tez.t ;
frozen_balances: Delegate.frozen_balance Cycle.Map.t ;
delegated_balance: Tez.t ;
delegated_contracts: Contract_hash.t list ;
deactivated: bool ;
grace_period: Cycle.t ;
}
let info_encoding =
let open Data_encoding in
conv
(fun { balance ; frozen_balance ; frozen_balances ; delegated_balance ;
delegated_contracts ; deactivated ; grace_period } ->
(balance, frozen_balance, frozen_balances, delegated_balance,
delegated_contracts, deactivated, grace_period))
(fun (balance, frozen_balance, frozen_balances, delegated_balance,
delegated_contracts, deactivated, grace_period) ->
{ balance ; frozen_balance ; frozen_balances ; delegated_balance ;
delegated_contracts ; deactivated ; grace_period })
(obj7
(req "balance" Tez.encoding)
(req "frozen_balance" Tez.encoding)
(req "frozen_balances" Delegate.frozen_balances_encoding)
(req "delegated_balance" Tez.encoding)
(req "delegated_contracts" (list Contract_hash.encoding))
(req "deactivated" bool)
(req "grace_period" Cycle.encoding))
module S = struct
let path = RPC_path.(open_root / "delegate")
open Data_encoding
type list_query = {
active: bool ;
inactive: bool ;
}
let list_query :list_query RPC_query.t =
let open RPC_query in
query (fun active inactive -> { active ; inactive })
|+ flag "active" (fun t -> t.active)
|+ flag "inactive" (fun t -> t.inactive)
|> seal
let list_delegate =
RPC_service.get_service
~description:
"List all registred delegates."
~query: list_query
~output: (list Signature.Public_key_hash.encoding)
path
let path = RPC_path.(path /: Signature.Public_key_hash.rpc_arg)
let info =
RPC_service.get_service
~description:
"Everything about a delegate."
~query: RPC_query.empty
~output: info_encoding
path
let balance =
RPC_service.get_service
~description:
"Returns the full balance of a given delegate, \
including the frozen balances."
~query: RPC_query.empty
~output: Tez.encoding
RPC_path.(path / "balance")
let frozen_balance =
RPC_service.get_service
~description:
"Returns the total frozen balances of a given delegate, \
this includes the frozen deposits, rewards and fees."
~query: RPC_query.empty
~output: Tez.encoding
RPC_path.(path / "change")
let frozen_balances =
RPC_service.get_service
~description:
"Returns the amount of frozen tokens associated to a given delegate."
~query: RPC_query.empty
~output: Delegate.frozen_balances_encoding
RPC_path.(path / "frozen_balances")
let delegated_balance =
RPC_service.get_service
~description:
"Returns the total amount of token delegated to a given delegate. \
This includes the balance of all the contracts that delegates \
to it, but also the balance of the delegate itself and its frozen \
fees and deposits. The rewards do not count in the delegated balance \
until they are unfrozen."
~query: RPC_query.empty
~output: Tez.encoding
RPC_path.(path / "delegated_balance")
let delegated_contracts =
RPC_service.get_service
~description:
"Returns the list of contract that delegates to a given delegate."
~query: RPC_query.empty
~output: (list Contract_hash.encoding)
RPC_path.(path / "delegated_contracts")
let deactivated =
RPC_service.get_service
~description:
"Returns whether the delegate is currently tagged as deactivated or not."
~query: RPC_query.empty
~output: bool
RPC_path.(path / "deactivated")
let grace_period =
RPC_service.get_service
~description:
"Returns the cycle by the end of which the delegate might be \
deactivated, whether should she failed to execute any delegate \
action until then. \
A deactivated delegate might be reactivated \
(without loosing any rolls) by simply re-register as a delegate. \
For deactivated delegate this value contains the cycle by which \
they were deactivated."
~query: RPC_query.empty
~output: Cycle.encoding
RPC_path.(path / "grace_period")
end
let () =
let open Services_registration in
register0 S.list_delegate begin fun ctxt q () ->
Delegate.list ctxt >>= fun delegates ->
if q.active && q.inactive then
return delegates
else if q.active then
Lwt_list.filter_p
(fun pkh -> Delegate.deactivated ctxt pkh >|= not)
delegates >>= return
else if q.inactive then
Lwt_list.filter_p
(fun pkh -> Delegate.deactivated ctxt pkh)
delegates >>= return
else
return []
end ;
register1 S.info begin fun ctxt pkh () () ->
Delegate.full_balance ctxt pkh >>=? fun balance ->
Delegate.frozen_balance ctxt pkh >>=? fun frozen_balance ->
Delegate.frozen_balances ctxt pkh >>= fun frozen_balances ->
Delegate.delegated_balance ctxt pkh >>=? fun delegated_balance ->
Delegate.get_delegated_contracts ctxt pkh >>= fun delegated_contracts ->
Delegate.deactivated ctxt pkh >>= fun deactivated ->
Delegate.grace_period ctxt pkh >>=? fun grace_period ->
return {
balance ; frozen_balance ; frozen_balances ; delegated_balance ;
delegated_contracts ; deactivated ; grace_period
}
end ;
register1 S.balance begin fun ctxt pkh () () ->
Delegate.full_balance ctxt pkh
end ;
register1 S.frozen_balance begin fun ctxt pkh () () ->
Delegate.frozen_balance ctxt pkh
end ;
register1 S.frozen_balances begin fun ctxt pkh () () ->
Delegate.frozen_balances ctxt pkh >>= return
end ;
register1 S.delegated_balance begin fun ctxt pkh () () ->
Delegate.delegated_balance ctxt pkh
end ;
register1 S.delegated_contracts begin fun ctxt pkh () () ->
Delegate.get_delegated_contracts ctxt pkh >>= return
end ;
register1 S.deactivated begin fun ctxt pkh () () ->
Delegate.deactivated ctxt pkh >>= return
end ;
register1 S.grace_period begin fun ctxt pkh () () ->
Delegate.grace_period ctxt pkh
end
let list ctxt block ?(active = true) ?(inactive = false) () =
RPC_context.make_call0 S.list_delegate ctxt block { active ; inactive } ()
let info ctxt block pkh =
RPC_context.make_call1 S.info ctxt block pkh () ()
let balance ctxt block pkh =
RPC_context.make_call1 S.balance ctxt block pkh () ()
let frozen_balance ctxt block pkh =
RPC_context.make_call1 S.frozen_balance ctxt block pkh () ()
let frozen_balances ctxt block pkh =
RPC_context.make_call1 S.frozen_balances ctxt block pkh () ()
let delegated_balance ctxt block pkh =
RPC_context.make_call1 S.delegated_balance ctxt block pkh () ()
let delegated_contracts ctxt block pkh =
RPC_context.make_call1 S.delegated_contracts ctxt block pkh () ()
let deactivated ctxt block pkh =
RPC_context.make_call1 S.deactivated ctxt block pkh () ()
let grace_period ctxt block pkh =
RPC_context.make_call1 S.grace_period ctxt block pkh () ()
module Baker = struct module Baker = struct
module S = struct module S = struct
@ -322,37 +537,6 @@ module Endorser = struct
end end
module S = struct
let frozen_balances_encoding =
let open Delegate in
Data_encoding.(
conv
(fun { deposit ; fees ; rewards } ->
(deposit, fees, rewards))
(fun (deposit, fees, rewards) ->
{ deposit ; fees ; rewards }
)
(obj3
(req "deposit" Tez.encoding)
(req "fees" Tez.encoding)
(req "rewards" Tez.encoding)))
let frozen_balances =
RPC_service.post_service
~description: "Returns the amount of frozen tokens associated to a given key."
~query: RPC_query.empty
~input: Data_encoding.empty
~output: frozen_balances_encoding
RPC_path.(open_root / "delegate" /: Signature.Public_key_hash.rpc_arg / "frozen_balances")
end
let () =
let open Services_registration in
register1 S.frozen_balances begin fun ctxt pkh () () ->
Delegate.frozen_balances ctxt pkh
end
let frozen_balances ctxt block pkh =
RPC_context.make_call1 S.frozen_balances ctxt block pkh () ()
let baking_rights = Baker.I.baking_rights let baking_rights = Baker.I.baking_rights
let endorsement_rights = Endorser.I.endorsement_rights let endorsement_rights = Endorser.I.endorsement_rights

View File

@ -9,10 +9,64 @@
open Alpha_context open Alpha_context
val list:
'a #RPC_context.simple -> 'a ->
?active:bool ->
?inactive:bool ->
unit -> Signature.Public_key_hash.t list shell_tzresult Lwt.t
type info = {
balance: Tez.t ;
frozen_balance: Tez.t ;
frozen_balances: Delegate.frozen_balance Cycle.Map.t ;
delegated_balance: Tez.t ;
delegated_contracts: Contract_hash.t list ;
deactivated: bool ;
grace_period: Cycle.t ;
}
val info_encoding: info Data_encoding.t
val info:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
info shell_tzresult Lwt.t
val balance:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
Tez.t shell_tzresult Lwt.t
val frozen_balance:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
Tez.t shell_tzresult Lwt.t
val frozen_balances: val frozen_balances:
'a #RPC_context.simple -> 'a -> 'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t -> Signature.Public_key_hash.t ->
Delegate.frozen_balances shell_tzresult Lwt.t Delegate.frozen_balance Cycle.Map.t shell_tzresult Lwt.t
val delegated_balance:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
Tez.t shell_tzresult Lwt.t
val delegated_contracts:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
Contract_hash.t list shell_tzresult Lwt.t
val deactivated:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
bool shell_tzresult Lwt.t
val grace_period:
'a #RPC_context.simple -> 'a ->
Signature.Public_key_hash.t ->
Cycle.t shell_tzresult Lwt.t
module Baker : sig module Baker : sig

View File

@ -193,6 +193,9 @@ let remove ctxt contract =
let fold = Storage.Delegates.fold let fold = Storage.Delegates.fold
let list = Storage.Delegates.elements let list = Storage.Delegates.elements
let get_delegated_contracts ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in
Storage.Contract.Delegated.elements (ctxt, contract)
let get_frozen_deposit ctxt contract cycle = let get_frozen_deposit ctxt contract cycle =
Storage.Contract.Frozen_deposits.get_option (ctxt, contract) cycle >>=? function Storage.Contract.Frozen_deposits.get_option (ctxt, contract) cycle >>=? function
@ -349,41 +352,107 @@ let has_frozen_balance ctxt delegate cycle =
get_frozen_rewards ctxt contract cycle >>=? fun rewards -> get_frozen_rewards ctxt contract cycle >>=? fun rewards ->
return Tez_repr.(rewards <> zero) return Tez_repr.(rewards <> zero)
type frozen_balances = { type frozen_balance = {
deposit : Tez_repr.t ; deposit : Tez_repr.t ;
fees : Tez_repr.t ; fees : Tez_repr.t ;
rewards : Tez_repr.t ; rewards : Tez_repr.t ;
} }
let frozen_balance_encoding =
let open Data_encoding in
conv
(fun { deposit ; fees ; rewards } -> (deposit, fees, rewards))
(fun (deposit, fees, rewards) -> { deposit ; fees ; rewards })
(obj3
(req "deposit" Tez_repr.encoding)
(req "fees" Tez_repr.encoding)
(req "rewards" Tez_repr.encoding))
let frozen_balances_encoding =
let open Data_encoding in
conv
(Cycle_repr.Map.bindings)
(List.fold_left
(fun m (c, b) -> Cycle_repr.Map.add c b m)
Cycle_repr.Map.empty)
(list (merge_objs
(obj1 (req "cycle" Cycle_repr.encoding))
frozen_balance_encoding))
let empty_frozen_balance =
{ deposit = Tez_repr.zero ;
fees = Tez_repr.zero ;
rewards = Tez_repr.zero }
let frozen_balances ctxt delegate = let frozen_balances ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in
let map = Cycle_repr.Map.empty in
Storage.Contract.Frozen_deposits.fold
(ctxt, contract) ~init:map
~f:(fun cycle amount map ->
Lwt.return
(Cycle_repr.Map.add cycle
{ empty_frozen_balance with deposit = amount } map)) >>= fun map ->
Storage.Contract.Frozen_fees.fold
(ctxt, contract) ~init:map
~f:(fun cycle amount map ->
let balance =
match Cycle_repr.Map.find_opt cycle map with
| None -> empty_frozen_balance
| Some balance -> balance in
Lwt.return
(Cycle_repr.Map.add cycle
{ balance with fees = amount } map)) >>= fun map ->
Storage.Contract.Frozen_rewards.fold
(ctxt, contract) ~init:map
~f:(fun cycle amount map ->
let balance =
match Cycle_repr.Map.find_opt cycle map with
| None -> empty_frozen_balance
| Some balance -> balance in
Lwt.return
(Cycle_repr.Map.add cycle
{ balance with rewards = amount } map)) >>= fun map ->
Lwt.return map
let frozen_balance ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in let contract = Contract_repr.implicit_contract delegate in
let balance = Ok Tez_repr.zero in let balance = Ok Tez_repr.zero in
Storage.Contract.Frozen_deposits.fold Storage.Contract.Frozen_deposits.fold
(ctxt, contract) ~init:balance (ctxt, contract) ~init:balance
~f:(fun _cycle amount acc -> ~f:(fun _cycle amount acc ->
Lwt.return acc >>=? fun acc -> Lwt.return acc >>=? fun acc ->
Lwt.return (Tez_repr.(acc +? amount))) >>=? fun deposit -> Lwt.return (Tez_repr.(acc +? amount))) >>= fun balance ->
Storage.Contract.Frozen_fees.fold Storage.Contract.Frozen_fees.fold
(ctxt, contract) ~init:balance (ctxt, contract) ~init:balance
~f:(fun _cycle amount acc -> ~f:(fun _cycle amount acc ->
Lwt.return acc >>=? fun acc -> Lwt.return acc >>=? fun acc ->
Lwt.return (Tez_repr.(acc +? amount))) >>=? fun fees -> Lwt.return (Tez_repr.(acc +? amount))) >>= fun balance ->
Storage.Contract.Frozen_rewards.fold Storage.Contract.Frozen_rewards.fold
(ctxt, contract) ~init:balance (ctxt, contract) ~init:balance
~f:(fun _cycle amount acc -> ~f:(fun _cycle amount acc ->
Lwt.return acc >>=? fun acc -> Lwt.return acc >>=? fun acc ->
Lwt.return (Tez_repr.(acc +? amount))) >>=? fun rewards -> Lwt.return (Tez_repr.(acc +? amount))) >>= fun balance ->
return { deposit ; fees ; rewards } Lwt.return balance
let frozen_balance ctxt delegate =
frozen_balances ctxt delegate >>=? fun { deposit ; fees ; rewards } ->
Error_monad.fold_left_s (fun amount sum -> Lwt.return Tez_repr.(amount +? sum))
Tez_repr.zero
[deposit; fees; rewards] >>=
Lwt.return
let full_balance ctxt delegate = let full_balance ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in let contract = Contract_repr.implicit_contract delegate in
frozen_balance ctxt delegate >>=? fun frozen_balance -> frozen_balance ctxt delegate >>=? fun frozen_balance ->
Storage.Contract.Balance.get ctxt contract >>=? fun balance -> Storage.Contract.Balance.get ctxt contract >>=? fun balance ->
Lwt.return Tez_repr.(frozen_balance +? balance) Lwt.return Tez_repr.(frozen_balance +? balance)
let deactivated ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in
Storage.Contract.Inactive_delegate.mem ctxt contract
let grace_period ctxt delegate =
let contract = Contract_repr.implicit_contract delegate in
Storage.Contract.Delegate_desactivation.get ctxt contract
let delegated_balance ctxt delegate =
let token_per_rolls = Constants_storage.tokens_per_roll ctxt in
Roll_storage.get_rolls ctxt delegate >>=? fun rolls ->
Roll_storage.get_change ctxt delegate >>=? fun change ->
let rolls = Int64.of_int (List.length rolls) in
Lwt.return Tez_repr.(token_per_rolls *? rolls) >>=? fun balance ->
Lwt.return Tez_repr.(balance +? change)

View File

@ -94,21 +94,27 @@ val has_frozen_balance:
Raw_context.t -> Signature.Public_key_hash.t -> Cycle_repr.t -> Raw_context.t -> Signature.Public_key_hash.t -> Cycle_repr.t ->
bool tzresult Lwt.t bool tzresult Lwt.t
(** Returns the amount of frozen tokens associated to a given key. *) (** Returns the amount of frozen deposit, fees and rewards associated
to a given delegate. *)
val frozen_balance: val frozen_balance:
Raw_context.t -> Signature.Public_key_hash.t -> Raw_context.t -> Signature.Public_key_hash.t ->
Tez_repr.t tzresult Lwt.t Tez_repr.t tzresult Lwt.t
type frozen_balances = { type frozen_balance = {
deposit : Tez_repr.t ; deposit : Tez_repr.t ;
fees : Tez_repr.t ; fees : Tez_repr.t ;
rewards : Tez_repr.t ; rewards : Tez_repr.t ;
} }
(** Returns the amount of frozen deposit, fees and rewards associated to a given key. *) val frozen_balance_encoding: frozen_balance Data_encoding.t
val frozen_balances_encoding: frozen_balance Cycle_repr.Map.t Data_encoding.t
(** Returns the amount of frozen deposit, fees and rewards associated
to a given delegate, indexed by the cycle by which at the end the
balance will be unfrozen. *)
val frozen_balances: val frozen_balances:
Raw_context.t -> Signature.Public_key_hash.t -> Raw_context.t -> Signature.Public_key_hash.t ->
frozen_balances tzresult Lwt.t frozen_balance Cycle_repr.Map.t Lwt.t
(** Returns the full 'balance' of the implicit contract associated to (** Returns the full 'balance' of the implicit contract associated to
a given key, i.e. the sum of the spendable balance and of the a given key, i.e. the sum of the spendable balance and of the
@ -116,3 +122,20 @@ val frozen_balances:
val full_balance: val full_balance:
Raw_context.t -> Signature.Public_key_hash.t -> Raw_context.t -> Signature.Public_key_hash.t ->
Tez_repr.t tzresult Lwt.t Tez_repr.t tzresult Lwt.t
(** Returns the list of contract that delegated towards a given delegate *)
val get_delegated_contracts:
Raw_context.t -> Signature.Public_key_hash.t ->
Contract_hash.t list Lwt.t
val delegated_balance:
Raw_context.t -> Signature.Public_key_hash.t ->
Tez_repr.t tzresult Lwt.t
val deactivated:
Raw_context.t -> Signature.Public_key_hash.t ->
bool Lwt.t
val grace_period:
Raw_context.t -> Signature.Public_key_hash.t ->
Cycle_repr.t tzresult Lwt.t

View File

@ -7,7 +7,7 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
type t type t = private int32
type roll = t type roll = t
val encoding: roll Data_encoding.t val encoding: roll Data_encoding.t

View File

@ -131,6 +131,23 @@ let baking_rights_owner c level ~priority =
let endorsement_rights_owner c level ~slot = let endorsement_rights_owner c level ~slot =
Random.owner c "endorsement" level slot Random.owner c "endorsement" level slot
let traverse_rolls ctxt head =
let rec loop acc roll =
Storage.Roll.Successor.get_option ctxt roll >>=? function
| None -> return (List.rev acc)
| Some next -> loop (next :: acc) next in
loop [head] head
let get_rolls ctxt delegate =
Storage.Roll.Delegate_roll_list.get_option ctxt delegate >>=? function
| None -> return []
| Some head_roll -> traverse_rolls ctxt head_roll
let get_change c delegate =
Storage.Roll.Delegate_change.get_option c delegate >>=? function
| None -> return Tez_repr.zero
| Some change -> return change
module Delegate = struct module Delegate = struct
let fresh_roll c = let fresh_roll c =

View File

@ -70,6 +70,11 @@ val delegate_pubkey:
Raw_context.t -> Signature.Public_key_hash.t -> Raw_context.t -> Signature.Public_key_hash.t ->
Signature.Public_key.t tzresult Lwt.t Signature.Public_key.t tzresult Lwt.t
val get_rolls:
Raw_context.t -> Signature.Public_key_hash.t -> Roll_repr.t list tzresult Lwt.t
val get_change:
Raw_context.t -> Signature.Public_key_hash.t -> Tez_repr.t tzresult Lwt.t
(**/**) (**/**)
val get_contract_delegate: val get_contract_delegate:

View File

@ -97,16 +97,23 @@ module Contract = struct
Alpha_services.Contract.balance rpc_ctxt ctxt contract Alpha_services.Contract.balance rpc_ctxt ctxt contract
| _ -> | _ ->
match Alpha_context.Contract.is_implicit contract with match Alpha_context.Contract.is_implicit contract with
| None -> invalid_arg "get_balance: no frozen accounts for an originated contract." | None ->
invalid_arg
"get_balance: no frozen accounts for an originated contract."
| Some pkh -> | Some pkh ->
Alpha_services.Delegate.frozen_balances rpc_ctxt ctxt pkh >>|? Alpha_services.Delegate.frozen_balances
fun Delegate.({deposit ; fees ; rewards }) -> rpc_ctxt ctxt pkh >>=? fun map ->
begin match kind with Lwt.return @@
| Deposit -> deposit Cycle.Map.fold
| Fees -> fees (fun _cycle { Delegate.deposit ; fees ; rewards } acc ->
| Rewards -> rewards acc >>?fun acc ->
| _ -> invalid_arg "get_balance: pass Main, Deposit, Fees or Rewards." match kind with
end | Deposit -> Test_tez.Tez.(acc +? deposit)
| Fees -> Test_tez.Tez.(acc +? fees)
| Rewards -> Test_tez.Tez.(acc +? rewards)
| _ -> assert false)
map
(Ok Tez.zero)
end end
let counter ctxt contract = let counter ctxt contract =