Skip to content

Instantly share code, notes, and snippets.

@mg6maciej
Created June 22, 2018 05:44
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 mg6maciej/f38820866aa8db3e3227079592e67491 to your computer and use it in GitHub Desktop.
Save mg6maciej/f38820866aa8db3e3227079592e67491 to your computer and use it in GitHub Desktop.
CryptoKittiesBreed.sol
pragma solidity ^0.4.23;
contract ComposableRegistry {
function ownerOf(address erc721, uint tokenId) public view returns (address);
function parent(address erc721, uint tokenId) public view returns (address, uint);
function transfer(address toErc721, uint toTokenId, address erc721, uint tokenId) public;
function transferToAddress(address to, address erc721, uint tokenId) public;
}
contract CryptoKitties {
function ownerOf(uint tokenId) public view returns (address);
function transfer(address to, uint tokenId) public;
function transferFrom(address from, address to, uint tokenId) public;
function sireAllowedToAddress(uint tokenId) public view returns (address);
function breedWithAuto(uint matron, uint sire) public payable;
}
contract Breed {
ComposableRegistry public composableRegistry;
CryptoKitties public cryptoKitties = CryptoKitties(0x06012);
function breed(uint matron, uint sire) public payable {
address matronParentContract;
uint matronParentTokenId;
address matronOwner = cryptoKitties.ownerOf(matron);
if (matronOwner == msg.sender) {
cryptoKitties.transferFrom(msg.sender, this, matron);
} else {
(matronParentContract, matronParentTokenId) = composableRegistry.parent(cryptoKitties, matron);
require(composableRegistry.ownerOf(matronParentContract, matronParentTokenId) == msg.sender);
composableRegistry.transferToAddress(this, cryptoKitties, matron);
}
address sireParentContract;
uint sireParentTokenId;
address sireAddress = cryptoKitties.sireAllowedToAddress(sire);
address sireOwner = cryptoKitties.ownerOf(sire);
if (sireOwner == msg.sender) {
if (sireAddress != address(this)) {
cryptoKitties.transferFrom(msg.sender, this, sire);
}
} else {
(sireParentContract, sireParentTokenId) = composableRegistry.parent(cryptoKitties, sire);
require(composableRegistry.ownerOf(sireParentContract, sireParentTokenId) == msg.sender);
composableRegistry.transferToAddress(this, cryptoKitties, sire);
}
// THE THING
cryptoKitties.breedWithAuto.value(msg.value)(matron, sire);
// END
if (matronOwner == msg.sender) {
cryptoKitties.transfer(msg.sender, matron);
} else {
composableRegistry.transfer(matronParentContract, matronParentTokenId, cryptoKitties, matron);
}
if (sireOwner == msg.sender) {
if (cryptoKitties.ownerOf(sire) == address(this)) {
cryptoKitties.transfer(msg.sender, sire);
}
} else {
composableRegistry.transfer(sireParentContract, sireParentTokenId, cryptoKitties, sire);
}
msg.sender.transfer(address(this).balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment