Alpha: use recursive removal when possible

This commit is contained in:
Grégoire Henry 2017-11-19 18:00:04 +01:00 committed by Benjamin Canou
parent 450d0dba4e
commit 3fcc6df975
2 changed files with 5 additions and 10 deletions

View File

@ -47,10 +47,11 @@ let pay_rewards_for_cycle c cycle =
match c with
| Error _ -> Lwt.return c
| Ok c ->
Storage.Rewards.Amount.remove (c, cycle) delegate >>= fun c ->
Contract_storage.credit c
(Contract_repr.default_contract delegate)
amount)
amount) >>=? fun c ->
Storage.Rewards.Amount.clear (c, cycle) >>= fun c ->
return c
let pay_due_rewards c =
let timestamp = Raw_context.current_timestamp c in

View File

@ -18,15 +18,9 @@ let get_contract_delegate c contract =
| None -> Storage.Contract.Delegate.get_option c contract
let clear_cycle c cycle =
Storage.Roll.Last_for_cycle.get c cycle >>=? fun last ->
Storage.Roll.Last_for_cycle.delete c cycle >>=? fun c ->
let rec loop c roll =
if Roll_repr.(roll = last) then
return c
else
Storage.Roll.Owner_for_cycle.delete (c, cycle) roll >>=? fun c ->
loop c (Roll_repr.succ roll) in
loop c Roll_repr.first
Storage.Roll.Owner_for_cycle.clear (c, cycle) >>= fun c ->
return c
let fold ctxt ~f init =
Storage.Roll.Next.get ctxt >>=? fun last ->