Last active
April 27, 2023 17:12
-
-
Save ravachol70/8267cd1937af77870f808dd633f90ab0 to your computer and use it in GitHub Desktop.
TFT Interface
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
| pragma solidity ^0.8.0; | |
| import "./ITFT.sol"; | |
| import "ipfs://QmbG59n6yMw6r2F3TqY6UcY6Ucmi6xE31p6j9nBjQLV7qu"; | |
| contract TFTToken is ITFT { | |
| string public name; | |
| string public symbol; | |
| uint8 public decimals; | |
| uint256 public totalSupply; | |
| mapping(address => uint256) public balances; | |
| mapping(address => mapping(address => uint256)) public allowed; | |
| struct Inflection { | |
| bytes32[] blobs; | |
| uint256 bitmap; | |
| } | |
| mapping(uint256 => Inflection) public inflections; | |
| constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupply) { | |
| name = _name; | |
| symbol = _symbol; | |
| decimals = _decimals; | |
| totalSupply = _totalSupply; | |
| balances[msg.sender] = _totalSupply; | |
| } | |
| function createInflection(uint256 _inflectionId, bytes32[] memory _blobs) public { | |
| inflections[_inflectionId].blobs = _blobs; | |
| uint256 bitmap = 0; | |
| for (uint256 i = 0; i < _blobs.length; i++) { | |
| bitmap |= uint256(1) << i; | |
| } | |
| inflections[_inflectionId].bitmap = bitmap; | |
| emit InflectionCreated(_inflectionId, _blobs); | |
| } | |
| function deleteInflection(uint256 _inflectionId) public { | |
| delete inflections[_inflectionId]; | |
| emit InflectionDeleted(_inflectionId); | |
| } | |
| function compareInflections(uint256 _inflectionId1, uint256 _inflectionId2) public view returns (bool) { | |
| uint256 bitmap1 = inflections[_inflectionId1].bitmap; | |
| uint256 bitmap2 = inflections[_inflectionId2].bitmap; | |
| if (bitmap1 & bitmap2 != bitmap1) { | |
| return false; | |
| } | |
| for (uint256 i = 0; i < inflections[_inflectionId1].blobs.length; i++) { | |
| if (bitmap1 & (uint256(1) << i) != 0) { | |
| if (inflections[_inflectionId1].blobs[i] != inflections[_inflectionId2].blobs[i]) { | |
| return false; | |
| } | |
| } | |
| } | |
| return true; | |
| } | |
| function transfer(address _to, uint256 _value) public returns (bool) { | |
| require(balances[msg.sender] >= _value && _value > 0); | |
| balances[msg.sender] -= _value; | |
| balances[_to] += _value; | |
| emit Transfer(msg.sender, _to, _value); | |
| return true; | |
| } | |
| function approve(address _spender, uint256 _value) public returns (bool) { | |
| allowed[msg.sender][_spender] = _value; | |
| emit Approval(msg.sender, _spender, _value); | |
| return true; | |
| } | |
| function transferFrom(address from, address to, uint256 tokenId) public override { | |
| require(_exists(tokenId), "Token does not exist"); | |
| require(ownerOf(tokenId) == from, "Sender is not the owner of token"); | |
| require(_isApprovedOrOwner(msg.sender, tokenId), "Sender is not approved to transfer this token"); | |
| // Update token approvals and ownership | |
| _approve(address(0), tokenId); | |
| _transfer(from, to, tokenId); | |
| // Emit 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