Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
CryptoPunks v1 vs. v2
作成日
4 年前
差分は期限切れになりません
クリア
エクスポート
共有
説明
21 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
140 行
すべてコピー
129 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
250 行
すべてコピー
/**
/**
コピー
コピー済み
コピー
コピー済み
*Submitted for verification at Etherscan.io on 2017-
06-17
*Submitted for verification at Etherscan.io on 2017-
07-19
*/
*/
pragma solidity ^0.4.8;
pragma solidity ^0.4.8;
コピー
コピー済み
コピー
コピー済み
contract CryptoPunks
{
contract CryptoPunks
Market
{
// You can use this hash to verify the image file containing all the punks
// You can use this hash to verify the image file containing all the punks
string public imageHash = "ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b";
string public imageHash = "ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b";
address owner;
address owner;
string public standard = 'CryptoPunks';
string public standard = 'CryptoPunks';
string public name;
string public name;
string public symbol;
string public symbol;
uint8 public decimals;
uint8 public decimals;
uint256 public totalSupply;
uint256 public totalSupply;
uint public nextPunkIndexToAssign = 0;
uint public nextPunkIndexToAssign = 0;
コピー
コピー済み
コピー
コピー済み
//
bool public allPunksAssigned = false;
bool public allPunksAssigned = false;
uint public punksRemainingToAssign = 0;
uint public punksRemainingToAssign = 0;
コピー
コピー済み
コピー
コピー済み
uint public numberOfPunksToReserve;
uint public numberOfPunksReserved = 0;
//mapping (address => uint) public addressToPunkIndex;
//mapping (address => uint) public addressToPunkIndex;
mapping (uint => address) public punkIndexToAddress;
mapping (uint => address) public punkIndexToAddress;
/* This creates an array with all balances */
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public balanceOf;
struct Offer {
struct Offer {
bool isForSale;
bool isForSale;
uint punkIndex;
uint punkIndex;
address seller;
address seller;
uint minValue; // in ether
uint minValue; // in ether
address onlySellTo; // specify to sell only to a specific person
address onlySellTo; // specify to sell only to a specific person
}
}
コピー
コピー済み
コピー
コピー済み
struct Bid {
bool hasBid;
uint punkIndex;
address bidder;
uint value;
}
// A record of punks that are offered for sale at a specific minimum value, and perhaps to a specific person
// A record of punks that are offered for sale at a specific minimum value, and perhaps to a specific person
mapping (uint => Offer) public punksOfferedForSale;
mapping (uint => Offer) public punksOfferedForSale;
コピー
コピー済み
コピー
コピー済み
// A record of the highest punk bid
mapping (uint => Bid) public punkBids;
mapping (address => uint) public pendingWithdrawals;
mapping (address => uint) public pendingWithdrawals;
event Assign(address indexed to, uint256 punkIndex);
event Assign(address indexed to, uint256 punkIndex);
event Transfer(address indexed from, address indexed to, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);
event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex);
event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex);
event PunkOffered(uint indexed punkIndex, uint minValue, address indexed toAddress);
event PunkOffered(uint indexed punkIndex, uint minValue, address indexed toAddress);
コピー
コピー済み
コピー
コピー済み
event PunkBidEntered(uint indexed punkIndex, uint value, address indexed fromAddress);
event PunkBidWithdrawn(uint indexed punkIndex, uint value, address indexed fromAddress);
event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress);
event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress);
event PunkNoLongerForSale(uint indexed punkIndex);
event PunkNoLongerForSale(uint indexed punkIndex);
/* Initializes contract with initial supply tokens to the creator of the contract */
/* Initializes contract with initial supply tokens to the creator of the contract */
コピー
コピー済み
コピー
コピー済み
function CryptoPunks
() payable {
function CryptoPunks
Market
() payable {
// balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
// balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
owner = msg.sender;
owner = msg.sender;
totalSupply = 10000; // Update total supply
totalSupply = 10000; // Update total supply
punksRemainingToAssign = totalSupply;
punksRemainingToAssign = totalSupply;
コピー
コピー済み
コピー
コピー済み
numberOfPunksToReserve = 1000;
name = "CRYPTOPUNKS"; // Set the name for display purposes
name = "CRYPTOPUNKS"; // Set the name for display purposes
symbol = "Ͼ"; // Set the symbol for display purposes
symbol = "Ͼ"; // Set the symbol for display purposes
decimals = 0; // Amount of decimals for display purposes
decimals = 0; // Amount of decimals for display purposes
}
}
コピー
コピー済み
コピー
コピー済み
function
reservePunksForOwner(
uint
maxForThisRun
) {
function
setInitialOwner(address to,
uint
punkIndex
) {
if (msg.sender != owner) throw;
if (msg.sender != owner) throw;
コピー
コピー済み
コピー
コピー済み
if (
numberOfPunksReserved >= numberOfPunksToReserve
) throw;
if (
allPunksAssigned
) throw;
uint numberPunksReservedThisRun = 0
;
if (punkIndex >= 10000) throw
;
while (numberOfPunksReserved < numberOfPunksToReserve && numberPunksReservedThisRun < maxForThisRun) {
if (punkIndexToAddress[punkIndex] != to) {
punkIndexToAddress[nextPunkIndexToAssign] = msg.sender;
if (punkIndexToAddress[punkIndex] != 0x0) {
Assign(msg.sender, nextPunkIndexToAssign);
balanceOf[punkIndexToAddress[punkIndex]]--;
numberPunksReservedThisRun++;
} else {
nextPunkIndexToAssign++
;
punksRemainingToAssign--;
}
punkIndexToAddress[punkIndex] = to;
balanceOf[to]++;
Assign(to, punkIndex)
;
}
}
コピー
コピー済み
コピー
コピー済み
punksRemainingToAssign -= numberPunksReservedThisRun;
}
numberOfPunksReserved += numberPunksReservedThisRun;
balanceOf[msg.sender] += numberPunksReservedThisRun;
function setInitialOwners(address[] addresses, uint[] indices) {
if (msg.sender != owner) throw;
uint n = addresses.length;
for (uint i = 0; i < n; i++) {
setInitialOwner(addresses[i], indices[i]);
}
}
function allInitialOwnersAssigned() {
if (msg.sender != owner) throw;
allPunksAssigned = true;
}
}
function getPunk(uint punkIndex) {
function getPunk(uint punkIndex) {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
if (punksRemainingToAssign == 0) throw;
if (punksRemainingToAssign == 0) throw;
if (punkIndexToAddress[punkIndex] != 0x0) throw;
if (punkIndexToAddress[punkIndex] != 0x0) throw;
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
punkIndexToAddress[punkIndex] = msg.sender;
punkIndexToAddress[punkIndex] = msg.sender;
balanceOf[msg.sender]++;
balanceOf[msg.sender]++;
punksRemainingToAssign--;
punksRemainingToAssign--;
Assign(msg.sender, punkIndex);
Assign(msg.sender, punkIndex);
}
}
// Transfer ownership of a punk to another user without requiring payment
// Transfer ownership of a punk to another user without requiring payment
function transferPunk(address to, uint punkIndex) {
function transferPunk(address to, uint punkIndex) {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
if (punksOfferedForSale[punkIndex].isForSale) {
punkNoLongerForSale(punkIndex);
}
punkIndexToAddress[punkIndex] = to;
punkIndexToAddress[punkIndex] = to;
balanceOf[msg.sender]--;
balanceOf[msg.sender]--;
balanceOf[to]++;
balanceOf[to]++;
Transfer(msg.sender, to, 1);
Transfer(msg.sender, to, 1);
PunkTransfer(msg.sender, to, punkIndex);
PunkTransfer(msg.sender, to, punkIndex);
コピー
コピー済み
コピー
コピー済み
// Check for the case where there is a bid from the new owner and refund it.
// Any other bid can stay in place.
Bid bid = punkBids[punkIndex];
if (bid.bidder == to) {
// Kill bid and refund value
pendingWithdrawals[to] += bid.value;
punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0);
}
}
}
function punkNoLongerForSale(uint punkIndex) {
function punkNoLongerForSale(uint punkIndex) {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
punksOfferedForSale[punkIndex] = Offer(false, punkIndex, msg.sender, 0, 0x0);
punksOfferedForSale[punkIndex] = Offer(false, punkIndex, msg.sender, 0, 0x0);
PunkNoLongerForSale(punkIndex);
PunkNoLongerForSale(punkIndex);
}
}
function offerPunkForSale(uint punkIndex, uint minSalePriceInWei) {
function offerPunkForSale(uint punkIndex, uint minSalePriceInWei) {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, 0x0);
punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, 0x0);
PunkOffered(punkIndex, minSalePriceInWei, 0x0);
PunkOffered(punkIndex, minSalePriceInWei, 0x0);
}
}
function offerPunkForSaleToAddress(uint punkIndex, uint minSalePriceInWei, address toAddress) {
function offerPunkForSaleToAddress(uint punkIndex, uint minSalePriceInWei, address toAddress) {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, toAddress);
punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, toAddress);
PunkOffered(punkIndex, minSalePriceInWei, toAddress);
PunkOffered(punkIndex, minSalePriceInWei, toAddress);
}
}
function buyPunk(uint punkIndex) payable {
function buyPunk(uint punkIndex) payable {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
Offer offer = punksOfferedForSale[punkIndex];
Offer offer = punksOfferedForSale[punkIndex];
コピー
コピー済み
コピー
コピー済み
if (punkIndex >= 10000) throw;
if (!offer.isForSale) throw; // punk not actually for sale
if (!offer.isForSale) throw; // punk not actually for sale
if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) throw; // punk not supposed to be sold to this user
if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) throw; // punk not supposed to be sold to this user
if (msg.value < offer.minValue) throw; // Didn't send enough ETH
if (msg.value < offer.minValue) throw; // Didn't send enough ETH
if (offer.seller != punkIndexToAddress[punkIndex]) throw; // Seller no longer owner of punk
if (offer.seller != punkIndexToAddress[punkIndex]) throw; // Seller no longer owner of punk
コピー
コピー済み
コピー
コピー済み
address seller = offer.seller;
punkIndexToAddress[punkIndex] = msg.sender;
punkIndexToAddress[punkIndex] = msg.sender;
コピー
コピー済み
コピー
コピー済み
balanceOf[
offer.
seller]--;
balanceOf[
seller]--;
balanceOf[msg.sender]++;
balanceOf[msg.sender]++;
コピー
コピー済み
コピー
コピー済み
Transfer(
offer.
seller, msg.sender, 1);
Transfer(
seller, msg.sender, 1);
punkNoLongerForSale(punkIndex);
punkNoLongerForSale(punkIndex);
コピー
コピー済み
コピー
コピー済み
pendingWithdrawals[
offer.
seller] += msg.value;
pendingWithdrawals[
seller] += msg.value;
PunkBought(punkIndex, msg.value,
offer.
seller, msg.sender);
PunkBought(punkIndex, msg.value,
seller, msg.sender);
// Check for the case where there is a bid from the new owner and refund it.
// Any other bid can stay in place.
Bid bid = punkBids[punkIndex];
if (bid.bidder == msg.sender) {
// Kill bid and refund value
pendingWithdrawals[msg.sender] += bid.value;
punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0);
}
}
}
function withdraw() {
function withdraw() {
コピー
コピー済み
コピー
コピー済み
if (!allPunksAssigned) throw;
uint amount = pendingWithdrawals[msg.sender];
uint amount = pendingWithdrawals[msg.sender];
// Remember to zero the pending refund before
// Remember to zero the pending refund before
// sending to prevent re-entrancy attacks
// sending to prevent re-entrancy attacks
pendingWithdrawals[msg.sender] = 0;
pendingWithdrawals[msg.sender] = 0;
msg.sender.transfer(amount);
msg.sender.transfer(amount);
}
}
コピー
コピー済み
コピー
コピー済み
function enterBidForPunk(uint punkIndex) payable {
if (punkIndex >= 10000) throw;
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] == 0x0) throw;
if (punkIndexToAddress[punkIndex] == msg.sender) throw;
if (msg.value == 0) throw;
Bid existing = punkBids[punkIndex];
if (msg.value <= existing.value) throw;
if (existing.value > 0) {
// Refund the failing bid
pendingWithdrawals[existing.bidder] += existing.value;
}
punkBids[punkIndex] = Bid(true, punkIndex, msg.sender, msg.value);
PunkBidEntered(punkIndex, msg.value, msg.sender);
}
function acceptBidForPunk(uint punkIndex, uint minPrice) {
if (punkIndex >= 10000) throw;
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] != msg.sender) throw;
address seller = msg.sender;
Bid bid = punkBids[punkIndex];
if (bid.value == 0) throw;
if (bid.value < minPrice) throw;
punkIndexToAddress[punkIndex] = bid.bidder;
balanceOf[seller]--;
balanceOf[bid.bidder]++;
Transfer(seller, bid.bidder, 1);
punksOfferedForSale[punkIndex] = Offer(false, punkIndex, bid.bidder, 0, 0x0);
uint amount = bid.value;
punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0);
pendingWithdrawals[seller] += amount;
PunkBought(punkIndex, bid.value, seller, bid.bidder);
}
function withdrawBidForPunk(uint punkIndex) {
if (punkIndex >= 10000) throw;
if (!allPunksAssigned) throw;
if (punkIndexToAddress[punkIndex] == 0x0) throw;
if (punkIndexToAddress[punkIndex] == msg.sender) throw;
Bid bid = punkBids[punkIndex];
if (bid.bidder != msg.sender) throw;
PunkBidWithdrawn(punkIndex, bid.value, msg.sender);
uint amount = bid.value;
punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0);
// Refund the bid money
msg.sender.transfer(amount);
}
}
}
保存された差分
原文
ファイルを開く
/** *Submitted for verification at Etherscan.io on 2017-06-17 */ pragma solidity ^0.4.8; contract CryptoPunks { // You can use this hash to verify the image file containing all the punks string public imageHash = "ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b"; address owner; string public standard = 'CryptoPunks'; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; uint public nextPunkIndexToAssign = 0; //bool public allPunksAssigned = false; uint public punksRemainingToAssign = 0; uint public numberOfPunksToReserve; uint public numberOfPunksReserved = 0; //mapping (address => uint) public addressToPunkIndex; mapping (uint => address) public punkIndexToAddress; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; struct Offer { bool isForSale; uint punkIndex; address seller; uint minValue; // in ether address onlySellTo; // specify to sell only to a specific person } // A record of punks that are offered for sale at a specific minimum value, and perhaps to a specific person mapping (uint => Offer) public punksOfferedForSale; mapping (address => uint) public pendingWithdrawals; event Assign(address indexed to, uint256 punkIndex); event Transfer(address indexed from, address indexed to, uint256 value); event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex); event PunkOffered(uint indexed punkIndex, uint minValue, address indexed toAddress); event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress); event PunkNoLongerForSale(uint indexed punkIndex); /* Initializes contract with initial supply tokens to the creator of the contract */ function CryptoPunks() payable { // balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens owner = msg.sender; totalSupply = 10000; // Update total supply punksRemainingToAssign = totalSupply; numberOfPunksToReserve = 1000; name = "CRYPTOPUNKS"; // Set the name for display purposes symbol = "Ͼ"; // Set the symbol for display purposes decimals = 0; // Amount of decimals for display purposes } function reservePunksForOwner(uint maxForThisRun) { if (msg.sender != owner) throw; if (numberOfPunksReserved >= numberOfPunksToReserve) throw; uint numberPunksReservedThisRun = 0; while (numberOfPunksReserved < numberOfPunksToReserve && numberPunksReservedThisRun < maxForThisRun) { punkIndexToAddress[nextPunkIndexToAssign] = msg.sender; Assign(msg.sender, nextPunkIndexToAssign); numberPunksReservedThisRun++; nextPunkIndexToAssign++; } punksRemainingToAssign -= numberPunksReservedThisRun; numberOfPunksReserved += numberPunksReservedThisRun; balanceOf[msg.sender] += numberPunksReservedThisRun; } function getPunk(uint punkIndex) { if (punksRemainingToAssign == 0) throw; if (punkIndexToAddress[punkIndex] != 0x0) throw; punkIndexToAddress[punkIndex] = msg.sender; balanceOf[msg.sender]++; punksRemainingToAssign--; Assign(msg.sender, punkIndex); } // Transfer ownership of a punk to another user without requiring payment function transferPunk(address to, uint punkIndex) { if (punkIndexToAddress[punkIndex] != msg.sender) throw; punkIndexToAddress[punkIndex] = to; balanceOf[msg.sender]--; balanceOf[to]++; Transfer(msg.sender, to, 1); PunkTransfer(msg.sender, to, punkIndex); } function punkNoLongerForSale(uint punkIndex) { if (punkIndexToAddress[punkIndex] != msg.sender) throw; punksOfferedForSale[punkIndex] = Offer(false, punkIndex, msg.sender, 0, 0x0); PunkNoLongerForSale(punkIndex); } function offerPunkForSale(uint punkIndex, uint minSalePriceInWei) { if (punkIndexToAddress[punkIndex] != msg.sender) throw; punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, 0x0); PunkOffered(punkIndex, minSalePriceInWei, 0x0); } function offerPunkForSaleToAddress(uint punkIndex, uint minSalePriceInWei, address toAddress) { if (punkIndexToAddress[punkIndex] != msg.sender) throw; punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, toAddress); PunkOffered(punkIndex, minSalePriceInWei, toAddress); } function buyPunk(uint punkIndex) payable { Offer offer = punksOfferedForSale[punkIndex]; if (!offer.isForSale) throw; // punk not actually for sale if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) throw; // punk not supposed to be sold to this user if (msg.value < offer.minValue) throw; // Didn't send enough ETH if (offer.seller != punkIndexToAddress[punkIndex]) throw; // Seller no longer owner of punk punkIndexToAddress[punkIndex] = msg.sender; balanceOf[offer.seller]--; balanceOf[msg.sender]++; Transfer(offer.seller, msg.sender, 1); punkNoLongerForSale(punkIndex); pendingWithdrawals[offer.seller] += msg.value; PunkBought(punkIndex, msg.value, offer.seller, msg.sender); } function withdraw() { uint amount = pendingWithdrawals[msg.sender]; // Remember to zero the pending refund before // sending to prevent re-entrancy attacks pendingWithdrawals[msg.sender] = 0; msg.sender.transfer(amount); } }
変更されたテキスト
ファイルを開く
/** *Submitted for verification at Etherscan.io on 2017-07-19 */ pragma solidity ^0.4.8; contract CryptoPunksMarket { // You can use this hash to verify the image file containing all the punks string public imageHash = "ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b"; address owner; string public standard = 'CryptoPunks'; string public name; string public symbol; uint8 public decimals; uint256 public totalSupply; uint public nextPunkIndexToAssign = 0; bool public allPunksAssigned = false; uint public punksRemainingToAssign = 0; //mapping (address => uint) public addressToPunkIndex; mapping (uint => address) public punkIndexToAddress; /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; struct Offer { bool isForSale; uint punkIndex; address seller; uint minValue; // in ether address onlySellTo; // specify to sell only to a specific person } struct Bid { bool hasBid; uint punkIndex; address bidder; uint value; } // A record of punks that are offered for sale at a specific minimum value, and perhaps to a specific person mapping (uint => Offer) public punksOfferedForSale; // A record of the highest punk bid mapping (uint => Bid) public punkBids; mapping (address => uint) public pendingWithdrawals; event Assign(address indexed to, uint256 punkIndex); event Transfer(address indexed from, address indexed to, uint256 value); event PunkTransfer(address indexed from, address indexed to, uint256 punkIndex); event PunkOffered(uint indexed punkIndex, uint minValue, address indexed toAddress); event PunkBidEntered(uint indexed punkIndex, uint value, address indexed fromAddress); event PunkBidWithdrawn(uint indexed punkIndex, uint value, address indexed fromAddress); event PunkBought(uint indexed punkIndex, uint value, address indexed fromAddress, address indexed toAddress); event PunkNoLongerForSale(uint indexed punkIndex); /* Initializes contract with initial supply tokens to the creator of the contract */ function CryptoPunksMarket() payable { // balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens owner = msg.sender; totalSupply = 10000; // Update total supply punksRemainingToAssign = totalSupply; name = "CRYPTOPUNKS"; // Set the name for display purposes symbol = "Ͼ"; // Set the symbol for display purposes decimals = 0; // Amount of decimals for display purposes } function setInitialOwner(address to, uint punkIndex) { if (msg.sender != owner) throw; if (allPunksAssigned) throw; if (punkIndex >= 10000) throw; if (punkIndexToAddress[punkIndex] != to) { if (punkIndexToAddress[punkIndex] != 0x0) { balanceOf[punkIndexToAddress[punkIndex]]--; } else { punksRemainingToAssign--; } punkIndexToAddress[punkIndex] = to; balanceOf[to]++; Assign(to, punkIndex); } } function setInitialOwners(address[] addresses, uint[] indices) { if (msg.sender != owner) throw; uint n = addresses.length; for (uint i = 0; i < n; i++) { setInitialOwner(addresses[i], indices[i]); } } function allInitialOwnersAssigned() { if (msg.sender != owner) throw; allPunksAssigned = true; } function getPunk(uint punkIndex) { if (!allPunksAssigned) throw; if (punksRemainingToAssign == 0) throw; if (punkIndexToAddress[punkIndex] != 0x0) throw; if (punkIndex >= 10000) throw; punkIndexToAddress[punkIndex] = msg.sender; balanceOf[msg.sender]++; punksRemainingToAssign--; Assign(msg.sender, punkIndex); } // Transfer ownership of a punk to another user without requiring payment function transferPunk(address to, uint punkIndex) { if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] != msg.sender) throw; if (punkIndex >= 10000) throw; if (punksOfferedForSale[punkIndex].isForSale) { punkNoLongerForSale(punkIndex); } punkIndexToAddress[punkIndex] = to; balanceOf[msg.sender]--; balanceOf[to]++; Transfer(msg.sender, to, 1); PunkTransfer(msg.sender, to, punkIndex); // Check for the case where there is a bid from the new owner and refund it. // Any other bid can stay in place. Bid bid = punkBids[punkIndex]; if (bid.bidder == to) { // Kill bid and refund value pendingWithdrawals[to] += bid.value; punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0); } } function punkNoLongerForSale(uint punkIndex) { if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] != msg.sender) throw; if (punkIndex >= 10000) throw; punksOfferedForSale[punkIndex] = Offer(false, punkIndex, msg.sender, 0, 0x0); PunkNoLongerForSale(punkIndex); } function offerPunkForSale(uint punkIndex, uint minSalePriceInWei) { if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] != msg.sender) throw; if (punkIndex >= 10000) throw; punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, 0x0); PunkOffered(punkIndex, minSalePriceInWei, 0x0); } function offerPunkForSaleToAddress(uint punkIndex, uint minSalePriceInWei, address toAddress) { if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] != msg.sender) throw; if (punkIndex >= 10000) throw; punksOfferedForSale[punkIndex] = Offer(true, punkIndex, msg.sender, minSalePriceInWei, toAddress); PunkOffered(punkIndex, minSalePriceInWei, toAddress); } function buyPunk(uint punkIndex) payable { if (!allPunksAssigned) throw; Offer offer = punksOfferedForSale[punkIndex]; if (punkIndex >= 10000) throw; if (!offer.isForSale) throw; // punk not actually for sale if (offer.onlySellTo != 0x0 && offer.onlySellTo != msg.sender) throw; // punk not supposed to be sold to this user if (msg.value < offer.minValue) throw; // Didn't send enough ETH if (offer.seller != punkIndexToAddress[punkIndex]) throw; // Seller no longer owner of punk address seller = offer.seller; punkIndexToAddress[punkIndex] = msg.sender; balanceOf[seller]--; balanceOf[msg.sender]++; Transfer(seller, msg.sender, 1); punkNoLongerForSale(punkIndex); pendingWithdrawals[seller] += msg.value; PunkBought(punkIndex, msg.value, seller, msg.sender); // Check for the case where there is a bid from the new owner and refund it. // Any other bid can stay in place. Bid bid = punkBids[punkIndex]; if (bid.bidder == msg.sender) { // Kill bid and refund value pendingWithdrawals[msg.sender] += bid.value; punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0); } } function withdraw() { if (!allPunksAssigned) throw; uint amount = pendingWithdrawals[msg.sender]; // Remember to zero the pending refund before // sending to prevent re-entrancy attacks pendingWithdrawals[msg.sender] = 0; msg.sender.transfer(amount); } function enterBidForPunk(uint punkIndex) payable { if (punkIndex >= 10000) throw; if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] == 0x0) throw; if (punkIndexToAddress[punkIndex] == msg.sender) throw; if (msg.value == 0) throw; Bid existing = punkBids[punkIndex]; if (msg.value <= existing.value) throw; if (existing.value > 0) { // Refund the failing bid pendingWithdrawals[existing.bidder] += existing.value; } punkBids[punkIndex] = Bid(true, punkIndex, msg.sender, msg.value); PunkBidEntered(punkIndex, msg.value, msg.sender); } function acceptBidForPunk(uint punkIndex, uint minPrice) { if (punkIndex >= 10000) throw; if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] != msg.sender) throw; address seller = msg.sender; Bid bid = punkBids[punkIndex]; if (bid.value == 0) throw; if (bid.value < minPrice) throw; punkIndexToAddress[punkIndex] = bid.bidder; balanceOf[seller]--; balanceOf[bid.bidder]++; Transfer(seller, bid.bidder, 1); punksOfferedForSale[punkIndex] = Offer(false, punkIndex, bid.bidder, 0, 0x0); uint amount = bid.value; punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0); pendingWithdrawals[seller] += amount; PunkBought(punkIndex, bid.value, seller, bid.bidder); } function withdrawBidForPunk(uint punkIndex) { if (punkIndex >= 10000) throw; if (!allPunksAssigned) throw; if (punkIndexToAddress[punkIndex] == 0x0) throw; if (punkIndexToAddress[punkIndex] == msg.sender) throw; Bid bid = punkBids[punkIndex]; if (bid.bidder != msg.sender) throw; PunkBidWithdrawn(punkIndex, bid.value, msg.sender); uint amount = bid.value; punkBids[punkIndex] = Bid(false, punkIndex, 0x0, 0); // Refund the bid money msg.sender.transfer(amount); } }
違いを見つける