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
| Delegate_operations { source ; operations = contents } ->
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 () ->
(* 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 ->
apply_delegate_operation_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
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 unsigned_header = Block_header.forge_unsigned shell proto in
Ed25519.Signature.check key signature unsigned_header in

View File

@ -182,7 +182,7 @@ let () =
Data_encoding.(obj1 (req "message" string))
(function Failure s -> Some s | _ -> None)
(fun s -> Failure s)
let failwith msg = fail (Failure msg)
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
| Some _ -> Storage.Contract.Global_counter.get c) >>=? fun counter ->
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
match delegate with
| None -> return c
@ -303,23 +303,23 @@ let get_manager c contract =
let update_manager_key c contract = function
| Some public_key ->
begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> (* key revealed for the second time *)
if Ed25519.Public_key.(v = public_key) then return (c,v)
else fail (Inconsistent_public_key (v,public_key))
| (Manager_repr.Hash v) ->
let actual_hash = Ed25519.Public_key.hash public_key in
if (Ed25519.Public_key_hash.equal actual_hash v) then
let v = (Manager_repr.public_key public_key) in
Storage.Contract.Manager.set c contract v >>=? fun c ->
return (c,public_key) (* reveal and update key *)
else fail (Inconsistent_hash (public_key,v,actual_hash))
end
begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> (* key revealed for the second time *)
if Ed25519.Public_key.(v = public_key) then return (c,v)
else fail (Inconsistent_public_key (v,public_key))
| (Manager_repr.Hash v) ->
let actual_hash = Ed25519.Public_key.hash public_key in
if (Ed25519.Public_key_hash.equal actual_hash v) then
let v = (Manager_repr.Public_key public_key) in
Storage.Contract.Manager.set c contract v >>=? fun c ->
return (c,public_key) (* reveal and update key *)
else fail (Inconsistent_hash (public_key,v,actual_hash))
end
| None ->
begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> return (c,v) (* already revealed *)
| (Manager_repr.Hash v) -> fail (Missing_public_key (v))
end
begin Storage.Contract.Manager.get c contract >>=? function
| (Manager_repr.Public_key v) -> return (c,v) (* already revealed *)
| (Manager_repr.Hash v) -> fail (Missing_public_key (v))
end
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 update_manager_key:
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_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
let hash hash = Hash hash
let public_key hash = Public_key hash
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 =
case ~tag hash_encoding
(function
| Hash hash -> Some hash
| _ -> None)
(fun hash -> Hash hash)
case ~tag Ed25519.Public_key_hash.encoding
(function
| Hash hash -> Some hash
| _ -> None)
(fun hash -> Hash hash)
let pubkey_case tag =
case ~tag pubkey_encoding
(function
| Public_key hash -> Some hash
| _ -> None)
(fun hash -> Public_key hash)
case ~tag Ed25519.Public_key.encoding
(function
| Public_key hash -> Some hash
| _ -> None)
(fun hash -> Public_key hash)
let encoding =

View File

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

View File

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

View File

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