Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submission #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion DeadmansSwitch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ pragma solidity ^0.8.0;
contract DeadmansSwitch {
// TODO: Declare state variables
// Hint: You'll need variables for the owner, beneficiary, and last check-in block
address owner;
address beneficiary;
uint last_block;

// TODO: Implement constructor
constructor(address _beneficiary) {
constructor(address _beneficiary) payable {
// Hint: Initialize state variables
require(_beneficiary != address(0), "Beneficiary cannot be the zero address");
owner = msg.sender;
beneficiary = _beneficiary;
last_block = block.number;
}

// TODO: Implement still_alive function
function still_alive() public {
// Hint: Update the last check-in block
require(msg.sender == owner, "Only the owner can call this function");
last_block = getCurrentBlock();
}

// TODO: Implement release funds function
function releaseFunds() public {
// Hint: Check if 10 blocks have passed since last check-in
// If so, transfer the contract balance to the beneficiary
require(getCurrentBlock() > getLastCheckInBlock() + 10, "Owner is still alive!");
require(address(this).balance > 0, "No funds to release");

payable(beneficiary).transfer(address(this).balance);
}

// TODO: Implement receive function to allow the contract to receive Ether
Expand All @@ -27,6 +40,7 @@ contract DeadmansSwitch {
// Helper function for testing (optional)
function getLastCheckInBlock() public view returns (uint256) {
// TODO: Return the last check-in block
return last_block;
}

// Helper function for testing (optional)
Expand Down