Merge branch 'master' into crypto-box

This commit is contained in:
Eitan Chatav 2016-11-16 17:09:24 -08:00
commit 65795dba2c
85 changed files with 1142 additions and 581 deletions

View File

@ -12,7 +12,8 @@ all: ${TZCOMPILER} ${TZNODE} ${TZCLIENT}
## Protocol environment ## Protocol environment
############################################################################ ############################################################################
PROTOCOL_ENV_INTFS := $(addprefix proto/environment/, \ PROTOCOL_ENV_INTFS := \
$(addprefix proto/environment/, \
pervasives.mli \ pervasives.mli \
compare.mli \ compare.mli \
\ \
@ -29,6 +30,8 @@ PROTOCOL_ENV_INTFS := $(addprefix proto/environment/, \
\ \
uri.mli \ uri.mli \
data_encoding.mli \ data_encoding.mli \
error_monad.mli \
logging.mli \
time.mli \ time.mli \
base48.mli \ base48.mli \
hash.mli \ hash.mli \
@ -39,10 +42,7 @@ PROTOCOL_ENV_INTFS := $(addprefix proto/environment/, \
\ \
fitness.mli \ fitness.mli \
updater.mli \ updater.mli \
) \ )
utils/logging.mli \
utils/error_monad_sig.ml \
utils/error_monad.mli
.INTERMEDIATE: node/updater/environment_gen .INTERMEDIATE: node/updater/environment_gen
.SECONDARY: node/updater/proto_environment.mli .SECONDARY: node/updater/proto_environment.mli
@ -73,9 +73,6 @@ clean::
EMBEDDED_PROTOCOL_LIB_CMIS := \ EMBEDDED_PROTOCOL_LIB_CMIS := \
tmp/camlinternalFormatBasics.cmi \ tmp/camlinternalFormatBasics.cmi \
utils/error_monad.cmi \
proto/environment/error_monad.mli \
proto/environment/logging.mli \
node/updater/proto_environment.cmi \ node/updater/proto_environment.cmi \
node/updater/register.cmi node/updater/register.cmi
@ -102,16 +99,15 @@ clean::
UTILS_LIB_INTFS := \ UTILS_LIB_INTFS := \
utils/mBytes.mli \ utils/mBytes.mli \
utils/utils.mli \
utils/base48.mli \ utils/base48.mli \
utils/hex_encode.mli \ utils/hex_encode.mli \
utils/utils.mli \
utils/cli_entries.mli \ utils/cli_entries.mli \
utils/compare.mli \ utils/compare.mli \
utils/data_encoding.mli \ utils/data_encoding.mli \
utils/crypto_box.mli \ utils/crypto_box.mli \
utils/time.mli \ utils/time.mli \
utils/hash.mli \ utils/hash.mli \
utils/ed25519.mli \
utils/error_monad.mli \ utils/error_monad.mli \
utils/logging.mli \ utils/logging.mli \
utils/lwt_utils.mli \ utils/lwt_utils.mli \
@ -119,16 +115,15 @@ UTILS_LIB_INTFS := \
UTILS_LIB_IMPLS := \ UTILS_LIB_IMPLS := \
utils/mBytes.ml \ utils/mBytes.ml \
utils/base48.ml \
utils/hex_encode.ml \
utils/utils.ml \ utils/utils.ml \
utils/hex_encode.ml \
utils/base48.ml \
utils/cli_entries.ml \ utils/cli_entries.ml \
utils/compare.ml \ utils/compare.ml \
utils/data_encoding.ml \ utils/data_encoding.ml \
utils/crypto_box.ml \ utils/crypto_box.ml \
utils/time.ml \ utils/time.ml \
utils/hash.ml \ utils/hash.ml \
utils/ed25519.ml \
utils/error_monad_sig.ml \ utils/error_monad_sig.ml \
utils/error_monad.ml \ utils/error_monad.ml \
utils/logging.ml \ utils/logging.ml \
@ -320,7 +315,7 @@ proto/embedded_proto_%.cmxa: \
CLIENT_PROTO_INCLUDES := \ CLIENT_PROTO_INCLUDES := \
utils node/updater node/db node/net node/shell client \ utils node/updater node/db node/net node/shell client \
$(shell ocamlfind query lwt ocplib-json-typed) $(shell ocamlfind query lwt ocplib-json-typed sodium)
proto/client_embedded_proto_%.cmxa: \ proto/client_embedded_proto_%.cmxa: \
${TZCOMPILER} \ ${TZCOMPILER} \
@ -347,6 +342,7 @@ CLIENT_LIB_INTFS := \
client/client_version.mli \ client/client_version.mli \
client/client_node_rpcs.mli \ client/client_node_rpcs.mli \
client/client_generic_rpcs.mli \ client/client_generic_rpcs.mli \
client/client_helpers.mli \
client/client_aliases.mli \ client/client_aliases.mli \
client/client_keys.mli \ client/client_keys.mli \
client/client_protocols.mli \ client/client_protocols.mli \
@ -356,6 +352,7 @@ CLIENT_LIB_IMPLS := \
client/client_config.ml \ client/client_config.ml \
client/client_node_rpcs.ml \ client/client_node_rpcs.ml \
client/client_generic_rpcs.ml \ client/client_generic_rpcs.ml \
client/client_helpers.ml \
client/client_aliases.ml \ client/client_aliases.ml \
client/client_keys.ml \ client/client_keys.ml \
client/client_protocols.ml \ client/client_protocols.ml \

View File

@ -0,0 +1,38 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Client_config
let () =
let open Cli_entries in
register_group "helpers" "Various helpers"
let unique = ref false
let unique_arg =
"-unique",
Arg.Set unique,
"Fail when there is more than one possible completion."
let commands () = Cli_entries.[
command
~desc: "Lookup for the possible completion of a \
given prefix of Base48Check-encoded hash. This actually \
works only for blocks, operations, public key and contract \
identifiers."
~args: [unique_arg]
(prefixes [ "complete" ] @@ string "prefix" "the prefix of the Base48Check-encoded hash to be completed" @@ stop)
(fun prefix () ->
Client_node_rpcs.complete ~block:(block ()) prefix >>= fun completions ->
match completions with
| [] -> Pervasives.exit 3
| _ :: _ :: _ when !unique -> Pervasives.exit 3
| completions ->
List.iter print_endline completions ;
Lwt.return_unit)
]

View File

@ -0,0 +1,10 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
val commands: unit -> Cli_entries.command list

View File

@ -7,6 +7,8 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = Environment.Ed25519
module Public_key_hash = Client_aliases.Alias (struct module Public_key_hash = Client_aliases.Alias (struct
type t = Ed25519.Public_key_hash.t type t = Ed25519.Public_key_hash.t
let encoding = Ed25519.Public_key_hash.encoding let encoding = Ed25519.Public_key_hash.encoding

View File

@ -7,8 +7,10 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = Environment.Ed25519
module Public_key_hash : Client_aliases.Alias with type t = Ed25519.public_key_hash module Public_key_hash :
Client_aliases.Alias with type t = Ed25519.Public_key_hash.t
module Public_key : Client_aliases.Alias with type t = Ed25519.public_key module Public_key : Client_aliases.Alias with type t = Ed25519.public_key
module Secret_key : Client_aliases.Alias with type t = Ed25519.secret_key module Secret_key : Client_aliases.Alias with type t = Ed25519.secret_key

View File

@ -150,6 +150,12 @@ let inject_operation ?(wait = true) ?force operation =
call_service0 Services.inject_operation (operation, wait, force) call_service0 Services.inject_operation (operation, wait, force)
let inject_protocol ?(wait = true) ?force protocol = let inject_protocol ?(wait = true) ?force protocol =
call_service0 Services.inject_protocol (protocol, wait, force) call_service0 Services.inject_protocol (protocol, wait, force)
let complete ?block prefix =
match block with
| None ->
call_service1 Services.complete prefix ()
| Some block ->
call_service2 Services.Blocks.complete block prefix ()
let describe ?recurse path = let describe ?recurse path =
let prefix, arg = RPC.forge_request Services.describe () recurse in let prefix, arg = RPC.forge_request Services.describe () recurse in
get_json (prefix @ path) arg >>= get_json (prefix @ path) arg >>=
@ -196,6 +202,8 @@ module Blocks = struct
call_service1 Services.Blocks.pending_operations block () call_service1 Services.Blocks.pending_operations block ()
let info ?(operations = false) h = let info ?(operations = false) h =
call_service1 Services.Blocks.info h operations call_service1 Services.Blocks.info h operations
let complete block prefix =
call_service2 Services.Blocks.complete block prefix ()
let list ?operations ?length ?heads ?delay ?min_date ?min_heads () = let list ?operations ?length ?heads ?delay ?min_date ?min_heads () =
call_service0 Services.Blocks.list call_service0 Services.Blocks.list
{ operations; length ; heads ; monitor = Some false ; delay ; { operations; length ; heads ; monitor = Some false ; delay ;

View File

@ -104,6 +104,8 @@ module Protocols : sig
(Protocol_hash.t * Store.protocol option) list Lwt.t (Protocol_hash.t * Store.protocol option) list Lwt.t
end end
val complete: ?block:Blocks.block -> string -> string list Lwt.t
val describe: ?recurse:bool -> string list -> RPC.Description.directory_descr Lwt.t val describe: ?recurse:bool -> string list -> RPC.Description.directory_descr Lwt.t
(** Low-level *) (** Low-level *)

View File

@ -11,6 +11,7 @@ open Client_proto_args
open Client_proto_contracts open Client_proto_contracts
open Client_proto_programs open Client_proto_programs
open Client_keys open Client_keys
module Ed25519 = Environment.Ed25519
let handle_error f () = let handle_error f () =
f () >>= Client_proto_rpcs.handle_error f () >>= Client_proto_rpcs.handle_error

View File

@ -7,6 +7,8 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = Environment.Ed25519
module RawContractAlias = Client_aliases.Alias (struct module RawContractAlias = Client_aliases.Alias (struct
type t = Contract.t type t = Contract.t
let encoding = Contract.encoding let encoding = Contract.encoding
@ -101,7 +103,7 @@ let get_delegate block source =
let may_check_key sourcePubKey sourcePubKeyHash = let may_check_key sourcePubKey sourcePubKeyHash =
match sourcePubKey with match sourcePubKey with
| Some sourcePubKey -> | Some sourcePubKey ->
if not (Ed25519.equal_hash (Ed25519.hash sourcePubKey) sourcePubKeyHash) if not (Ed25519.Public_key_hash.equal (Ed25519.hash sourcePubKey) sourcePubKeyHash)
then then
failwith "Invalid public key in `client_proto_endorsement`" failwith "Invalid public key in `client_proto_endorsement`"
else else

View File

@ -9,7 +9,7 @@
let protocol = let protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"TnrnfGHMCPAcxtMAHXdpfebbnn2XvPAxq7DHbpeJbKTkJQPgcgRGr" "4prgmSgbaeMKbgLtLjpsHaDD9QvG2dbC2bLq2XBmyxd2RJgLFpcAg"
let () = let () =
Client_version.register protocol @@ Client_version.register protocol @@

View File

@ -7,6 +7,7 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = Environment.Ed25519
open Client_proto_args open Client_proto_args
let report_parse_error _prefix exn _lexbuf = let report_parse_error _prefix exn _lexbuf =

View File

@ -10,6 +10,8 @@
open Logging.Client.Endorsement open Logging.Client.Endorsement
open Cli_entries open Cli_entries
module Ed25519 = Environment.Ed25519
module State : sig module State : sig
val get_endorsement: val get_endorsement:

View File

@ -8,6 +8,7 @@
(**************************************************************************) (**************************************************************************)
open Logging.Client.Mining open Logging.Client.Mining
module Ed25519 = Environment.Ed25519
let generate_proof_of_work_nonce () = let generate_proof_of_work_nonce () =
Sodium.Random.Bigbytes.generate Constants.proof_of_work_nonce_size Sodium.Random.Bigbytes.generate Constants.proof_of_work_nonce_size

View File

@ -7,6 +7,8 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = Environment.Ed25519
open Logging.Client.Mining open Logging.Client.Mining
open Operation open Operation

View File

@ -9,7 +9,7 @@
let protocol = let protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK"
let demo () = let demo () =
let block = Client_config.block () in let block = Client_config.block () in

View File

@ -31,6 +31,7 @@ let main () =
Client_generic_rpcs.commands @ Client_generic_rpcs.commands @
Client_keys.commands () @ Client_keys.commands () @
Client_protocols.commands () @ Client_protocols.commands () @
Client_helpers.commands () @
Client_version.commands_for_version version in Client_version.commands_for_version version in
Client_config.parse_args ~version Client_config.parse_args ~version
(Cli_entries.usage commands) (Cli_entries.usage commands)

View File

@ -8,8 +8,5 @@
(**************************************************************************) (**************************************************************************)
val camlinternalFormatBasics_cmi: string val camlinternalFormatBasics_cmi: string
val error_monad_cmi: string
val error_monad_mli: string
val logging_mli: string
val proto_environment_cmi: string val proto_environment_cmi: string
val register_cmi: string val register_cmi: string

View File

@ -258,31 +258,38 @@ let link_shared ?(static=false) output objects =
let create_register_file client file hash packname modules = let create_register_file client file hash packname modules =
let unit = List.hd (List.rev modules) in let unit = List.hd (List.rev modules) in
let error_monad = packname ^ ".Local_error_monad.Error_monad" in let environment_module = packname ^ ".Local_environment.Environment" in
let error_monad_module = environment_module ^ ".Error_monad" in
let context_module = environment_module ^ ".Context" in
let hash_module = environment_module ^ ".Hash" in
create_file file create_file file
(Printf.sprintf (Printf.sprintf
"module Packed_protocol = struct\n\ "module Packed_protocol = struct\n\
\ let hash = (Hash.Protocol_hash.of_b48check %S)\n\ \ let hash = (%s.Protocol_hash.of_b48check %S)\n\
\ type error = %s.error = ..\n\ \ type error = %s.error = ..\n\
\ type 'a tzresult = 'a %s.tzresult\n\ \ type 'a tzresult = 'a %s.tzresult\n\
\ include %s.%s\n\ \ include %s.%s\n\
\ let error_encoding = %s.error_encoding ()\n\ \ let error_encoding = %s.error_encoding ()\n\
\ let classify_errors = %s.classify_errors\n\ \ let classify_errors = %s.classify_errors\n\
\ let pp = %s.pp\n\ \ let pp = %s.pp\n\
\ let complete_b48prefix = %s.complete
\ end\n\ \ end\n\
\ %s\n\ \ %s\n\
" "
hash_module
(Protocol_hash.to_b48check hash) (Protocol_hash.to_b48check hash)
error_monad error_monad_module
error_monad error_monad_module
packname (String.capitalize_ascii unit) packname (String.capitalize_ascii unit)
error_monad error_monad_module
error_monad error_monad_module
error_monad error_monad_module
context_module
(if client then (if client then
"include Register.Make(Packed_protocol)" "include Register.Make(Packed_protocol)"
else else
"let () = Register.register (module Packed_protocol : PACKED_PROTOCOL)")) Printf.sprintf
"let () = Register.register (%s.__cast (module Packed_protocol : %s.PACKED_PROTOCOL))" environment_module environment_module))
let mktemp_dir () = let mktemp_dir () =
Filename.get_temp_dir_name () // Filename.get_temp_dir_name () //
@ -391,44 +398,30 @@ let main () =
if keep_object then if keep_object then
create_file (build_dir // ".tezos_compiler") (md5 ^ "\n"); create_file (build_dir // ".tezos_compiler") (md5 ^ "\n");
Compenv.implicit_modules :=
if client then [ "Environment" ] else [ "Proto_environment" ] ;
(* Compile the /ad-hoc/ Error_monad. *) (* Compile the /ad-hoc/ Error_monad. *)
List.iter (dump_cmi sigs_dir) tezos_protocol_env ; List.iter (dump_cmi sigs_dir) tezos_protocol_env ;
at_exit (fun () -> List.iter (unlink_cmi sigs_dir) tezos_protocol_env ) ; at_exit (fun () -> List.iter (unlink_cmi sigs_dir) tezos_protocol_env ) ;
let error_monad_unit = "local_error_monad" in let local_environment_unit = "local_environment" in
let error_monad_ml = build_dir // error_monad_unit ^ ".ml" in let local_environment_ml = build_dir // local_environment_unit ^ ".ml" in
create_file error_monad_ml @@ Printf.sprintf {| create_file local_environment_ml @@ Printf.sprintf {|
module Error_monad = struct module Environment = %s.Make(struct let name = %S end)()
type error_category = [ `Branch | `Temporary | `Permanent ]
include Error_monad.Make()
end
module Logging = Logging.Make(struct let name = %S end)
|} |}
(if client then "Environment" else "Proto_environment")
logname ; logname ;
let error_monad_mli = build_dir // error_monad_unit ^ ".mli" in
create_file error_monad_mli @@ Printf.sprintf {|
module Error_monad : sig %s end
module Logging : sig %s end
|}
Embedded_cmis.error_monad_mli
Embedded_cmis.logging_mli ;
if not keep_object then if not keep_object then
at_exit (fun () -> at_exit (fun () ->
safe_unlink error_monad_mli ; safe_unlink local_environment_ml) ;
safe_unlink error_monad_ml) ; let local_environment_object =
let error_monad_object =
compile_units compile_units
~ctxt ~ctxt
~for_pack:packname ~for_pack:packname
~keep_object ~keep_object
~build_dir ~source_dir:build_dir [error_monad_unit] ~build_dir ~source_dir:build_dir [local_environment_unit]
in in
Compenv.implicit_modules := Compenv.implicit_modules :=
!Compenv.implicit_modules @ [ "Local_environment"; "Environment" ;
[ "Local_error_monad"; "Error_monad" ; "Hash" ; "Logging" ]; "Error_monad" ; "Hash" ; "Logging" ];
(* Compile the protocol *) (* Compile the protocol *)
let objects = let objects =
@ -437,7 +430,7 @@ let main () =
~update_needed ~update_needed
~keep_object ~for_pack:packname ~build_dir ~source_dir units in ~keep_object ~for_pack:packname ~build_dir ~source_dir units in
pack_objects ~ctxt ~keep_object pack_objects ~ctxt ~keep_object
packed_objects (error_monad_object @ objects) ; packed_objects (local_environment_object @ objects) ;
(* Compiler the 'registering module' *) (* Compiler the 'registering module' *)
List.iter (dump_cmi sigs_dir) register_env; List.iter (dump_cmi sigs_dir) register_env;

View File

@ -30,6 +30,7 @@ module rec S : sig
val update_path: t -> IrminPath.t -> v -> unit Lwt.t val update_path: t -> IrminPath.t -> v -> unit Lwt.t
val mem: v -> IrminPath.t -> bool Lwt.t val mem: v -> IrminPath.t -> bool Lwt.t
val dir_mem: v -> IrminPath.t -> bool Lwt.t
val get: v -> IrminPath.t -> MBytes.t option Lwt.t val get: v -> IrminPath.t -> MBytes.t option Lwt.t
val set: v -> IrminPath.t -> MBytes.t-> v Lwt.t val set: v -> IrminPath.t -> MBytes.t-> v Lwt.t
val del: v -> IrminPath.t -> v Lwt.t val del: v -> IrminPath.t -> v Lwt.t
@ -187,6 +188,11 @@ let mem (module View : VIEW) key =
GitStore.FunView.mem View.v (data_key key) >>= fun v -> GitStore.FunView.mem View.v (data_key key) >>= fun v ->
Lwt.return v Lwt.return v
let dir_mem (module View : VIEW) key =
let module GitStore = View.Store in
GitStore.FunView.dir_mem View.v (data_key key) >>= fun v ->
Lwt.return v
let raw_get (module View : VIEW) key = let raw_get (module View : VIEW) key =
let module GitStore = View.Store in let module GitStore = View.Store in
GitStore.FunView.get View.v key >>= function GitStore.FunView.get View.v key >>= function

View File

@ -466,6 +466,11 @@ module Make (S: Irmin.S) = struct
| None -> Lwt.return false | None -> Lwt.return false
| _ -> Lwt.return true | _ -> Lwt.return true
let dir_mem t k =
sub t k >>= function
| Some _ -> Lwt.return true
| None -> Lwt.return false
let list_aux t path = let list_aux t path =
sub t path >>= function sub t path >>= function
| None -> Lwt.return [] | None -> Lwt.return []
@ -662,6 +667,7 @@ end
module type S = sig module type S = sig
include Irmin.RO include Irmin.RO
val dir_mem: t -> key -> bool Lwt.t
val update: t -> key -> value -> t Lwt.t val update: t -> key -> value -> t Lwt.t
val remove: t -> key -> t Lwt.t val remove: t -> key -> t Lwt.t
val list: t -> key -> key list Lwt.t val list: t -> key -> key list Lwt.t

View File

@ -9,6 +9,7 @@
module type S = sig module type S = sig
include Irmin.RO include Irmin.RO
val dir_mem: t -> key -> bool Lwt.t
val update: t -> key -> value -> t Lwt.t val update: t -> key -> value -> t Lwt.t
val remove: t -> key -> t Lwt.t val remove: t -> key -> t Lwt.t
val list: t -> key -> key list Lwt.t val list: t -> key -> key list Lwt.t

View File

@ -19,12 +19,12 @@ type value = MBytes.t
module type STORE = sig module type STORE = sig
type t type t
val mem: t -> key -> bool Lwt.t val mem: t -> key -> bool Lwt.t
val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val list: t -> key list -> key list Lwt.t val list: t -> key list -> key list Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val keys: t -> key list Lwt.t val keys: t -> key list Lwt.t
end end
@ -37,7 +37,6 @@ module type BYTES_STORE = sig
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val list: t -> key list -> key list Lwt.t val list: t -> key list -> key list Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val keys: t -> key list Lwt.t val keys: t -> key list Lwt.t
end end
@ -49,7 +48,6 @@ module type TYPED_STORE = sig
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val keys: t -> key list Lwt.t val keys: t -> key list Lwt.t
end end
@ -583,3 +581,37 @@ module MakeBufferedPersistentTypedMap
(Map : Map.S with type key = K.t) (Map : Map.S with type key = K.t)
= =
MakeBufferedPersistentMap(S)(K)(TypedValue(T))(Map) MakeBufferedPersistentMap(S)(K)(TypedValue(T))(Map)
module MakeHashResolver
(Store : sig
type t
val dir_mem: t -> string list -> bool Lwt.t
val list: t -> string list list -> string list list Lwt.t
val prefix: string list
end)
(H: HASH) = struct
let plen = List.length Store.prefix
let build path =
H.of_path @@
Utils.remove_elem_from_list plen path
let resolve t p =
let rec loop prefix = function
| [] ->
Lwt.return [build prefix]
| "" :: ds ->
Store.list t [ prefix] >>= fun prefixes ->
Lwt_list.map_p (fun prefix -> loop prefix ds) prefixes
>|= List.flatten
| [d] ->
Store.list t [prefix] >>= fun prefixes ->
Lwt_list.filter_map_p (fun prefix ->
match remove_prefix d (List.hd (List.rev prefix)) with
| None -> Lwt.return_none
| Some _ -> Lwt.return (Some (build prefix))
) prefixes
| d :: ds ->
Store.dir_mem t (prefix @ [d]) >>= function
| true -> loop (prefix @ [d]) ds
| false -> Lwt.return_nil in
loop Store.prefix (H.prefix_path p)
end

View File

@ -22,12 +22,12 @@ type value = MBytes.t
module type STORE = sig module type STORE = sig
type t type t
val mem: t -> key -> bool Lwt.t val mem: t -> key -> bool Lwt.t
val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val list: t -> key list -> key list Lwt.t val list: t -> key list -> key list Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val keys: t -> key list Lwt.t val keys: t -> key list Lwt.t
end end
@ -258,3 +258,14 @@ module MakeBufferedPersistentTypedMap
and type key := K.t and type key := K.t
and type value := T.value and type value := T.value
and module Map := Map and module Map := Map
module MakeHashResolver
(Store : sig
type t
val dir_mem: t -> string list -> bool Lwt.t
val list: t -> string list list -> string list list Lwt.t
val prefix: string list
end)
(H: HASH) : sig
val resolve : Store.t -> string -> H.t list Lwt.t
end

View File

@ -50,6 +50,14 @@ module FS = struct
let file = file_of_key root key in let file = file_of_key root key in
Lwt.return (Sys.file_exists file && not (Sys.is_directory file)) Lwt.return (Sys.file_exists file && not (Sys.is_directory file))
let dir_mem root key =
let file = file_of_key root key in
Lwt.return (Sys.file_exists file && Sys.is_directory file)
let exists root key =
let file = file_of_key root key in
Sys.file_exists file
let get root key = let get root key =
mem root key >>= function mem root key >>= function
| true -> | true ->
@ -135,6 +143,7 @@ end
module type IMPERATIVE_STORE = sig module type IMPERATIVE_STORE = sig
type t type t
val mem: t -> key -> bool Lwt.t val mem: t -> key -> bool Lwt.t
val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val get_exn: t -> key -> value Lwt.t val get_exn: t -> key -> value Lwt.t
val set: t -> key -> value -> unit Lwt.t val set: t -> key -> value -> unit Lwt.t
@ -206,6 +215,7 @@ module Make (K : KEY) (V : Persist.VALUE) = struct
type key = K.t type key = K.t
type value = V.t type value = V.t
let mem t k = FS.mem t (K.to_path k) let mem t k = FS.mem t (K.to_path k)
let dir_mem t k = FS.dir_mem t (K.to_path k)
let get t k = let get t k =
FS.get t (K.to_path k) >|= function FS.get t (K.to_path k) >|= function
| None -> None | None -> None
@ -307,6 +317,14 @@ module Block_errors_key = struct
end end
module Block_errors = Make (Block_errors_key) (Errors_value) module Block_errors = Make (Block_errors_key) (Errors_value)
module Block_resolver =
Persist.MakeHashResolver
(struct
include FS
let prefix = ["blocks"]
end)
(Block_hash)
module Block = struct module Block = struct
type t = FS.t type t = FS.t
type key = Block_hash.t type key = Block_hash.t
@ -458,6 +476,15 @@ module Operation_errors_key = struct
end end
module Operation_errors = Make (Operation_errors_key) (Errors_value) module Operation_errors = Make (Operation_errors_key) (Errors_value)
module Operation_resolver =
Persist.MakeHashResolver
(struct
include FS
let mem t k = Lwt.return (exists t k)
let prefix = ["operations"]
end)
(Operation_hash)
module Operation = struct module Operation = struct
type t = FS.t type t = FS.t
type key = Operation_hash.t type key = Operation_hash.t
@ -715,6 +742,12 @@ let net_destroy ~root { net_genesis } =
let init root = let init root =
raw_init ~root:(Filename.concat root "global") () >>= fun t -> raw_init ~root:(Filename.concat root "global") () >>= fun t ->
Base48.register_resolver
Block_hash.b48check_encoding
(fun s -> Block_resolver.resolve t s);
Base48.register_resolver
Operation_hash.b48check_encoding
(fun s -> Operation_resolver.resolve t s);
Lwt.return Lwt.return
{ block = Persist.share t ; { block = Persist.share t ;
blockchain = Persist.share t ; blockchain = Persist.share t ;

View File

@ -27,6 +27,7 @@ end
module type IMPERATIVE_STORE = sig module type IMPERATIVE_STORE = sig
type t type t
val mem: t -> key -> bool Lwt.t val mem: t -> key -> bool Lwt.t
val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val get_exn: t -> key -> value Lwt.t val get_exn: t -> key -> value Lwt.t
val set: t -> key -> value -> unit Lwt.t val set: t -> key -> value -> unit Lwt.t

View File

@ -330,7 +330,7 @@ module RPC = struct
let prevalidation_hash = let prevalidation_hash =
Block_hash.of_b48check Block_hash.of_b48check
"Et22nEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "eeeeeeeeeeeeeegqJHARhSaNXggmMs8K3tvsgn4rBprkvpFAMVD5d"
let get_net node = function let get_net node = function
| `Head _ | `Prevalidation -> node.global_validator, node.global_net | `Head _ | `Prevalidation -> node.global_validator, node.global_net
@ -498,6 +498,20 @@ module RPC = struct
Proto.fitness ctxt >>= fun fitness -> Proto.fitness ctxt >>= fun fitness ->
return (fitness, r) return (fitness, r)
let complete node ?block str =
match block with
| None ->
Base48.complete str
| Some block ->
get_context node block >>= function
| None -> Lwt.fail Not_found
| Some ctxt ->
Context.get_protocol ctxt >>= fun protocol_hash ->
let (module Proto) = Updater.get_exn protocol_hash in
Base48.complete str >>= fun l1 ->
Proto.complete_b48prefix ctxt str >>= fun l2 ->
Lwt.return (l1 @ l2)
let context_dir node block = let context_dir node block =
get_context node block >>= function get_context node block >>= function
| None -> Lwt.return None | None -> Lwt.return None

View File

@ -72,6 +72,12 @@ module RPC : sig
val validate: t -> State.net_id -> Block_hash.t -> unit tzresult Lwt.t val validate: t -> State.net_id -> Block_hash.t -> unit tzresult Lwt.t
val context_dir:
t -> block -> 'a RPC.directory option Lwt.t
val complete:
t -> ?block:block -> string -> string list Lwt.t
end end
val shutdown: t -> unit Lwt.t val shutdown: t -> unit Lwt.t

View File

@ -434,6 +434,14 @@ let build_rpc_directory node =
let implementation () = let implementation () =
RPC.Answer.return Data_encoding.Json.(schema (Error_monad.error_encoding ())) in RPC.Answer.return Data_encoding.Json.(schema (Error_monad.error_encoding ())) in
RPC.register0 dir RPC.Error.service implementation in RPC.register0 dir RPC.Error.service implementation in
let dir =
RPC.register1 dir Services.complete
(fun s () ->
Node.RPC.complete node s >>= RPC.Answer.return) in
let dir =
RPC.register2 dir Services.Blocks.complete
(fun block s () ->
Node.RPC.complete node ~block s >>= RPC.Answer.return) in
let dir = let dir =
RPC.register_describe_directory_service dir Services.describe in RPC.register_describe_directory_service dir Services.describe in
dir dir

View File

@ -255,6 +255,19 @@ module Blocks = struct
~output: (RPC.Error.wrap preapply_result_encoding) ~output: (RPC.Error.wrap preapply_result_encoding)
RPC.Path.(block_path / "preapply") RPC.Path.(block_path / "preapply")
let complete =
let prefix_arg =
let destruct s = Ok s
and construct s = s in
RPC.Arg.make ~name:"prefix" ~destruct ~construct () in
RPC.service
~description: "Try to complete a prefix of a Base48Check-encoded data. \
This RPC is actually able to complete hashes of \
block, operations, public_keys and contracts."
~input: empty
~output: (list string)
RPC.Path.(block_path / "complete" /: prefix_arg )
type list_param = { type list_param = {
operations: bool option ; operations: bool option ;
length: int option ; length: int option ;
@ -329,6 +342,8 @@ module Blocks = struct
~output: (obj1 (req "blocks" (list (list block_info_encoding)))) ~output: (obj1 (req "blocks" (list (list block_info_encoding))))
RPC.Path.(root / "blocks") RPC.Path.(root / "blocks")
end end
module Operations = struct module Operations = struct
@ -583,6 +598,19 @@ let inject_protocol =
(obj1 (req "injectedProtocol" Protocol_hash.encoding))) (obj1 (req "injectedProtocol" Protocol_hash.encoding)))
RPC.Path.(root / "inject_protocol") RPC.Path.(root / "inject_protocol")
let complete =
let prefix_arg =
let destruct s = Ok s
and construct s = s in
RPC.Arg.make ~name:"prefix" ~destruct ~construct () in
RPC.service
~description: "Try to complete a prefix of a Base48Check-encoded data. \
This RPC is actually able to complete hashes of \
block and hashes of operations."
~input: empty
~output: (list string)
RPC.Path.(root / "complete" /: prefix_arg )
let describe = let describe =
RPC.Description.service RPC.Description.service
~description: "RPCs documentation and input/output schema" ~description: "RPCs documentation and input/output schema"

View File

@ -80,6 +80,8 @@ module Blocks : sig
val preapply: val preapply:
(unit, unit * block, preapply_param, preapply_result tzresult) RPC.service (unit, unit * block, preapply_param, preapply_result tzresult) RPC.service
val complete: (unit, (unit * block) * string, unit, string list) RPC.service
val proto_path: (unit, unit * block) RPC.Path.path val proto_path: (unit, unit * block) RPC.Path.path
end end
@ -132,5 +134,7 @@ val inject_protocol:
(unit, unit, (unit, unit,
(Store.protocol * bool * bool option), Protocol_hash.t tzresult) RPC.service (Store.protocol * bool * bool option), Protocol_hash.t tzresult) RPC.service
val complete: (unit, unit * string, unit, string list) RPC.service
val describe: val describe:
(unit, unit, bool option, RPC.Description.directory_descr) RPC.service (unit, unit, bool option, RPC.Description.directory_descr) RPC.service

View File

@ -7,6 +7,128 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
module Ed25519 = struct
type secret_key = Sodium.Sign.secret_key
type public_key = Sodium.Sign.public_key
type signature = MBytes.t
let sign key msg =
Sodium.Sign.Bigbytes.(of_signature @@ sign_detached key msg)
let check_signature public_key signature msg =
try
Sodium.Sign.Bigbytes.(verify public_key (to_signature signature) msg) ;
true
with _ -> false
let append_signature key msg =
MBytes.concat msg (sign key msg)
module Public_key_hash = Hash.Make_SHA256(Base48)(struct
let name = "Ed25519.Public_key_hash"
let title = "An Ed25519 public key ID"
let b48check_prefix = Base48.Prefix.ed25519_public_key_hash
end)
let hash v =
Public_key_hash.hash_bytes
[ Sodium.Sign.Bigbytes.of_public_key v ]
let generate_key () =
let secret, pub = Sodium.Sign.random_keypair () in
(hash pub, pub, secret)
type Base48.data +=
| Public_key of public_key
| Secret_key of secret_key
| Signature of signature
let b48check_public_key_encoding =
Base48.register_encoding
~prefix: Base48.Prefix.ed25519_public_key
~to_raw:(fun x -> Bytes.to_string (Sodium.Sign.Bytes.of_public_key x))
~of_raw:(fun x ->
try Some (Sodium.Sign.Bytes.to_public_key (Bytes.of_string x))
with _ -> None)
~wrap:(fun x -> Public_key x)
let b48check_secret_key_encoding =
Base48.register_encoding
~prefix: Base48.Prefix.ed25519_secret_key
~to_raw:(fun x -> Bytes.to_string (Sodium.Sign.Bytes.of_secret_key x))
~of_raw:(fun x ->
try Some (Sodium.Sign.Bytes.to_secret_key (Bytes.of_string x))
with _ -> None)
~wrap:(fun x -> Secret_key x)
let b48check_signature_encoding =
Base48.register_encoding
~prefix: Base48.Prefix.ed25519_signature
~to_raw:MBytes.to_string
~of_raw:(fun s -> Some (MBytes.of_string s))
~wrap:(fun x -> Signature x)
let public_key_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 public key (Base48Check encoded)" @@
conv
(fun s -> Base48.simple_encode b48check_public_key_encoding s)
(fun s ->
match Base48.simple_decode b48check_public_key_encoding s with
| Some x -> x
| None -> Data_encoding.Json.cannot_destruct
"Ed25519 public key: unexpected prefix.")
string)
~binary:
(conv
Sodium.Sign.Bigbytes.of_public_key
Sodium.Sign.Bigbytes.to_public_key
bytes)
let secret_key_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 secret key (Base48Check encoded)" @@
conv
(fun s -> Base48.simple_encode b48check_secret_key_encoding s)
(fun s ->
match Base48.simple_decode b48check_secret_key_encoding s with
| Some x -> x
| None -> Data_encoding.Json.cannot_destruct
"Ed25519 secret key: unexpected prefix.")
string)
~binary:
(conv
Sodium.Sign.Bigbytes.of_secret_key
Sodium.Sign.Bigbytes.to_secret_key
bytes)
let signature_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 signature (Base48Check encoded)" @@
conv
(fun s -> Base48.simple_encode b48check_signature_encoding s)
(fun s ->
match Base48.simple_decode b48check_signature_encoding s with
| Some x -> x
| None -> Data_encoding.Json.cannot_destruct
"Ed25519 signature: unexpected prefix.")
string)
~binary: (Fixed.bytes 64)
end
module Make(Param : sig val name: string end)() = struct
include Pervasives include Pervasives
module Pervasives = Pervasives module Pervasives = Pervasives
module Compare = Compare module Compare = Compare
@ -29,20 +151,26 @@ module MBytes = MBytes
module Uri = Uri module Uri = Uri
module Data_encoding = Data_encoding module Data_encoding = Data_encoding
module Time = Time module Time = Time
module Base48 = Base48
module Hash = Hash
module Ed25519 = Ed25519 module Ed25519 = Ed25519
module Hash = Hash
module Persist = Persist module Persist = Persist
module Context = Context
module RPC = RPC module RPC = RPC
module Fitness = Fitness module Fitness = Fitness
module Updater = Updater module Updater = Updater
module Error_monad = struct
(* Internal usage *) type error_category = [ `Branch | `Temporary | `Permanent ]
include Error_monad.Make()
module Error_monad_sig = Error_monad_sig end
module Error_monad = Error_monad module Logging = Logging.Make(Param)
module Logging = Logging module Base48 = struct
include Base48
include Make(struct type context = Context.t end)
end
module Context = struct
include Context
let register_resolver = Base48.register_resolver
let complete = Base48.complete
end
module type PACKED_PROTOCOL = sig module type PACKED_PROTOCOL = sig
val hash : Protocol_hash.t val hash : Protocol_hash.t
@ -50,4 +178,8 @@ module type PACKED_PROTOCOL = sig
val error_encoding : error Data_encoding.t val error_encoding : error Data_encoding.t
val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ] val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ]
val pp : Format.formatter -> error -> unit val pp : Format.formatter -> error -> unit
val complete_b48prefix :
?alphabet:string -> Context.t -> string -> string list Lwt.t
end
end end

View File

@ -21,6 +21,11 @@ let dump_file oc file =
let included = ["Pervasives"] let included = ["Pervasives"]
let () =
Printf.fprintf mli
"module Make(Param : sig val name: string end)() : sig\n"
let () = let () =
for i = 2 to Array.length Sys.argv - 1 do for i = 2 to Array.length Sys.argv - 1 do
let file = Sys.argv.(i) in let file = Sys.argv.(i) in
@ -36,10 +41,12 @@ let () =
dump_file mli file; dump_file mli file;
Printf.fprintf mli "end\n"; Printf.fprintf mli "end\n";
if unit = "Result" then begin if unit = "Result" then begin
Printf.fprintf mli "type ('a, 'b) result = ('a, 'b) Result.result = Ok of 'a | Error of 'b\n"; Printf.fprintf mli
"type ('a, 'b) result = ('a, 'b) Result.result = Ok of 'a | Error of 'b\n";
end; end;
done done
let () = let () =
Printf.fprintf mli {| Printf.fprintf mli {|
module type PACKED_PROTOCOL = sig module type PACKED_PROTOCOL = sig
@ -48,9 +55,12 @@ module type PACKED_PROTOCOL = sig
val error_encoding : error Data_encoding.t val error_encoding : error Data_encoding.t
val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ] val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ]
val pp : Format.formatter -> error -> unit val pp : Format.formatter -> error -> unit
val complete_b48prefix :
?alphabet:string -> Context.t -> string -> string list Lwt.t
end end
val __cast: (module PACKED_PROTOCOL) -> (module Protocol.PACKED_PROTOCOL) val __cast: (module PACKED_PROTOCOL) -> (module Protocol.PACKED_PROTOCOL)
|} |}
let () = let () =
Printf.fprintf mli "end\n" ;
close_out mli close_out mli

View File

@ -7,7 +7,11 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
include Environment module Make(Param : sig val name: string end)() = struct
include Environment.Make(Param)()
let __cast (type error) (module X : PACKED_PROTOCOL) = let __cast (type error) (module X : PACKED_PROTOCOL) =
(module X : Protocol.PACKED_PROTOCOL) (module X : Protocol.PACKED_PROTOCOL)
end

View File

@ -135,4 +135,6 @@ module type PACKED_PROTOCOL = sig
val error_encoding : error Data_encoding.t val error_encoding : error Data_encoding.t
val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ] val classify_errors : error list -> [ `Branch | `Temporary | `Permanent ]
val pp : Format.formatter -> error -> unit val pp : Format.formatter -> error -> unit
val complete_b48prefix :
?alphabet:string -> Context.t -> string -> string list Lwt.t
end end

View File

@ -29,8 +29,7 @@ module Make(Proto : Protocol.PACKED_PROTOCOL) = struct
(function ecoerrors -> Ecoproto_error ecoerrors) (function ecoerrors -> Ecoproto_error ecoerrors)
end end
let register proto = let register (module Proto : Protocol.PACKED_PROTOCOL) =
let module Proto = (val Proto_environment.__cast proto) in
let module V = struct let module V = struct
include Proto include Proto
include Make(Proto) include Make(Proto)

View File

@ -12,4 +12,4 @@ module Make(Proto : Protocol.PACKED_PROTOCOL) : sig
val wrap_error: 'a Proto.tzresult -> 'a tzresult val wrap_error: 'a Proto.tzresult -> 'a tzresult
end end
val register: (module Proto_environment.PACKED_PROTOCOL) -> unit val register: (module Protocol.PACKED_PROTOCOL) -> unit

View File

@ -16,6 +16,8 @@ module type REGISTRED_PROTOCOL = sig
val hash: Protocol_hash.t val hash: Protocol_hash.t
include Protocol.PROTOCOL with type error := error include Protocol.PROTOCOL with type error := error
and type 'a tzresult := 'a tzresult and type 'a tzresult := 'a tzresult
val complete_b48prefix :
?alphabet:string -> Context.t -> string -> string list Lwt.t
end end
type net_id = Store.net_id = Net of Block_hash.t type net_id = Store.net_id = Net of Block_hash.t

View File

@ -68,6 +68,8 @@ module type REGISTRED_PROTOCOL = sig
(* exception Ecoproto_error of error list *) (* exception Ecoproto_error of error list *)
include Protocol.PROTOCOL with type error := error include Protocol.PROTOCOL with type error := error
and type 'a tzresult := 'a tzresult and type 'a tzresult := 'a tzresult
val complete_b48prefix :
?alphabet:string -> Context.t -> string -> string list Lwt.t
end end
type component = Tezos_compiler.Protocol.component = { type component = Tezos_compiler.Protocol.component = {

View File

@ -12,15 +12,15 @@ open Logging.Node.Main
let genesis_block = let genesis_block =
Block_hash.of_b48check Block_hash.of_b48check
"qBeeesNtMrdyRDj6hSK2PxEN9R67brGSm64EFRjJSBTTqLcQCRHNR" "eeHfgnr9QeDNvcMgSfATNeDeec4KG4CkHHkNNJt5B9xdVmsxhsHNR"
let genesis_protocol = let genesis_protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"TnrnfGHMCPAcxtMAHXdpfebbnn2XvPAxq7DHbpeJbKTkJQPgcgRGr" "4prgmSgbaeMKbgLtLjpsHaDD9QvG2dbC2bLq2XBmyxd2RJgLFpcAg"
let test_protocol = let test_protocol =
Some (Protocol_hash.of_b48check Some (Protocol_hash.of_b48check
"JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK")
let genesis_time = let genesis_time =
Time.of_notation_exn "2016-08-01T00:00:00Z" Time.of_notation_exn "2016-08-01T00:00:00Z"

View File

@ -1,9 +1,9 @@
B ../../node/updater/ B ../../node/updater/
B _tzbuild B _tzbuild
FLG -nopervasives FLG -nopervasives
FLG -open Proto_environment FLG -open Local_environment
FLG -open Environment
FLG -open Hash FLG -open Hash
FLG -open Local_error_monad
FLG -open Error_monad FLG -open Error_monad
FLG -open Logging FLG -open Logging
FLG -w -40 FLG -w -40

View File

@ -1,8 +1,10 @@
{ {
"hash": "TnrnfGHMCPAcxtMAHXdpfebbnn2XvPAxq7DHbpeJbKTkJQPgcgRGr", "hash": "4prgmSgbaeMKbgLtLjpsHaDD9QvG2dbC2bLq2XBmyxd2RJgLFpcAg",
"modules": [ "modules": [
"Misc", "Misc",
"Tezos_hash", "Tezos_hash",
"Qty_repr", "Qty_repr",
"Tez_repr", "Tez_repr",
"Period_repr", "Period_repr",

View File

@ -22,10 +22,10 @@ let encoding =
module Map = struct module Map = struct
module Raw = Map.Make(struct module Raw = Map.Make(struct
type t = asset * Ed25519.public_key_hash type t = asset * Ed25519.Public_key_hash.t
let compare (a1, pk1) (a2, pk2) = let compare (a1, pk1) (a2, pk2) =
if Compare.Int32.(a1 = a2) then if Compare.Int32.(a1 = a2) then
Ed25519.compare_hash pk1 pk2 Ed25519.Public_key_hash.compare pk1 pk2
else else
Compare.Int32.compare a1 a2 Compare.Int32.compare a1 a2
end) end)
@ -54,7 +54,7 @@ let encoding =
(Json.wrap_error of_tuple_list_exn) (Json.wrap_error of_tuple_list_exn)
(list (list
(tup2 (tup2
(tup2 encoding Ed25519.public_key_hash_encoding) (tup2 encoding Ed25519.Public_key_hash.encoding)
Tez_repr.encoding))) Tez_repr.encoding)))
end end

View File

@ -17,6 +17,6 @@ module Map : sig
type t type t
val empty: t val empty: t
val add: val add:
t -> asset -> Ed25519.public_key_hash -> Tez_repr.tez -> t tzresult t -> asset -> Ed25519.Public_key_hash.t -> Tez_repr.tez -> t tzresult
val encoding: t Data_encoding.t val encoding: t Data_encoding.t
end end

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
type account = { type account = {
public_key_hash : Ed25519.public_key_hash ; public_key_hash : Ed25519.Public_key_hash.t ;
public_key : Ed25519.public_key ; public_key : Ed25519.public_key ;
secret_key : Ed25519.secret_key ; secret_key : Ed25519.secret_key ;
} }
@ -94,7 +94,7 @@ let account_encoding =
(fun (public_key_hash, public_key, secret_key) -> (fun (public_key_hash, public_key, secret_key) ->
{ public_key_hash ; public_key ; secret_key }) { public_key_hash ; public_key ; secret_key })
(obj3 (obj3
(req "publicKeyHash" Ed25519.public_key_hash_encoding) (req "publicKeyHash" Ed25519.Public_key_hash.encoding)
(req "publicKey" Ed25519.public_key_encoding) (req "publicKey" Ed25519.public_key_encoding)
(req "secretKey" Ed25519.secret_key_encoding)) (req "secretKey" Ed25519.secret_key_encoding))

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
type account = { type account = {
public_key_hash : Ed25519.public_key_hash ; public_key_hash : Ed25519.Public_key_hash.t ;
public_key : Ed25519.public_key ; public_key : Ed25519.public_key ;
secret_key : Ed25519.secret_key ; secret_key : Ed25519.secret_key ;
} }

View File

@ -10,15 +10,15 @@
open Tezos_hash open Tezos_hash
type descr = { type descr = {
manager: Ed25519.public_key_hash ; manager: Ed25519.Public_key_hash.t ;
delegate: Ed25519.public_key_hash option ; delegate: Ed25519.Public_key_hash.t option ;
spendable: bool ; spendable: bool ;
delegatable: bool ; delegatable: bool ;
script: Script_repr.t ; script: Script_repr.t ;
} }
type t = type t =
| Default of Ed25519.public_key_hash | Default of Ed25519.Public_key_hash.t
| Hash of Contract_hash.t | Hash of Contract_hash.t
type contract = t type contract = t
@ -29,12 +29,10 @@ let to_b48check = function
| Hash h -> Contract_hash.to_b48check h | Hash h -> Contract_hash.to_b48check h
let of_b48check s = let of_b48check s =
try
match Base48.decode s with match Base48.decode s with
| Ed25519.Public_key_hash.Hash h -> ok (Default h) | Some (Ed25519.Public_key_hash.Hash h) -> ok (Default h)
| Contract_hash.Hash h -> ok (Hash h) | Some (Contract_hash.Hash h) -> ok (Hash h)
| _ -> error (Invalid_contract_notation s) | _ -> error (Invalid_contract_notation s)
with _ -> error (Invalid_contract_notation s)
let encoding = let encoding =
let open Data_encoding in let open Data_encoding in
@ -50,7 +48,7 @@ let encoding =
splitted splitted
~binary: ~binary:
(union ~tag_size:`Uint8 [ (union ~tag_size:`Uint8 [
case ~tag:0 Ed25519.public_key_hash_encoding case ~tag:0 Ed25519.Public_key_hash.encoding
(function Default k -> Some k | _ -> None) (function Default k -> Some k | _ -> None)
(fun k -> Default k) ; (fun k -> Default k) ;
case ~tag:1 Contract_hash.encoding case ~tag:1 Contract_hash.encoding
@ -96,8 +94,8 @@ let descr_encoding =
(fun (manager, delegate, spendable, delegatable, script) -> (fun (manager, delegate, spendable, delegatable, script) ->
{ manager; delegate; spendable; delegatable; script }) { manager; delegate; spendable; delegatable; script })
(obj5 (obj5
(req "manager" Ed25519.public_key_hash_encoding) (req "manager" Ed25519.Public_key_hash.encoding)
(opt "delegate" Ed25519.public_key_hash_encoding) (opt "delegate" Ed25519.Public_key_hash.encoding)
(dft "spendable" bool false) (dft "spendable" bool false)
(dft "delegatable" bool false) (dft "delegatable" bool false)
(req "script" Script_repr.encoding)) (req "script" Script_repr.encoding))
@ -105,7 +103,7 @@ let descr_encoding =
let generic_contract ~manager ~delegate ~spendable ~delegatable ~script = let generic_contract ~manager ~delegate ~spendable ~delegatable ~script =
match delegate, spendable, delegatable, script with match delegate, spendable, delegatable, script with
| Some delegate, true, false, Script_repr.No_script | Some delegate, true, false, Script_repr.No_script
when Ed25519.equal_hash manager delegate -> when Ed25519.Public_key_hash.equal manager delegate ->
default_contract manager default_contract manager
| _ -> | _ ->
let data = let data =
@ -130,7 +128,7 @@ let arg =
let compare l1 l2 = let compare l1 l2 =
match l1, l2 with match l1, l2 with
| Default pkh1, Default pkh2 -> | Default pkh1, Default pkh2 ->
Ed25519.compare_hash pkh1 pkh2 Ed25519.Public_key_hash.compare pkh1 pkh2
| Hash h1, Hash h2 -> | Hash h1, Hash h2 ->
Contract_hash.compare h1 h2 Contract_hash.compare h1 h2
| Default _, Hash _ -> -1 | Default _, Hash _ -> -1

View File

@ -10,13 +10,13 @@
open Tezos_hash open Tezos_hash
type t = private type t = private
| Default of Ed25519.public_key_hash | Default of Ed25519.Public_key_hash.t
| Hash of Contract_hash.t | Hash of Contract_hash.t
type contract = t type contract = t
type descr = { type descr = {
manager: Ed25519.public_key_hash ; manager: Ed25519.Public_key_hash.t ;
delegate: Ed25519.public_key_hash option ; delegate: Ed25519.Public_key_hash.t option ;
spendable: bool ; spendable: bool ;
delegatable: bool ; delegatable: bool ;
script: Script_repr.t ; script: Script_repr.t ;
@ -24,13 +24,13 @@ type descr = {
include Compare.S with type t := contract include Compare.S with type t := contract
val default_contract : Ed25519.public_key_hash -> contract val default_contract : Ed25519.Public_key_hash.t -> contract
val is_default : contract -> Ed25519.public_key_hash option val is_default : contract -> Ed25519.Public_key_hash.t option
val generic_contract : val generic_contract :
manager:Ed25519.public_key_hash -> manager:Ed25519.Public_key_hash.t ->
delegate:Ed25519.public_key_hash option -> delegate:Ed25519.Public_key_hash.t option ->
spendable:bool -> spendable:bool ->
delegatable:bool -> delegatable:bool ->
script:Script_repr.t -> script:Script_repr.t ->

View File

@ -33,9 +33,9 @@ val is_delegatable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
val get_descr: Storage.t -> Contract_repr.t -> Contract_repr.descr tzresult Lwt.t val get_descr: Storage.t -> Contract_repr.t -> Contract_repr.descr tzresult Lwt.t
val get_manager: Storage.t -> Contract_repr.t -> Ed25519.public_key_hash tzresult Lwt.t val get_manager: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t
val get_delegate: Storage.t -> Contract_repr.t -> Ed25519.public_key_hash tzresult Lwt.t val get_delegate: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t
val get_delegate_opt: Storage.t -> Contract_repr.t -> Ed25519.public_key_hash option tzresult Lwt.t val get_delegate_opt: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t option tzresult Lwt.t
val get_balance: Storage.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t val get_balance: Storage.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t
val get_assets: Storage.t -> Contract_repr.t -> Asset_repr.Map.t tzresult Lwt.t val get_assets: Storage.t -> Contract_repr.t -> Asset_repr.Map.t tzresult Lwt.t
val get_counter: Storage.t -> Contract_repr.t -> int32 tzresult Lwt.t val get_counter: Storage.t -> Contract_repr.t -> int32 tzresult Lwt.t
@ -49,7 +49,7 @@ val update_script_storage: Storage.t -> Contract_repr.t -> Script_repr.expr ->
Storage.t tzresult Lwt.t Storage.t tzresult Lwt.t
(** fails if the contract is not delegatable *) (** fails if the contract is not delegatable *)
val set_delegate : Storage.t -> Contract_repr.t -> Ed25519.public_key_hash option -> Storage.t tzresult Lwt.t val set_delegate : Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t option -> Storage.t tzresult Lwt.t
val credit : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t val credit : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
@ -60,14 +60,14 @@ val spend : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt
val unconditional_spend : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t val unconditional_spend : Storage.t -> Contract_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
val issue : val issue :
Storage.t -> Contract_repr.t -> Asset_repr.t -> Ed25519.public_key_hash -> Tez_repr.t -> Storage.t tzresult Lwt.t Storage.t -> Contract_repr.t -> Asset_repr.t -> Ed25519.Public_key_hash.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
val originate : val originate :
Storage.t -> Storage.t ->
balance:Tez_repr.t -> balance:Tez_repr.t ->
manager:Ed25519.public_key_hash -> manager:Ed25519.Public_key_hash.t ->
script:Script_repr.t -> script:Script_repr.t ->
delegate:Ed25519.public_key_hash option -> delegate:Ed25519.Public_key_hash.t option ->
spendable:bool -> spendable:bool ->
delegatable:bool -> delegatable:bool ->
(Storage.t * Contract_repr.t) tzresult Lwt.t (Storage.t * Contract_repr.t) tzresult Lwt.t

View File

@ -55,7 +55,7 @@ let reveal c level nonce =
type status = Storage.Seed.nonce_status = type status = Storage.Seed.nonce_status =
| Unrevealed of { | Unrevealed of {
nonce_hash: Tezos_hash.Nonce_hash.t ; nonce_hash: Tezos_hash.Nonce_hash.t ;
delegate_to_reward: Ed25519.public_key_hash ; delegate_to_reward: Ed25519.Public_key_hash.t ;
reward_amount: Tez_repr.t ; reward_amount: Tez_repr.t ;
} }
| Revealed of nonce | Revealed of nonce

View File

@ -21,17 +21,17 @@ val encoding: nonce Data_encoding.t
val record_hash: val record_hash:
Storage.t -> Storage.t ->
Ed25519.public_key_hash -> Tez_repr.t -> Ed25519.Public_key_hash.t -> Tez_repr.t ->
Nonce_hash.t -> Storage.t tzresult Lwt.t Nonce_hash.t -> Storage.t tzresult Lwt.t
val reveal: val reveal:
Storage.t -> Level_repr.t -> nonce -> Storage.t -> Level_repr.t -> nonce ->
(Storage.t * Ed25519.public_key_hash * Tez_repr.t) tzresult Lwt.t (Storage.t * Ed25519.Public_key_hash.t * Tez_repr.t) tzresult Lwt.t
type status = type status =
| Unrevealed of { | Unrevealed of {
nonce_hash: Tezos_hash.Nonce_hash.t ; nonce_hash: Tezos_hash.Nonce_hash.t ;
delegate_to_reward: Ed25519.public_key_hash ; delegate_to_reward: Ed25519.Public_key_hash.t ;
reward_amount: Tez_repr.t ; reward_amount: Tez_repr.t ;
} }
| Revealed of nonce | Revealed of nonce

View File

@ -46,18 +46,18 @@ and manager_operation =
destination: Contract_repr.contract ; destination: Contract_repr.contract ;
} }
| Origination of { | Origination of {
manager: Ed25519.public_key_hash ; manager: Ed25519.Public_key_hash.t ;
delegate: Ed25519.public_key_hash option ; delegate: Ed25519.Public_key_hash.t option ;
script: Script_repr.t ; script: Script_repr.t ;
spendable: bool ; spendable: bool ;
delegatable: bool ; delegatable: bool ;
credit: Tez_repr.tez ; credit: Tez_repr.tez ;
} }
| Issuance of { | Issuance of {
asset: Asset_repr.asset * Ed25519.public_key_hash ; asset: Asset_repr.asset * Ed25519.Public_key_hash.t ;
amount: Tez_repr.tez ; amount: Tez_repr.tez ;
} }
| Delegation of Ed25519.public_key_hash option | Delegation of Ed25519.Public_key_hash.t option
and delegate_operation = and delegate_operation =
| Endorsement of { | Endorsement of {
@ -99,11 +99,11 @@ module Encoding = struct
let origination_encoding = let origination_encoding =
(obj7 (obj7
(req "kind" (constant "origination")) (req "kind" (constant "origination"))
(req "managerPubkey" Ed25519.public_key_hash_encoding) (req "managerPubkey" Ed25519.Public_key_hash.encoding)
(req "balance" Tez_repr.encoding) (req "balance" Tez_repr.encoding)
(opt "spendable" bool) (opt "spendable" bool)
(opt "delegatable" bool) (opt "delegatable" bool)
(opt "delegate" Ed25519.public_key_hash_encoding) (opt "delegate" Ed25519.Public_key_hash.encoding)
(req "script" Script_repr.encoding)) (req "script" Script_repr.encoding))
let origination_case tag = let origination_case tag =
@ -125,7 +125,7 @@ module Encoding = struct
let issuance_encoding = let issuance_encoding =
(obj3 (obj3
(req "kind" (constant "issuance")) (req "kind" (constant "issuance"))
(req "asset" (tup2 Asset_repr.encoding Ed25519.public_key_hash_encoding)) (req "asset" (tup2 Asset_repr.encoding Ed25519.Public_key_hash.encoding))
(req "quantity" Tez_repr.encoding)) (req "quantity" Tez_repr.encoding))
let issuance_case tag = let issuance_case tag =
@ -138,7 +138,7 @@ module Encoding = struct
let delegation_encoding = let delegation_encoding =
(obj2 (obj2
(req "kind" (constant "delegation")) (req "kind" (constant "delegation"))
(opt "delegate" Ed25519.public_key_hash_encoding)) (opt "delegate" Ed25519.Public_key_hash.encoding))
let delegation_case tag = let delegation_case tag =
case ~tag delegation_encoding case ~tag delegation_encoding

View File

@ -46,18 +46,18 @@ and manager_operation =
destination: Contract_repr.contract ; destination: Contract_repr.contract ;
} }
| Origination of { | Origination of {
manager: Ed25519.public_key_hash ; manager: Ed25519.Public_key_hash.t ;
delegate: Ed25519.public_key_hash option ; delegate: Ed25519.Public_key_hash.t option ;
script: Script_repr.t ; script: Script_repr.t ;
spendable: bool ; spendable: bool ;
delegatable: bool ; delegatable: bool ;
credit: Tez_repr.tez ; credit: Tez_repr.tez ;
} }
| Issuance of { | Issuance of {
asset: Asset_repr.t * Ed25519.public_key_hash ; asset: Asset_repr.t * Ed25519.Public_key_hash.t ;
amount: Tez_repr.tez ; amount: Tez_repr.tez ;
} }
| Delegation of Ed25519.public_key_hash option | Delegation of Ed25519.Public_key_hash.t option
and delegate_operation = and delegate_operation =
| Endorsement of { | Endorsement of {

View File

@ -8,10 +8,10 @@
(**************************************************************************) (**************************************************************************)
val record: val record:
Storage.t -> Ed25519.public_key_hash -> Cycle_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t Storage.t -> Ed25519.Public_key_hash.t -> Cycle_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
val discard: val discard:
Storage.t -> Ed25519.public_key_hash -> Cycle_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t Storage.t -> Ed25519.Public_key_hash.t -> Cycle_repr.t -> Tez_repr.t -> Storage.t tzresult Lwt.t
val pay_due_rewards: Storage.t -> Storage.t tzresult Lwt.t val pay_due_rewards: Storage.t -> Storage.t tzresult Lwt.t

View File

@ -36,11 +36,11 @@ val clear_cycle :
val mining_rights_owner : val mining_rights_owner :
Storage.t -> Level_repr.t -> priority:int32 -> Storage.t -> Level_repr.t -> priority:int32 ->
Ed25519.public_key_hash tzresult Lwt.t Ed25519.Public_key_hash.t tzresult Lwt.t
val endorsement_rights_owner : val endorsement_rights_owner :
Storage.t -> Level_repr.t -> slot:int -> Storage.t -> Level_repr.t -> slot:int ->
Ed25519.public_key_hash tzresult Lwt.t Ed25519.Public_key_hash.t tzresult Lwt.t
module Contract : sig module Contract : sig
@ -60,4 +60,4 @@ end
(**/**) (**/**)
val get_contract_delegate: val get_contract_delegate:
Storage.t -> Contract_repr.t -> Ed25519.public_key_hash option tzresult Lwt.t Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t option tzresult Lwt.t

View File

@ -191,7 +191,7 @@ module Context = struct
let pk_encoding = let pk_encoding =
(obj2 (obj2
(req "hash" Ed25519.public_key_hash_encoding) (req "hash" Ed25519.Public_key_hash.encoding)
(req "public_key" Ed25519.public_key_encoding)) (req "public_key" Ed25519.public_key_encoding))
let list custom_root = let list custom_root =
@ -225,14 +225,14 @@ module Context = struct
RPC.service RPC.service
~description: "Access the manager of a contract." ~description: "Access the manager of a contract."
~input: empty ~input: empty
~output: (wrap_tzerror Ed25519.public_key_hash_encoding) ~output: (wrap_tzerror Ed25519.Public_key_hash.encoding)
RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "manager") RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "manager")
let delegate custom_root = let delegate custom_root =
RPC.service RPC.service
~description: "Access the delegate of a contract, if any." ~description: "Access the delegate of a contract, if any."
~input: empty ~input: empty
~output: (wrap_tzerror (option Ed25519.public_key_hash_encoding)) ~output: (wrap_tzerror (option Ed25519.Public_key_hash.encoding))
RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "delegate") RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "delegate")
let counter custom_root = let counter custom_root =
@ -292,12 +292,12 @@ module Context = struct
(fun (manager,balance,spendable,delegate,script,assets,counter) -> (fun (manager,balance,spendable,delegate,script,assets,counter) ->
{manager;balance;spendable;delegate;script;assets;counter}) @@ {manager;balance;spendable;delegate;script;assets;counter}) @@
obj7 obj7
(req "manager" Ed25519.public_key_hash_encoding) (req "manager" Ed25519.Public_key_hash.encoding)
(req "balance" Tez.encoding) (req "balance" Tez.encoding)
(req "spendable" bool) (req "spendable" bool)
(req "delegate" @@ obj2 (req "delegate" @@ obj2
(req "setable" bool) (req "setable" bool)
(opt "value" Ed25519.public_key_hash_encoding)) (opt "value" Ed25519.Public_key_hash.encoding))
(dft "script" Script.encoding No_script) (dft "script" Script.encoding No_script)
(req "assets" Asset.Map.encoding) (req "assets" Asset.Map.encoding)
(req "counter" int32)) (req "counter" int32))
@ -404,7 +404,7 @@ module Helpers = struct
(req "mining_rights" (req "mining_rights"
(list (list
(obj2 (obj2
(req "delegate" Ed25519.public_key_hash_encoding) (req "delegate" Ed25519.Public_key_hash.encoding)
(req "timestamp" Timestamp.encoding))))) (req "timestamp" Timestamp.encoding)))))
RPC.Path.(custom_root / "helpers" / "rights" / "mining") RPC.Path.(custom_root / "helpers" / "rights" / "mining")
@ -418,7 +418,7 @@ module Helpers = struct
obj2 obj2
(req "level" Raw_level.encoding) (req "level" Raw_level.encoding)
(req "delegates" (req "delegates"
(list Ed25519.public_key_hash_encoding))) (list Ed25519.Public_key_hash.encoding)))
RPC.Path.(custom_root / "helpers" / "rights" RPC.Path.(custom_root / "helpers" / "rights"
/ "mining" / "level" /: Raw_level.arg ) / "mining" / "level" /: Raw_level.arg )
@ -447,7 +447,7 @@ module Helpers = struct
~input: empty ~input: empty
~output: (wrap_tzerror @@ ~output: (wrap_tzerror @@
obj1 (req "delegates" obj1 (req "delegates"
(list Ed25519.public_key_hash_encoding))) (list Ed25519.Public_key_hash.encoding)))
RPC.Path.(custom_root / "helpers" / "rights" RPC.Path.(custom_root / "helpers" / "rights"
/ "mining" / "delegate" ) / "mining" / "delegate" )
@ -460,7 +460,7 @@ module Helpers = struct
obj2 obj2
(req "level" Raw_level.encoding) (req "level" Raw_level.encoding)
(req "delegates" (req "delegates"
(list Ed25519.public_key_hash_encoding))) (list Ed25519.Public_key_hash.encoding)))
RPC.Path.(custom_root / "helpers" / "rights" / "endorsement") RPC.Path.(custom_root / "helpers" / "rights" / "endorsement")
let endorsement_rights_for_level custom_root = let endorsement_rights_for_level custom_root =
@ -472,7 +472,7 @@ module Helpers = struct
obj2 obj2
(req "level" Raw_level.encoding) (req "level" Raw_level.encoding)
(req "delegates" (req "delegates"
(list Ed25519.public_key_hash_encoding))) (list Ed25519.Public_key_hash.encoding)))
RPC.Path.(custom_root / "helpers" / "rights" RPC.Path.(custom_root / "helpers" / "rights"
/ "endorsement" / "level" /: Raw_level.arg ) / "endorsement" / "level" /: Raw_level.arg )
@ -501,7 +501,7 @@ module Helpers = struct
~input: empty ~input: empty
~output: (wrap_tzerror @@ ~output: (wrap_tzerror @@
obj1 (req "delegates" obj1 (req "delegates"
(list Ed25519.public_key_hash_encoding))) (list Ed25519.Public_key_hash.encoding)))
RPC.Path.(custom_root / "helpers" / "rights" RPC.Path.(custom_root / "helpers" / "rights"
/ "endorsement" / "delegate" ) / "endorsement" / "delegate" )

View File

@ -60,6 +60,8 @@ module Key = struct
let next_cycle_to_be_rewarded = store_root ["next_cycle_to_be_rewarded"] let next_cycle_to_be_rewarded = store_root ["next_cycle_to_be_rewarded"]
let rewards = store_root ["rewards"] let rewards = store_root ["rewards"]
let public_keys = ["public_keys" ; "ed25519"]
module Roll = struct module Roll = struct
let store_root l = store_root ("rolls" :: l) let store_root l = store_root ("rolls" :: l)
let next = store_root [ "next" ] let next = store_root [ "next" ]
@ -86,15 +88,17 @@ module Key = struct
end end
module Contract = struct module Contract = struct
let store_root l = store_root ("contracts" :: l) let store_root l = store_root ("contracts" :: l)
let set = store_root ["set"] let set = store_root ["set"]
let pubkey_contract l = store_root ("pubkey" :: l)
let generic_contract l = store_root ("generic" :: l)
let contract_store c l = let contract_store c l =
store_root @@
match c with match c with
| Contract_repr.Default k -> | Contract_repr.Default k ->
"pubkey" :: Ed25519.hash_path k @ l pubkey_contract @@ Ed25519.Public_key_hash.to_path k @ l
| Contract_repr.Hash h -> | Contract_repr.Hash h ->
"generic" :: Contract_hash.to_path h @ l generic_contract @@ Contract_hash.to_path h @ l
let roll_list c = contract_store c ["roll_list"] let roll_list c = contract_store c ["roll_list"]
let change c = contract_store c ["change"] let change c = contract_store c ["change"]
let balance c = contract_store c ["balance"] let balance c = contract_store c ["balance"]
@ -197,10 +201,10 @@ module Roll = struct
module Owner_for_cycle = module Owner_for_cycle =
Make_indexed_data_storage(struct Make_indexed_data_storage(struct
type key = Cycle_repr.t * Roll_repr.t type key = Cycle_repr.t * Roll_repr.t
type value = Ed25519.public_key_hash type value = Ed25519.Public_key_hash.t
let name = "roll owner for current cycle" let name = "roll owner for current cycle"
let key = Key.Cycle.roll_owner let key = Key.Cycle.roll_owner
let encoding = Ed25519.public_key_hash_encoding let encoding = Ed25519.Public_key_hash.encoding
end) end)
module Contract_roll_list = module Contract_roll_list =
@ -235,6 +239,7 @@ module Contract = struct
let encoding = Data_encoding.int32 let encoding = Data_encoding.int32
end) end)
(** FIXME REMOVE : use 'list' *)
module Set = module Set =
Make_data_set_storage(struct Make_data_set_storage(struct
type value = Contract_repr.t type value = Contract_repr.t
@ -266,10 +271,10 @@ module Contract = struct
module Manager = module Manager =
Make_indexed_data_storage(struct Make_indexed_data_storage(struct
type key = Contract_repr.t type key = Contract_repr.t
type value = Ed25519.public_key_hash type value = Ed25519.Public_key_hash.t
let name = "contract manager" let name = "contract manager"
let key = Key.Contract.manager let key = Key.Contract.manager
let encoding = Ed25519.public_key_hash_encoding let encoding = Ed25519.Public_key_hash.encoding
end) end)
module Spendable = module Spendable =
@ -293,10 +298,10 @@ module Contract = struct
module Delegate = module Delegate =
Make_indexed_data_storage(struct Make_indexed_data_storage(struct
type key = Contract_repr.t type key = Contract_repr.t
type value = Ed25519.public_key_hash type value = Ed25519.Public_key_hash.t
let name = "contract delegate" let name = "contract delegate"
let key = Key.Contract.delegate let key = Key.Contract.delegate
let encoding = Ed25519.public_key_hash_encoding let encoding = Ed25519.Public_key_hash.encoding
end) end)
module Counter = module Counter =
@ -376,7 +381,7 @@ module Vote = struct
module Proposals = module Proposals =
Make_data_set_storage Make_data_set_storage
(struct (struct
type value = Protocol_hash.t * Ed25519.public_key_hash type value = Protocol_hash.t * Ed25519.Public_key_hash.t
let name = "proposals" let name = "proposals"
let encoding = let encoding =
Data_encoding.tup2 Data_encoding.tup2
@ -401,7 +406,7 @@ module Public_key =
Make_iterable_data_storage (Ed25519.Public_key_hash) Make_iterable_data_storage (Ed25519.Public_key_hash)
(struct (struct
type value = Ed25519.public_key type value = Ed25519.public_key
let key = ["public_keys"] let key = Key.public_keys
let name = "public keys" let name = "public keys"
let encoding = Ed25519.public_key_encoding let encoding = Ed25519.public_key_encoding
end) end)
@ -413,7 +418,7 @@ module Seed = struct
type nonce_status = type nonce_status =
| Unrevealed of { | Unrevealed of {
nonce_hash: Tezos_hash.Nonce_hash.t ; nonce_hash: Tezos_hash.Nonce_hash.t ;
delegate_to_reward: Ed25519.public_key_hash ; delegate_to_reward: Ed25519.Public_key_hash.t ;
reward_amount: Tez_repr.t ; reward_amount: Tez_repr.t ;
} }
| Revealed of Seed_repr.nonce | Revealed of Seed_repr.nonce
@ -482,7 +487,7 @@ module Rewards = struct
module Amount = module Amount =
Raw_make_iterable_data_storage(struct Raw_make_iterable_data_storage(struct
type t = Ed25519.public_key_hash * Cycle_repr.t type t = Ed25519.Public_key_hash.t * Cycle_repr.t
let prefix = Key.rewards let prefix = Key.rewards
let length = Ed25519.Public_key_hash.path_len + 1 let length = Ed25519.Public_key_hash.path_len + 1
let to_path (pkh, c) = let to_path (pkh, c) =
@ -515,3 +520,15 @@ let fork_test_network (c, constants) =
Updater.fork_test_network c >>= fun c -> Lwt.return (c, constants) Updater.fork_test_network c >>= fun c -> Lwt.return (c, constants)
let set_test_protocol (c, constants) h = let set_test_protocol (c, constants) h =
Updater.set_test_protocol c h >>= fun c -> Lwt.return (c, constants) Updater.set_test_protocol c h >>= fun c -> Lwt.return (c, constants)
(** Resolver *)
let () =
Storage_functors.register_resolvers
(module Contract_hash)
[ Key.Contract.generic_contract [] ] ;
Storage_functors.register_resolvers
(module Ed25519.Public_key_hash)
[ Key.Contract.pubkey_contract [] ;
Key.public_keys ]

View File

@ -109,7 +109,7 @@ module Roll : sig
module Owner_for_cycle : Indexed_data_storage module Owner_for_cycle : Indexed_data_storage
with type key = Cycle_repr.t * Roll_repr.t with type key = Cycle_repr.t * Roll_repr.t
and type value = Ed25519.public_key_hash and type value = Ed25519.Public_key_hash.t
and type context := t and type context := t
end end
@ -144,13 +144,13 @@ module Contract : sig
(** The manager of a contract *) (** The manager of a contract *)
module Manager : Indexed_data_storage module Manager : Indexed_data_storage
with type key = Contract_repr.t with type key = Contract_repr.t
and type value = Ed25519.public_key_hash and type value = Ed25519.Public_key_hash.t
and type context := t and type context := t
(** The delegate of a contract, if any. *) (** The delegate of a contract, if any. *)
module Delegate : Indexed_data_storage module Delegate : Indexed_data_storage
with type key = Contract_repr.t with type key = Contract_repr.t
and type value = Ed25519.public_key_hash and type value = Ed25519.Public_key_hash.t
and type context := t and type context := t
module Spendable : Indexed_data_storage module Spendable : Indexed_data_storage
@ -201,16 +201,16 @@ module Vote : sig
and type context := t and type context := t
module Listings : Iterable_data_storage module Listings : Iterable_data_storage
with type key = Ed25519.public_key_hash with type key = Ed25519.Public_key_hash.t
and type value = int32 (* number of rolls for the key. *) and type value = int32 (* number of rolls for the key. *)
and type context := t and type context := t
module Proposals : Data_set_storage module Proposals : Data_set_storage
with type value = Protocol_hash.t * Ed25519.public_key_hash with type value = Protocol_hash.t * Ed25519.Public_key_hash.t
and type context := t and type context := t
module Ballots : Iterable_data_storage module Ballots : Iterable_data_storage
with type key = Ed25519.public_key_hash with type key = Ed25519.Public_key_hash.t
and type value = Vote_repr.ballot and type value = Vote_repr.ballot
and type context := t and type context := t
@ -220,7 +220,7 @@ end
(** Keys *) (** Keys *)
module Public_key : Iterable_data_storage module Public_key : Iterable_data_storage
with type key = Ed25519.public_key_hash with type key = Ed25519.Public_key_hash.t
and type value = Ed25519.public_key and type value = Ed25519.public_key
and type context := t and type context := t
@ -234,7 +234,7 @@ module Seed : sig
type nonce_status = type nonce_status =
| Unrevealed of { | Unrevealed of {
nonce_hash: Tezos_hash.Nonce_hash.t ; nonce_hash: Tezos_hash.Nonce_hash.t ;
delegate_to_reward: Ed25519.public_key_hash ; delegate_to_reward: Ed25519.Public_key_hash.t ;
reward_amount: Tez_repr.t ; reward_amount: Tez_repr.t ;
} }
| Revealed of Seed_repr.nonce | Revealed of Seed_repr.nonce
@ -266,7 +266,7 @@ module Rewards : sig
and type context := t and type context := t
module Amount : Iterable_data_storage module Amount : Iterable_data_storage
with type key = Ed25519.public_key_hash * Cycle_repr.t with type key = Ed25519.Public_key_hash.t * Cycle_repr.t
and type value = Tez_repr.t and type value = Tez_repr.t
and type context := t and type context := t

View File

@ -202,10 +202,9 @@ end
module Make_data_set_storage (P : Single_data_description) = struct module Make_data_set_storage (P : Single_data_description) = struct
module Key = struct module Key = struct
include Hash.Make_SHA256(struct include Hash.Make_minimal_SHA256(struct
let name = P.name let name = P.name
let title = ("A " ^ P.name ^ "key") let title = ("A " ^ P.name ^ "key")
let prefix = None
end) end)
let prefix = P.key let prefix = P.key
let length = path_len let length = path_len
@ -352,3 +351,31 @@ module Make_iterable_data_storage (H: HASH) (P: Single_data_description) =
let prefix = P.key let prefix = P.key
let length = path_len let length = path_len
end)(P) end)(P)
let register_resolvers (module H : Hash.HASH) prefixes =
let module Set = Hash_set(H) in
let resolvers =
List.map
(fun prefix ->
let module R = Persist.MakeHashResolver(struct
include Context
let prefix = prefix
end)(H) in
R.resolve)
prefixes in
let resolve c m =
match resolvers with
| [resolve] -> resolve c m
| resolvers ->
Lwt_list.map_p (fun resolve -> resolve c m) resolvers >|= fun hs ->
List.fold_left
(fun acc hs -> List.fold_left (fun acc h -> Set.add h acc) acc hs)
Set.empty hs |>
Set.elements in
Context.register_resolver H.b48check_encoding resolve

View File

@ -98,3 +98,5 @@ module Raw_make_iterable_data_storage (K: Persist.KEY) (P: Data_description) :
and type value = P.value and type value = P.value
and type context := context and type context := context
val register_resolvers: (module Hash.HASH) -> string list list -> unit

View File

@ -227,3 +227,10 @@ module Make_data_set_storage (P : Single_data_description) :
module Make_iterable_data_storage (H : HASH) (P: Single_data_description) : module Make_iterable_data_storage (H : HASH) (P: Single_data_description) :
Iterable_data_storage with type key = H.t and type value = P.value Iterable_data_storage with type key = H.t and type value = P.value
module Make_hash_resolver
(K: sig val prefix: string list end)
(H: Hash.HASH) : sig
val register : Store.t -> unit
end

View File

@ -39,7 +39,7 @@ module Script_int = Script_int_repr
module Script = Script_repr module Script = Script_repr
type public_key = Ed25519.public_key type public_key = Ed25519.public_key
type public_key_hash = Ed25519.public_key_hash type public_key_hash = Ed25519.Public_key_hash.t
type secret_key = Ed25519.secret_key type secret_key = Ed25519.secret_key
type signature = Ed25519.signature type signature = Ed25519.signature

View File

@ -26,7 +26,7 @@ module Nonce_hash_set = Tezos_hash.Nonce_hash_set
module Nonce_hash_map = Tezos_hash.Nonce_hash_map module Nonce_hash_map = Tezos_hash.Nonce_hash_map
type public_key = Ed25519.public_key type public_key = Ed25519.public_key
type public_key_hash = Ed25519.public_key_hash type public_key_hash = Ed25519.Public_key_hash.t
type secret_key = Ed25519.secret_key type secret_key = Ed25519.secret_key
type signature = Ed25519.signature type signature = Ed25519.signature

View File

@ -8,42 +8,44 @@
(**************************************************************************) (**************************************************************************)
module Prefix = struct module Prefix = struct
let random_state_hash = Base48.Prefix.protocol_prefix ^ "\001" let make x =
let nonce_hash = Base48.Prefix.protocol_prefix ^ "\002" assert (Compare.String.(Base48.Prefix.protocol_prefix = "\015")) ;
let script_expr_hash = Base48.Prefix.protocol_prefix ^ "\003" String.make 1 (char_of_int ((x lsl 4) lor 15))
let proposition_hash = Base48.Prefix.protocol_prefix ^ "\004" let public_key_hash = make 0
let contract_hash = Base48.Prefix.protocol_prefix ^ "\005" let contract_hash = make 1
let nonce_hash = make 2
let script_expr_hash = make 3
let random_state_hash = make 15 (* never used... *)
end end
module State_hash = Hash.Make_SHA256(struct module State_hash = Hash.Make_SHA256(Base48)(struct
let name = "random" let name = "random"
let title = "A random generation state" let title = "A random generation state"
let prefix = Some Prefix.random_state_hash let b48check_prefix = Prefix.random_state_hash
end) end)
module State_hash_set = Hash_set(State_hash) module State_hash_set = Hash_set(State_hash)
module State_hash_map = Hash_map(State_hash) module State_hash_map = Hash_map(State_hash)
module Nonce_hash = Hash.Make_SHA256(struct module Nonce_hash = Hash.Make_SHA256(Base48)(struct
let name = "cycle_nonce" let name = "cycle_nonce"
let title = "A nonce hash" let title = "A nonce hash"
let prefix = Some Prefix.nonce_hash let b48check_prefix = Prefix.nonce_hash
end) end)
module Nonce_hash_set = Hash_set(Nonce_hash) module Nonce_hash_set = Hash_set(Nonce_hash)
module Nonce_hash_map = Hash_map(Nonce_hash) module Nonce_hash_map = Hash_map(Nonce_hash)
module Script_expr_hash = Hash.Make_SHA256(struct module Script_expr_hash = Hash.Make_SHA256(Base48)(struct
let name = "script_expr" let name = "script_expr"
let title = "A script expression ID" let title = "A script expression ID"
let prefix = Some Prefix.script_expr_hash let b48check_prefix = Prefix.script_expr_hash
end) end)
module Script_expr_hash_set = Hash_set(Script_expr_hash) module Script_expr_hash_set = Hash_set(Script_expr_hash)
module Script_expr_hash_map = Hash_map(Script_expr_hash) module Script_expr_hash_map = Hash_map(Script_expr_hash)
module Contract_hash = Hash.Make_SHA256(struct module Contract_hash = Hash.Make_SHA256(Base48)(struct
let name = "Contract_hash" let name = "Contract_hash"
let title = "A contract ID" let title = "A contract ID"
let prefix = Some Prefix.contract_hash let b48check_prefix = Prefix.contract_hash
end) end)
module Contract_hash_set = Hash_set(Contract_hash) module Contract_hash_set = Hash_set(Contract_hash)
module Contract_hash_map = Hash_map(Contract_hash) module Contract_hash_map = Hash_map(Contract_hash)

View File

@ -8,7 +8,7 @@
(**************************************************************************) (**************************************************************************)
val record_proposal: val record_proposal:
Storage.t -> Protocol_hash.t -> Ed25519.public_key_hash -> Storage.t -> Protocol_hash.t -> Ed25519.Public_key_hash.t ->
Storage.t tzresult Lwt.t Storage.t tzresult Lwt.t
val get_proposals: val get_proposals:
@ -23,7 +23,7 @@ type ballots = {
} }
val record_ballot: val record_ballot:
Storage.t -> Ed25519.public_key_hash -> Vote_repr.ballot -> Storage.t -> Ed25519.Public_key_hash.t -> Vote_repr.ballot ->
Storage.t tzresult Lwt.t Storage.t tzresult Lwt.t
val get_ballots: Storage.t -> ballots tzresult Lwt.t val get_ballots: Storage.t -> ballots tzresult Lwt.t
val clear_ballots: Storage.t -> Storage.t Lwt.t val clear_ballots: Storage.t -> Storage.t Lwt.t
@ -33,7 +33,7 @@ val clear_listings: Storage.t -> Storage.t tzresult Lwt.t
val listing_size: Storage.t -> int32 tzresult Lwt.t val listing_size: Storage.t -> int32 tzresult Lwt.t
val in_listings: val in_listings:
Storage.t -> Ed25519.public_key_hash -> bool Lwt.t Storage.t -> Ed25519.Public_key_hash.t -> bool Lwt.t
val get_current_quorum: Storage.t -> int32 tzresult Lwt.t val get_current_quorum: Storage.t -> int32 tzresult Lwt.t
val set_current_quorum: Storage.t -> int32 -> Storage.t tzresult Lwt.t val set_current_quorum: Storage.t -> int32 -> Storage.t tzresult Lwt.t

View File

@ -1,8 +1,9 @@
B ../../node/updater/ B ../../node/updater/
B _tzbuild B _tzbuild
FLG -nopervasives FLG -nopervasives
FLG -open Proto_environment FLG -open Local_environment
FLG -open Environment
FLG -open Hash FLG -open Hash
FLG -open Local_error_monad
FLG -open Error_monad FLG -open Error_monad
FLG -open Logging
FLG -w -40 FLG -w -40

View File

@ -1,4 +1,4 @@
{ {
"hash": "JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", "hash": "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK",
"modules": ["Error", "Services", "Main"] "modules": ["Error", "Services", "Main"]
} }

View File

@ -1,15 +1,20 @@
type data = ..
val decode: ?alphabet:string -> string -> data
val encode: ?alphabet:string -> data -> string
val register:
prefix:string ->
read:(data -> string option) ->
build:(string -> data) ->
unit
module Prefix : sig module Prefix : sig
val protocol_prefix: string val protocol_prefix: string
end end
type 'a encoding
val simple_decode: ?alphabet:string -> 'a encoding -> string -> 'a option
val simple_encode: ?alphabet:string -> 'a encoding -> 'a -> string
type data = ..
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> data) ->
'a encoding
val decode: ?alphabet:string -> string -> data option

View File

@ -7,3 +7,9 @@ include Persist.STORE
val get_genesis_time: t -> Time.t Lwt.t val get_genesis_time: t -> Time.t Lwt.t
val get_genesis_block: t -> Block_hash.t Lwt.t val get_genesis_block: t -> Block_hash.t Lwt.t
val register_resolver:
'a Base48.encoding -> (t -> string -> 'a list Lwt.t) -> unit
val complete:
?alphabet:string -> t -> string -> string list Lwt.t

View File

@ -22,25 +22,11 @@ val check_signature : public_key -> signature -> MBytes.t -> bool
module Public_key_hash : Hash.HASH module Public_key_hash : Hash.HASH
(** A Sha256 hash of an Ed25519 public key for use as an ID *)
type public_key_hash = Public_key_hash.t
(** Hashes an Ed25519 public key *) (** Hashes an Ed25519 public key *)
val hash : public_key -> public_key_hash val hash : public_key -> Public_key_hash.t
(** For using IDs as keys in the database *)
val hash_path : public_key_hash -> string list
(** ID comparison *)
val equal_hash : public_key_hash -> public_key_hash -> bool
(** ID comparison *)
val compare_hash : public_key_hash -> public_key_hash -> int
(** {2 Serializers} **********************************************************) (** {2 Serializers} **********************************************************)
val public_key_hash_encoding : public_key_hash Data_encoding.t
val public_key_encoding : public_key Data_encoding.t val public_key_encoding : public_key Data_encoding.t
val secret_key_encoding : secret_key Data_encoding.t val secret_key_encoding : secret_key Data_encoding.t

View File

@ -1,5 +1,5 @@
(** Tezos - Manipulation and creation of hashes *)
(** Tezos - Manipulation and creation of hashes *)
(** {2 Hash Types} ************************************************************) (** {2 Hash Types} ************************************************************)
@ -8,9 +8,14 @@
various kinds of hashes in the system at typing time. Each type is various kinds of hashes in the system at typing time. Each type is
equipped with functions to use it as is of as keys in the database equipped with functions to use it as is of as keys in the database
or in memory sets and maps. *) or in memory sets and maps. *)
module type HASH = sig
module type MINIMAL_HASH = sig
type t type t
val name: string
val title: string
val hash_bytes: MBytes.t list -> t val hash_bytes: MBytes.t list -> t
val hash_string: string list -> t val hash_string: string list -> t
val size: int (* in bytes *) val size: int (* in bytes *)
@ -20,20 +25,30 @@ module type HASH = sig
val to_raw: t -> string val to_raw: t -> string
val of_hex: string -> t val of_hex: string -> t
val to_hex: t -> string val to_hex: t -> string
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val to_bytes: t -> MBytes.t val to_bytes: t -> MBytes.t
val of_bytes: MBytes.t -> t val of_bytes: MBytes.t -> t
val read: MBytes.t -> int -> t val read: MBytes.t -> int -> t
val write: MBytes.t -> int -> t -> unit val write: MBytes.t -> int -> t -> unit
val to_path: t -> string list val to_path: t -> string list
val of_path: string list -> t val of_path: string list -> t
val prefix_path: string -> string list
val path_len: int val path_len: int
end
module type HASH = sig
include MINIMAL_HASH
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val encoding: t Data_encoding.t val encoding: t Data_encoding.t
val pp: Format.formatter -> t -> unit val pp: Format.formatter -> t -> unit
val pp_short: Format.formatter -> t -> unit val pp_short: Format.formatter -> t -> unit
type Base48.data += Hash of t type Base48.data += Hash of t
val b48check_encoding: t Base48.encoding
end end
(** {2 Building Hashes} *******************************************************) (** {2 Building Hashes} *******************************************************)
@ -41,14 +56,30 @@ end
(** The parameters for creating a new Hash type using (** The parameters for creating a new Hash type using
{!Make_SHA256}. Both {!name} and {!title} are only informative, {!Make_SHA256}. Both {!name} and {!title} are only informative,
used in error messages and serializers. *) used in error messages and serializers. *)
module type Name = sig module type Name = sig
val name : string val name : string
val title : string val title : string
val prefix : string option end
module type PrefixedName = sig
include Name
val b48check_prefix : string
end end
(** Builds a new Hash type using Sha256. *) (** Builds a new Hash type using Sha256. *)
module Make_SHA256 (Name:Name) : HASH
module Make_minimal_SHA256 (Name : Name) : MINIMAL_HASH
module Make_SHA256
(Register : sig
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> Base48.data) ->
'a Base48.encoding
end)
(Name : PrefixedName) : HASH
(** Builds a Set of values of some Hash type. *) (** Builds a Set of values of some Hash type. *)
module Hash_set (Hash : HASH) : sig module Hash_set (Hash : HASH) : sig
@ -78,3 +109,4 @@ module Operation_hash_map : module type of Hash_map (Operation_hash)
module Protocol_hash : HASH module Protocol_hash : HASH
module Protocol_hash_set : Set.S with type elt = Protocol_hash.t module Protocol_hash_set : Set.S with type elt = Protocol_hash.t
module Protocol_hash_map : module type of Hash_map (Protocol_hash) module Protocol_hash_map : module type of Hash_map (Protocol_hash)

View File

@ -13,12 +13,12 @@ type value = MBytes.t
module type STORE = sig module type STORE = sig
type t type t
val mem: t -> key -> bool Lwt.t val mem: t -> key -> bool Lwt.t
val dir_mem: t -> key -> bool Lwt.t
val get: t -> key -> value option Lwt.t val get: t -> key -> value option Lwt.t
val set: t -> key -> value -> t Lwt.t val set: t -> key -> value -> t Lwt.t
val del: t -> key -> t Lwt.t val del: t -> key -> t Lwt.t
val list: t -> key list -> key list Lwt.t val list: t -> key list -> key list Lwt.t
val remove_rec: t -> key -> t Lwt.t val remove_rec: t -> key -> t Lwt.t
val keys: t -> key list Lwt.t val keys: t -> key list Lwt.t
end end
@ -196,3 +196,14 @@ module MakeBufferedPersistentTypedMap
and type key := K.t and type key := K.t
and type value := T.value and type value := T.value
and module Map := Map and module Map := Map
module MakeHashResolver
(Store : sig
type t
val dir_mem: t -> key -> bool Lwt.t
val list: t -> key list -> key list Lwt.t
val prefix: string list
end)
(H: Hash.HASH) : sig
val resolve : Store.t -> string -> H.t list Lwt.t
end

View File

@ -7,6 +7,11 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
open Utils
let (>>=) = Lwt.bind
let (>|=) = Lwt.(>|=)
let decode_alphabet alphabet = let decode_alphabet alphabet =
let str = Bytes.make 256 '\255' in let str = Bytes.make 256 '\255' in
for i = 0 to String.length alphabet - 1 do for i = 0 to String.length alphabet - 1 do
@ -15,7 +20,7 @@ let decode_alphabet alphabet =
Bytes.to_string str Bytes.to_string str
let default_alphabet = let default_alphabet =
"eXMNE9qvHPQDdcFx5J86rT7VRm2atAypGhgLfbS3CKjnksB4" "eE2NXaQvHPqDdTJxfF36jb7VRmp9tAyMgG4L5cS8CKrnksBh"
let default_decode_alphabet = decode_alphabet default_alphabet let default_decode_alphabet = decode_alphabet default_alphabet
@ -85,74 +90,144 @@ let sha256 s =
computed_hash computed_hash
let safe_encode ?alphabet s = let safe_encode ?alphabet s =
raw_encode ?alphabet (String.sub (sha256 (sha256 s)) 0 4 ^ s) raw_encode ?alphabet (s ^ String.sub (sha256 (sha256 s)) 0 4)
let safe_decode ?alphabet s = let safe_decode ?alphabet s =
let s = raw_decode ?alphabet s in let s = raw_decode ?alphabet s in
let len = String.length s in let len = String.length s in
let msg_hash = String.sub s 0 4 in let msg = String.sub s 0 (len-4)
let msg = String.sub s 4 (len-4) in and msg_hash = String.sub s (len-4) 4 in
if msg_hash <> String.sub (sha256 (sha256 msg)) 0 4 then if msg_hash <> String.sub (sha256 (sha256 msg)) 0 4 then
invalid_arg "safe_decode" ; invalid_arg "safe_decode" ;
msg msg
type data = .. type data = ..
type kinds = type 'a encoding = {
Kind : { prefix: string; prefix: string;
read: data -> string option ; to_raw: 'a -> string ;
build: string -> data } -> kinds of_raw: string -> 'a option ;
wrap: 'a -> data ;
}
let kinds = ref ([] : kinds list) let simple_decode ?alphabet { prefix ; of_raw } s =
safe_decode ?alphabet s |>
remove_prefix ~prefix |>
Utils.apply_option ~f:of_raw
let remove_prefix ~prefix s = let simple_encode ?alphabet { prefix ; to_raw } d =
let x = String.length prefix in safe_encode ?alphabet (prefix ^ to_raw d)
let n = String.length s in
if n >= x && String.sub s 0 x = prefix then
Some (String.sub s x (n - x))
else
None
exception Unknown_prefix type registred_encoding = Encoding : 'a encoding -> registred_encoding
module MakeEncodings(E: sig
val encodings: registred_encoding list
end) = struct
let encodings = ref E.encodings
let ambiguous_prefix prefix encodings =
List.exists (fun (Encoding { prefix = s }) ->
remove_prefix s prefix <> None ||
remove_prefix prefix s <> None)
encodings
let register_encoding ~prefix ~to_raw ~of_raw ~wrap =
if ambiguous_prefix prefix !encodings then
Format.ksprintf invalid_arg
"Base48.register_encoding: duplicate prefix: %S" prefix ;
let encoding = { prefix ; to_raw ; of_raw ; wrap } in
encodings := Encoding encoding :: !encodings ;
encoding
let decode ?alphabet s = let decode ?alphabet s =
let rec find s = function let rec find s = function
| [] -> raise Unknown_prefix | [] -> None
| Kind { prefix ; build } :: kinds -> | Encoding { prefix ; of_raw ; wrap } :: encodings ->
match remove_prefix ~prefix s with match remove_prefix ~prefix s with
| None -> find s kinds | None -> find s encodings
| Some msg -> build msg in | Some msg -> of_raw msg |> Utils.map_option ~f:wrap in
let s = safe_decode ?alphabet s in let s = safe_decode ?alphabet s in
find s !kinds find s !encodings
exception Unregistred_kind end
let encode ?alphabet s = type 'a resolver =
Resolver : {
encoding: 'h encoding ;
resolver: 'a -> string -> 'h list Lwt.t ;
} -> 'a resolver
module MakeResolvers(R: sig
type context
val encodings: registred_encoding list ref
end) = struct
let resolvers = ref []
let register_resolver
(type a)
(encoding : a encoding)
(resolver : R.context -> string -> a list Lwt.t) =
try
resolvers := Resolver { encoding ; resolver } :: !resolvers
with Not_found ->
invalid_arg "Base48.register_resolver: unregistred encodings"
type context = R.context
let complete ?alphabet context request =
(* One may extract from the prefix of a Base48-encoded value, a
prefix of the original encoded value. Given that `48 = 3 * 2^4`,
every "digits" in the Base48-prefix (i.e. a "bytes" in its ascii
representation), provides for sure 4 bits of the original data.
Hence, when we decode a prefix of a Base48-encoded value of
length `n`, the `n/2` first bytes of the decoded value are (for
sure) a prefix of the original value. *)
let n = String.length request in
let s = raw_decode request ?alphabet in
let partial = String.sub s 0 (n / 2) in
let rec find s = function let rec find s = function
| [] -> raise Unregistred_kind | [] -> Lwt.return_nil
| Kind { prefix ; read } :: kinds -> | Resolver { encoding ; resolver } :: resolvers ->
match read s with match remove_prefix ~prefix:encoding.prefix s with
| None -> find s kinds | None -> find s resolvers
| Some msg -> safe_encode ?alphabet (prefix ^ msg) in | Some msg ->
try find s !kinds resolver context msg >|= fun msgs ->
with Not_found -> raise Unknown_prefix filter_map
(fun msg ->
let res = simple_encode encoding ?alphabet msg in
Utils.remove_prefix ~prefix:request res |>
Utils.map_option ~f:(fun _ -> res))
msgs in
find partial !resolvers
let register ~prefix ~read ~build = end
match List.find (fun (Kind {prefix=s}) -> remove_prefix s prefix <> None || remove_prefix prefix s <> None) !kinds with
| exception Not_found -> include MakeEncodings(struct let encodings = [] end)
kinds := Kind { prefix ; read ; build } :: !kinds include MakeResolvers(struct
| Kind { prefix = s } -> type context = unit
Format.kasprintf let encodings = encodings
Pervasives.failwith end)
"Base49.register: Conflicting prefixes: %S and %S." prefix s ;
let register_resolver enc f = register_resolver enc (fun () s -> f s)
let complete ?alphabet s = complete ?alphabet () s
module Make(C: sig type context end) = struct
include MakeEncodings(struct let encodings = !encodings end)
include MakeResolvers(struct
type context = C.context
let encodings = encodings
end)
end
module Prefix = struct module Prefix = struct
let block_hash = "\000" let block_hash = "\000"
let operation_hash = "\001" let operation_hash = "\001"
let protocol_hash = "\002" let protocol_hash = "\002"
let public_key_hash = "\003" let ed25519_public_key_hash = "\003"
let public_key = "\004" let ed25519_public_key = "\012"
let secret_key = "\005" let ed25519_secret_key = "\013"
let signature = "\006" let ed25519_signature = "\014"
let protocol_prefix = "\255" let protocol_prefix = "\015"
end end

View File

@ -7,27 +7,131 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
(** {1 Prefixed Base48Check encodings} *)
(** Like Bitcoin's Base58Check, all the data encoded in Tezos are
prefixed with a constant which depends on the kind of encoded
data.
The [Prefix] exports all the prefix used by the Tezos Shell. Each
version of the economical protocol might complete this list.
Unlike Bitcoin's Base58Check, the prefix in the unencoded-data
is visible in the encoded data.
*)
module Prefix : sig
val block_hash: string
(** Prefix for block hashes: "\000".
(in Base48: "e" "f" or "g") *)
val operation_hash: string
(** Prefix for operation hashes: "\001".
(in Base48: "E" "F" or "G") *)
val protocol_hash: string
(** Prefix for protocol-version hashes: "\002".
(in Base48: "2" "3" or "4") *)
val ed25519_public_key_hash: string
(** Prefix for Ed25519 public key hashes: "\003". *)
val ed25519_public_key: string
(** Prefix for Ed25519 public key: "\012". *)
val ed25519_secret_key: string
(** Prefix for Ed25519 secret key: "\013". *)
val ed25519_signature: string
(** Prefix for Ed25519 signature key: "\014". *)
val protocol_prefix: string
(** Prefix for all the encodings defined by economical protocol:
"\015". *)
end
(** An extensible sum-type for decoded data: one case per known
"prefix". See for instance [Hash.Block_hash.Hash] or
[Environment.Ed25519.Public_key_hash]. *)
type data = ..
(** Abstract representation of registred encodings. The type paramater
is the type of the encoded data, for instance [Hash.Block_hash.t]. *)
type 'a encoding = private {
prefix: string;
to_raw: 'a -> string ;
of_raw: string -> 'a option ;
wrap: 'a -> data ;
}
(** Register a new encoding. The function might raise `Invalid_arg` if
the provided [prefix] overlap with a previously registred
prefix. The [to_raw] and [of_raw] are the ad-hoc
serialisation/deserialisation for the data. The [wrap] should wrap
the deserialised value into the extensible sum-type [data] (see
the generic function [decode]). *)
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> data) ->
'a encoding
(** Encoder for a given kind of data. *)
val simple_encode: ?alphabet:string -> 'a encoding -> 'a -> string
(** Decoder for a given kind of data. It returns [None] when
the decoded data does not start with the expected prefix. *)
val simple_decode: ?alphabet:string -> 'a encoding -> string -> 'a option
(** Generic decoder. It returns [None] when the decoded data does
not start with a registred prefix. *)
val decode: ?alphabet:string -> string -> data option
(** {2 Completion of partial Base48Check value} *)
(** Register a (global) resolver for a previsously
registred kind af data. *)
val register_resolver: 'a encoding -> (string -> 'a list Lwt.t) -> unit
(** Try to complete a prefix of a Base48Check encoded data, by using
the previously registered resolver associated to this kind of
data. Note that a prefix of [n] characters of a Base48-encoded
value provides at least [n/2] bytes of a prefix of the original value. *)
val complete: ?alphabet:string -> string -> string list Lwt.t
(** {1 Low-level: distinct registering function for economical protocol} *)
(** See [src/proto/environment/base48.mli]} for an inlined
documentation. *)
module Make(C: sig type context end) : sig
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> data) ->
'a encoding
val decode: ?alphabet:string -> string -> data option
val register_resolver:
'a encoding -> (C.context -> string -> 'a list Lwt.t) -> unit
val complete:
?alphabet:string -> C.context -> string -> string list Lwt.t
end
(** {2 Low-level Base48Check encodings} *)
(** Base48Check-encoding/decoding functions (with error detections). *)
val safe_encode: ?alphabet:string -> string -> string val safe_encode: ?alphabet:string -> string -> string
val safe_decode: ?alphabet:string -> string -> string val safe_decode: ?alphabet:string -> string -> string
type data = .. (** Base48-encoding/decoding functions (without error detections). *)
val raw_encode: ?alphabet:string -> string -> string
val raw_decode: ?alphabet:string -> string -> string
val decode: ?alphabet:string -> string -> data
val encode: ?alphabet:string -> data -> string
val register:
prefix:string ->
read:(data -> string option) ->
build:(string -> data) ->
unit
module Prefix : sig
val block_hash: string
val operation_hash: string
val protocol_hash: string
val public_key_hash: string
val public_key: string
val secret_key: string
val signature: string
val protocol_prefix: string
end

View File

@ -1,134 +0,0 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(* Tezos - Ed25519 cryptography (simple interface to Sodium) *)
(*-- Signature ---------------------------------------------------------------*)
type secret_key = Sodium.Sign.secret_key
type public_key = Sodium.Sign.public_key
type signature = MBytes.t
let sign key msg =
Sodium.Sign.Bigbytes.(of_signature @@ sign_detached key msg)
let check_signature public_key signature msg =
try Sodium.Sign.Bigbytes.(verify public_key (to_signature signature) msg) ; true
with _ -> false
let append_signature key msg =
MBytes.concat msg (sign key msg)
(*-- Hashed public keys for user ID ------------------------------------------*)
module Public_key_hash = Hash.Make_SHA256(struct
let name = "Ed25519.Public_key_hash"
let title = "An Ed25519 public key ID"
let prefix = Some Base48.Prefix.public_key_hash
end)
type public_key_hash = Public_key_hash.t
let hash v =
Public_key_hash.hash_bytes
[ Sodium.Sign.Bigbytes.of_public_key v ]
let hash_path = Public_key_hash.to_path
let hash_hex = Public_key_hash.to_hex
let equal_hash = Public_key_hash.equal
let compare_hash = Public_key_hash.compare
let generate_key () =
let secret, pub = Sodium.Sign.random_keypair () in
(hash pub, pub, secret)
(*-- JSON Serializers --------------------------------------------------------*)
type Base48.data +=
| Public_key of public_key
| Secret_key of secret_key
| Signature of signature
let () =
Base48.register
~prefix:Base48.Prefix.public_key
~read:(function Public_key x -> Some (Bytes.to_string (Sodium.Sign.Bytes.of_public_key x)) | _ -> None)
~build:(fun x -> Public_key (Sodium.Sign.Bytes.to_public_key (Bytes.of_string x)))
let () =
Base48.register
~prefix:Base48.Prefix.secret_key
~read:(function Secret_key x -> Some (Bytes.to_string (Sodium.Sign.Bytes.of_secret_key x)) | _ -> None)
~build:(fun x -> Secret_key (Sodium.Sign.Bytes.to_secret_key (Bytes.of_string x)))
let () =
Base48.register
~prefix:Base48.Prefix.signature
~read:(function Signature x -> Some (MBytes.to_string x) | _ -> None)
~build:(fun x -> Signature (MBytes.of_string x))
let public_key_hash_encoding =
Public_key_hash.encoding
let public_key_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 public key (Base48Check encoded)" @@
conv
(fun s -> Base48.encode (Public_key s))
(fun s ->
match Base48.decode s with
| Public_key x -> x
| _ -> Data_encoding.Json.cannot_destruct
"Ed25519 public key: unexpected prefix.")
string)
~binary:
(conv
Sodium.Sign.Bigbytes.of_public_key
Sodium.Sign.Bigbytes.to_public_key
bytes)
let secret_key_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 secret key (Base48Check encoded)" @@
conv
(fun s -> Base48.encode (Secret_key s))
(fun s ->
match Base48.decode s with
| Secret_key x -> x
| _ -> Data_encoding.Json.cannot_destruct
"Ed25519 secret key: unexpected prefix.")
string)
~binary:
(conv
Sodium.Sign.Bigbytes.of_secret_key
Sodium.Sign.Bigbytes.to_secret_key
bytes)
let signature_encoding =
let open Data_encoding in
splitted
~json:
(describe
~title: "An Ed25519 signature (Base48Check encoded)" @@
conv
(fun s -> Base48.encode (Signature s))
(fun s ->
match Base48.decode s with
| Signature x -> x
| _ ->
Data_encoding.Json.cannot_destruct
"Ed25519 signature: unexpected prefix.")
string)
~binary: (Fixed.bytes 64)

View File

@ -1,63 +0,0 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(** Tezos - Ed25519 cryptography *)
(** {2 Signature} ************************************************************)
(** An Ed25519 public key *)
type public_key = Sodium.Sign.public_key
(** An Ed25519 secret key *)
type secret_key = Sodium.Sign.secret_key
(** The result of signing a sequence of bytes with a secret key *)
type signature
(** Signs a sequence of bytes with a secret key *)
val sign : secret_key -> MBytes.t -> signature
val append_signature : secret_key -> MBytes.t -> MBytes.t
(** Checks a signature *)
val check_signature : public_key -> signature -> MBytes.t -> bool
(** {2 Hashed public keys for user ID} ***************************************)
module Public_key_hash : Hash.HASH
(** A Sha256 hash of an Ed25519 public key for use as an ID *)
type public_key_hash = Public_key_hash.t
(** Hashes an Ed25519 public key *)
val hash : public_key -> public_key_hash
(** For using IDs as keys in the database *)
val hash_path : public_key_hash -> string list
(** ID comparison *)
val equal_hash : public_key_hash -> public_key_hash -> bool
(** ID comparison *)
val compare_hash : public_key_hash -> public_key_hash -> int
(** {2 Serializers} **********************************************************)
val public_key_hash_encoding : public_key_hash Data_encoding.t
val public_key_encoding : public_key Data_encoding.t
val secret_key_encoding : secret_key Data_encoding.t
val signature_encoding : signature Data_encoding.t
(** {2 Key pairs generation} *************************************************)
val generate_key : unit -> public_key_hash * public_key * secret_key

View File

@ -15,9 +15,13 @@ open Utils
(*-- Signatures -------------------------------------------------------------*) (*-- Signatures -------------------------------------------------------------*)
module type HASH = sig module type MINIMAL_HASH = sig
type t type t
val name: string
val title: string
val hash_bytes: MBytes.t list -> t val hash_bytes: MBytes.t list -> t
val hash_string: string list -> t val hash_string: string list -> t
val size: int (* in bytes *) val size: int (* in bytes *)
@ -27,34 +31,50 @@ module type HASH = sig
val to_raw: t -> string val to_raw: t -> string
val of_hex: string -> t val of_hex: string -> t
val to_hex: t -> string val to_hex: t -> string
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val to_bytes: t -> MBytes.t val to_bytes: t -> MBytes.t
val of_bytes: MBytes.t -> t val of_bytes: MBytes.t -> t
val read: MBytes.t -> int -> t val read: MBytes.t -> int -> t
val write: MBytes.t -> int -> t -> unit val write: MBytes.t -> int -> t -> unit
val to_path: t -> string list val to_path: t -> string list
val of_path: string list -> t val of_path: string list -> t
val prefix_path: string -> string list
val path_len: int val path_len: int
end
module type HASH = sig
include MINIMAL_HASH
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val encoding: t Data_encoding.t val encoding: t Data_encoding.t
val pp: Format.formatter -> t -> unit val pp: Format.formatter -> t -> unit
val pp_short: Format.formatter -> t -> unit val pp_short: Format.formatter -> t -> unit
type Base48.data += Hash of t type Base48.data += Hash of t
val b48check_encoding: t Base48.encoding
end end
module type Name = sig module type Name = sig
val name: string val name: string
val title: string val title: string
val prefix : string option end
module type PrefixedName = sig
include Name
val b48check_prefix: string
end end
(*-- Type specific Hash builder ---------------------------------------------*) (*-- Type specific Hash builder ---------------------------------------------*)
module Make_SHA256 (K : Name) = struct module Make_minimal_SHA256 (K : Name) = struct
type t = string type t = string
include K
let size = 32 (* SHA256 *) let size = 32 (* SHA256 *)
let of_raw s = let of_raw s =
@ -70,25 +90,6 @@ module Make_SHA256 (K : Name) = struct
let of_hex s = of_raw (Hex_encode.hex_decode s) let of_hex s = of_raw (Hex_encode.hex_decode s)
let to_hex s = Hex_encode.hex_encode s let to_hex s = Hex_encode.hex_encode s
type Base48.data += Hash of t
let () =
match K.prefix with
| Some prefix ->
Base48.register
~prefix
~read:(function Hash x -> Some x | _ -> None)
~build:(fun x -> Hash x)
| None -> ()
let of_b48check s =
match Base48.decode s with
| Hash x -> x
| _ -> Format.kasprintf failwith "Unexpected hash (%s)" K.name
let to_b48check s = Base48.encode (Hash s)
let to_short_b48check s = String.sub (to_b48check s) 0 8
let compare = String.compare let compare = String.compare
let equal : t -> t -> bool = (=) let equal : t -> t -> bool = (=)
@ -141,18 +142,58 @@ module Make_SHA256 (K : Name) = struct
let equal = equal let equal = equal
end) end)
let path_len = 5 let path_len = 6
let to_path key = let to_path key =
let key = to_hex key in let key = to_hex key in
[ String.sub key 0 2 ; String.sub key 2 2 ; [ String.sub key 0 2 ; String.sub key 2 2 ;
String.sub key 4 2 ; String.sub key 6 2 ; String.sub key 4 2 ; String.sub key 6 2 ;
String.sub key 8 (size * 2 - 8) ] String.sub key 8 2 ; String.sub key 10 (size * 2 - 10) ]
let of_path path = let of_path path =
let path = String.concat "" path in let path = String.concat "" path in
of_hex path of_hex path
let prefix_path p =
let p = to_hex p in
let len = String.length p in
let p1 = if len >= 2 then String.sub p 0 2 else ""
and p2 = if len >= 4 then String.sub p 2 2 else ""
and p3 = if len >= 6 then String.sub p 4 2 else ""
and p4 = if len >= 8 then String.sub p 6 2 else ""
and p5 = if len >= 10 then String.sub p 8 2 else ""
and p6 = if len > 10 then String.sub p 10 (len - 10) else "" in
[ p1 ; p2 ; p3 ; p4 ; p5 ; p6 ]
end
module Make_SHA256 (R : sig
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> Base48.data) ->
'a Base48.encoding
end) (K : PrefixedName) = struct
include Make_minimal_SHA256(K)
(* Serializers *) (* Serializers *)
type Base48.data += Hash of t
let b48check_encoding =
R.register_encoding
~prefix: K.b48check_prefix
~wrap: (fun x -> Hash x)
~of_raw:(fun s -> Some s) ~to_raw
let of_b48check s =
match Base48.simple_decode b48check_encoding s with
| Some x -> x
| None -> Format.kasprintf failwith "Unexpected hash (%s)" K.name
let to_b48check s = Base48.simple_encode b48check_encoding s
let to_short_b48check s = String.sub (to_b48check s) 0 12
let encoding = let encoding =
let open Data_encoding in let open Data_encoding in
splitted splitted
@ -207,10 +248,10 @@ module Hash_table (Hash : HASH)
(*-- Pre-instanciated hashes ------------------------------------------------*) (*-- Pre-instanciated hashes ------------------------------------------------*)
module Block_hash = module Block_hash =
Make_SHA256 (struct Make_SHA256 (Base48) (struct
let name = "Block_hash" let name = "Block_hash"
let title = "A Tezos block ID" let title = "A Tezos block ID"
let prefix = Some Base48.Prefix.block_hash let b48check_prefix = Base48.Prefix.block_hash
end) end)
module Block_hash_set = Hash_set (Block_hash) module Block_hash_set = Hash_set (Block_hash)
@ -218,10 +259,10 @@ module Block_hash_map = Hash_map (Block_hash)
module Block_hash_table = Hash_table (Block_hash) module Block_hash_table = Hash_table (Block_hash)
module Operation_hash = module Operation_hash =
Make_SHA256 (struct Make_SHA256 (Base48) (struct
let name = "Operation_hash" let name = "Operation_hash"
let title = "A Tezos operation ID" let title = "A Tezos operation ID"
let prefix = Some Base48.Prefix.operation_hash let b48check_prefix = Base48.Prefix.operation_hash
end) end)
module Operation_hash_set = Hash_set (Operation_hash) module Operation_hash_set = Hash_set (Operation_hash)
@ -229,10 +270,10 @@ module Operation_hash_map = Hash_map (Operation_hash)
module Operation_hash_table = Hash_table (Operation_hash) module Operation_hash_table = Hash_table (Operation_hash)
module Protocol_hash = module Protocol_hash =
Make_SHA256 (struct Make_SHA256 (Base48) (struct
let name = "Protocol_hash" let name = "Protocol_hash"
let title = "A Tezos protocol ID" let title = "A Tezos protocol ID"
let prefix = Some Base48.Prefix.protocol_hash let b48check_prefix = Base48.Prefix.protocol_hash
end) end)
module Protocol_hash_set = Hash_set (Protocol_hash) module Protocol_hash_set = Hash_set (Protocol_hash)

View File

@ -17,9 +17,14 @@
various kinds of hashes in the system at typing time. Each type is various kinds of hashes in the system at typing time. Each type is
equipped with functions to use it as is of as keys in the database equipped with functions to use it as is of as keys in the database
or in memory sets and maps. *) or in memory sets and maps. *)
module type HASH = sig
module type MINIMAL_HASH = sig
type t type t
val name: string
val title: string
val hash_bytes: MBytes.t list -> t val hash_bytes: MBytes.t list -> t
val hash_string: string list -> t val hash_string: string list -> t
val size: int (* in bytes *) val size: int (* in bytes *)
@ -29,20 +34,30 @@ module type HASH = sig
val to_raw: t -> string val to_raw: t -> string
val of_hex: string -> t val of_hex: string -> t
val to_hex: t -> string val to_hex: t -> string
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val to_bytes: t -> MBytes.t val to_bytes: t -> MBytes.t
val of_bytes: MBytes.t -> t val of_bytes: MBytes.t -> t
val read: MBytes.t -> int -> t val read: MBytes.t -> int -> t
val write: MBytes.t -> int -> t -> unit val write: MBytes.t -> int -> t -> unit
val to_path: t -> string list val to_path: t -> string list
val of_path: string list -> t val of_path: string list -> t
val prefix_path: string -> string list
val path_len: int val path_len: int
end
module type HASH = sig
include MINIMAL_HASH
val of_b48check: string -> t
val to_b48check: t -> string
val to_short_b48check: t -> string
val encoding: t Data_encoding.t val encoding: t Data_encoding.t
val pp: Format.formatter -> t -> unit val pp: Format.formatter -> t -> unit
val pp_short: Format.formatter -> t -> unit val pp_short: Format.formatter -> t -> unit
type Base48.data += Hash of t type Base48.data += Hash of t
val b48check_encoding: t Base48.encoding
end end
(** {2 Building Hashes} *******************************************************) (** {2 Building Hashes} *******************************************************)
@ -50,14 +65,29 @@ end
(** The parameters for creating a new Hash type using (** The parameters for creating a new Hash type using
{!Make_SHA256}. Both {!name} and {!title} are only informative, {!Make_SHA256}. Both {!name} and {!title} are only informative,
used in error messages and serializers. *) used in error messages and serializers. *)
module type Name = sig module type Name = sig
val name : string val name : string
val title : string val title : string
val prefix : string option end
module type PrefixedName = sig
include Name
val b48check_prefix : string
end end
(** Builds a new Hash type using Sha256. *) (** Builds a new Hash type using Sha256. *)
module Make_SHA256 (Name:Name) : HASH module Make_minimal_SHA256 (Name : Name) : MINIMAL_HASH
module Make_SHA256
(Register : sig
val register_encoding:
prefix: string ->
to_raw: ('a -> string) ->
of_raw: (string -> 'a option) ->
wrap: ('a -> Base48.data) ->
'a Base48.encoding
end)
(Name : PrefixedName) : HASH
(** Builds a Set of values of some Hash type. *) (** Builds a Set of values of some Hash type. *)
module Hash_set (Hash : HASH) : sig module Hash_set (Hash : HASH) : sig
@ -101,3 +131,4 @@ module Protocol_hash : HASH
module Protocol_hash_set : module type of Hash_set (Protocol_hash) module Protocol_hash_set : module type of Hash_set (Protocol_hash)
module Protocol_hash_map : module type of Hash_map (Protocol_hash) module Protocol_hash_map : module type of Hash_map (Protocol_hash)
module Protocol_hash_table : module type of Hash_table (Protocol_hash) module Protocol_hash_table : module type of Hash_table (Protocol_hash)

View File

@ -96,6 +96,10 @@ let map_option ~f = function
| None -> None | None -> None
| Some x -> Some (f x) | Some x -> Some (f x)
let apply_option ~f = function
| None -> None
| Some x -> f x
let iter_option ~f = function let iter_option ~f = function
| None -> () | None -> ()
| Some x -> f x | Some x -> f x
@ -122,6 +126,14 @@ let rec remove_elem_from_list nb = function
| l when nb <= 0 -> l | l when nb <= 0 -> l
| _ :: tl -> remove_elem_from_list (nb - 1) tl | _ :: tl -> remove_elem_from_list (nb - 1) tl
let remove_prefix ~prefix s =
let x = String.length prefix in
let n = String.length s in
if n >= x && String.sub s 0 x = prefix then
Some (String.sub s x (n - x))
else
None
let finalize f g = try let res = f () in g (); res with exn -> g (); raise exn let finalize f g = try let res = f () in g (); res with exn -> g (); raise exn
let read_file ?(bin=false) fn = let read_file ?(bin=false) fn =

View File

@ -27,6 +27,7 @@ val split_path: string -> string list
val split: char -> ?limit: int -> string -> string list val split: char -> ?limit: int -> string -> string list
val map_option: f:('a -> 'b) -> 'a option -> 'b option val map_option: f:('a -> 'b) -> 'a option -> 'b option
val apply_option: f:('a -> 'b option) -> 'a option -> 'b option
val iter_option: f:('a -> unit) -> 'a option -> unit val iter_option: f:('a -> unit) -> 'a option -> unit
val unopt: 'a -> 'a option -> 'a val unopt: 'a -> 'a option -> 'a
val unopt_list: 'a option list -> 'a list val unopt_list: 'a option list -> 'a list
@ -36,6 +37,8 @@ val display_paragraph: Format.formatter -> string -> unit
(** [remove nb list] remove the first [nb] elements from the list [list]. *) (** [remove nb list] remove the first [nb] elements from the list [list]. *)
val remove_elem_from_list: int -> 'a list -> 'a list val remove_elem_from_list: int -> 'a list -> 'a list
val remove_prefix: prefix:string -> string -> string option
val filter_map: ('a -> 'b option) -> 'a list -> 'b list val filter_map: ('a -> 'b option) -> 'a list -> 'b list
val finalize: (unit -> 'a) -> (unit -> unit) -> 'a val finalize: (unit -> 'a) -> (unit -> unit) -> 'a

View File

@ -7,6 +7,7 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
open Hash
open Kaputt.Abbreviations open Kaputt.Abbreviations
include Kaputt.Assertion include Kaputt.Assertion
@ -21,6 +22,15 @@ let equal_persist_list ?msg l1 l2 =
Printf.sprintf "[%s]" res in Printf.sprintf "[%s]" res in
Assert.make_equal_list ?msg (=) pr_persist l1 l2 Assert.make_equal_list ?msg (=) pr_persist l1 l2
let equal_block_hash_list ?msg l1 l2 =
let msg = format_msg msg in
let pr_block_hash = Block_hash.to_short_b48check in
Assert.make_equal_list ?msg Block_hash.equal pr_block_hash l1 l2
let equal_string_list ?msg l1 l2 =
let msg = format_msg msg in
Assert.make_equal_list ?msg (=) (fun x -> x) l1 l2
let equal_string_option ?msg o1 o2 = let equal_string_option ?msg o1 o2 =
let msg = format_msg msg in let msg = format_msg msg in
let prn = function let prn = function

View File

@ -7,7 +7,7 @@
(* *) (* *)
(**************************************************************************) (**************************************************************************)
open Hash
include (module type of struct include Kaputt.Assertion end) include (module type of struct include Kaputt.Assertion end)
val fail_msg : ('a, Format.formatter, unit, 'b) format4 -> 'a val fail_msg : ('a, Format.formatter, unit, 'b) format4 -> 'a
@ -17,6 +17,12 @@ val fail : string -> string -> ('a, Format.formatter, unit, 'b) format4 -> 'a
val equal_persist_list : val equal_persist_list :
?msg:string -> Persist.key list -> Persist.key list -> unit ?msg:string -> Persist.key list -> Persist.key list -> unit
val equal_block_hash_list :
?msg:string -> Block_hash.t list -> Block_hash.t list -> unit
val equal_string_list :
?msg:string -> string list -> string list -> unit
val equal_string_option : ?msg:string -> string option -> string option -> unit val equal_string_option : ?msg:string -> string option -> string option -> unit
val equal_error_monad : val equal_error_monad :
@ -26,14 +32,14 @@ val equal_block_map : ?msg:string -> eq:('a -> 'a -> bool) -> 'a -> 'a -> unit
val equal_operation : val equal_operation :
?msg:string -> ?msg:string ->
(Hash.Operation_hash.t * State.Operation.operation) option -> (Operation_hash.t * State.Operation.operation) option ->
(Hash.Operation_hash.t * State.Operation.operation) option -> (Operation_hash.t * State.Operation.operation) option ->
unit unit
val equal_block : val equal_block :
?msg:string -> ?msg:string ->
(Hash.Block_hash.t * Store.block) option -> (Block_hash.t * Store.block) option ->
(Hash.Block_hash.t * Store.block) option -> (Block_hash.t * Store.block) option ->
unit unit
val equal_result : val equal_result :

View File

@ -78,7 +78,7 @@ let bootstrap_accounts () =
let create_account name = let create_account name =
let secret_key, public_key = Sodium.Sign.random_keypair () in let secret_key, public_key = Sodium.Sign.random_keypair () in
let public_key_hash = Ed25519.hash public_key in let public_key_hash = Environment.Ed25519.hash public_key in
let contract = Contract.default_contract public_key_hash in let contract = Contract.default_contract public_key_hash in
Lwt.return { name ; contract ; public_key_hash ; public_key ; secret_key } Lwt.return { name ; contract ; public_key_hash ; public_key ; secret_key }

View File

@ -18,11 +18,11 @@ let (//) = Filename.concat
let genesis_block = let genesis_block =
Block_hash.of_b48check Block_hash.of_b48check
"Et22nEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "eeeeeeeeeeeeeegqJHARhSaNXggmMs8K3tvsgn4rBprkvpFAMVD5d"
let genesis_protocol = let genesis_protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK"
let genesis_time = let genesis_time =
Time.of_seconds 0L Time.of_seconds 0L

View File

@ -16,11 +16,11 @@ let (//) = Filename.concat
let genesis_block = let genesis_block =
Block_hash.of_b48check Block_hash.of_b48check
"Et22nEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "eeeeeeeeeeeeeegqJHARhSaNXggmMs8K3tvsgn4rBprkvpFAMVD5d"
let genesis_protocol = let genesis_protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK"
let genesis_time = let genesis_time =
Time.of_seconds 0L Time.of_seconds 0L

View File

@ -18,11 +18,11 @@ let (//) = Filename.concat
let genesis_block = let genesis_block =
Block_hash.of_b48check Block_hash.of_b48check
"Et22nEeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "eeeeeeeeeeeeeegqJHARhSaNXggmMs8K3tvsgn4rBprkvpFAMVD5d"
let genesis_protocol = let genesis_protocol =
Protocol_hash.of_b48check Protocol_hash.of_b48check
"JF7Fxgeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" "2gagXCT66nmJ2mKh3a6Aeysy9CHaHsAJyDEGSyFNeFAxGCJehsKpK"
let genesis_time = let genesis_time =
Time.of_seconds 0L Time.of_seconds 0L
@ -88,6 +88,11 @@ let b2 = lolblock "Tacatlopo"
let bh2 = Store.Block.hash b2.data let bh2 = Store.Block.hash b2.data
let b3 = lolblock ~operations:[oph1;oph2] "Persil" let b3 = lolblock ~operations:[oph1;oph2] "Persil"
let bh3 = Store.Block.hash b3.data let bh3 = Store.Block.hash b3.data
let bh3' =
let raw = Bytes.of_string @@ Block_hash.to_raw bh3 in
Bytes.set raw 31 '\000' ;
Bytes.set raw 30 '\000' ;
Block_hash.of_raw @@ Bytes.to_string raw
let check_block s h b = let check_block s h b =
Block.full_get s h >>= function Block.full_get s h >>= function
@ -110,6 +115,20 @@ let test_block (s: Store.store) =
check_block s bh2 b2 >>= fun () -> check_block s bh2 b2 >>= fun () ->
check_block s bh3 b3) check_block s bh3 b3)
let test_expand (s: Store.store) =
Persist.use s.block (fun s ->
Block.full_set s bh1 b1 >>= fun () ->
Block.full_set s bh2 b2 >>= fun () ->
Block.full_set s bh3 b3 >>= fun () ->
Block.full_set s bh3' b3 >>= fun () ->
Base48.complete (Block_hash.to_short_b48check bh1) >>= fun res ->
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b48check bh1] ;
Base48.complete (Block_hash.to_short_b48check bh2) >>= fun res ->
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b48check bh2] ;
Base48.complete (Block_hash.to_short_b48check bh3) >>= fun res ->
Assert.equal_string_list ~msg:__LOC__ res [Block_hash.to_b48check bh3] ;
Lwt.return_unit)
(** Generic store *) (** Generic store *)
@ -235,6 +254,7 @@ let test_hashmap (s: Store.store) =
let tests : (string * (store -> unit Lwt.t)) list = [ let tests : (string * (store -> unit Lwt.t)) list = [
"init", test_init ; "init", test_init ;
"expand", test_expand ;
"operation", test_operation ; "operation", test_operation ;
"block", test_block ; "block", test_block ;
"generic", test_generic ; "generic", test_generic ;