Alpha/PRC use more Data_encoding.def
This commit is contained in:
parent
33c3d1fcbd
commit
371b84fa5d
@ -20,6 +20,7 @@ type shell_header = {
|
|||||||
|
|
||||||
let shell_header_encoding =
|
let shell_header_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
def "block_header.shell" @@
|
||||||
conv
|
conv
|
||||||
(fun { level ; proto_level ; predecessor ;
|
(fun { level ; proto_level ; predecessor ;
|
||||||
timestamp ; validation_passes ; operations_hash ; fitness ;
|
timestamp ; validation_passes ; operations_hash ; fitness ;
|
||||||
|
@ -166,6 +166,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
let raw_block_header_encoding =
|
let raw_block_header_encoding =
|
||||||
|
def "raw_block_header" @@
|
||||||
conv
|
conv
|
||||||
(fun { shell ; protocol_data } -> (shell, protocol_data))
|
(fun { shell ; protocol_data } -> (shell, protocol_data))
|
||||||
(fun (shell, protocol_data) -> { shell ; protocol_data } )
|
(fun (shell, protocol_data) -> { shell ; protocol_data } )
|
||||||
@ -181,6 +182,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
let block_header_encoding =
|
let block_header_encoding =
|
||||||
|
def "block_header" @@
|
||||||
conv
|
conv
|
||||||
(fun { chain_id ; hash ; shell ; protocol_data } ->
|
(fun { chain_id ; hash ; shell ; protocol_data } ->
|
||||||
(((), chain_id, hash), { shell ; protocol_data }))
|
(((), chain_id, hash), { shell ; protocol_data }))
|
||||||
@ -204,6 +206,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
let block_metadata_encoding =
|
let block_metadata_encoding =
|
||||||
|
def "block_header_metadata" @@
|
||||||
conv
|
conv
|
||||||
(fun { protocol_data ; test_chain_status ; max_operations_ttl ;
|
(fun { protocol_data ; test_chain_status ; max_operations_ttl ;
|
||||||
max_operation_data_length ; max_block_header_length ;
|
max_operation_data_length ; max_block_header_length ;
|
||||||
@ -252,6 +255,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
let operation_encoding =
|
let operation_encoding =
|
||||||
|
def "operation" @@
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
conv
|
conv
|
||||||
(fun { chain_id ; hash ; shell ; protocol_data ; metadata } ->
|
(fun { chain_id ; hash ; shell ; protocol_data ; metadata } ->
|
||||||
@ -942,3 +946,14 @@ module Fake_protocol = struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
module Empty = Make(Fake_protocol)(Fake_protocol)
|
module Empty = Make(Fake_protocol)(Fake_protocol)
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Printexc.register_printer
|
||||||
|
(function
|
||||||
|
| (Json_schema.Cannot_parse _
|
||||||
|
| Json_schema.Dangling_reference _
|
||||||
|
| Json_schema.Bad_reference _
|
||||||
|
| Json_schema.Unexpected _
|
||||||
|
| Json_schema.Duplicate_definition _ ) as exn ->
|
||||||
|
Some (Format.asprintf "%a" (fun ppf -> Json_schema.print_error ppf) exn)
|
||||||
|
| _ -> None)
|
||||||
|
@ -10,6 +10,19 @@
|
|||||||
open Alpha_context
|
open Alpha_context
|
||||||
open Data_encoding
|
open Data_encoding
|
||||||
|
|
||||||
|
let error_encoding =
|
||||||
|
def "error"
|
||||||
|
(* FIXME RPC /chains/blocks/head/errors lint*)
|
||||||
|
~description:"... FIXME ..." @@
|
||||||
|
splitted
|
||||||
|
~json:(conv
|
||||||
|
(fun err ->
|
||||||
|
Data_encoding.Json.construct Error_monad.error_encoding err)
|
||||||
|
(fun json ->
|
||||||
|
Data_encoding.Json.destruct Error_monad.error_encoding json)
|
||||||
|
json)
|
||||||
|
~binary:Error_monad.error_encoding
|
||||||
|
|
||||||
type balance =
|
type balance =
|
||||||
| Contract of Contract.t
|
| Contract of Contract.t
|
||||||
| Rewards of Signature.Public_key_hash.t * Cycle.t
|
| Rewards of Signature.Public_key_hash.t * Cycle.t
|
||||||
@ -17,6 +30,7 @@ type balance =
|
|||||||
| Deposits of Signature.Public_key_hash.t * Cycle.t
|
| Deposits of Signature.Public_key_hash.t * Cycle.t
|
||||||
|
|
||||||
let balance_encoding =
|
let balance_encoding =
|
||||||
|
def "operation_metadata.alpha.balance" @@
|
||||||
union
|
union
|
||||||
[ case (Tag 0)
|
[ case (Tag 0)
|
||||||
(obj2
|
(obj2
|
||||||
@ -54,6 +68,7 @@ type balance_update =
|
|||||||
| Credited of Tez.t
|
| Credited of Tez.t
|
||||||
|
|
||||||
let balance_update_encoding =
|
let balance_update_encoding =
|
||||||
|
def "operation_metadata.alpha.balance_update" @@
|
||||||
union
|
union
|
||||||
[ case (Tag 0)
|
[ case (Tag 0)
|
||||||
(obj1 (req "credited" Tez.encoding))
|
(obj1 (req "credited" Tez.encoding))
|
||||||
@ -67,6 +82,7 @@ let balance_update_encoding =
|
|||||||
type balance_updates = (balance * balance_update) list
|
type balance_updates = (balance * balance_update) list
|
||||||
|
|
||||||
let balance_updates_encoding =
|
let balance_updates_encoding =
|
||||||
|
def "operation_metadata.alpha.balance_updates" @@
|
||||||
list (merge_objs balance_encoding balance_update_encoding)
|
list (merge_objs balance_encoding balance_update_encoding)
|
||||||
|
|
||||||
type anonymous_operation_result =
|
type anonymous_operation_result =
|
||||||
@ -203,7 +219,7 @@ let manager_operation_result_encoding =
|
|||||||
case (Tag 4)
|
case (Tag 4)
|
||||||
(obj2
|
(obj2
|
||||||
(req "status" (constant "failed"))
|
(req "status" (constant "failed"))
|
||||||
(req "errors" (list Error_monad.error_encoding)))
|
(req "errors" (list error_encoding)))
|
||||||
(function Failed errs -> Some ((), errs) | _ -> None)
|
(function Failed errs -> Some ((), errs) | _ -> None)
|
||||||
(fun ((), errs) -> Failed errs) ;
|
(fun ((), errs) -> Failed errs) ;
|
||||||
case (Tag 5)
|
case (Tag 5)
|
||||||
@ -227,6 +243,7 @@ type operation_result =
|
|||||||
| Sourced_operation_result of sourced_operation_result
|
| Sourced_operation_result of sourced_operation_result
|
||||||
|
|
||||||
let encoding =
|
let encoding =
|
||||||
|
def "alpha.metadata" @@
|
||||||
union
|
union
|
||||||
[ case (Tag 0)
|
[ case (Tag 0)
|
||||||
(obj2
|
(obj2
|
||||||
|
@ -35,6 +35,7 @@ let shell_header_encoding = Block_header.shell_header_encoding
|
|||||||
|
|
||||||
let contents_encoding =
|
let contents_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
def "block_header.alpha.unsigned_contents" @@
|
||||||
conv
|
conv
|
||||||
(fun { priority ; seed_nonce_hash ; proof_of_work_nonce } ->
|
(fun { priority ; seed_nonce_hash ; proof_of_work_nonce } ->
|
||||||
(priority, proof_of_work_nonce, seed_nonce_hash))
|
(priority, proof_of_work_nonce, seed_nonce_hash))
|
||||||
@ -48,6 +49,7 @@ let contents_encoding =
|
|||||||
|
|
||||||
let protocol_data_encoding =
|
let protocol_data_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
def "block_header.alpha.signed_contents" @@
|
||||||
conv
|
conv
|
||||||
(fun { contents ; signature } -> (contents, signature))
|
(fun { contents ; signature } -> (contents, signature))
|
||||||
(fun (contents, signature) -> { contents ; signature })
|
(fun (contents, signature) -> { contents ; signature })
|
||||||
@ -70,6 +72,7 @@ let unsigned_encoding =
|
|||||||
|
|
||||||
let encoding =
|
let encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
def "block_header.alpha.full_header" @@
|
||||||
conv
|
conv
|
||||||
(fun { shell ; protocol_data } ->
|
(fun { shell ; protocol_data } ->
|
||||||
(shell, protocol_data))
|
(shell, protocol_data))
|
||||||
@ -86,6 +89,7 @@ type metadata = {
|
|||||||
}
|
}
|
||||||
let metadata_encoding =
|
let metadata_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
|
def "block_header.alpha.metadata" @@
|
||||||
conv
|
conv
|
||||||
(fun { baker ; level ; voting_period_kind } ->
|
(fun { baker ; level ; voting_period_kind } ->
|
||||||
(baker, level, voting_period_kind))
|
(baker, level, voting_period_kind))
|
||||||
|
@ -407,7 +407,7 @@ module Encoding = struct
|
|||||||
(obj1 (varopt "signature" Signature.encoding)))
|
(obj1 (varopt "signature" Signature.encoding)))
|
||||||
|
|
||||||
let operation_encoding =
|
let operation_encoding =
|
||||||
mu "operation"
|
mu "operation.alpha"
|
||||||
(fun encoding ->
|
(fun encoding ->
|
||||||
conv
|
conv
|
||||||
(fun { shell ; protocol_data } -> (shell, protocol_data))
|
(fun { shell ; protocol_data } -> (shell, protocol_data))
|
||||||
@ -430,6 +430,7 @@ module Encoding = struct
|
|||||||
contents_encoding
|
contents_encoding
|
||||||
|
|
||||||
let internal_operation_encoding =
|
let internal_operation_encoding =
|
||||||
|
def "operation.alpha.internal_operation" @@
|
||||||
conv
|
conv
|
||||||
(fun { source ; operation ; nonce } -> ((source, nonce), operation))
|
(fun { source ; operation ; nonce } -> ((source, nonce), operation))
|
||||||
(fun ((source, nonce), operation) -> { source ; operation ; nonce })
|
(fun ((source, nonce), operation) -> { source ; operation ; nonce })
|
||||||
|
Loading…
Reference in New Issue
Block a user