github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/fvm/evm/testutils/contracts/dummy_kitty.sol (about)

     1  // SPDX-License-Identifier: GPL-3.0
     2  
     3  contract DummyKitty {		
     4      event BirthEvent(address owner, uint256 kittyId, uint256 matronId, uint256 sireId, uint256 genes);
     5      event TransferEvent(address from, address to, uint256 tokenId);
     6  
     7      struct Kitty {
     8          uint256 genes;
     9          uint64 birthTime;
    10          uint32 matronId;
    11          uint32 sireId;
    12          uint16 generation;
    13      }
    14  
    15      uint256 idCounter;
    16  
    17      // @dev all kitties 
    18      Kitty[] kitties;
    19  
    20      /// @dev a mapping from cat IDs to the address that owns them. 
    21      mapping (uint256 => address) public kittyIndexToOwner;
    22  
    23      // @dev a mapping from owner address to count of tokens that address owns.
    24      mapping (address => uint256) ownershipTokenCount;
    25  
    26      /// @dev a method to transfer kitty
    27      function Transfer(address _from, address _to, uint256 _tokenId) external {
    28          // Since the number of kittens is capped to 2^32 we can't overflow this
    29          ownershipTokenCount[_to]++;
    30          // transfer ownership
    31          kittyIndexToOwner[_tokenId] = _to;
    32          // When creating new kittens _from is 0x0, but we can't account that address.
    33          if (_from != address(0)) {
    34              ownershipTokenCount[_from]--;
    35          }
    36          // Emit the transfer event.
    37          emit TransferEvent(_from, _to, _tokenId);
    38      }
    39  
    40      /// @dev a method callable by anyone to create a kitty
    41      function CreateKitty(
    42          uint256 _matronId,
    43          uint256 _sireId,
    44          uint256 _generation,
    45          uint256 _genes
    46      )
    47          external
    48          returns (uint)
    49      {
    50  
    51          require(_matronId == uint256(uint32(_matronId)));
    52          require(_sireId == uint256(uint32(_sireId)));
    53          require(_generation == uint256(uint16(_generation)));
    54  
    55          Kitty memory _kitty = Kitty({
    56              genes: _genes,
    57              birthTime: uint64(block.timestamp),
    58              matronId: uint32(_matronId),
    59              sireId: uint32(_sireId),
    60              generation: uint16(_generation)
    61          });
    62  
    63          kitties.push(_kitty);
    64  
    65          emit BirthEvent(
    66              msg.sender,
    67              idCounter,
    68              uint256(_kitty.matronId),
    69              uint256(_kitty.sireId),
    70              _kitty.genes
    71          );
    72  
    73          this.Transfer(address(0), msg.sender, idCounter);
    74  
    75          idCounter++;
    76  
    77          return idCounter;
    78      }
    79  }