Multiple Beneficiaries
We want to have multiple beneficiaries, as opposed to a single one before.
So we remove the state variables receiver
and allowance
and introduce mapping (address=> uint) allowance;
Instead of having 2 withdraw functions, one for owner and one for beneficiary, we will have one withdraw function that can check ownership condition and has a modifier.
modifier ownerOrBeneficiary
ensures that only either the owner or a beneficiary can call the function.
For the second condition in the require statement.
We don't have a locked list of beneficiary addresses to compare against, so we will simply check if said address has a balance that can meet requested withdrawal amount.
function withdraw(...)
The nested if condition checks if its a beneficiary, if so, reduceAllowance()
is executed - this will update the balance of beneficiary.
We are being lazy with the withdrawal function for owner. In that, when the owner withdraws, balances are not updated. Also there is the question of accounting, from which addresses is he withdrawing from. Ignore this hole as it is a learning exmaple.
function reduceAllowance
made internal arbitrarily for inheritance stuff later.
Last updated