Skip to content

Instantly share code, notes, and snippets.

@quilime
Created May 12, 2018 14:56
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 quilime/d93565c3fbf4f50d7fb55a89b6c81940 to your computer and use it in GitHub Desktop.
Save quilime/d93565c3fbf4f50d7fb55a89b6c81940 to your computer and use it in GitHub Desktop.
Simple License Expiration Example
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