You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

130 lines
3.2 KiB

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
library Utils {
function isAdmin(address[] memory _admins,address owner) internal pure returns(bool) {
bool _admin;
for(uint256 i=0;i<_admins.length;i++){
if(_admins[i] == owner){
_admin = true;
break;
}
}
return _admin;
}
function isNftBlacks(uint256[] memory _tokens,uint256 _tokenIds) internal pure returns(bool) {
bool _black;
for(uint256 i=0;i<_tokens.length;i++){
if(_tokens[i] == _tokenIds){
_black = true;
break;
}
}
return _black;
}
function addNftBlacks (uint256[] memory _tokens,uint256[] memory _ids) internal pure returns(uint256[] memory) {
uint256 length = _tokens.length + _ids.length;
uint256[] memory tokens = new uint256[](length);
uint256 index = 0;
for(uint256 i=0;i<_tokens.length;i++){
tokens[index] = _tokens[i];
index++;
}
for(uint256 i=0;i<_ids.length;i++){
tokens[index] = _ids[i];
index++;
}
return tokens;
}
function deleteNftBlacks (uint256[] memory _tokens,uint256[] memory _dels) internal pure returns(uint256[] memory) {
bool[] memory toDelete = new bool[](_tokens.length);
// 標記要刪除的元素
for(uint256 i=0;i<_dels.length;i++){
for(uint256 j=0;j<_tokens.length;j++){
if(_tokens[j] == _dels[i]){
toDelete[j] = true;
break;
}
}
}
// 計算數組長度
uint256 size = 0;
for(uint256 i=0;i<_tokens.length;i++){
if(!toDelete[i]){
size++;
}
}
uint256[] memory _newTokens = new uint256[](size);
uint256 index =0 ;
for(uint256 i=0;i<_tokens.length;i++){
if(!toDelete[i]){
_newTokens[index] = _tokens[i];
index++;
}
}
return _newTokens;
}
function addAdmin (address[] memory _admins,address[] memory _adds) internal pure returns(address[] memory) {
uint256 _length = _admins.length + _adds.length;
address[] memory _newTokens = new address[](_length);
uint256 index = 0;
for(uint256 i=0;i<_admins.length;i++){
_newTokens[index] = _admins[i];
index++;
}
for(uint256 i=0;i<_adds.length;i++){
_newTokens[index] = _adds[i];
index++;
}
return _newTokens;
}
function deleteAdmin (address[] memory _admins,address[] memory _dels) internal pure returns(address[] memory) {
bool[] memory toDelete = new bool[](_admins.length);
// 標記要刪除的元素
for(uint256 i=0;i<_dels.length;i++){
for(uint256 j=0;j<_admins.length;j++){
if(_admins[j] == _dels[i]){
toDelete[j] = true;
break;
}
}
}
// 計算數組長度
uint256 size = 0;
for(uint256 i=0;i<_admins.length;i++){
if(!toDelete[i]){
size++;
}
}
address[] memory newAdmins = new address[](size);
uint256 index =0 ;
for(uint256 i=0;i<_admins.length;i++){
if(!toDelete[i]){
newAdmins[index] = _admins[i];
index++;
}
}
return newAdmins;
}
}