Alpha: do not produce multiple revelations
This commit is contained in:
parent
89d9d83b15
commit
dcf27f48d9
@ -456,6 +456,8 @@ module Contract : sig
|
|||||||
|
|
||||||
val get_manager_key:
|
val get_manager_key:
|
||||||
context -> contract -> public_key tzresult Lwt.t
|
context -> contract -> public_key tzresult Lwt.t
|
||||||
|
val is_manager_key_revealed:
|
||||||
|
context -> contract -> bool tzresult Lwt.t
|
||||||
|
|
||||||
val reveal_manager_key:
|
val reveal_manager_key:
|
||||||
context -> contract -> public_key -> context tzresult Lwt.t
|
context -> contract -> public_key -> context tzresult Lwt.t
|
||||||
|
@ -60,6 +60,16 @@ module S = struct
|
|||||||
~output: (obj1 (req "manager" Signature.Public_key_hash.encoding))
|
~output: (obj1 (req "manager" Signature.Public_key_hash.encoding))
|
||||||
RPC_path.(custom_root /: Contract.arg / "manager")
|
RPC_path.(custom_root /: Contract.arg / "manager")
|
||||||
|
|
||||||
|
let manager_key =
|
||||||
|
RPC_service.post_service
|
||||||
|
~description: "Access the manager of a contract."
|
||||||
|
~query: RPC_query.empty
|
||||||
|
~input: empty
|
||||||
|
~output: (obj2
|
||||||
|
(req "manager" Signature.Public_key_hash.encoding)
|
||||||
|
(opt "key" Signature.Public_key.encoding))
|
||||||
|
RPC_path.(custom_root /: Contract.arg / "manager_key")
|
||||||
|
|
||||||
let delegate =
|
let delegate =
|
||||||
RPC_service.post_service
|
RPC_service.post_service
|
||||||
~description: "Access the delegate of a contract, if any."
|
~description: "Access the delegate of a contract, if any."
|
||||||
@ -148,6 +158,14 @@ let () =
|
|||||||
| Some v -> return v) in
|
| Some v -> return v) in
|
||||||
register_field S.balance Contract.get_balance ;
|
register_field S.balance Contract.get_balance ;
|
||||||
register_field S.manager Contract.get_manager ;
|
register_field S.manager Contract.get_manager ;
|
||||||
|
register_field S.manager_key
|
||||||
|
(fun ctxt c ->
|
||||||
|
Contract.get_manager ctxt c >>=? fun mgr ->
|
||||||
|
Contract.is_manager_key_revealed ctxt c >>=? fun revealed ->
|
||||||
|
if revealed then
|
||||||
|
Contract.get_manager_key ctxt c >>=? fun key ->
|
||||||
|
return (mgr, Some key)
|
||||||
|
else return (mgr, None)) ;
|
||||||
register_opt_field S.delegate Delegate.get ;
|
register_opt_field S.delegate Delegate.get ;
|
||||||
register_field S.counter Contract.get_counter ;
|
register_field S.counter Contract.get_counter ;
|
||||||
register_field S.spendable Contract.is_spendable ;
|
register_field S.spendable Contract.is_spendable ;
|
||||||
@ -179,6 +197,9 @@ let balance ctxt block contract =
|
|||||||
let manager ctxt block contract =
|
let manager ctxt block contract =
|
||||||
RPC_context.make_call1 S.manager ctxt block contract () ()
|
RPC_context.make_call1 S.manager ctxt block contract () ()
|
||||||
|
|
||||||
|
let manager_key ctxt block contract =
|
||||||
|
RPC_context.make_call1 S.manager_key ctxt block contract () ()
|
||||||
|
|
||||||
let delegate ctxt block contract =
|
let delegate ctxt block contract =
|
||||||
RPC_context.make_call1 S.delegate ctxt block contract () ()
|
RPC_context.make_call1 S.delegate ctxt block contract () ()
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ val balance:
|
|||||||
val manager:
|
val manager:
|
||||||
'a #RPC_context.simple -> 'a -> Contract.t -> public_key_hash shell_tzresult Lwt.t
|
'a #RPC_context.simple -> 'a -> Contract.t -> public_key_hash shell_tzresult Lwt.t
|
||||||
|
|
||||||
|
val manager_key:
|
||||||
|
'a #RPC_context.simple -> 'a -> Contract.t -> (public_key_hash * public_key option) shell_tzresult Lwt.t
|
||||||
|
|
||||||
val delegate:
|
val delegate:
|
||||||
'a #RPC_context.simple -> 'a -> Contract.t -> public_key_hash shell_tzresult Lwt.t
|
'a #RPC_context.simple -> 'a -> Contract.t -> public_key_hash shell_tzresult Lwt.t
|
||||||
|
|
||||||
|
@ -295,6 +295,12 @@ let get_manager_key c contract =
|
|||||||
| Some (Manager_repr.Hash _) -> fail (Unrevealed_manager_key contract)
|
| Some (Manager_repr.Hash _) -> fail (Unrevealed_manager_key contract)
|
||||||
| Some (Manager_repr.Public_key v) -> return v
|
| Some (Manager_repr.Public_key v) -> return v
|
||||||
|
|
||||||
|
let is_manager_key_revealed c contract =
|
||||||
|
Storage.Contract.Manager.get_option c contract >>=? function
|
||||||
|
| None -> return false
|
||||||
|
| Some (Manager_repr.Hash _) -> return false
|
||||||
|
| Some (Manager_repr.Public_key _) -> return true
|
||||||
|
|
||||||
let reveal_manager_key c contract public_key =
|
let reveal_manager_key c contract public_key =
|
||||||
Storage.Contract.Manager.get c contract >>=? function
|
Storage.Contract.Manager.get c contract >>=? function
|
||||||
| Public_key _ -> fail (Previously_revealed_key contract)
|
| Public_key _ -> fail (Previously_revealed_key contract)
|
||||||
|
@ -45,6 +45,8 @@ val get_manager:
|
|||||||
|
|
||||||
val get_manager_key:
|
val get_manager_key:
|
||||||
Raw_context.t -> Contract_repr.t -> Signature.Public_key.t tzresult Lwt.t
|
Raw_context.t -> Contract_repr.t -> Signature.Public_key.t tzresult Lwt.t
|
||||||
|
val is_manager_key_revealed:
|
||||||
|
Raw_context.t -> Contract_repr.t -> bool tzresult Lwt.t
|
||||||
|
|
||||||
val reveal_manager_key:
|
val reveal_manager_key:
|
||||||
Raw_context.t -> Contract_repr.t -> Signature.Public_key.t ->
|
Raw_context.t -> Contract_repr.t -> Signature.Public_key.t ->
|
||||||
|
@ -298,7 +298,13 @@ module Forge = struct
|
|||||||
|
|
||||||
let operations ctxt
|
let operations ctxt
|
||||||
block ~branch ~source ?sourcePubKey ~counter ~fee operations =
|
block ~branch ~source ?sourcePubKey ~counter ~fee operations =
|
||||||
|
Contract_services.manager_key ctxt block source >>= function
|
||||||
|
| Error _ as e -> Lwt.return e
|
||||||
|
| Ok (_, revealed) ->
|
||||||
let operations =
|
let operations =
|
||||||
|
match revealed with
|
||||||
|
| Some _ -> operations
|
||||||
|
| None ->
|
||||||
match sourcePubKey with
|
match sourcePubKey with
|
||||||
| None -> operations
|
| None -> operations
|
||||||
| Some pk -> Reveal pk :: operations in
|
| Some pk -> Reveal pk :: operations in
|
||||||
|
@ -181,6 +181,7 @@ let contain_error_alpha ?msg ~f = function
|
|||||||
let unknown_contract ~msg =
|
let unknown_contract ~msg =
|
||||||
let f = function
|
let f = function
|
||||||
| Proto_alpha.Raw_context.Storage_error _ -> true
|
| Proto_alpha.Raw_context.Storage_error _ -> true
|
||||||
|
| Proto_alpha.Contract_storage.Empty_implicit_contract _ -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
in
|
in
|
||||||
contain_error_alpha ~msg ~f
|
contain_error_alpha ~msg ~f
|
||||||
|
@ -17,13 +17,14 @@ let manager (src : Helpers_account.t) ?(fee = Tez.zero) operations context =
|
|||||||
Alpha_context.prepare
|
Alpha_context.prepare
|
||||||
~level:0l ~timestamp:(Time.now ()) ~fitness:[] context >>=? fun context ->
|
~level:0l ~timestamp:(Time.now ()) ~fitness:[] context >>=? fun context ->
|
||||||
Contract.get_counter context src.contract >>=? fun counter ->
|
Contract.get_counter context src.contract >>=? fun counter ->
|
||||||
|
Contract.is_manager_key_revealed context src.contract >>=? fun revealed ->
|
||||||
let counter = Int32.succ counter in
|
let counter = Int32.succ counter in
|
||||||
return @@
|
return @@
|
||||||
Manager_operations {
|
Manager_operations {
|
||||||
source = src.contract ;
|
source = src.contract ;
|
||||||
fee ;
|
fee ;
|
||||||
counter ;
|
counter ;
|
||||||
operations = Reveal src.pub :: operations ;
|
operations = (if revealed then operations else Reveal src.pub :: operations) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user