Created
May 12, 2018 14:56
-
-
Save quilime/d93565c3fbf4f50d7fb55a89b6c81940 to your computer and use it in GitHub Desktop.
Simple License Expiration Example
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.4.4; | |
// ***************************************************************** | |
// DEMO!! UNVETTED CODE! DO NOT DEPLOY!!! | |
// Please seek expert guidance and perform a solidity security audit | |
// before using it in financially important code. | |
// ***************************************************************** | |
contract ArtLicenseExpiration { | |
address public artwork; // the artwork -- artist has the public/private key | |
address public buyer; // the buyer of the piece -- who bought the piece | |
uint256 expirationDate = 1544590800; // 12/12/2018 @ 12:00pm (UTC) | |
constructor(address _buyer) public { | |
// immutible -- you could make this modifiable if | |
// you were to sell the art to another buyer | |
buyer = _buyer; | |
artwork = msg.sender; | |
} | |
function isExpired() public returns(bool) { | |
require(msg.sender == artwork, "Only the art can call this function."); | |
// use of "now": "now" does not mean current time. | |
// Now is an alias for block.timestamp. Block.timestamp can be influenced | |
// by miners to a certain degree, be careful. | |
return (now >= expirationDate); | |
} | |
function setExpirationDate() public(uint256 _expirationDate) { | |
require(msg.sender == artwork, "Only the art can call this function."); | |
expirationDate = _expirationDate; | |
} | |
function() payable { | |
// maybe anyone can renew the license? The buyer would still own it | |
require(msg.sender == buyer, "Only the buyer can call this function."); | |
// here is where you calculate how much you want to charge for time. | |
// in this example the artwork is worth 1 Wei = 1 second of time | |
// this is a VERY expensive piece :) | |
expirationDate += msg.value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment