Proto: Rename Public_key to Delegates_pubkey

This commit is contained in:
Pietro Abate 2017-11-13 12:32:05 +01:00 committed by Benjamin Canou
parent de8967540f
commit 102ba49149
8 changed files with 39 additions and 51 deletions

View File

@ -174,10 +174,10 @@ let apply_sourced_operation
(ctxt, origination_nonce, None) contents (ctxt, origination_nonce, None) contents
| Delegate_operations { source ; operations = contents } -> | Delegate_operations { source ; operations = contents } ->
let delegate = Ed25519.Public_key.hash source in let delegate = Ed25519.Public_key.hash source in
Public_key.reveal ctxt delegate source >>=? fun ctxt -> Delegates_pubkey.reveal ctxt delegate source >>=? fun ctxt ->
Operation.check_signature source operation >>=? fun () -> Operation.check_signature source operation >>=? fun () ->
(* TODO, see how to extract the public key hash after this operation to (* TODO, see how to extract the public key hash after this operation to
pass it to apply_delegate_operation_content *) pass it to apply_delegate_operation_content *)
fold_left_s (fun ctxt content -> fold_left_s (fun ctxt content ->
apply_delegate_operation_content apply_delegate_operation_content
ctxt delegate pred_block block_prio content) ctxt delegate pred_block block_prio content)

View File

@ -232,7 +232,7 @@ let check_proof_of_work_stamp ctxt block =
fail Invalid_stamp fail Invalid_stamp
let check_signature ctxt block id = let check_signature ctxt block id =
Public_key.get ctxt id >>=? fun key -> Delegates_pubkey.get ctxt id >>=? fun key ->
let check_signature key { Block_header.proto ; shell ; signature } = let check_signature key { Block_header.proto ; shell ; signature } =
let unsigned_header = Block_header.forge_unsigned shell proto in let unsigned_header = Block_header.forge_unsigned shell proto in
Ed25519.Signature.check key signature unsigned_header in Ed25519.Signature.check key signature unsigned_header in

View File

@ -182,7 +182,7 @@ let () =
Data_encoding.(obj1 (req "message" string)) Data_encoding.(obj1 (req "message" string))
(function Failure s -> Some s | _ -> None) (function Failure s -> Some s | _ -> None)
(fun s -> Failure s) (fun s -> Failure s)
let failwith msg = fail (Failure msg) let failwith msg = fail (Failure msg)
let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~delegatable = let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~delegatable =
@ -190,7 +190,7 @@ let create_base c contract ~balance ~manager ~delegate ?script ~spendable ~deleg
| None -> return 0l | None -> return 0l
| Some _ -> Storage.Contract.Global_counter.get c) >>=? fun counter -> | Some _ -> Storage.Contract.Global_counter.get c) >>=? fun counter ->
Storage.Contract.Balance.init c contract balance >>=? fun c -> Storage.Contract.Balance.init c contract balance >>=? fun c ->
Storage.Contract.Manager.init c contract (Manager_repr.hash manager) >>=? fun c -> Storage.Contract.Manager.init c contract (Manager_repr.Hash manager) >>=? fun c ->
begin begin
match delegate with match delegate with
| None -> return c | None -> return c
@ -303,23 +303,23 @@ let get_manager c contract =
let update_manager_key c contract = function let update_manager_key c contract = function
| Some public_key -> | Some public_key ->
begin Storage.Contract.Manager.get c contract >>=? function begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> (* key revealed for the second time *) | (Manager_repr.Public_key v) -> (* key revealed for the second time *)
if Ed25519.Public_key.(v = public_key) then return (c,v) if Ed25519.Public_key.(v = public_key) then return (c,v)
else fail (Inconsistent_public_key (v,public_key)) else fail (Inconsistent_public_key (v,public_key))
| (Manager_repr.Hash v) -> | (Manager_repr.Hash v) ->
let actual_hash = Ed25519.Public_key.hash public_key in let actual_hash = Ed25519.Public_key.hash public_key in
if (Ed25519.Public_key_hash.equal actual_hash v) then if (Ed25519.Public_key_hash.equal actual_hash v) then
let v = (Manager_repr.public_key public_key) in let v = (Manager_repr.Public_key public_key) in
Storage.Contract.Manager.set c contract v >>=? fun c -> Storage.Contract.Manager.set c contract v >>=? fun c ->
return (c,public_key) (* reveal and update key *) return (c,public_key) (* reveal and update key *)
else fail (Inconsistent_hash (public_key,v,actual_hash)) else fail (Inconsistent_hash (public_key,v,actual_hash))
end end
| None -> | None ->
begin Storage.Contract.Manager.get c contract >>=? function begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> return (c,v) (* already revealed *) | (Manager_repr.Public_key v) -> return (c,v) (* already revealed *)
| (Manager_repr.Hash v) -> fail (Missing_public_key (v)) | (Manager_repr.Hash v) -> fail (Missing_public_key (v))
end end
let get_delegate_opt = Roll_storage.get_contract_delegate let get_delegate_opt = Roll_storage.get_contract_delegate

View File

@ -37,7 +37,7 @@ val is_spendable : Storage.t -> Contract_repr.t -> bool tzresult Lwt.t
val get_manager: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t val get_manager: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t tzresult Lwt.t
val update_manager_key: val update_manager_key:
Storage.t -> Contract_repr.t -> Ed25519.Public_key.t option -> Storage.t -> Contract_repr.t -> Ed25519.Public_key.t option ->
(Storage.t * Ed25519.Public_key.t) tzresult Lwt.t (Storage.t * Ed25519.Public_key.t) tzresult Lwt.t
val get_delegate_opt: Storage.t -> Contract_repr.t -> Ed25519.Public_key_hash.t 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

View File

@ -15,34 +15,21 @@ type manager_key =
type t = manager_key type t = manager_key
let hash hash = Hash hash
let public_key hash = Public_key hash
open Data_encoding open Data_encoding
let hash_encoding =
(obj1
(req "hash" Ed25519.Public_key_hash.encoding)
)
let pubkey_encoding =
(obj1
(req "public_key" Ed25519.Public_key.encoding)
)
let hash_case tag = let hash_case tag =
case ~tag hash_encoding case ~tag Ed25519.Public_key_hash.encoding
(function (function
| Hash hash -> Some hash | Hash hash -> Some hash
| _ -> None) | _ -> None)
(fun hash -> Hash hash) (fun hash -> Hash hash)
let pubkey_case tag = let pubkey_case tag =
case ~tag pubkey_encoding case ~tag Ed25519.Public_key.encoding
(function (function
| Public_key hash -> Some hash | Public_key hash -> Some hash
| _ -> None) | _ -> None)
(fun hash -> Public_key hash) (fun hash -> Public_key hash)
let encoding = let encoding =

View File

@ -185,11 +185,11 @@ let () = register0 Services.Context.Nonce.hash nonce_hash
(*-- Context.Key -------------------------------------------------------------*) (*-- Context.Key -------------------------------------------------------------*)
let get_key ctxt hash () = let get_key ctxt hash () =
Public_key.get ctxt hash >>=? fun pk -> Delegates_pubkey.get ctxt hash >>=? fun pk ->
return (hash, pk) return (hash, pk)
let () = register2 Services.Context.Key.get get_key let () = register2 Services.Context.Key.get get_key
let () = register0 Services.Context.Key.list Public_key.list let () = register0 Services.Context.Key.list Delegates_pubkey.list
(*-- Context.Contract --------------------------------------------------------*) (*-- Context.Contract --------------------------------------------------------*)
@ -469,7 +469,7 @@ let operation_public_key ctxt = function
| None -> return None | None -> return None
| Some public_key -> | Some public_key ->
let hash = Ed25519.Public_key.hash public_key in let hash = Ed25519.Public_key.hash public_key in
Public_key.get_option ctxt hash >>=? function Delegates_pubkey.get_option ctxt hash >>=? function
| None -> return (Some public_key) | None -> return (Some public_key)
| Some _ -> return None | Some _ -> return None
@ -499,7 +499,7 @@ let check_signature ctxt signature shell contents =
| Some key -> return key | Some key -> return key
| None -> | None ->
Contract.get_manager ctxt op.source >>=? fun manager -> Contract.get_manager ctxt op.source >>=? fun manager ->
Public_key.get ctxt manager Delegates_pubkey.get ctxt manager
end >>=? fun public_key -> end >>=? fun public_key ->
Operation.check_signature public_key Operation.check_signature public_key
{ signature ; shell ; contents ; hash = dummy_hash } { signature ; shell ; contents ; hash = dummy_hash }

View File

@ -87,7 +87,7 @@ module Constants = struct
constants.dictator_pubkey constants.dictator_pubkey
end end
module Public_key = Public_key_storage module Delegates_pubkey = Public_key_storage
module Voting_period = Voting_period_repr module Voting_period = Voting_period_repr

View File

@ -282,7 +282,8 @@ module Constants : sig
end end
module Public_key : sig (** Global storage for all delegates public keys *)
module Delegates_pubkey : sig
val get: val get:
context -> public_key_hash -> public_key tzresult Lwt.t context -> public_key_hash -> public_key tzresult Lwt.t