-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
70 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/IWeightManager.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract WeightManager is Ownable, IWeightManager { | ||
mapping(address => mapping(uint256 => uint256)) public weights; | ||
mapping(address => address) public operators; | ||
|
||
modifier onlyOperator(address _nft) { | ||
if (operators[_nft] != msg.sender) { | ||
revert NotOperator(); | ||
} | ||
_; | ||
} | ||
|
||
function addOperator(address _nft, address _operator) external onlyOwner { | ||
if (operators[_nft] != address(0)) revert DuplicateOperator(); | ||
operators[_nft] = _operator; | ||
emit OperatorSet(_nft, _operator); | ||
} | ||
|
||
function changeOperator(address _nft, address _operator) external onlyOperator(_nft) { | ||
operators[_nft] = _operator; | ||
emit OperatorSet(_nft, _operator); | ||
} | ||
|
||
function setWeight(address _nft, uint256 _tokenId, uint256 _weight) external onlyOperator(_nft) { | ||
weights[_nft][_tokenId] = _weight; | ||
} | ||
|
||
function weight(address _nft, uint256 _tokenId) external view override returns (uint256) { | ||
if (operators[_nft] == address(0)) { | ||
return 1; | ||
} | ||
return weights[_nft][_tokenId]; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
interface IWeightManager { | ||
error DuplicateOperator(); | ||
error NotOperator(); | ||
event OperatorSet(address indexed nft, address indexed operator); | ||
|
||
function weight(address nft, uint256 tokenId) external view returns (uint256); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,16 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import {IWeightedNFT} from "../interfaces/IWeightedNFT.sol"; | ||
|
||
contract TestDeviceNFT is IWeightedNFT, ERC721 { | ||
mapping(uint256 => uint256) public weightOf; | ||
contract TestDeviceNFT is ERC721 { | ||
|
||
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) { | ||
_mint(msg.sender, 1); | ||
_mint(msg.sender, 2); | ||
_mint(msg.sender, 3); | ||
weightOf[1] = 1 ether; | ||
weightOf[2] = 2 ether; | ||
weightOf[3] = 3 ether; | ||
} | ||
|
||
function weight(uint256 tokenId) external view returns (uint256) { | ||
return weightOf[tokenId]; | ||
} | ||
|
||
function nft() external view override returns (address) { | ||
return address(this); | ||
} | ||
|
||
function setWeight(uint256 _tokenId, uint256 _weight) public { | ||
weightOf[_tokenId] = _weight; | ||
} | ||
|
||
function mint(address to, uint tokenId) external { | ||
_mint(to, tokenId); | ||
weightOf[tokenId] = 1 ether; | ||
} | ||
} |
This file contains 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
This file contains 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