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

Solution for week-2 unidao updated #16

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
72 changes: 42 additions & 30 deletions DeadmansSwitch.sol
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// SPDX-License-Identifier: MIT
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
contract DeadmansSwitch {
// TODO: Declare state variables
// Hint: You'll need variables for the owner, beneficiary, and last check-in block
address beneficiary;
address owner;
uint256 lastCheckIn;
// TODO: Implement constructor
constructor(address _beneficiary) {
// Hint: Initialize state variables
beneficiary = _beneficiary;
owner = msg.sender;
lastCheckIn = block.number;
}

// TODO: Implement constructor
constructor(address _beneficiary) {
// Hint: Initialize state variables
}
// TODO: Implement still_alive function
function still_alive() public {
// Hint: Update the last check-in block
require(msg.sender == owner,"Only owner can send still_alive calls");
lastCheckIn=block.number;
}

// TODO: Implement still_alive function
function still_alive() public {
// Hint: Update the last check-in block
}
// 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(block.number > 10 + lastCheckIn,"Owner is Still alive"); // checking whether the period is over
require(address(this).balance > 0,"No balance to transfer");
payable(beneficiary).transfer(address(this).balance);

// 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
}
}
// event received(address , uint);
// TODO: Implement receive function to allow the contract to receive Ether
receive() external payable {}

// TODO: Implement receive function to allow the contract to receive Ether
receive() external payable {}
// Helper function for testing (optional)
function getLastCheckInBlock() public view returns (uint256) {
// TODO: Return the last check-in block
return lastCheckIn;
}

// Helper function for testing (optional)
function getLastCheckInBlock() public view returns (uint256) {
// TODO: Return the last check-in block
}

// Helper function for testing (optional)
function getCurrentBlock() public view returns (uint256) {
return block.number;
}
}
// Helper function for testing (optional)
function getCurrentBlock() public view returns (uint256) {
return block.number;
}
}