Data_encoding: add descriptions and case names

This commit is contained in:
Milo Davis 2018-04-30 20:24:37 -04:00 committed by Benjamin Canou
parent ec7eeaaa0e
commit bb2738bf12
4 changed files with 21 additions and 1 deletions

View File

@ -50,9 +50,11 @@ module Public_key_hash = struct
def "public_key_hash" ~description:title @@
union [
case (Tag 0) Ed25519.Public_key_hash.encoding
~name:"Ed25519"
(function Ed25519 x -> Some x | _ -> None)
(function x -> Ed25519 x);
case (Tag 1) Secp256k1.Public_key_hash.encoding
~name:"Secp256k1"
(function Secp256k1 x -> Some x | _ -> None)
(function x -> Secp256k1 x)
]
@ -240,9 +242,11 @@ module Public_key = struct
def "public_key" ~description:title @@
union [
case (Tag 0) Ed25519.Public_key.encoding
~name:"Ed25519"
(function Ed25519 x -> Some x | _ -> None)
(function x -> Ed25519 x);
case (Tag 1) Secp256k1.Public_key.encoding
~name:"Secp256k1"
(function Secp256k1 x -> Some x | _ -> None)
(function x -> Secp256k1 x)
]
@ -323,9 +327,11 @@ module Secret_key = struct
def "secret_key" ~description:title @@
union [
case (Tag 0) Ed25519.Secret_key.encoding
~name:"Ed25519"
(function Ed25519 x -> Some x | _ -> None)
(function x -> Ed25519 x);
case (Tag 1) Secp256k1.Secret_key.encoding
~name:"Secp256k1"
(function Secp256k1 x -> Some x | _ -> None)
(function x -> Secp256k1 x)
]

View File

@ -120,19 +120,23 @@ let canonical_encoding ~variant prim_encoding =
obj1 (req "string" string) in
let int_encoding tag =
case tag int_encoding
~name:"Int"
(function Int (_, v) -> Some v | _ -> None)
(fun v -> Int (0, v)) in
let string_encoding tag =
case tag string_encoding
~name:"String"
(function String (_, v) -> Some v | _ -> None)
(fun v -> String (0, v)) in
let seq_encoding tag expr_encoding =
case tag (list expr_encoding)
~name:"Sequence"
(function Seq (_, v, _annot) -> Some v | _ -> None)
(fun args -> Seq (0, args, None)) in
let byte_string = Bounded.string 255 in
let application_encoding tag expr_encoding =
case tag
~name:"Generic prim (any number of args with or without annot)"
(obj3 (req "prim" prim_encoding)
(req "args" (list expr_encoding))
(opt "annot" byte_string))
@ -152,12 +156,14 @@ let canonical_encoding ~variant prim_encoding =
seq_encoding (Tag 2) expr_encoding ;
(* No args, no annot *)
case (Tag 3)
~name:"Prim (no args, annot)"
(obj1 (req "prim" prim_encoding))
(function Prim (_, v, [], None) -> Some v
| _ -> None)
(fun v -> Prim (0, v, [], None)) ;
(* No args, with annot *)
case (Tag 4)
~name:"Prim (no args + annot)"
(obj2 (req "prim" prim_encoding)
(req "annot" byte_string))
(function
@ -166,6 +172,7 @@ let canonical_encoding ~variant prim_encoding =
(function (prim, annot) -> Prim (0, prim, [], Some annot)) ;
(* Single arg, no annot *)
case (Tag 5)
~name:"Prim (1 arg, no annot)"
(obj2 (req "prim" prim_encoding)
(req "arg" expr_encoding))
(function
@ -174,6 +181,7 @@ let canonical_encoding ~variant prim_encoding =
(function (prim, arg) -> Prim (0, prim, [ arg ], None)) ;
(* Single arg, with annot *)
case (Tag 6)
~name:"Prim (1 arg + annot)"
(obj3 (req "prim" prim_encoding)
(req "arg" expr_encoding)
(req "annot" byte_string))
@ -183,6 +191,7 @@ let canonical_encoding ~variant prim_encoding =
(fun (prim, arg, annot) -> Prim (0, prim, [ arg ], Some annot)) ;
(* Two args, no annot *)
case (Tag 7)
~name:"Prim (2 args, no annot)"
(obj3 (req "prim" prim_encoding)
(req "arg1" expr_encoding)
(req "arg2" expr_encoding))
@ -192,6 +201,7 @@ let canonical_encoding ~variant prim_encoding =
(fun (prim, arg1, arg2) -> Prim (0, prim, [ arg1 ; arg2 ], None)) ;
(* Two args, with annot *)
case (Tag 8)
~name:"Prim (2 args + annot)"
(obj4 (req "prim" prim_encoding)
(req "arg1" expr_encoding)
(req "arg2" expr_encoding)

View File

@ -16,6 +16,7 @@ type t = (Block_hash.t * Nonce.t) list
let encoding : t Data_encoding.t =
let open Data_encoding in
def "seed_nonce" @@
list
(obj2
(req "block" Block_hash.encoding)

View File

@ -58,10 +58,13 @@ let encoding =
splitted
~binary:
(union ~tag_size:`Uint8 [
case (Tag 0) Signature.Public_key_hash.encoding
case (Tag 0)
~name:"Implicit"
Signature.Public_key_hash.encoding
(function Implicit k -> Some k | _ -> None)
(fun k -> Implicit k) ;
case (Tag 1) Contract_hash.encoding
~name:"Originated"
(function Originated k -> Some k | _ -> None)
(fun k -> Originated k) ;
])