Alpha/RPC: some renaming in delegate services
This commit is contained in:
parent
ebc00b6463
commit
1460aba927
@ -637,13 +637,17 @@ module Delegate : sig
|
|||||||
}
|
}
|
||||||
|
|
||||||
val frozen_balance_encoding: frozen_balance Data_encoding.t
|
val frozen_balance_encoding: frozen_balance Data_encoding.t
|
||||||
val frozen_balances_encoding: frozen_balance Cycle.Map.t Data_encoding.t
|
val frozen_balance_by_cycle_encoding: frozen_balance Cycle.Map.t Data_encoding.t
|
||||||
|
|
||||||
val frozen_balances:
|
val frozen_balance_by_cycle:
|
||||||
context -> Signature.Public_key_hash.t ->
|
context -> Signature.Public_key_hash.t ->
|
||||||
frozen_balance Cycle.Map.t Lwt.t
|
frozen_balance Cycle.Map.t Lwt.t
|
||||||
|
|
||||||
val get_delegated_contracts:
|
val staking_balance:
|
||||||
|
context -> Signature.Public_key_hash.t ->
|
||||||
|
Tez.t tzresult Lwt.t
|
||||||
|
|
||||||
|
val delegated_contracts:
|
||||||
context -> Signature.Public_key_hash.t ->
|
context -> Signature.Public_key_hash.t ->
|
||||||
Contract_hash.t list Lwt.t
|
Contract_hash.t list Lwt.t
|
||||||
|
|
||||||
|
@ -12,9 +12,10 @@ open Alpha_context
|
|||||||
type info = {
|
type info = {
|
||||||
balance: Tez.t ;
|
balance: Tez.t ;
|
||||||
frozen_balance: Tez.t ;
|
frozen_balance: Tez.t ;
|
||||||
frozen_balances: Delegate.frozen_balance Cycle.Map.t ;
|
frozen_balance_by_cycle: Delegate.frozen_balance Cycle.Map.t ;
|
||||||
delegated_balance: Tez.t ;
|
staking_balance: Tez.t ;
|
||||||
delegated_contracts: Contract_hash.t list ;
|
delegated_contracts: Contract_hash.t list ;
|
||||||
|
delegated_balance: Tez.t ;
|
||||||
deactivated: bool ;
|
deactivated: bool ;
|
||||||
grace_period: Cycle.t ;
|
grace_period: Cycle.t ;
|
||||||
}
|
}
|
||||||
@ -22,20 +23,25 @@ type info = {
|
|||||||
let info_encoding =
|
let info_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
conv
|
conv
|
||||||
(fun { balance ; frozen_balance ; frozen_balances ; delegated_balance ;
|
(fun { balance ; frozen_balance ; frozen_balance_by_cycle ;
|
||||||
delegated_contracts ; deactivated ; grace_period } ->
|
staking_balance ; delegated_contracts ; delegated_balance ;
|
||||||
(balance, frozen_balance, frozen_balances, delegated_balance,
|
deactivated ; grace_period } ->
|
||||||
delegated_contracts, deactivated, grace_period))
|
(balance, frozen_balance, frozen_balance_by_cycle,
|
||||||
(fun (balance, frozen_balance, frozen_balances, delegated_balance,
|
staking_balance, delegated_contracts, delegated_balance,
|
||||||
delegated_contracts, deactivated, grace_period) ->
|
deactivated, grace_period))
|
||||||
{ balance ; frozen_balance ; frozen_balances ; delegated_balance ;
|
(fun (balance, frozen_balance, frozen_balance_by_cycle,
|
||||||
delegated_contracts ; deactivated ; grace_period })
|
staking_balance, delegated_contracts, delegated_balance,
|
||||||
(obj7
|
deactivated, grace_period) ->
|
||||||
|
{ balance ; frozen_balance ; frozen_balance_by_cycle ;
|
||||||
|
staking_balance ; delegated_contracts ; delegated_balance ;
|
||||||
|
deactivated ; grace_period })
|
||||||
|
(obj8
|
||||||
(req "balance" Tez.encoding)
|
(req "balance" Tez.encoding)
|
||||||
(req "frozen_balance" Tez.encoding)
|
(req "frozen_balance" Tez.encoding)
|
||||||
(req "frozen_balances" Delegate.frozen_balances_encoding)
|
(req "frozen_balance_by_cycle" Delegate.frozen_balance_by_cycle_encoding)
|
||||||
(req "delegated_balance" Tez.encoding)
|
(req "staking_balance" Tez.encoding)
|
||||||
(req "delegated_contracts" (list Contract_hash.encoding))
|
(req "delegated_contracts" (list Contract_hash.encoding))
|
||||||
|
(req "delegated_balance" Tez.encoding)
|
||||||
(req "deactivated" bool)
|
(req "deactivated" bool)
|
||||||
(req "grace_period" Cycle.encoding))
|
(req "grace_period" Cycle.encoding))
|
||||||
|
|
||||||
@ -92,15 +98,16 @@ module S = struct
|
|||||||
~output: Tez.encoding
|
~output: Tez.encoding
|
||||||
RPC_path.(path / "frozen_balance")
|
RPC_path.(path / "frozen_balance")
|
||||||
|
|
||||||
let frozen_balances =
|
let frozen_balance_by_cycle =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
~description:
|
~description:
|
||||||
"Returns the amount of frozen tokens associated to a given delegate."
|
"Returns the frozen balances of a given delegate, \
|
||||||
|
indexed by the cycle by which it will be unfrozen"
|
||||||
~query: RPC_query.empty
|
~query: RPC_query.empty
|
||||||
~output: Delegate.frozen_balances_encoding
|
~output: Delegate.frozen_balance_by_cycle_encoding
|
||||||
RPC_path.(path / "frozen_balances")
|
RPC_path.(path / "frozen_balance_by_cycle")
|
||||||
|
|
||||||
let delegated_balance =
|
let staking_balance =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
~description:
|
~description:
|
||||||
"Returns the total amount of token delegated to a given delegate. \
|
"Returns the total amount of token delegated to a given delegate. \
|
||||||
@ -110,7 +117,7 @@ module S = struct
|
|||||||
until they are unfrozen."
|
until they are unfrozen."
|
||||||
~query: RPC_query.empty
|
~query: RPC_query.empty
|
||||||
~output: Tez.encoding
|
~output: Tez.encoding
|
||||||
RPC_path.(path / "delegated_balance")
|
RPC_path.(path / "staking_balance")
|
||||||
|
|
||||||
let delegated_contracts =
|
let delegated_contracts =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
@ -120,6 +127,16 @@ module S = struct
|
|||||||
~output: (list Contract_hash.encoding)
|
~output: (list Contract_hash.encoding)
|
||||||
RPC_path.(path / "delegated_contracts")
|
RPC_path.(path / "delegated_contracts")
|
||||||
|
|
||||||
|
let delegated_balance =
|
||||||
|
RPC_service.get_service
|
||||||
|
~description:
|
||||||
|
"The includes the balance of all the contracts that delegates \
|
||||||
|
to it. This excludes the delegate own balance and its frozen \
|
||||||
|
balances."
|
||||||
|
~query: RPC_query.empty
|
||||||
|
~output: Tez.encoding
|
||||||
|
RPC_path.(path / "delegated_balance")
|
||||||
|
|
||||||
let deactivated =
|
let deactivated =
|
||||||
RPC_service.get_service
|
RPC_service.get_service
|
||||||
~description:
|
~description:
|
||||||
@ -164,14 +181,16 @@ let () =
|
|||||||
register1 S.info begin fun ctxt pkh () () ->
|
register1 S.info begin fun ctxt pkh () () ->
|
||||||
Delegate.full_balance ctxt pkh >>=? fun balance ->
|
Delegate.full_balance ctxt pkh >>=? fun balance ->
|
||||||
Delegate.frozen_balance ctxt pkh >>=? fun frozen_balance ->
|
Delegate.frozen_balance ctxt pkh >>=? fun frozen_balance ->
|
||||||
Delegate.frozen_balances ctxt pkh >>= fun frozen_balances ->
|
Delegate.frozen_balance_by_cycle ctxt pkh >>= fun frozen_balance_by_cycle ->
|
||||||
|
Delegate.staking_balance ctxt pkh >>=? fun staking_balance ->
|
||||||
|
Delegate.delegated_contracts ctxt pkh >>= fun delegated_contracts ->
|
||||||
Delegate.delegated_balance ctxt pkh >>=? fun delegated_balance ->
|
Delegate.delegated_balance ctxt pkh >>=? fun delegated_balance ->
|
||||||
Delegate.get_delegated_contracts ctxt pkh >>= fun delegated_contracts ->
|
|
||||||
Delegate.deactivated ctxt pkh >>= fun deactivated ->
|
Delegate.deactivated ctxt pkh >>= fun deactivated ->
|
||||||
Delegate.grace_period ctxt pkh >>=? fun grace_period ->
|
Delegate.grace_period ctxt pkh >>=? fun grace_period ->
|
||||||
return {
|
return {
|
||||||
balance ; frozen_balance ; frozen_balances ; delegated_balance ;
|
balance ; frozen_balance ; frozen_balance_by_cycle ;
|
||||||
delegated_contracts ; deactivated ; grace_period
|
staking_balance ; delegated_contracts ; delegated_balance ;
|
||||||
|
deactivated ; grace_period
|
||||||
}
|
}
|
||||||
end ;
|
end ;
|
||||||
register1 S.balance begin fun ctxt pkh () () ->
|
register1 S.balance begin fun ctxt pkh () () ->
|
||||||
@ -180,15 +199,18 @@ let () =
|
|||||||
register1 S.frozen_balance begin fun ctxt pkh () () ->
|
register1 S.frozen_balance begin fun ctxt pkh () () ->
|
||||||
Delegate.frozen_balance ctxt pkh
|
Delegate.frozen_balance ctxt pkh
|
||||||
end ;
|
end ;
|
||||||
register1 S.frozen_balances begin fun ctxt pkh () () ->
|
register1 S.frozen_balance_by_cycle begin fun ctxt pkh () () ->
|
||||||
Delegate.frozen_balances ctxt pkh >>= return
|
Delegate.frozen_balance_by_cycle ctxt pkh >>= return
|
||||||
|
end ;
|
||||||
|
register1 S.staking_balance begin fun ctxt pkh () () ->
|
||||||
|
Delegate.staking_balance ctxt pkh
|
||||||
|
end ;
|
||||||
|
register1 S.delegated_contracts begin fun ctxt pkh () () ->
|
||||||
|
Delegate.delegated_contracts ctxt pkh >>= return
|
||||||
end ;
|
end ;
|
||||||
register1 S.delegated_balance begin fun ctxt pkh () () ->
|
register1 S.delegated_balance begin fun ctxt pkh () () ->
|
||||||
Delegate.delegated_balance ctxt pkh
|
Delegate.delegated_balance ctxt pkh
|
||||||
end ;
|
end ;
|
||||||
register1 S.delegated_contracts begin fun ctxt pkh () () ->
|
|
||||||
Delegate.get_delegated_contracts ctxt pkh >>= return
|
|
||||||
end ;
|
|
||||||
register1 S.deactivated begin fun ctxt pkh () () ->
|
register1 S.deactivated begin fun ctxt pkh () () ->
|
||||||
Delegate.deactivated ctxt pkh >>= return
|
Delegate.deactivated ctxt pkh >>= return
|
||||||
end ;
|
end ;
|
||||||
@ -208,15 +230,18 @@ let balance ctxt block pkh =
|
|||||||
let frozen_balance ctxt block pkh =
|
let frozen_balance ctxt block pkh =
|
||||||
RPC_context.make_call1 S.frozen_balance ctxt block pkh () ()
|
RPC_context.make_call1 S.frozen_balance ctxt block pkh () ()
|
||||||
|
|
||||||
let frozen_balances ctxt block pkh =
|
let frozen_balance_by_cycle ctxt block pkh =
|
||||||
RPC_context.make_call1 S.frozen_balances ctxt block pkh () ()
|
RPC_context.make_call1 S.frozen_balance_by_cycle ctxt block pkh () ()
|
||||||
|
|
||||||
let delegated_balance ctxt block pkh =
|
let staking_balance ctxt block pkh =
|
||||||
RPC_context.make_call1 S.delegated_balance ctxt block pkh () ()
|
RPC_context.make_call1 S.staking_balance ctxt block pkh () ()
|
||||||
|
|
||||||
let delegated_contracts ctxt block pkh =
|
let delegated_contracts ctxt block pkh =
|
||||||
RPC_context.make_call1 S.delegated_contracts ctxt block pkh () ()
|
RPC_context.make_call1 S.delegated_contracts ctxt block pkh () ()
|
||||||
|
|
||||||
|
let delegated_balance ctxt block pkh =
|
||||||
|
RPC_context.make_call1 S.delegated_balance ctxt block pkh () ()
|
||||||
|
|
||||||
let deactivated ctxt block pkh =
|
let deactivated ctxt block pkh =
|
||||||
RPC_context.make_call1 S.deactivated ctxt block pkh () ()
|
RPC_context.make_call1 S.deactivated ctxt block pkh () ()
|
||||||
|
|
||||||
|
@ -18,9 +18,10 @@ val list:
|
|||||||
type info = {
|
type info = {
|
||||||
balance: Tez.t ;
|
balance: Tez.t ;
|
||||||
frozen_balance: Tez.t ;
|
frozen_balance: Tez.t ;
|
||||||
frozen_balances: Delegate.frozen_balance Cycle.Map.t ;
|
frozen_balance_by_cycle: Delegate.frozen_balance Cycle.Map.t ;
|
||||||
delegated_balance: Tez.t ;
|
staking_balance: Tez.t ;
|
||||||
delegated_contracts: Contract_hash.t list ;
|
delegated_contracts: Contract_hash.t list ;
|
||||||
|
delegated_balance: Tez.t ;
|
||||||
deactivated: bool ;
|
deactivated: bool ;
|
||||||
grace_period: Cycle.t ;
|
grace_period: Cycle.t ;
|
||||||
}
|
}
|
||||||
@ -42,12 +43,12 @@ val frozen_balance:
|
|||||||
Signature.Public_key_hash.t ->
|
Signature.Public_key_hash.t ->
|
||||||
Tez.t shell_tzresult Lwt.t
|
Tez.t shell_tzresult Lwt.t
|
||||||
|
|
||||||
val frozen_balances:
|
val frozen_balance_by_cycle:
|
||||||
'a #RPC_context.simple -> 'a ->
|
'a #RPC_context.simple -> 'a ->
|
||||||
Signature.Public_key_hash.t ->
|
Signature.Public_key_hash.t ->
|
||||||
Delegate.frozen_balance Cycle.Map.t shell_tzresult Lwt.t
|
Delegate.frozen_balance Cycle.Map.t shell_tzresult Lwt.t
|
||||||
|
|
||||||
val delegated_balance:
|
val staking_balance:
|
||||||
'a #RPC_context.simple -> 'a ->
|
'a #RPC_context.simple -> 'a ->
|
||||||
Signature.Public_key_hash.t ->
|
Signature.Public_key_hash.t ->
|
||||||
Tez.t shell_tzresult Lwt.t
|
Tez.t shell_tzresult Lwt.t
|
||||||
@ -57,6 +58,11 @@ val delegated_contracts:
|
|||||||
Signature.Public_key_hash.t ->
|
Signature.Public_key_hash.t ->
|
||||||
Contract_hash.t list shell_tzresult Lwt.t
|
Contract_hash.t list shell_tzresult Lwt.t
|
||||||
|
|
||||||
|
val delegated_balance:
|
||||||
|
'a #RPC_context.simple -> 'a ->
|
||||||
|
Signature.Public_key_hash.t ->
|
||||||
|
Tez.t shell_tzresult Lwt.t
|
||||||
|
|
||||||
val deactivated:
|
val deactivated:
|
||||||
'a #RPC_context.simple -> 'a ->
|
'a #RPC_context.simple -> 'a ->
|
||||||
Signature.Public_key_hash.t ->
|
Signature.Public_key_hash.t ->
|
||||||
|
@ -193,7 +193,7 @@ 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 delegated_contracts ctxt delegate =
|
||||||
let contract = Contract_repr.implicit_contract delegate in
|
let contract = Contract_repr.implicit_contract delegate in
|
||||||
Storage.Contract.Delegated.elements (ctxt, contract)
|
Storage.Contract.Delegated.elements (ctxt, contract)
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ let frozen_balance_encoding =
|
|||||||
(req "fees" Tez_repr.encoding)
|
(req "fees" Tez_repr.encoding)
|
||||||
(req "rewards" Tez_repr.encoding))
|
(req "rewards" Tez_repr.encoding))
|
||||||
|
|
||||||
let frozen_balances_encoding =
|
let frozen_balance_by_cycle_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
conv
|
conv
|
||||||
(Cycle_repr.Map.bindings)
|
(Cycle_repr.Map.bindings)
|
||||||
@ -384,7 +384,7 @@ let empty_frozen_balance =
|
|||||||
fees = Tez_repr.zero ;
|
fees = Tez_repr.zero ;
|
||||||
rewards = Tez_repr.zero }
|
rewards = Tez_repr.zero }
|
||||||
|
|
||||||
let frozen_balances ctxt delegate =
|
let frozen_balance_by_cycle ctxt delegate =
|
||||||
let contract = Contract_repr.implicit_contract delegate in
|
let contract = Contract_repr.implicit_contract delegate in
|
||||||
let map = Cycle_repr.Map.empty in
|
let map = Cycle_repr.Map.empty in
|
||||||
Storage.Contract.Frozen_deposits.fold
|
Storage.Contract.Frozen_deposits.fold
|
||||||
@ -449,10 +449,26 @@ let grace_period ctxt delegate =
|
|||||||
let contract = Contract_repr.implicit_contract delegate in
|
let contract = Contract_repr.implicit_contract delegate in
|
||||||
Storage.Contract.Delegate_desactivation.get ctxt contract
|
Storage.Contract.Delegate_desactivation.get ctxt contract
|
||||||
|
|
||||||
let delegated_balance ctxt delegate =
|
let staking_balance ctxt delegate =
|
||||||
let token_per_rolls = Constants_storage.tokens_per_roll ctxt in
|
let token_per_rolls = Constants_storage.tokens_per_roll ctxt in
|
||||||
Roll_storage.get_rolls ctxt delegate >>=? fun rolls ->
|
Roll_storage.get_rolls ctxt delegate >>=? fun rolls ->
|
||||||
Roll_storage.get_change ctxt delegate >>=? fun change ->
|
Roll_storage.get_change ctxt delegate >>=? fun change ->
|
||||||
let rolls = Int64.of_int (List.length rolls) in
|
let rolls = Int64.of_int (List.length rolls) in
|
||||||
Lwt.return Tez_repr.(token_per_rolls *? rolls) >>=? fun balance ->
|
Lwt.return Tez_repr.(token_per_rolls *? rolls) >>=? fun balance ->
|
||||||
Lwt.return Tez_repr.(balance +? change)
|
Lwt.return Tez_repr.(balance +? change)
|
||||||
|
|
||||||
|
let delegated_balance ctxt delegate =
|
||||||
|
let contract = Contract_repr.implicit_contract delegate in
|
||||||
|
staking_balance ctxt delegate >>=? fun staking_balance ->
|
||||||
|
Storage.Contract.Balance.get ctxt contract >>= fun self_staking_balance ->
|
||||||
|
Storage.Contract.Frozen_deposits.fold
|
||||||
|
(ctxt, contract) ~init:self_staking_balance
|
||||||
|
~f:(fun _cycle amount acc ->
|
||||||
|
Lwt.return acc >>=? fun acc ->
|
||||||
|
Lwt.return (Tez_repr.(acc +? amount))) >>= fun self_staking_balance ->
|
||||||
|
Storage.Contract.Frozen_fees.fold
|
||||||
|
(ctxt, contract) ~init:self_staking_balance
|
||||||
|
~f:(fun _cycle amount acc ->
|
||||||
|
Lwt.return acc >>=? fun acc ->
|
||||||
|
Lwt.return (Tez_repr.(acc +? amount))) >>=? fun self_staking_balance ->
|
||||||
|
Lwt.return Tez_repr.(staking_balance -? self_staking_balance)
|
||||||
|
@ -107,12 +107,13 @@ type frozen_balance = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val frozen_balance_encoding: frozen_balance Data_encoding.t
|
val frozen_balance_encoding: frozen_balance Data_encoding.t
|
||||||
val frozen_balances_encoding: frozen_balance Cycle_repr.Map.t Data_encoding.t
|
val frozen_balance_by_cycle_encoding:
|
||||||
|
frozen_balance Cycle_repr.Map.t Data_encoding.t
|
||||||
|
|
||||||
(** Returns the amount of frozen deposit, fees and rewards associated
|
(** Returns the amount of frozen deposit, fees and rewards associated
|
||||||
to a given delegate, indexed by the cycle by which at the end the
|
to a given delegate, indexed by the cycle by which at the end the
|
||||||
balance will be unfrozen. *)
|
balance will be unfrozen. *)
|
||||||
val frozen_balances:
|
val frozen_balance_by_cycle:
|
||||||
Raw_context.t -> Signature.Public_key_hash.t ->
|
Raw_context.t -> Signature.Public_key_hash.t ->
|
||||||
frozen_balance Cycle_repr.Map.t Lwt.t
|
frozen_balance Cycle_repr.Map.t Lwt.t
|
||||||
|
|
||||||
@ -123,8 +124,12 @@ 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
|
||||||
|
|
||||||
|
val staking_balance:
|
||||||
|
Raw_context.t -> Signature.Public_key_hash.t ->
|
||||||
|
Tez_repr.t tzresult Lwt.t
|
||||||
|
|
||||||
(** Returns the list of contract that delegated towards a given delegate *)
|
(** Returns the list of contract that delegated towards a given delegate *)
|
||||||
val get_delegated_contracts:
|
val delegated_contracts:
|
||||||
Raw_context.t -> Signature.Public_key_hash.t ->
|
Raw_context.t -> Signature.Public_key_hash.t ->
|
||||||
Contract_hash.t list Lwt.t
|
Contract_hash.t list Lwt.t
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ module Contract = struct
|
|||||||
invalid_arg
|
invalid_arg
|
||||||
"get_balance: no frozen accounts for an originated contract."
|
"get_balance: no frozen accounts for an originated contract."
|
||||||
| Some pkh ->
|
| Some pkh ->
|
||||||
Alpha_services.Delegate.frozen_balances
|
Alpha_services.Delegate.frozen_balance_by_cycle
|
||||||
rpc_ctxt ctxt pkh >>=? fun map ->
|
rpc_ctxt ctxt pkh >>=? fun map ->
|
||||||
Lwt.return @@
|
Lwt.return @@
|
||||||
Cycle.Map.fold
|
Cycle.Map.fold
|
||||||
|
Loading…
Reference in New Issue
Block a user