编译器
0.4.18+commit.9cf6e910
文件 1 的 5:CoinBase.sol
pragma solidity ^0.4.18;
import "./Ownable.sol";
contract CoinBase is Ownable {
bool public constant implementsERC721 = true;
mapping(address => uint256) public coinBalance;
mapping(uint256 => address) public coinIdToOwner;
mapping(uint256 => address) public coinIdToApprovedAddress;
event Transfer(address indexed from, address indexed to, uint256 coinId);
event Approval(address indexed owner, address indexed approved, uint256 coinId);
function balanceOf(address walletAddress) public view returns (uint256 balance) {
return coinBalance[walletAddress];
}
function ownerOf(uint256 coinId) public view returns (address walletAddress) {
return coinIdToOwner[coinId];
}
function approve(address newCoinOwner, uint256 coinId) public {
require(coinIdToOwner[coinId] == msg.sender);
coinIdToApprovedAddress[coinId] = newCoinOwner;
Approval(msg.sender, newCoinOwner, coinId);
}
function approveTransfer(address newCoinOwner, uint256 coinId) public {
approve(newCoinOwner, coinId);
}
function approvedFor(uint256 coinId) public view returns (address approvedWallet) {
return coinIdToApprovedAddress[coinId];
}
function getApproved(uint256 coinId) public view returns (address approvedWallet) {
return approvedFor(coinId);
}
function takeOwnership(uint256 coinId) public {
require(coinIdToApprovedAddress[coinId] == msg.sender);
address _from = coinIdToOwner[coinId];
_transfer(_from, msg.sender, coinId);
}
function transferFrom(address currentCoinOwner, address newCoinOwner, uint256 coinId) public {
require(newCoinOwner != address(0));
require(newCoinOwner != address(this));
require(coinIdToApprovedAddress[coinId] == msg.sender);
require(coinIdToOwner[coinId] == currentCoinOwner);
_transfer(currentCoinOwner, newCoinOwner, coinId);
}
function transfer(address newCoinOwner, uint256 coinId) public {
require(newCoinOwner != address(0));
require(newCoinOwner != address(this));
require(coinIdToOwner[coinId] == msg.sender);
_transfer(msg.sender, newCoinOwner, coinId);
}
function _transfer(address currentCoinOwner, address newCoinOwner, uint256 coinId) internal {
if (coinIdToOwner[coinId] != address(0)) {
delete coinIdToApprovedAddress[coinId];
coinBalance[currentCoinOwner] -= 1;
}
coinIdToOwner[coinId] = newCoinOwner;
coinBalance[newCoinOwner] += 1;
Transfer(currentCoinOwner, newCoinOwner, coinId);
}
}
文件 2 的 5:Ownable.sol
pragma solidity ^0.4.18;
contract Ownable {
address public owner;
address public scriptAddress;
function Ownable() public {
owner = msg.sender;
scriptAddress = address(0);
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
modifier onlyOwnerOrScript() {
require(msg.sender == owner || msg.sender == scriptAddress);
_;
}
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
owner = newOwner;
}
function setScriptAddress(address newScriptAddress) public onlyOwner {
scriptAddress = newScriptAddress;
}
}
文件 3 的 5:TheValentineCoin.sol
pragma solidity ^0.4.18;
import "./Ownable.sol";
import "./CoinBase.sol";
import "./TheValentineCoinBase.sol";
import "./TheValentineCoinAdministration.sol";
contract TheValentineCoin is TheValentineCoinAdministration {
uint256 public constant coinPrice = 33 finney;
event ReservedCoin(address to);
function () public payable {
require(reservationActive == true);
require(msg.value >= coinPrice);
ReservedCoin(msg.sender);
}
function distributeCoin(uint256 coinId, address newCoinOwner, string coinEngraving) public onlyOwnerOrScript {
if (bytes(coinEngraving).length != 0) {
engravings[coinId] = coinEngraving;
}
_transfer(owner, newCoinOwner, coinId);
}
function destruct() public onlyOwner {
selfdestruct(owner);
}
}
文件 4 的 5:TheValentineCoinAdministration.sol
pragma solidity ^0.4.18;
import "./Ownable.sol";
import "./CoinBase.sol";
import "./TheValentineCoinBase.sol";
contract TheValentineCoinAdministration is TheValentineCoinBase {
bool public reservationActive;
function TheValentineCoinAdministration() public {
reservationActive = true;
}
function emergencyCoinErasure(uint256 coinId, string erasureReason) public onlyOwner {
require(bytes(engravings[coinId]).length != 0);
engravings[coinId] = erasureReason;
}
function sendMoneyToScript() public onlyOwner {
require(scriptAddress != address(0));
require(this.balance >= 33 finney);
scriptAddress.transfer(33 finney);
}
function toggleReservationState() public onlyOwnerOrScript {
reservationActive = !reservationActive;
}
function withdrawFunds() public onlyOwner {
owner.transfer(this.balance);
}
}
文件 5 的 5:TheValentineCoinBase.sol
pragma solidity ^0.4.18;
import "./Ownable.sol";
import "./CoinBase.sol";
contract TheValentineCoinBase is CoinBase {
string public constant name = "The Valentine Coin";
string public constant symbol = "VALENTINE";
uint256 public constant totalSupply = 33333;
mapping(uint256 => string) public engravings;
function engravingOf(uint256 coinId) public view returns (string coinEngraving) {
return engravings[coinId];
}
function engrave(uint256 coinId, string coinEngraving) public {
require(ownerOf(coinId) == msg.sender);
require(bytes(engravings[coinId]).length == 0);
require(bytes(coinEngraving).length > 0);
engravings[coinId] = coinEngraving;
}
}
{
"compilationTarget": {
"TheValentineCoin.sol": "TheValentineCoin"
},
"libraries": {},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"coinId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"approvedWallet","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newCoinOwner","type":"address"},{"name":"coinId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"implementsERC721","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"coinId","type":"uint256"},{"name":"coinEngraving","type":"string"}],"name":"engrave","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"currentCoinOwner","type":"address"},{"name":"newCoinOwner","type":"address"},{"name":"coinId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdrawFunds","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"coinId","type":"uint256"}],"name":"approvedFor","outputs":[{"name":"approvedWallet","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"destruct","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newScriptAddress","type":"address"}],"name":"setScriptAddress","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"scriptAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"coinId","type":"uint256"},{"name":"newCoinOwner","type":"address"},{"name":"coinEngraving","type":"string"}],"name":"distributeCoin","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"coinId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"walletAddress","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"walletAddress","type":"address"}],"name":"balanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"coinId","type":"uint256"}],"name":"engravingOf","outputs":[{"name":"coinEngraving","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"coinIdToOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"reservationActive","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newCoinOwner","type":"address"},{"name":"coinId","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"coinPrice","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"coinId","type":"uint256"}],"name":"takeOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"toggleReservationState","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"coinIdToApprovedAddress","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"sendMoneyToScript","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"coinId","type":"uint256"},{"name":"erasureReason","type":"string"}],"name":"emergencyCoinErasure","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"engravings","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newCoinOwner","type":"address"},{"name":"coinId","type":"uint256"}],"name":"approveTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"coinBalance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"to","type":"address"}],"name":"ReservedCoin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"coinId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"approved","type":"address"},{"indexed":false,"name":"coinId","type":"uint256"}],"name":"Approval","type":"event"}]