From 2eaae225ffbfe0a4dedd3a4a4eb4b0200cd58fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Thu, 15 Mar 2018 13:16:06 +0100 Subject: [PATCH] Alpha: forbid delegation to the current delegate --- .../lib_protocol/src/delegate_storage.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/proto_alpha/lib_protocol/src/delegate_storage.ml b/src/proto_alpha/lib_protocol/src/delegate_storage.ml index 6fe8bc01e..24e5c810b 100644 --- a/src/proto_alpha/lib_protocol/src/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/src/delegate_storage.ml @@ -10,6 +10,8 @@ type error += | Non_delegatable_contract of Contract_repr.contract (* `Permanent *) | No_deletion of Ed25519.Public_key_hash.t (* `Permanent *) + | Active_delegate (* `Temporary *) + | Current_delegate (* `Temporary *) let () = register_error_kind @@ -108,6 +110,18 @@ let set c contract delegate = else if not (delegatable || self_delegation) then fail (Non_delegatable_contract contract) else + begin + Storage.Contract.Delegate.get_option c contract >>=? function + | Some current_delegate + when Ed25519.Public_key_hash.equal delegate current_delegate -> + if self_delegation then + Storage.Contract.Inactive_delegate.mem c contract >>= function + | true -> return () + | false -> fail Active_delegate + else + fail Current_delegate + | None | Some _ -> return () + end >>=? fun () -> Storage.Contract.Balance.get c contract >>=? fun balance -> unlink c contract balance >>=? fun c -> Storage.Contract.Delegate.init_set c contract delegate >>= fun c ->