Client/test: minor code simplification

This commit is contained in:
Grégoire Henry 2018-02-11 19:17:40 +01:00
parent 3b95f77225
commit 4a1da9407e

View File

@ -21,8 +21,10 @@ let rpc_config = ref {
logger = RPC_client.null_logger ; logger = RPC_client.null_logger ;
} }
let rpc_ctxt = let build_rpc_context config =
ref (new RPC_client.http_ctxt !rpc_config Media_type.all_media_types) new RPC_client.http_ctxt config Media_type.all_media_types
let rpc_ctxt = ref (build_rpc_context !rpc_config)
(* Context that does not write to alias files *) (* Context that does not write to alias files *)
let no_write_context config block : Client_commands.full_context = object let no_write_context config block : Client_commands.full_context = object
@ -54,8 +56,7 @@ let init ?exe ?(sandbox = "sandbox.json") ?rpc_port () =
| None -> () | None -> ()
| Some port -> | Some port ->
rpc_config := { !rpc_config with port } ; rpc_config := { !rpc_config with port } ;
rpc_ctxt := rpc_ctxt := build_rpc_context !rpc_config ;
new RPC_client.http_ctxt !rpc_config Media_type.all_media_types ;
end ; end ;
let pid = let pid =
Node_helpers.fork_node Node_helpers.fork_node
@ -253,10 +254,9 @@ module Protocol = struct
return (Tezos_base.Operation.of_bytes_exn signed_bytes) return (Tezos_base.Operation.of_bytes_exn signed_bytes)
let ballot ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) ~proposal ballot = let ballot ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) ~proposal ballot =
let rpc = new RPC_client.http_ctxt !rpc_config Media_type.all_media_types in Block_services.info !rpc_ctxt block >>=? fun block_info ->
Block_services.info rpc block >>=? fun block_info -> Client_proto_rpcs.Context.next_level !rpc_ctxt block >>=? fun next_level ->
Client_proto_rpcs.Context.next_level rpc block >>=? fun next_level -> Client_proto_rpcs.Helpers.Forge.Delegate.ballot !rpc_ctxt block
Client_proto_rpcs.Helpers.Forge.Delegate.ballot rpc block
~branch:block_info.hash ~branch:block_info.hash
~source:pk ~source:pk
~period:next_level.voting_period ~period:next_level.voting_period
@ -464,9 +464,8 @@ module Endorse = struct
source source
slot = slot =
let block = Block_services.last_baked_block block in let block = Block_services.last_baked_block block in
let rpc = new RPC_client.http_ctxt !rpc_config Media_type.all_media_types in Block_services.info !rpc_ctxt block >>=? fun { hash ; _ } ->
Block_services.info rpc block >>=? fun { hash ; _ } -> Client_proto_rpcs.Helpers.Forge.Delegate.endorsement !rpc_ctxt
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement rpc
block block
~branch:hash ~branch:hash
~source ~source
@ -532,12 +531,11 @@ module Endorse = struct
let endorsement_rights let endorsement_rights
?(max_priority = 1024) ?(max_priority = 1024)
(contract : Account.t) block = (contract : Account.t) block =
let rpc = new RPC_client.http_ctxt !rpc_config Media_type.all_media_types in Client_proto_rpcs.Context.level !rpc_ctxt block >>=? fun level ->
Client_proto_rpcs.Context.level rpc block >>=? fun level ->
let delegate = contract.pkh in let delegate = contract.pkh in
let level = level.level in let level = level.level in
Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate
rpc !rpc_ctxt
~max_priority ~max_priority
~first_level:level ~first_level:level
~last_level:level ~last_level:level