RPC: share some RPC_arg
definitions in lib_base
This commit is contained in:
parent
60503aa6fa
commit
fe559a1f73
@ -108,6 +108,19 @@ module T = struct
|
||||
(fun i -> i) ;
|
||||
])
|
||||
|
||||
let rpc_arg =
|
||||
RPC_arg.make
|
||||
~name:(Format.asprintf "date")
|
||||
~descr:(Format.asprintf "A date in seconds from epoch")
|
||||
~destruct:
|
||||
(fun s ->
|
||||
match Int64.of_string s with
|
||||
| exception _ ->
|
||||
Error (Format.asprintf "failed to parse time (epoch): %S" s)
|
||||
| v -> Ok v)
|
||||
~construct:Int64.to_string
|
||||
()
|
||||
|
||||
type 'a timed_data = {
|
||||
data: 'a ;
|
||||
time: t ;
|
||||
|
@ -40,6 +40,8 @@ val now : unit -> t
|
||||
val encoding : t Data_encoding.t
|
||||
val rfc_encoding : t Data_encoding.t
|
||||
|
||||
val rpc_arg : t RPC_arg.t
|
||||
|
||||
val pp_hum : Format.formatter -> t -> unit
|
||||
|
||||
type 'a timed_data = {
|
||||
|
@ -161,6 +161,21 @@ module Make (R : sig
|
||||
let to_short_b58check s =
|
||||
String.sub (to_b58check s) 0 (10 + 2 * String.length K.b58check_prefix)
|
||||
|
||||
let rpc_arg =
|
||||
RPC_arg.make
|
||||
~name:(Format.asprintf "hash.%s" K.name)
|
||||
~descr:(Format.asprintf "A b58check-encoded hash (%s)" K.name)
|
||||
~destruct:
|
||||
(fun s ->
|
||||
match of_b58check_opt s with
|
||||
| None ->
|
||||
Error (Format.asprintf
|
||||
"failed to decode b58check-encoded hash (%s): %S"
|
||||
K.name s)
|
||||
| Some v -> Ok v)
|
||||
~construct:to_b58check
|
||||
()
|
||||
|
||||
let encoding =
|
||||
let open Data_encoding in
|
||||
splitted
|
||||
|
@ -6,11 +6,13 @@
|
||||
(flags (:standard -open Tezos_stdlib
|
||||
-open Tezos_data_encoding
|
||||
-open Tezos_stdlib_lwt
|
||||
-open Tezos_rpc_base
|
||||
-open Tezos_error_monad__Error_monad))
|
||||
(libraries (tezos-stdlib
|
||||
tezos-stdlib-lwt
|
||||
tezos-data-encoding
|
||||
tezos-error-monad
|
||||
tezos-rpc-base
|
||||
nocrypto
|
||||
sodium
|
||||
zarith))))
|
||||
|
@ -153,3 +153,16 @@ let zero =
|
||||
match of_hex (String.make (size * 2) '0') with
|
||||
| Some c -> c
|
||||
| None -> assert false
|
||||
|
||||
|
||||
let rpc_arg =
|
||||
RPC_arg.make
|
||||
~name:(Format.asprintf "hash.%s" name)
|
||||
~descr:(Format.asprintf "A b58check-encoded hash (%s)" name)
|
||||
~destruct:
|
||||
(fun s ->
|
||||
match of_b58check_opt s with
|
||||
| None -> Error ""
|
||||
| Some v -> Ok v)
|
||||
~construct:to_b58check
|
||||
()
|
||||
|
@ -72,6 +72,8 @@ module type HASH = sig
|
||||
type Base58.data += Hash of t
|
||||
val b58check_encoding: t Base58.encoding
|
||||
|
||||
val rpc_arg: t RPC_arg.t
|
||||
|
||||
module Set : sig
|
||||
include Set.S with type elt = t
|
||||
val encoding: t Data_encoding.t
|
||||
|
@ -13,6 +13,7 @@ depends: [
|
||||
"tezos-stdlib-lwt"
|
||||
"tezos-data-encoding"
|
||||
"tezos-error-monad"
|
||||
"tezos-rpc-base"
|
||||
"nocrypto"
|
||||
"sodium"
|
||||
"zarith"
|
||||
|
@ -266,18 +266,7 @@ module Context = struct
|
||||
|
||||
module Key = struct
|
||||
|
||||
let public_key_hash_arg =
|
||||
let construct = Ed25519.Public_key_hash.to_b58check in
|
||||
let destruct hash =
|
||||
match Ed25519.Public_key_hash.of_b58check_opt hash with
|
||||
| None -> Error "Cannot parse public key hash"
|
||||
| Some public_key_hash -> Ok public_key_hash in
|
||||
RPC_arg.make
|
||||
~descr:"A public key hash"
|
||||
~name: "public_key_hash"
|
||||
~construct
|
||||
~destruct
|
||||
()
|
||||
let public_key_hash_arg = Ed25519.Public_key_hash.rpc_arg
|
||||
|
||||
let pk_encoding =
|
||||
(obj2
|
||||
|
@ -459,15 +459,7 @@ end
|
||||
|
||||
module Protocols = struct
|
||||
|
||||
let protocols_arg =
|
||||
let name = "protocol_id" in
|
||||
let descr =
|
||||
"A protocol identifier in hexadecimal." in
|
||||
let construct = Protocol_hash.to_b58check in
|
||||
let destruct h =
|
||||
try Ok (Protocol_hash.of_b58check_exn h)
|
||||
with _ -> Error "Can't parse hash" in
|
||||
RPC_arg.make ~name ~descr ~construct ~destruct ()
|
||||
let protocols_arg = Protocol_hash.rpc_arg
|
||||
|
||||
let contents =
|
||||
RPC_service.post_service
|
||||
@ -516,14 +508,7 @@ module Network = struct
|
||||
open P2p_types
|
||||
|
||||
let (peer_id_arg : P2p_types.Peer_id.t RPC_arg.arg) =
|
||||
RPC_arg.make
|
||||
~name:"peer_id"
|
||||
~descr:"A network global identifier, also known as an identity."
|
||||
~destruct:(fun s -> try
|
||||
Ok (Crypto_box.Public_key_hash.of_b58check_exn s)
|
||||
with Failure msg -> Error msg)
|
||||
~construct:Crypto_box.Public_key_hash.to_b58check
|
||||
()
|
||||
Crypto_box.Public_key_hash.rpc_arg
|
||||
|
||||
let point_arg =
|
||||
RPC_arg.make
|
||||
|
@ -29,23 +29,25 @@
|
||||
v1/compare.mli
|
||||
v1/data_encoding.mli
|
||||
v1/error_monad.mli
|
||||
v1/micheline.mli
|
||||
v1/logging.mli
|
||||
v1/time.mli
|
||||
v1/base58.mli
|
||||
v1/hash.mli
|
||||
v1/blake2B.mli
|
||||
v1/ed25519.mli
|
||||
|
||||
;; Tezos specifics
|
||||
v1/tezos_data.mli
|
||||
v1/context.mli
|
||||
v1/RPC_arg.mli
|
||||
v1/RPC_path.mli
|
||||
v1/RPC_query.mli
|
||||
v1/RPC_service.mli
|
||||
v1/RPC_answer.mli
|
||||
v1/RPC_directory.mli
|
||||
|
||||
v1/base58.mli
|
||||
v1/hash.mli
|
||||
v1/blake2B.mli
|
||||
v1/ed25519.mli
|
||||
|
||||
;; Tezos specifics
|
||||
v1/micheline.mli
|
||||
v1/tezos_data.mli
|
||||
v1/context.mli
|
||||
v1/updater.mli
|
||||
|
||||
))
|
||||
|
@ -68,6 +68,8 @@ module type HASH = sig
|
||||
type Base58.data += Hash of t
|
||||
val b58check_encoding: t Base58.encoding
|
||||
|
||||
val rpc_arg: t RPC_arg.t
|
||||
|
||||
module Set : sig
|
||||
include Set.S with type elt = t
|
||||
val encoding: t Data_encoding.t
|
||||
|
Loading…
Reference in New Issue
Block a user