2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
open Cli_entries
|
|
|
|
open Tezos_context
|
|
|
|
open Logging.Client.Revelation
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let inject_seed_nonce_revelation cctxt block ?force ?wait nonces =
|
2016-09-08 21:13:10 +04:00
|
|
|
let operations =
|
|
|
|
List.map
|
|
|
|
(fun (level, nonce) ->
|
|
|
|
Seed_nonce_revelation { level ; nonce }) nonces in
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_node_rpcs.Blocks.net cctxt block >>= fun net ->
|
|
|
|
Client_proto_rpcs.Helpers.Forge.Anonymous.operations cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
block ~net operations >>=? fun bytes ->
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_node_rpcs.inject_operation cctxt ?force ?wait bytes >>=? fun oph ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return oph
|
|
|
|
|
|
|
|
type Error_monad.error += Bad_revelation
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let forge_seed_nonce_revelation cctxt
|
|
|
|
block ?(force = false) redempted_nonces =
|
2016-09-08 21:13:10 +04:00
|
|
|
begin
|
|
|
|
if force then return redempted_nonces else
|
|
|
|
map_filter_s (fun (level, nonce) ->
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_proto_rpcs.Context.Nonce.get cctxt block level >>=? function
|
2016-09-08 21:13:10 +04:00
|
|
|
| Forgotten ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Too late revelation for level %a"
|
2016-11-22 20:59:09 +04:00
|
|
|
Raw_level.pp level >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return None
|
|
|
|
| Revealed _ ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Ignoring previously-revealed nonce for level %a"
|
2016-11-22 20:59:09 +04:00
|
|
|
Raw_level.pp level >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return None
|
|
|
|
| Missing nonce_hash ->
|
|
|
|
if Nonce.check_hash nonce nonce_hash then
|
|
|
|
return (Some (level, nonce))
|
|
|
|
else
|
|
|
|
lwt_log_error "Incoherent nonce for level %a"
|
|
|
|
Raw_level.pp level >>= fun () ->
|
|
|
|
return None)
|
|
|
|
redempted_nonces
|
|
|
|
end >>=? fun nonces ->
|
|
|
|
match nonces with
|
|
|
|
| [] ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "No nonce to reveal" >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
| _ ->
|
2016-12-03 16:05:02 +04:00
|
|
|
inject_seed_nonce_revelation cctxt
|
2016-09-08 21:13:10 +04:00
|
|
|
block ~force ~wait:true nonces >>=? fun oph ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.answer "Operation successfully injected in the node." >>= fun () ->
|
|
|
|
cctxt.answer "Operation hash is '%a'." Operation_hash.pp_short oph >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|