Last active
April 30, 2021 00:35
-
-
Save apow2/2ecb040acbebaca979e0b185eb022bf5 to your computer and use it in GitHub Desktop.
Basic Contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract Base{ | |
event Transfer(address from, address to, uint256 tokenId); | |
mapping (uint256 => address) public IndexToOwner; | |
mapping (address => uint256) public ownershipTokenCount; | |
mapping (uint256 => address) public IndexToApproved; | |
function getMyTokens(address myaddress) view public returns(uint[] memory){ | |
uint num = ownershipTokenCount[myaddress]; | |
uint found = 0; | |
uint[] memory myTokens = new uint[](num); | |
while (found<num){ | |
for (uint i=0; i<100; i++){ | |
if (IndexToOwner[i]==myaddress){ | |
myTokens[found] = i; | |
found++; | |
} | |
} | |
} | |
return myTokens; | |
} | |
function _transfer(address _from, address _to, uint256 _tokenId) internal { | |
ownershipTokenCount[_to]++; | |
IndexToOwner[_tokenId] = _to; | |
if (_from != address(0)) { | |
ownershipTokenCount[_from]--; | |
// clear any previously approved ownership exchange | |
delete IndexToApproved[_tokenId]; | |
} | |
// Emit the transfer event. | |
emit Transfer(_from, _to, _tokenId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment