Skip to content

Instantly share code, notes, and snippets.

@pirapira
Last active October 19, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirapira/6d32c42fc0ff32e2ebc08e50f477db35 to your computer and use it in GitHub Desktop.
Save pirapira/6d32c42fc0ff32e2ebc08e50f477db35 to your computer and use it in GitHub Desktop.
// This code does not compile yet.
// Should Bamboo support this kind of nesting contracts, which represent substates and a superstate?
contract Alive(address hotWallet, address vaultKey, address recoveryKey) {
case(void destroy()) {
if (sender(msg) != recoveryKey) abort;
return then become Destroyed();
}
case(void recover(address _newHotWallet)) {
if (sender(msg) != recoveryKey) abort;
return then become Alive(hotWallet, vaultKey, recoveryKey).Vault();
}
contract Vault() {
case(void unvault(uint256 amount)) {
if (sender(msg) != vaultKey) abort;
uint256 unvaultPeriod = 60 * 60 * 24 * 7 * 2; // two weeks
if (now(block) + unvaultPeriod < now(block)) abort;
return then become Alive(hotWallet, vaultKey, recoveryKey).UnVaulting(now(block) + unvaultPeriod, amount);
}
}
contract UnVaulting(uint256 redeemtime, uint256 amount) {
case(void redeem()) {
if (amount > balance(this)) abort;
void = hotwallet.default() with amount reentrance { abort; };
return then become Alive(hotwallet, vaultKey, recoveryKey).Vault();
}
}
}
contract Destroyed() {
// any call just throws;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment