Skip to content

Safeguard and Maintenance

Andreas E edited this page Jan 23, 2020 · 6 revisions

Safe-guard and Maintenance Functions of the Contract

Ideas and Brainstorming only, for now.

Main functions of the contract:

receive() external payable { } to receive coins from anybody, primarily from the mining pool, without them calling a function.

function splitAndPay(uint cost) public { } to split the coin balance of the contract (address(this).balance, in short this.balance) to transfer the covering cost to the costcenter and the remaining value to the beneficiary.

Safe-guarding:

  • We will apply no restriction to the payable receive function, as we allow the contract to receive funds from anybody without limitations.

  • Restrictions have to be considered to limit the permission to call the splitAndPay function, since we want to have it run with the proper amount of electricity costs for the mining facility, and only once a month roughly, particularly at the time when the mining facility has received their utility bill.

Therefore we will keep a hash table with the addresses of delegates to a boolean, a true indicating that they have been authorised to perform data changing calls to the contract: mapping(address => bool) delegates.

Any function that will change state data on the contract or does some value transfers, e.g. actually sending out coins to the costcenter and the beneficiary, will use a require function to ensure valid entry conditions for the function, in this case that the call is initiated by one of the delegates: require(delegates[msg.sender], "Permission was not delegated"). We'll see later that we safe-guard several functions with this restriction and therefore will make this a modifier onlyDelegates.

  • As a non-technical but functional safe-guard, maybe even as a business use-case, we may want to add a withdraw function that sends all remaining funds to a pre-defined address (maybe the contract owner). This function shall be technically simple, as a last-resort method if anything goes wrong but we have accumulated a fair amount of wealth.

Maintenance:

  • Having added restrictions as safe-guards for some specific functionality of the contract we need to add the possibility to change those restrictions:
    • function addDelegate(address _address) public onlyDelegates { delegates[_address] = true }
    • function delDelegate(address _address) public onlyDelegates { if (delegates[_address]) { delegates[_address] = false } }

Note that the constructor() function of the contract shall set an initial delegate (e.g. owner = msg.sender; delegates[owner] = true). Otherwise we renounce from the possibility to use restricted functions ourselves. Also, when revoking delegates we should safe-guard that safe-guard itself not to remove a very last remaining delegate, leaving the list of allowed ones empty.

  • We don't want to hard-code the payee addresses for the costcenter and the beneficiary into the contract, we rather want to have them as state variables which we can set and change. For this we'll add updatePayees() functions and restrict their access using the modifier to our list of delegates.

It makes sense to initiate those payee addresses with relevant wallet addresses when creating the contract, i.e. the constructor should take them as input.