Alpha: better error message when registering delegates
This commit is contained in:
parent
a95e601284
commit
040ac648eb
@ -12,6 +12,7 @@ type error +=
|
|||||||
| No_deletion of Ed25519.Public_key_hash.t (* `Permanent *)
|
| No_deletion of Ed25519.Public_key_hash.t (* `Permanent *)
|
||||||
| Active_delegate (* `Temporary *)
|
| Active_delegate (* `Temporary *)
|
||||||
| Current_delegate (* `Temporary *)
|
| Current_delegate (* `Temporary *)
|
||||||
|
| Empty_delegate_account of Ed25519.Public_key_hash.t (* `Temporary *)
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
register_error_kind
|
register_error_kind
|
||||||
@ -58,7 +59,20 @@ let () =
|
|||||||
"The contract is already delegated to the same delegate")
|
"The contract is already delegated to the same delegate")
|
||||||
Data_encoding.empty
|
Data_encoding.empty
|
||||||
(function Current_delegate -> Some () | _ -> None)
|
(function Current_delegate -> Some () | _ -> None)
|
||||||
(fun () -> Current_delegate)
|
(fun () -> Current_delegate) ;
|
||||||
|
register_error_kind
|
||||||
|
`Permanent
|
||||||
|
~id:"delegate.empty_delegate_account"
|
||||||
|
~title:"Empty delegate account"
|
||||||
|
~description:"Cannot register a delegate when its implicit account is empty"
|
||||||
|
~pp:(fun ppf delegate ->
|
||||||
|
Format.fprintf ppf
|
||||||
|
"Delegate registration is forbidden when the delegate
|
||||||
|
implicit account is empty (%a)"
|
||||||
|
Ed25519.Public_key_hash.pp delegate)
|
||||||
|
Data_encoding.(obj1 (req "delegate" Ed25519.Public_key_hash.encoding))
|
||||||
|
(function Empty_delegate_account c -> Some c | _ -> None)
|
||||||
|
(fun c -> Empty_delegate_account c)
|
||||||
|
|
||||||
let is_delegatable c contract =
|
let is_delegatable c contract =
|
||||||
match Contract_repr.is_implicit contract with
|
match Contract_repr.is_implicit contract with
|
||||||
@ -144,6 +158,10 @@ let set c contract delegate =
|
|||||||
fail Current_delegate
|
fail Current_delegate
|
||||||
| None | Some _ -> return ()
|
| None | Some _ -> return ()
|
||||||
end >>=? fun () ->
|
end >>=? fun () ->
|
||||||
|
Storage.Contract.Balance.mem c contract >>= fun exists ->
|
||||||
|
fail_when
|
||||||
|
(self_delegation && not exists)
|
||||||
|
(Empty_delegate_account delegate) >>=? fun () ->
|
||||||
Storage.Contract.Balance.get c contract >>=? fun balance ->
|
Storage.Contract.Balance.get c contract >>=? fun balance ->
|
||||||
unlink c contract balance >>=? fun c ->
|
unlink c contract balance >>=? fun c ->
|
||||||
Storage.Contract.Delegate.init_set c contract delegate >>= fun c ->
|
Storage.Contract.Delegate.init_set c contract delegate >>= fun c ->
|
||||||
|
Loading…
Reference in New Issue
Block a user