From b66963207552c53c91381c7f246afe773fc29507 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Fri, 20 Apr 2018 22:50:38 +0200 Subject: [PATCH] Alpha: check delegatable flag before removing the delegate --- src/proto_alpha/lib_protocol/src/delegate_storage.ml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/src/delegate_storage.ml b/src/proto_alpha/lib_protocol/src/delegate_storage.ml index bc618f02d..c696fcf9b 100644 --- a/src/proto_alpha/lib_protocol/src/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/src/delegate_storage.ml @@ -128,10 +128,14 @@ let set c contract delegate = | Some pkh -> fail (No_deletion pkh) | None -> - Storage.Contract.Balance.get c contract >>=? fun balance -> - unlink c contract balance >>=? fun c -> - Storage.Contract.Delegate.remove c contract >>= fun c -> - return c + is_delegatable c contract >>=? fun delegatable -> + if delegatable then + Storage.Contract.Balance.get c contract >>=? fun balance -> + unlink c contract balance >>=? fun c -> + Storage.Contract.Delegate.remove c contract >>= fun c -> + return c + else + fail (Non_delegatable_contract contract) end | Some delegate -> known c delegate >>=? fun known_delegate ->