Alpha/PRC use more Data_encoding.def

This commit is contained in:
Grégoire Henry 2018-04-30 19:00:45 +02:00 committed by Benjamin Canou
parent 33c3d1fcbd
commit 371b84fa5d
5 changed files with 40 additions and 2 deletions

View File

@ -20,6 +20,7 @@ type shell_header = {
let shell_header_encoding =
let open Data_encoding in
def "block_header.shell" @@
conv
(fun { level ; proto_level ; predecessor ;
timestamp ; validation_passes ; operations_hash ; fitness ;

View File

@ -166,6 +166,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
}
let raw_block_header_encoding =
def "raw_block_header" @@
conv
(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 =
def "block_header" @@
conv
(fun { 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 =
def "block_header_metadata" @@
conv
(fun { protocol_data ; test_chain_status ; max_operations_ttl ;
max_operation_data_length ; max_block_header_length ;
@ -252,6 +255,7 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct
}
let operation_encoding =
def "operation" @@
let open Data_encoding in
conv
(fun { chain_id ; hash ; shell ; protocol_data ; metadata } ->
@ -942,3 +946,14 @@ module Fake_protocol = struct
end
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)

View File

@ -10,6 +10,19 @@
open Alpha_context
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 =
| Contract of Contract.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
let balance_encoding =
def "operation_metadata.alpha.balance" @@
union
[ case (Tag 0)
(obj2
@ -54,6 +68,7 @@ type balance_update =
| Credited of Tez.t
let balance_update_encoding =
def "operation_metadata.alpha.balance_update" @@
union
[ case (Tag 0)
(obj1 (req "credited" Tez.encoding))
@ -67,6 +82,7 @@ let balance_update_encoding =
type balance_updates = (balance * balance_update) list
let balance_updates_encoding =
def "operation_metadata.alpha.balance_updates" @@
list (merge_objs balance_encoding balance_update_encoding)
type anonymous_operation_result =
@ -203,7 +219,7 @@ let manager_operation_result_encoding =
case (Tag 4)
(obj2
(req "status" (constant "failed"))
(req "errors" (list Error_monad.error_encoding)))
(req "errors" (list error_encoding)))
(function Failed errs -> Some ((), errs) | _ -> None)
(fun ((), errs) -> Failed errs) ;
case (Tag 5)
@ -227,6 +243,7 @@ type operation_result =
| Sourced_operation_result of sourced_operation_result
let encoding =
def "alpha.metadata" @@
union
[ case (Tag 0)
(obj2

View File

@ -35,6 +35,7 @@ let shell_header_encoding = Block_header.shell_header_encoding
let contents_encoding =
let open Data_encoding in
def "block_header.alpha.unsigned_contents" @@
conv
(fun { priority ; seed_nonce_hash ; proof_of_work_nonce } ->
(priority, proof_of_work_nonce, seed_nonce_hash))
@ -48,6 +49,7 @@ let contents_encoding =
let protocol_data_encoding =
let open Data_encoding in
def "block_header.alpha.signed_contents" @@
conv
(fun { contents ; signature } -> (contents, signature))
(fun (contents, signature) -> { contents ; signature })
@ -70,6 +72,7 @@ let unsigned_encoding =
let encoding =
let open Data_encoding in
def "block_header.alpha.full_header" @@
conv
(fun { shell ; protocol_data } ->
(shell, protocol_data))
@ -86,6 +89,7 @@ type metadata = {
}
let metadata_encoding =
let open Data_encoding in
def "block_header.alpha.metadata" @@
conv
(fun { baker ; level ; voting_period_kind } ->
(baker, level, voting_period_kind))

View File

@ -407,7 +407,7 @@ module Encoding = struct
(obj1 (varopt "signature" Signature.encoding)))
let operation_encoding =
mu "operation"
mu "operation.alpha"
(fun encoding ->
conv
(fun { shell ; protocol_data } -> (shell, protocol_data))
@ -430,6 +430,7 @@ module Encoding = struct
contents_encoding
let internal_operation_encoding =
def "operation.alpha.internal_operation" @@
conv
(fun { source ; operation ; nonce } -> ((source, nonce), operation))
(fun ((source, nonce), operation) -> { source ; operation ; nonce })