WeiReceiver is an abstract smart contract. Every moneyflow node is a WeiReceiver. It can send ETH further or be a terminal node. In the last case it is called "a destination".
processFunds() – use this payable function to send ETH to the node;
isNeedsMoney() – returns true if node can receive ETH;
getMinWeiNeeded() – returns a minimum amount of ETH, which node will accept;
getTotalWeiNeeded() – returns a maximum amount of ETH, which node will accept.
The basic algorithm for moneyflow is to first request getTotalWeiNeed() from moneyflow entry point (root node), and then send ETH by calling processFunds() function with the correct amount.
There are 2 types of WeiReceivers currently:
Absolute - consumes absolute amounts of ETH, e.g.: 1 ETH;
Relative - consumes relative amounts of ETH, e.g.: 20%.
The difference between getMinWeiNeeded() or getTotalWeiNeed() exists only in cases when the current scheme has at least one relative receiver, or when minimal amount is not equal to total needed amount (absolute expense). If the scheme consists of absolute receivers with equal minimal amount and total needed amount only, the behavior of this two functions is the same.
// Consumes 10%WeiRelativeExpense relativeExpense = new WeiRelativeExpense(100000);bool isNeeds = relativeExpense.isNeedsMoney(); // trueuint minNeeded = relativeExpense.getMinWeiNeeded(); // 0uint totalNeeded = relativeExpense.getTotalWeiNeeded(100*eth); // 10*eth is 10% of 100 eth// will consume 10 ETHrelativeExpense.processFunds.value(totalNeeded)(100*eth);WeiAbsoluteExpense absoluteExpense = new WeiAbsoluteExpense(10*eth, 10*eth);isNeeds = absoluteExpense.isNeedsMoney(); // trueminNeeded = absoluteExpense.getMinWeiNeeded(); // 10*ethtotalNeeded = absoluteExpense.getTotalWeiNeeded(10*eth); // 10*eth// will consume 10 ETH one time only (but not less/more)absoluteExpense.processFunds.value(totalNeeded)(10*eth);