Client/Alpha: display the "real" metadata when --wait
is used
This commit is contained in:
parent
89cbe0f8fa
commit
ebc00b6463
@ -16,9 +16,11 @@ let wait_for_operation_inclusion
|
||||
|
||||
(* Table of known blocks:
|
||||
- None: if neither the block or its predecessors contains the operation
|
||||
- (Some n): if the `n-th` predecessors of the block contains the operation *)
|
||||
- (Some ((hash, i, j), n)):
|
||||
if the `hash` contains the operation in list `i` at position `j`
|
||||
and if `hash` denotes the `n-th` predecessors of the block. *)
|
||||
|
||||
let blocks : int option Block_hash.Table.t =
|
||||
let blocks : ((Block_hash.t * int * int) * int) option Block_hash.Table.t =
|
||||
Block_hash.Table.create confirmations in
|
||||
|
||||
(* Fetch _all_ the 'unknown' predecessors af a block. *)
|
||||
@ -49,37 +51,44 @@ let wait_for_operation_inclusion
|
||||
Shell_services.Blocks.Header.Shell.predecessor
|
||||
ctxt ~chain ~block () >>=? fun predecessor ->
|
||||
match Block_hash.Table.find blocks predecessor with
|
||||
| Some n ->
|
||||
| Some (block_with_op, n) ->
|
||||
ctxt#answer
|
||||
"Operation received %d confirmations as of block: %a"
|
||||
(n+1) Block_hash.pp hash >>= fun () ->
|
||||
Block_hash.Table.add blocks hash (Some (block_with_op, n+1)) ;
|
||||
if n+1 < confirmations then begin
|
||||
Block_hash.Table.add blocks hash (Some (n+1)) ;
|
||||
return false
|
||||
return None
|
||||
end else
|
||||
return true
|
||||
return (Some block_with_op)
|
||||
| None ->
|
||||
Shell_services.Blocks.Operation_hash.operation_hashes
|
||||
ctxt ~chain ~block () >>=? fun operations ->
|
||||
let in_block =
|
||||
List.exists
|
||||
(List.exists
|
||||
(Operation_hash.equal operation_hash))
|
||||
operations in
|
||||
if not in_block then begin
|
||||
Block_hash.Table.add blocks hash None ;
|
||||
return false
|
||||
end else begin
|
||||
ctxt#answer
|
||||
"Operation found in block: %a"
|
||||
Block_hash.pp hash >>= fun () ->
|
||||
if confirmations <= 0 then
|
||||
return true
|
||||
else begin
|
||||
Block_hash.Table.add blocks hash (Some 0) ;
|
||||
return false
|
||||
end
|
||||
end in
|
||||
let exception Found of int * int in
|
||||
try
|
||||
List.iteri
|
||||
(fun i ops ->
|
||||
List.iteri (fun j op ->
|
||||
if Operation_hash.equal operation_hash op then
|
||||
raise (Found (i,j))) ops)
|
||||
operations ;
|
||||
None
|
||||
with Found (i,j) -> Some (i, j) in
|
||||
match in_block with
|
||||
| None ->
|
||||
Block_hash.Table.add blocks hash None ;
|
||||
return None
|
||||
| Some (i, j) -> begin
|
||||
ctxt#answer
|
||||
"Operation found in block: %a (pass: %d, offset: %d)"
|
||||
Block_hash.pp hash i j >>= fun () ->
|
||||
Block_hash.Table.add blocks hash (Some ((hash, i, j), 0)) ;
|
||||
if confirmations <= 0 then
|
||||
return (Some (hash, i, j))
|
||||
else begin
|
||||
return None
|
||||
end
|
||||
end in
|
||||
|
||||
Shell_services.Monitor.heads ctxt chain >>=? fun (stream, stop) ->
|
||||
Lwt_stream.get stream >>= function
|
||||
@ -88,10 +97,10 @@ let wait_for_operation_inclusion
|
||||
let rec loop n =
|
||||
if n >= 0 then
|
||||
process (`Hash (head, n)) >>=? function
|
||||
| true ->
|
||||
| Some block ->
|
||||
stop () ;
|
||||
return ()
|
||||
| false ->
|
||||
return block
|
||||
| None ->
|
||||
loop (n-1)
|
||||
else
|
||||
let exception WrapError of error list in
|
||||
@ -101,14 +110,21 @@ let wait_for_operation_inclusion
|
||||
Lwt_stream.find_s
|
||||
(fun block ->
|
||||
process (`Hash (block, 0)) >>= function
|
||||
| Ok b -> Lwt.return b
|
||||
| Ok None -> Lwt.return false
|
||||
| Ok (Some _) -> Lwt.return true
|
||||
| Error err ->
|
||||
Lwt.fail (WrapError err)) stream >>= return)
|
||||
(function
|
||||
| WrapError e -> Lwt.return (Error e)
|
||||
| exn -> Lwt.fail exn) >>=? fun _ ->
|
||||
stop () ;
|
||||
return () in
|
||||
| exn -> Lwt.fail exn) >>=? function
|
||||
| None ->
|
||||
failwith "..."
|
||||
| Some hash ->
|
||||
stop () ;
|
||||
match Block_hash.Table.find_opt blocks hash with
|
||||
| None | Some None -> assert false
|
||||
| Some (Some (hash, _)) ->
|
||||
return hash in
|
||||
Block_services.Empty.hash
|
||||
ctxt ~block:(`Hash (head, predecessors+1)) () >>=? fun oldest ->
|
||||
Block_hash.Table.add blocks oldest None ;
|
||||
|
@ -7,10 +7,17 @@
|
||||
(* *)
|
||||
(**************************************************************************)
|
||||
|
||||
(** [wait_for_operation_inclusion chain ~predecessors ~confirmations
|
||||
oph] waits for `oph` to appears in the main chain with at least
|
||||
`confirmations`. It returns the hash of the block that contains
|
||||
the operation and the operation position in the block.
|
||||
|
||||
This functions also looks for the operations in the `predecessors`
|
||||
of the intial chain head. *)
|
||||
val wait_for_operation_inclusion:
|
||||
#Client_context.full ->
|
||||
chain:Chain_services.chain ->
|
||||
?predecessors:int ->
|
||||
?confirmations:int ->
|
||||
Operation_hash.t ->
|
||||
unit tzresult Lwt.t
|
||||
(Block_hash.t * int * int) tzresult Lwt.t
|
||||
|
@ -181,13 +181,15 @@ let inject_operation
|
||||
cctxt#message "Operation hash is '%a'." Operation_hash.pp oph >>= fun () ->
|
||||
begin
|
||||
match confirmations with
|
||||
| None -> return ()
|
||||
| None -> return result
|
||||
| Some confirmations ->
|
||||
cctxt#message "Waiting for the operation to be included..." >>= fun () ->
|
||||
Client_confirmations.wait_for_operation_inclusion
|
||||
~confirmations cctxt ~chain oph >>=? fun _ ->
|
||||
return ()
|
||||
end >>=? fun () ->
|
||||
~confirmations cctxt ~chain oph >>=? fun (h, i , j) ->
|
||||
Alpha_block_services.Operation.operation
|
||||
cctxt ~block:(`Hash (h, 0)) i j >>=? fun op ->
|
||||
return op.metadata
|
||||
end >>=? fun result ->
|
||||
cctxt#message
|
||||
"@[<v 2>This sequence of operations was run:@,%a@]"
|
||||
Operation_result.pp_operation_result (op, result) >>= fun () ->
|
||||
|
Loading…
Reference in New Issue
Block a user