Created
October 29, 2021 22:57
-
-
Save hiroism007/86a44b7216d90a0302dae4be818a5b09 to your computer and use it in GitHub Desktop.
Test.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.1; | |
contract a42LockDev { | |
// 利用権 | |
struct Entitlement { | |
uint256 startTime; | |
uint256 endTime; | |
} | |
// アドレスごとの利用権のマッピング | |
mapping (address => Entitlement) internal entitlements; | |
// コントラクトの操作を行うアドレス | |
address constant internal owner = 0x1d5f4EcC1eD0983781Bd8b242bE33ea6C25a9a2C; | |
// 手数料/seconds | |
uint256 public fee = 0.00001 ether; | |
// 最低利用時間 | |
uint public minTime = 10 minutes; | |
modifier onlyOwner() { | |
require(msg.sender == owner); | |
_; | |
} | |
// 利用権を購入するメソッド | |
function buyEntitlement(address beneficiary, uint256 startTime, uint256 endTime) | |
payable | |
public | |
{ | |
require(beneficiary != address(0)); | |
require(endTime > startTime); | |
// 利用時間を計算 seconds | |
uint256 time = endTime - startTime; | |
require(time >= minTime); | |
// 手数料を計算 | |
uint256 price = time * fee; | |
// オーバーフロー対策 | |
// 本来は SafeMath を使うべき | |
require(price / time == fee); | |
require(msg.value >= price); | |
Entitlement storage entitlement = entitlements[beneficiary]; | |
entitlement.startTime = startTime; | |
entitlement.endTime = endTime; | |
} | |
// 利用権を確認するメソッド | |
function checkEntitlement(address wallet) | |
view | |
public | |
returns(bool) | |
{ | |
if (entitlements[wallet].startTime > now) { | |
return false; | |
} | |
if (entitlements[wallet].endTime < now) { | |
return false; | |
} | |
return true; | |
} | |
// 手数料を更新するメソッド | |
function updateFee(uint256 newFee) | |
onlyOwner | |
public | |
{ | |
fee = newFee; | |
} | |
// 手数料を引き出すメソッド | |
function withdraw(uint256 amount) | |
onlyOwner | |
public | |
{ | |
msg.sender.transfer(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment