File size: 5,395 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
  "language": "Solidity",
  "sources": {
    "contracts/SetLockable.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nimport { InvalidOwner } from \"./SetOwnerEnumerable.sol\";\nstruct LockableData { \n\n    mapping(address => uint256) lockableStatusIndex; \n\n    mapping(address => LockableStatus) lockableStatus;  \n} \n\n\n\n\nstruct LockableStatus {\n    bool isLocked;\n    uint256 lockedAt;\n    address custodian;\n    uint256 balance;\n    address[] approvedAll;\n    bool exists;\n}\n\nuint64 constant MAX_INT = 2**64 - 1;\n\nerror OnlyCustodianCanLock();\n\nerror OnlyOwnerCanSetCustodian();\n\nerror WalletLockedByOwner();\n\nerror InvalidTransferRecipient();\n\nerror NotApprovedOrOwner();\n\nerror ContractIsNot721Receiver();\n\nlibrary SetLockable {           \n\n    function lockWallet(LockableData storage self, address holder) public {\n        LockableStatus storage status = self.lockableStatus[holder];    \n        if (msg.sender != status.custodian) {\n            revert OnlyCustodianCanLock();\n        }       \n        status.isLocked = true;\n        status.lockedAt = block.timestamp;\n    }\n\n    function unlockWallet(LockableData storage self, address holder) public {        \n        LockableStatus storage status = self.lockableStatus[holder];\n        if (msg.sender != status.custodian) {\n            revert OnlyCustodianCanLock();\n        }                   \n        \n        status.isLocked = false;\n        status.lockedAt = MAX_INT;\n    }\n\n    function setCustodian(LockableData storage self, address custodianAddress,  address holder) public {\n        if (msg.sender != holder) {\n            revert OnlyOwnerCanSetCustodian();\n        }    \n        LockableStatus storage status = self.lockableStatus[holder];\n        status.custodian = custodianAddress;\n    }\n\n    function findCustodian(LockableData storage self, address wallet) public view returns (address) {\n        return self.lockableStatus[wallet].custodian;\n    }\n\n    function forceUnlock(LockableData storage self, address owner) public {        \n        LockableStatus storage status = self.lockableStatus[owner];\n        status.isLocked = false;\n        status.lockedAt = MAX_INT;\n    }\n            \n}"
    },
    "contracts/SetOwnerEnumerable.sol": {
      "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\nstruct OwnerEnumerableData { \n    mapping(uint256 => TokenOwnership) tokens;\n    mapping(address => uint256[]) ownedTokens;\n\n    mapping(address => mapping(uint256 => uint256)) ownedTokensIndex; \n\n    mapping(address => uint256[]) burnedTokens;\n\n    mapping(address => mapping(uint256 => uint256)) burnedTokensIndex; \n} \n\n\n\nstruct TokenOwnership {\n    address ownedBy;\n    bool exists;\n}\n\nerror TokenNonOwner(address requester, uint256 tokenId); \nerror InvalidOwner();\n\nlibrary SetOwnerEnumerable {\n    function addTokenToEnumeration(OwnerEnumerableData storage self, address to, uint256 tokenId) public {       \n        self.ownedTokens[to].push(tokenId);        \n        uint256 length = self.ownedTokens[to].length;\n        self.ownedTokensIndex[to][tokenId] = length-1;\n        self.tokens[tokenId] = TokenOwnership(to,true);\n    }\n\n    function addBurnToEnumeration(OwnerEnumerableData storage self, address to, uint256 tokenId) public {       \n        self.burnedTokens[to].push(tokenId);        \n        uint256 length = self.burnedTokens[to].length;\n        self.burnedTokensIndex[to][tokenId] = length-1;        \n    }    \n\n    function removeTokenFromEnumeration(OwnerEnumerableData storage self, address to, uint256 tokenId) public {\n\n        uint256 length = self.ownedTokens[to].length;\n        if (self.ownedTokensIndex[to][tokenId] > 0) {\n            if (self.ownedTokensIndex[to][tokenId] != length - 1) {\n                uint256 lastTokenId = self.ownedTokens[to][length - 1];\n                self.ownedTokens[to][self.ownedTokensIndex[to][tokenId]] = lastTokenId; \n                self.ownedTokensIndex[to][lastTokenId] = self.ownedTokensIndex[to][tokenId];\n            }\n        }\n\n        delete self.ownedTokensIndex[to][tokenId];\n        if (self.ownedTokens[to].length > 0) {\n            self.ownedTokens[to].pop();\n        }\n    }    \n\n    function findTokensOwned(OwnerEnumerableData storage self, address wallet) public view returns (uint256[] storage) {\n        return self.ownedTokens[wallet];\n    }  \n\n    function tokenIndex(OwnerEnumerableData storage self, address wallet, uint256 index) public view returns (uint256) {\n        return self.ownedTokens[wallet][index];\n    }    \n\n    function ownerOf(OwnerEnumerableData storage self, uint256 tokenId) public view returns (address) {\n        address owner = self.tokens[tokenId].ownedBy;\n        if (owner == address(0)) {\n            revert TokenNonOwner(owner,tokenId);\n        }\n        return owner;\n    }      \n}"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 1
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "metadata": {
      "useLiteralContent": true
    },
    "libraries": {}
  }
}