2017-02-24 18:38:42 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
let error_encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
describe
|
|
|
|
~description:
|
|
|
|
"The full list of error is available with \
|
|
|
|
the global RPC `/errors`"
|
|
|
|
(conv
|
|
|
|
(fun exn -> `A (List.map json_of_error exn))
|
|
|
|
(function `A exns -> List.map error_of_json exns | _ -> [])
|
|
|
|
json)
|
|
|
|
|
|
|
|
let wrap_tzerror encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
union [
|
|
|
|
case
|
|
|
|
(obj1 (req "ok" encoding))
|
|
|
|
(function Ok x -> Some x | _ -> None)
|
|
|
|
(fun x -> Ok x) ;
|
|
|
|
case
|
|
|
|
(obj1 (req "error" error_encoding))
|
|
|
|
(function Error x -> Some x | _ -> None)
|
|
|
|
(fun x -> Error x) ;
|
|
|
|
]
|
|
|
|
|
|
|
|
module Forge = struct
|
|
|
|
let block custom_root =
|
|
|
|
let open Data_encoding in
|
|
|
|
RPC.service
|
|
|
|
~description: "Forge a block"
|
|
|
|
~input:
|
2017-02-25 21:10:29 +04:00
|
|
|
(merge_objs
|
|
|
|
(obj4
|
2017-03-31 15:04:05 +04:00
|
|
|
(req "net_id" Net_id.encoding)
|
2017-02-25 21:10:29 +04:00
|
|
|
(req "predecessor" Block_hash.encoding)
|
|
|
|
(req "timestamp" Time.encoding)
|
2017-02-25 21:01:29 +04:00
|
|
|
(req "fitness" Fitness.encoding))
|
2017-02-25 21:10:29 +04:00
|
|
|
Data.Command.encoding)
|
2017-02-24 18:38:42 +04:00
|
|
|
~output: (obj1 (req "payload" bytes))
|
|
|
|
RPC.Path.(custom_root / "helpers" / "forge" / "block")
|
|
|
|
end
|
|
|
|
|
2017-02-25 21:01:27 +04:00
|
|
|
let int64_to_bytes i =
|
|
|
|
let b = MBytes.create 8 in
|
|
|
|
MBytes.set_int64 b 0 i;
|
|
|
|
b
|
|
|
|
|
2017-03-30 15:16:21 +04:00
|
|
|
let operations =
|
|
|
|
Operation_list_list_hash.compute [Operation_list_hash.empty]
|
|
|
|
|
2017-04-10 14:14:11 +04:00
|
|
|
let rpc_services : Updater.rpc_context RPC.directory =
|
2017-02-24 18:38:42 +04:00
|
|
|
let dir = RPC.empty in
|
|
|
|
let dir =
|
|
|
|
RPC.register
|
|
|
|
dir
|
|
|
|
(Forge.block RPC.Path.root)
|
2017-02-25 21:10:29 +04:00
|
|
|
(fun _ctxt ((net_id, predecessor, timestamp, fitness), command) ->
|
2017-03-30 15:16:21 +04:00
|
|
|
let shell = { Updater.net_id ; predecessor ; timestamp ; fitness ;
|
|
|
|
operations } in
|
2017-02-25 21:10:29 +04:00
|
|
|
let bytes = Data.Command.forge shell command in
|
|
|
|
RPC.Answer.return bytes) in
|
2017-02-24 18:38:42 +04:00
|
|
|
dir
|