Skip to content

Instantly share code, notes, and snippets.

@ravachol70
Created April 26, 2023 05:12
Show Gist options
  • Select an option

  • Save ravachol70/d6d1593043ae990fd6f9f0f90fbc4b32 to your computer and use it in GitHub Desktop.

Select an option

Save ravachol70/d6d1593043ae990fd6f9f0f90fbc4b32 to your computer and use it in GitHub Desktop.
TFT Comparator
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "ipfs://Qmb4pKzeErWgC8pU6cLzV7JU6R9jV7EDTZX3MkJa2wak6J";
contract TFTToken is ITFT {
struct InflectionData {
bytes32[] blobs;
mapping(bytes32 => bool) blobExists;
}
mapping(bytes32 => InflectionData) private _inflections;
function createInflection(bytes32 inflection, bytes32 blob) external override {
require(!_inflections[inflection].blobExists[blob], "Blob already exists for inflection");
_inflections[inflection].blobs.push(blob);
_inflections[inflection].blobExists[blob] = true;
}
function deleteInflection(bytes32 inflection, bytes32 blob) external override {
require(_inflections[inflection].blobExists[blob], "Blob does not exist for inflection");
bytes32[] storage blobs = _inflections[inflection].blobs;
for (uint i = 0; i < blobs.length; i++) {
if (blobs[i] == blob) {
blobs[i] = blobs[blobs.length - 1];
blobs.pop();
break;
}
}
delete _inflections[inflection].blobExists[blob];
}
function getInflectionData(bytes32 inflection) external view override returns (bytes32[] memory) {
return _inflections[inflection].blobs;
}
function compareInflections(bytes32 inflection, address otherToken) external view override returns (bool) {
ITFT other = ITFT(otherToken);
bytes32[] memory myInflections = getInflectionData(inflection);
bytes32[] memory otherInflections = other.getInflectionData(inflection);
if (myInflections.length != otherInflections.length) {
return false;
}
for (uint i = 0; i < myInflections.length; i++) {
bool found = false;
for (uint j = 0; j < otherInflections.length; j++) {
if (myInflections[i] == otherInflections[j]) {
found = true;
break;
}
}
if (!found) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment