Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function rebalance(address user) returns (bool) {
uint currentTimestamp = block.timestamp;
if (currentTimestamp == priorRebalanceTimestamp) {
return true;
}
uint incomingDelta = 0;
for (incomingStream in incomingStreamsOf(user)) {
rebalance(incomingStream.sender);
uint streamBalanceOfRecipient = streamBalanceOfRecipient(incomingStream.id);
if (streamBalanceOfRecipient <= users[incomingStream.sender].balance) {
incomingDelta += streamBalanceOfRecipient;
} else {
delete streams[incomingDelta.id];
for (allRemainingIncomingStream in incomingStreamsOf(user)) {
delete streams[allRemainingIncomingStream.id];
}
break;
}
}
uint outgoingDelta = 0;
for (outgoingStream in outgoingStreamsOf(user)) {
rebalance(outgoingStream.recipient);
uint streamBalanceOfRecipient = streamBalanceOfRecipient(incomingStream.id);
if (streamBalanceOfRecipient <= users[incomingStream.sender].balance) {
incomingDelta += streamBalanceOfRecipient;
} else {
delete streams[incomingDelta.id];
for (allRemainingIncomingStream in incomingStreamsOf(user)) {
delete streams[allRemainingIncomingStream.id];
}
break;
}
}
uint newUserBalance = users[user].balance + incomeDelta - outgoingDelta;
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.