add result.ml; polymorphic variant errors + refacto
This commit is contained in:
parent
9fd3b5a3cc
commit
42b0ec1445
36 changed files with 949 additions and 954 deletions
40
src/api.ml
40
src/api.ml
|
|
@ -8,11 +8,19 @@
|
|||
- uri *)
|
||||
|
||||
module DenominationHash = Hash.DenominationHash
|
||||
module Bytes32 = Signatures.Bytes32
|
||||
module Bytes64 = Signatures.Bytes64
|
||||
open Time
|
||||
open Signatures
|
||||
|
||||
let encode jsont v = Jsont_bytesrw.encode_string jsont v
|
||||
let decode jsont v = Jsont_bytesrw.decode_string jsont v
|
||||
let encode' jsont v = Jsont_bytesrw.encode_string jsont v
|
||||
let decode' jsont v = Jsont_bytesrw.decode_string jsont v
|
||||
|
||||
let encode jsont v =
|
||||
encode' jsont v |> Result.map_error (fun e -> `Json_encode e)
|
||||
|
||||
let decode jsont v =
|
||||
decode' jsont v |> Result.map_error (fun e -> `Json_decode e)
|
||||
|
||||
open Jsont.Object
|
||||
|
||||
|
|
@ -57,34 +65,6 @@ module B32 = struct
|
|||
~decode:B32.decode Caqti_type.string
|
||||
end
|
||||
|
||||
module Bytes32 = struct
|
||||
include Signatures.Bytes32
|
||||
|
||||
let jsont =
|
||||
let decode s = Result.bind (B32.decode s) of_octets in
|
||||
let encode b = to_octets b |> B32.encode in
|
||||
Jsont.of_of_string ~kind:"Bytes32" decode ~enc:encode
|
||||
|
||||
let caqti =
|
||||
Caqti_type.custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:of_octets Caqti_type.octets
|
||||
end
|
||||
|
||||
module Bytes64 = struct
|
||||
include Signatures.Bytes64
|
||||
|
||||
let jsont =
|
||||
let decode s = Result.bind (B32.decode s) of_octets in
|
||||
let encode b = to_octets b |> B32.encode in
|
||||
Jsont.of_of_string ~kind:"Bytes64" decode ~enc:encode
|
||||
|
||||
let caqti =
|
||||
Caqti_type.custom
|
||||
~encode:(fun v -> Ok (to_octets v))
|
||||
~decode:of_octets Caqti_type.octets
|
||||
end
|
||||
|
||||
module ErrorDetail = struct
|
||||
type t = {
|
||||
code: int;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue