From a2f1b6c889592cc35fdac0605ecedfed880f0736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Sat, 25 Feb 2017 13:24:53 +0100 Subject: [PATCH] Client: introduce `Client_blocks` --- src/Makefile | 1 + src/client/client_blocks.ml | 24 +++++++++++++++++++ src/client/client_blocks.mli | 18 ++++++++++++++ .../alpha/baker/client_mining_endorsement.ml | 9 +------ 4 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 src/client/client_blocks.ml create mode 100644 src/client/client_blocks.mli diff --git a/src/Makefile b/src/Makefile index e8475b8ca..8fee528f6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -469,6 +469,7 @@ CLIENT_LIB_IMPLS := \ client/client_aliases.ml \ client/client_keys.ml \ client/client_protocols.ml \ + client/client_blocks.ml \ WEBCLIENT_LIB_INTFS := \ diff --git a/src/client/client_blocks.ml b/src/client/client_blocks.ml new file mode 100644 index 000000000..aeb805ed4 --- /dev/null +++ b/src/client/client_blocks.ml @@ -0,0 +1,24 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2016. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +let get_block_hash cctxt = function + | `Hash hash -> Lwt.return hash + | `Genesis | `Head _ | `Test_head _ as block -> + Client_node_rpcs.Blocks.hash cctxt block + | `Prevalidation -> Client_node_rpcs.Blocks.hash cctxt (`Head 0) + | `Test_prevalidation -> Client_node_rpcs.Blocks.hash cctxt (`Test_head 0) + + +let get_block_info cctxt block = + let block = + match block with + | `Prevalidation -> `Head 0 + | `Test_prevalidation -> `Test_head 0 + | b -> b in + Client_node_rpcs.Blocks.info cctxt block diff --git a/src/client/client_blocks.mli b/src/client/client_blocks.mli new file mode 100644 index 000000000..7aa55429a --- /dev/null +++ b/src/client/client_blocks.mli @@ -0,0 +1,18 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2016. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +val get_block_hash: + Client_commands.context -> + Client_node_rpcs.Blocks.block -> + Block_hash.Table.key Lwt.t + +val get_block_info: + Client_commands.context -> + Client_node_rpcs.Blocks.block -> + Client_node_rpcs.Blocks.block_info Lwt.t diff --git a/src/client/embedded/alpha/baker/client_mining_endorsement.ml b/src/client/embedded/alpha/baker/client_mining_endorsement.ml index a9d005cf7..b2ee2c811 100644 --- a/src/client/embedded/alpha/baker/client_mining_endorsement.ml +++ b/src/client/embedded/alpha/baker/client_mining_endorsement.ml @@ -100,13 +100,6 @@ end = struct end -let get_block_hash cctxt = function - | `Hash hash -> Lwt.return hash - | `Genesis | `Head _ | `Test_head _ as block -> - Client_node_rpcs.Blocks.hash cctxt block - | `Prevalidation -> Client_node_rpcs.Blocks.hash cctxt (`Head 0) - | `Test_prevalidation -> Client_node_rpcs.Blocks.hash cctxt (`Test_head 0) - let get_signing_slots cctxt ?max_priority block delegate level = Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate cctxt ?max_priority ~first_level:level ~last_level:level @@ -119,7 +112,7 @@ let get_signing_slots cctxt ?max_priority block delegate level = let inject_endorsement cctxt block level ?wait ?force src_sk source slot = - get_block_hash cctxt block >>= fun block_hash -> + Client_blocks.get_block_hash cctxt block >>= fun block_hash -> Client_node_rpcs.Blocks.net cctxt block >>= fun net -> Client_proto_rpcs.Helpers.Forge.Delegate.endorsement cctxt block