KittyBase 合约定义了一个kitty 数据结构的数据
Kitty[] kitties;
这个数组包含了所有Kitty的数据,所以它就像一个Kitty的数据库一样。 无论何时创建一个新的猫,它都会被添加到这个数组中,数组的索引成为猫的ID,就像这个 ID为'1'的创世喵:

该合约还包含从猫的ID到其拥有者地址的映射,以跟踪拥有猫的人:
mapping (uint256 => address) public kittyIndexToOwner;
还有一些其他的映射也被定义,但为了保持这篇文章的合理长度,我不会仔细研究每一个细节。
每当小猫从一个人转移到下一个时,这个kittyIndexToOwner映射就会被更新以反映新的所有者:
///
@dev Assigns ownership of a specific Kitty to an address.
function _transfer(address _from, address _to, uint256 _tokenId) internal {
// Since the number of kittens is capped to 2^32 we can't overflow this
ownershipTokenCount[_to]++;
// transfer ownership
kittyIndexToOwner[_tokenId] = _to;
// When creating new kittens _from is 0x0, but we can't account that address.
if (_from != address(0)) {
ownershipTokenCount[_from]--;
// once the kitten is transferred also clear sire allowances
delete sireAllowedToAddress[_tokenId];
// clear any previously approved ownership exchange
delete kittyIndexToApproved[_tokenId];
}
// Emit the transfer event.
Transfer(_from, _to, _tokenId);
}
转移所有权 设置Kitty的ID指向接收人_to的地址。
现在我们来看看在创建一个新的kitty时会发生什么: