138 lines
4.2 KiB
OCaml
138 lines
4.2 KiB
OCaml
![]() |
(**************************************************************************)
|
||
|
(* *)
|
||
|
(* Copyright (c) 2014 - 2016. *)
|
||
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
||
|
(* *)
|
||
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
||
|
(* *)
|
||
|
(**************************************************************************)
|
||
|
|
||
|
module Net_id = Store.Net_id
|
||
|
|
||
|
type t =
|
||
|
|
||
|
| Get_current_branch of Net_id.t
|
||
|
| Current_branch of Net_id.t * Block_hash.t list (* Block locator *)
|
||
|
| Deactivate of Net_id.t
|
||
|
|
||
|
| Get_current_head of Net_id.t
|
||
|
| Current_head of Net_id.t * Block_hash.t * Operation_hash.t list
|
||
|
|
||
|
| Get_block_headers of Net_id.t * Block_hash.t list
|
||
|
| Block_header of Store.Block_header.t
|
||
|
|
||
|
| Get_operations of Net_id.t * Operation_hash.t list
|
||
|
| Operation of Store.Operation.t
|
||
|
|
||
|
| Get_protocols of Protocol_hash.t list
|
||
|
| Protocol of Tezos_compiler.Protocol.t
|
||
|
|
||
|
let encoding =
|
||
|
let open Data_encoding in
|
||
|
let case ?max_length ~tag encoding unwrap wrap =
|
||
|
P2p.Encoding { tag; encoding; wrap; unwrap; max_length } in
|
||
|
[
|
||
|
case ~tag:0x10
|
||
|
(obj1
|
||
|
(req "get_current_branch" Net_id.encoding))
|
||
|
(function
|
||
|
| Get_current_branch net_id -> Some net_id
|
||
|
| _ -> None)
|
||
|
(fun net_id -> Get_current_branch net_id) ;
|
||
|
|
||
|
case ~tag:0x11
|
||
|
(obj2
|
||
|
(req "net_id" Net_id.encoding)
|
||
|
(req "current_branch" (list Block_hash.encoding)))
|
||
|
(function
|
||
|
| Current_branch (net_id, bhs) -> Some (net_id, bhs)
|
||
|
| _ -> None)
|
||
|
(fun (net_id, bhs) -> Current_branch (net_id, bhs)) ;
|
||
|
|
||
|
case ~tag:0x12
|
||
|
(obj1
|
||
|
(req "deactivate" Net_id.encoding))
|
||
|
(function
|
||
|
| Deactivate net_id -> Some net_id
|
||
|
| _ -> None)
|
||
|
(fun net_id -> Deactivate net_id) ;
|
||
|
|
||
|
case ~tag:0x13
|
||
|
(obj1
|
||
|
(req "get_current_head" Net_id.encoding))
|
||
|
(function
|
||
|
| Get_current_head net_id -> Some net_id
|
||
|
| _ -> None)
|
||
|
(fun net_id -> Get_current_branch net_id) ;
|
||
|
|
||
|
case ~tag:0x14
|
||
|
(obj3
|
||
|
(req "net_id" Net_id.encoding)
|
||
|
(req "current_head" Block_hash.encoding)
|
||
|
(req "current_mempool" (list Operation_hash.encoding)))
|
||
|
(function
|
||
|
| Current_head (net_id, bh, ops) -> Some (net_id, bh, ops)
|
||
|
| _ -> None)
|
||
|
(fun (net_id, bh, ops) -> Current_head (net_id, bh, ops)) ;
|
||
|
|
||
|
case ~tag:0x20
|
||
|
(obj2
|
||
|
(req "net_id" Net_id.encoding)
|
||
|
(req "get_block_headers" (list Block_hash.encoding)))
|
||
|
(function
|
||
|
| Get_block_headers (net_id, bhs) -> Some (net_id, bhs)
|
||
|
| _ -> None)
|
||
|
(fun (net_id, bhs) -> Get_block_headers (net_id, bhs)) ;
|
||
|
|
||
|
case ~tag:0x21
|
||
|
(obj1 (req "block_header" Store.Block_header.encoding))
|
||
|
(function
|
||
|
| Block_header bh -> Some bh
|
||
|
| _ -> None)
|
||
|
(fun bh -> Block_header bh) ;
|
||
|
|
||
|
case ~tag:0x30
|
||
|
(obj2
|
||
|
(req "net_id" Net_id.encoding)
|
||
|
(req "get_operations" (list Operation_hash.encoding)))
|
||
|
(function
|
||
|
| Get_operations (net_id, bhs) -> Some (net_id, bhs)
|
||
|
| _ -> None)
|
||
|
(fun (net_id, bhs) -> Get_operations (net_id, bhs)) ;
|
||
|
|
||
|
case ~tag:0x31
|
||
|
(obj1 (req "operation" Store.Operation.encoding))
|
||
|
(function Operation o -> Some o | _ -> None)
|
||
|
(fun o -> Operation o);
|
||
|
|
||
|
case ~tag:0x40
|
||
|
(obj1
|
||
|
(req "get_protocols" (list Protocol_hash.encoding)))
|
||
|
(function
|
||
|
| Get_protocols protos -> Some protos
|
||
|
| _ -> None)
|
||
|
(fun protos -> Get_protocols protos);
|
||
|
|
||
|
case ~tag:0x41
|
||
|
(obj1 (req "protocol" Store.Protocol.encoding))
|
||
|
(function Protocol proto -> Some proto | _ -> None)
|
||
|
(fun proto -> Protocol proto);
|
||
|
|
||
|
]
|
||
|
|
||
|
let versions =
|
||
|
let open P2p.Version in
|
||
|
[ { name = "TEZOS" ;
|
||
|
major = 0 ;
|
||
|
minor = 0 ;
|
||
|
}
|
||
|
]
|
||
|
|
||
|
let cfg : _ P2p.message_config = { encoding ; versions }
|
||
|
|
||
|
let raw_encoding = P2p.Raw.encoding encoding
|
||
|
|
||
|
let pp_json ppf msg =
|
||
|
Format.pp_print_string ppf
|
||
|
(Data_encoding_ezjsonm.to_string (Data_encoding.Json.construct raw_encoding (Message msg)))
|