pragma solidity ^0.8.4;

interface IClaimed {
    function isClaimed(address nftAddress, uint tokenId, bytes32[] calldata proof) external returns(bool);
    function claim(address nftAddress, uint tokenId, address _claimedBy) external;
}

pragma experimental ABIEncoderV2;
pragma solidity ^0.8.4;


interface IERC721 {
    function burn(uint256 tokenId) external;
    function transferFrom(address from, address to, uint256 tokenId) external;
    function mint( address _to, uint256 _tokenId, string calldata _uri, string calldata _payload) external;
    function changeName(string calldata name, string calldata symbol) external;
    function updateTokenUri(uint256 _tokenId,string memory _uri) external;
    function tokenPayload(uint256 _tokenId) external view returns (string memory);
    function ownerOf(uint256 _tokenId) external returns (address _owner);
    function getApproved(uint256 _tokenId) external returns (address);
    function safeTransferFrom(address _from, address _to, uint256 _tokenId) external;
}

interface Ownable {
    function transferOwnership(address newOwner) external;
}

interface BasicERC20 {
    function burn(uint256 value) external;
    function mint(address account, uint256 amount) external;
    function decimals() external view returns (uint8);
}

contract Context {
    constructor() {}

    // solhint-disable-previous-line no-empty-blocks

    function _msgSender() internal view returns (address payable) {
        return payable(msg.sender);
    }
}


contract Bridged is Context {
    using SafeMath for uint256;
    using SafeMath for uint8;
    using SafeMath for uint;

    address public paymentAddress;
    
    mapping(uint => bool) public chainIds;
    mapping(uint => uint256) public chainBalances;
    
    constructor () {
        chainIds[1] = true;
        chainBalances[1] = 200000000000000000;
        chainIds[137] = true;
        chainBalances[137] = 200000000000000000;
        chainIds[80001] = true;
        chainBalances[80001] = 200000000000000000;
        chainIds[100] = true;
        chainBalances[100] = 200000000000000000;
        chainIds[56] = true;
        chainBalances[56] = 200000000000000000;
        chainIds[250] = true;
        chainBalances[250] = 200000000000000000;
    }
    
    function transferToChain(uint chainId, uint256 amount) public returns (bool) {
        require(chainIds[chainId], 'Invalid Chain ID');
        IERC20Token paymentToken = IERC20Token(paymentAddress);
        require(paymentToken.allowance(_msgSender(), address(this)) >= amount, 'Handler unable to spend ');
        require(paymentToken.transferFrom(_msgSender(), address(this), amount), 'Transfer ERROR');
        BasicERC20(paymentAddress).burn(amount);
        chainBalances[chainId] = chainBalances[chainId].add(amount);
        emit BridgeDeposit(_msgSender(), amount, chainId);
        
        return true;
    }
    
    function _transferFromChain(address _to, uint chainId, uint256 amount) internal returns (bool) {
        require(chainBalances[chainId] >= amount, 'Can not transfer more than deposited');
        require(chainIds[chainId], 'Invalid Chain ID');
        BasicERC20 paymentToken = BasicERC20(paymentAddress);
        paymentToken.mint(_to, amount);
        chainBalances[chainId] = chainBalances[chainId].sub(amount);
        emit BridgeWithdrawal(_msgSender(), amount, chainId);
        
        return true;
    }
    
    event BridgeDeposit(address indexed sender, uint256 indexed amount, uint chainId);
    event BridgeWithdrawal(address indexed sender, uint256 indexed amount, uint chainId);
    
    function _addChainId(uint chainId) internal returns (bool) {
        chainIds[chainId] = true;
        return true;
    }
    
    function _removeChainId(uint chainId) internal returns (bool) {
        chainIds[chainId] = false;
        return true;
    }
    
}

contract VaultHandlerV7a is ReentrancyGuard, Bridged { 
    
    using SafeMath for uint256;
    using SafeMath for uint8;
    address payable private owner;
    string public metadataBaseUri;
    bool public initialized;
    address public nftAddress;
    address public recipientAddress;
    address public claimAddress;
    uint256 public price;
    bool public shouldBurn = false;
    uint internal blockWindow = 3;
    
    struct PreMint {
        string payload;
        bytes32 preImage;
    }
    
    struct PreTransfer {
        string payload;
        bytes32 preImage;
        address _from;
    }
    
    struct Offer {
        uint tokenId;
        address _from;
    }

    mapping(address => mapping(uint => PreMint)) preMints;
    mapping(address => mapping(uint => PreMint)) preMintsByIndex;
    mapping(address => uint) preMintCounts;
    
    mapping(uint => PreTransfer) preTransfers;
    mapping(uint => mapping(uint => PreTransfer)) preTransfersByIndex;
    mapping(uint => uint) preTransferCounts;
    
    mapping(uint => Offer[]) offers;
    mapping(uint => Offer[]) rejected;
    mapping(address => mapping(uint => Offer)) offered;
    
    mapping(address => bool) public blacklisted;
    mapping(address => bool) public witnesses;
    mapping(uint256 => bool) usedNonces;
    mapping(uint256 => bool) public usedTokenIds;
    
    // event for EVM logging
    event OwnerSet(address indexed oldOwner, address indexed newOwner);
    
    // modifier to check if caller is owner
    modifier isOwner() {
        // If the first argument of 'require' evaluates to 'false', execution terminates and all
        // changes to the state and to Ether balances are reverted.
        // This used to consume all gas in old EVM versions, but not anymore.
        // It is often a good idea to use 'require' to check if functions are called correctly.
        // As a second argument, you can also provide an explanation about what went wrong.
        require(msg.sender == owner, "Caller is not owner");
        _;
    }

    // modifier to check if caller blacklisted
    modifier notBlacklisted() {
        require(!blacklisted[msg.sender], "Caller is blacklisted");
        _;
    }
    
    /**
     * @dev Change owner
     * @param newOwner address of new owner
     */
    function transferOwnership(address payable newOwner) public isOwner {
        emit OwnerSet(owner, newOwner);
        owner = newOwner;
    }
    
    /**
     * @dev Return owner address 
     * @return address of owner
     */
    function getOwner() external view returns (address) {
        return owner;
    }
    
    constructor(address _nftAddress, address _paymentAddress, address _recipientAddress, uint256 _price) {
        owner = _msgSender(); // 'msg.sender' is sender of current call, contract deployer for a constructor
        emit OwnerSet(address(0), owner);
        addWitness(owner);
        metadataBaseUri = "https://api.emblemvault.io/s:evmetadata/meta/";
        nftAddress = _nftAddress;
        paymentAddress = _paymentAddress;
        recipientAddress = _recipientAddress;
        initialized = true;
        uint decimals = BasicERC20(paymentAddress).decimals();
        price = _price * 10 ** decimals;
    }
    
    function claim(uint256 tokenId) public isOwner {
        bytes32[] memory proof;
        IClaimed claimer = IClaimed(claimAddress);
        require(!claimer.isClaimed(nftAddress, tokenId, proof), "Already Claimed");
        
        IERC721 token = IERC721(nftAddress);
        token.burn(tokenId);
    }

    function claimOnChain(uint256 tokenId) public nonReentrant notBlacklisted {
        bytes32[] memory proof;
        IClaimed claimer = IClaimed(claimAddress);
        require(!claimer.isClaimed(nftAddress, tokenId, proof), "Already Claimed");
        IERC721 token = IERC721(nftAddress);
        require(token.ownerOf(tokenId) == _msgSender(), "Not Token Owner");
        token.burn(tokenId);
        claimer.claim(nftAddress, tokenId, _msgSender());
    }

    function addClaimAddress(address _address) public isOwner {
        claimAddress = _address;
    }

    function toggleBlacklist(address _address) public isOwner {
        blacklisted[_address] = !blacklisted[_address];
    }

    function adjustBlockWindow(uint size) public isOwner {
        blockWindow = size;
    }

    function buyWithSignature2(address _to, uint256 _tokenId, string calldata _payload, uint256 _nonce, uint signedBlock, bytes calldata _signature) public payable notBlacklisted {
        bytes32[] memory proof;
        require(signedBlock.add(blockWindow) > block.number, 'Signature expired');
        require(!IClaimed(claimAddress).isClaimed(nftAddress, _tokenId, proof) && !usedTokenIds[_tokenId], "Already claimed");
        IERC721 nftToken = IERC721(nftAddress);
        if (shouldBurn) {
            require(IERC20Token(paymentAddress).transferFrom(msg.sender, address(this), price), 'Transfer ERROR'); // Payment sent to recipient
            BasicERC20(paymentAddress).burn(price);
        } else {
            require(IERC20Token(paymentAddress).transferFrom(msg.sender, address(recipientAddress), price), 'Transfer ERROR'); // Payment sent to recipient
        }
        
        address signer = getAddressFromSignature(_tokenId, _nonce, _payload, signedBlock, _signature);
        require(witnesses[signer], 'Not Witnessed');
        usedNonces[_nonce] = true;
        string memory _uri = concat(metadataBaseUri, uintToStr(_tokenId));
        nftToken.mint(_to, _tokenId, _uri, _payload);
        usedTokenIds[_tokenId] = true;
    }

    
    
    function buyWithSignature(address _to, uint256 _tokenId, string calldata _payload, uint256 _nonce, bytes calldata _signature) public isOwner payable {
        IERC20Token paymentToken = IERC20Token(paymentAddress);
        IERC721 nftToken = IERC721(nftAddress);
        if (shouldBurn) {
            require(paymentToken.transferFrom(msg.sender, address(this), price), 'Transfer ERROR'); // Payment sent to recipient
            BasicERC20(paymentAddress).burn(price);
        } else {
            require(paymentToken.transferFrom(msg.sender, address(recipientAddress), price), 'Transfer ERROR'); // Payment sent to recipient
        }        
        address signer = getAddressFromSignature(_tokenId, _nonce, _payload, _signature);
        require(witnesses[signer], 'Not Witnessed');
        usedNonces[_nonce] = true;
        string memory _uri = concat(metadataBaseUri, uintToStr(_tokenId));
        nftToken.mint(_to, _tokenId, _uri, _payload);
    }
    
    
    function addPreMint(address _for, string calldata _payload, uint256 _tokenId, bytes32 preImage) public isOwner {
        try IERC721(nftAddress).tokenPayload(_tokenId) returns (string memory) {
            revert('NFT Exists with this ID');
        } catch {
            require(!_duplicatePremint(_for, _tokenId), 'Duplicate PreMint');
            preMintCounts[_for] = preMintCounts[_for].add(1);
            preMints[_for][_tokenId] = PreMint(_payload, preImage);
            preMintsByIndex[_for][preMintCounts[_for]] = preMints[_for][_tokenId];
        }
    }
    
    function _duplicatePremint(address _for, uint256 _tokenId) internal view returns (bool) {
        string memory data = preMints[_for][_tokenId].payload;
        bytes32 NULL = keccak256(bytes(''));
        return keccak256(bytes(data)) != NULL;
    }
    
    function deletePreMint(address _for, uint256 _tokenId) public isOwner {
        delete preMintsByIndex[_for][preMintCounts[_for]];
        preMintCounts[_for] = preMintCounts[_for].sub(1);
        delete preMints[_for][_tokenId];
    }
    
    function getPreMint(address _for, uint256 _tokenId) public view returns (PreMint memory) {
        return preMints[_for][_tokenId];
    }
    
    function checkPreMintImage(string memory image, bytes32 preImage) public pure returns (bytes32, bytes32, bool) {
        bytes32 calculated = sha256(abi.encodePacked(image));
        bytes32 preBytes = preImage;
        return (calculated, preBytes, calculated == preBytes);
    }
    
    function getPreMintCount(address _for) public view returns (uint length) {
        return preMintCounts[_for];
    }
    
    function getPreMintByIndex(address _for, uint index) public view returns (PreMint memory) {
        return preMintsByIndex[_for][index];
    }
    
    function toggleShouldBurn() public isOwner {
        shouldBurn = !shouldBurn;
    }
    
    /* Transfer with code */
    function addWitness(address _witness) public isOwner {
        witnesses[_witness] = true;
    }

    function removeWitness(address _witness) public isOwner {
        witnesses[_witness] = false;
    }
    
    function getAddressFromSignature(uint256 _tokenId, uint256 _nonce, bytes memory signature) public view returns (address) {
        require(!usedNonces[_nonce]);
        bytes32 hash = keccak256(abi.encodePacked(concat(uintToStr(_tokenId), uintToStr(_nonce))));
        address addressFromSig = recoverSigner(hash, signature);
        return addressFromSig;
    }
    
    function getAddressFromSignature(uint256 _tokenId, uint256 _nonce, string calldata payload, bytes memory signature) public view returns (address) {
        require(!usedNonces[_nonce]);
        string memory combined = concat(uintToStr(_tokenId), payload);
        bytes32 hash = keccak256(abi.encodePacked(concat(combined, uintToStr(_nonce))));
        address addressFromSig = recoverSigner(hash, signature);
        return addressFromSig;
    }

    function getAddressFromSignature(uint256 _tokenId, uint256 _nonce, string calldata payload, uint blockNumber, bytes memory signature) public view returns (address) {
        require(!usedNonces[_nonce]);
        string memory combined = concat(concat(uintToStr(_tokenId), payload), uintToStr(blockNumber));
        bytes32 hash = keccak256(abi.encodePacked(concat(combined, uintToStr(_nonce))));
        address addressFromSig = recoverSigner(hash, signature);
        return addressFromSig;
    }
    
    function getAddressFromSignature(bytes32 _hash, bytes calldata signature) public pure returns (address) {
        address addressFromSig = recoverSigner(_hash, signature);
        return addressFromSig;
    }
    
    function getHash(string calldata _payload) public pure returns (bytes32) {
        bytes32 hash = keccak256(abi.encodePacked(_payload));
        return hash;
    }
    
    function transferWithCode(uint256 _tokenId, string calldata code, address _to, uint256 _nonce,  bytes memory signature) public payable notBlacklisted {
        require(witnesses[getAddressFromSignature(_tokenId, _nonce, signature)], 'Not Witnessed');
        IERC721 nftToken = IERC721(nftAddress);
        PreTransfer memory preTransfer = preTransfers[_tokenId];
        require(preTransfer.preImage == sha256(abi.encodePacked(code)), 'Code does not match'); // Payload should match
        nftToken.transferFrom(preTransfer._from, _to,  _tokenId);
        delete preTransfers[_tokenId];
        delete preTransfersByIndex[_tokenId][preTransferCounts[_tokenId]];
        preTransferCounts[_tokenId] = preTransferCounts[_tokenId].sub(1);
        usedNonces[_nonce] = true;
    }
    
    function addPreTransfer(uint256 _tokenId, bytes32 preImage) public {
        require(!_duplicatePretransfer(_tokenId), 'Duplicate PreTransfer');
        preTransferCounts[_tokenId] = preTransferCounts[_tokenId].add(1);
        preTransfers[_tokenId] = PreTransfer("payload", preImage, msg.sender);
        preTransfersByIndex[_tokenId][preTransferCounts[_tokenId]] = preTransfers[_tokenId];
    }
    
    function _duplicatePretransfer(uint256 _tokenId) internal view returns (bool) {
        string memory data = preTransfers[_tokenId].payload;
        bytes32 NULL = keccak256(bytes(''));
        return keccak256(bytes(data)) != NULL;
    }
    
    function deletePreTransfer(uint256 _tokenId) public {
        require(preTransfers[_tokenId]._from == msg.sender, 'PreTransfer does not belong to sender');
        delete preTransfersByIndex[_tokenId][preTransferCounts[_tokenId]];
        preTransferCounts[_tokenId] = preTransferCounts[_tokenId].sub(1);
        delete preTransfers[_tokenId];
    }
    
    function getPreTransfer(uint256 _tokenId) public view returns (PreTransfer memory) {
        return preTransfers[_tokenId];
    }
    
    function checkPreTransferImage(string memory image, bytes32 preImage) public pure returns (bytes32, bytes32, bool) {
        bytes32 calculated = sha256(abi.encodePacked(image));
        bytes32 preBytes = preImage;
        return (calculated, preBytes, calculated == preBytes);
    }
    
    function getPreTransferCount(uint256 _tokenId) public view returns (uint length) {
        return preTransferCounts[_tokenId];
    }
    
    function getPreTransferByIndex(uint256 _tokenId, uint index) public view returns (PreTransfer memory) {
        return preTransfersByIndex[_tokenId][index];
    }
    
    function changeMetadataBaseUri(string calldata _uri) public isOwner {
        metadataBaseUri = _uri;
    }
    
    function transferPaymentOwnership(address newOwner) external isOwner {
        Ownable paymentToken = Ownable(paymentAddress);
        paymentToken.transferOwnership(newOwner);
    }
    
    function transferNftOwnership(address newOwner) external isOwner {
        Ownable nftToken = Ownable(nftAddress);
        nftToken.transferOwnership(newOwner);
    }
    
    function mint( address _to, uint256 _tokenId, string calldata _uri, string calldata _payload) external isOwner {
        IERC721 nftToken = IERC721(nftAddress);
        nftToken.mint(_to, _tokenId, _uri, _payload);
    }
    
    function changeName(string calldata name, string calldata symbol) external isOwner {
        IERC721 nftToken = IERC721(nftAddress);
        nftToken.changeName(name, symbol);
    }
    
    function updateTokenUri(uint256 _tokenId,string memory _uri) external isOwner {
        IERC721 nftToken = IERC721(nftAddress);
        nftToken.updateTokenUri(_tokenId, _uri);
    }
    
    function getPaymentDecimals() public view returns (uint8){
        BasicERC20 token = BasicERC20(paymentAddress);
        return token.decimals();
    }
    
    function changePayment(address payment) public isOwner {
       paymentAddress = payment;
    }
    
    // function changeCoupon(address coupon) public isOwner {
    //   couponAddress = coupon;
    // }
    
    function changeRecipient(address _recipient) public isOwner {
       recipientAddress = _recipient;
    }
    
    function changeNft(address token) public isOwner {
        nftAddress = token;
    }
    
    function changePrice(uint256 _price) public isOwner {
        uint decimals = BasicERC20(paymentAddress).decimals();
        price = _price * 10 ** decimals;
    }
    
    // function changeOfferPrice(uint256 _price) public isOwner {
    //     uint decimals = BasicERC20(couponAddress).decimals();
    //     offerPrice = _price * 10 ** decimals;
    // }
    
    function addChainId(uint chainId) public isOwner returns (bool) {
        return (_addChainId(chainId));
    }
    
    function removeChainId(uint chainId) public isOwner returns (bool) {
        return (_removeChainId(chainId));
    }
    
    function transferFromChain(address _to, uint chainId, uint256 amount) public isOwner returns (bool) {
        return _transferFromChain(_to, chainId, amount);
    }
    
    function concat(string memory a, string memory b) internal pure returns (string memory) {
        return string(abi.encodePacked(a, b));
    }
    /**
    * @dev Recover signer address from a message by using their signature
    * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
    * @param sig bytes signature, the signature is generated using web3.eth.sign(). Inclusive "0x..."
    */
    function recoverSigner(bytes32 hash, bytes memory sig) internal pure returns (address) {
        require(sig.length == 65, "Require correct length");

        bytes32 r;
        bytes32 s;
        uint8 v;

        // Divide the signature in r, s and v variables
        assembly {
            r := mload(add(sig, 32))
            s := mload(add(sig, 64))
            v := byte(0, mload(add(sig, 96)))
        }

        // Version of signature should be 27 or 28, but 0 and 1 are also possible versions
        if (v < 27) {
            v += 27;
        }

        require(v == 27 || v == 28, "Signature version not match");

        return recoverSigner2(hash, v, r, s);
    }

    function recoverSigner2(bytes32 h, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        bytes memory prefix = "\x19Ethereum Signed Message:\n32";
        bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, h));
        address addr = ecrecover(prefixedHash, v, r, s);

        return addr;
    }
    
    function uintToStr(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }
    
    function stringToBytes32(string memory source) internal pure returns (bytes32 result) {
        bytes memory tempEmptyStringTest = bytes(source);
        if (tempEmptyStringTest.length == 0) {
            return 0x0;
        }
    
        assembly {
            result := mload(add(source, 32))
        }
    }
    function bytes32ToStr(bytes32 _bytes32) internal pure returns (string memory) {

        // string memory str = string(_bytes32);
        // TypeError: Explicit type conversion not allowed from "bytes32" to "string storage pointer"
        // thus we should fist convert bytes32 to bytes (to dynamically-sized byte array)
    
        bytes memory bytesArray = new bytes(32);
        for (uint256 i; i < 32; i++) {
            bytesArray[i] = _bytes32[i];
            }
        return string(bytesArray);
    }
    function asciiToInteger(bytes32 x) public pure returns (uint256) {
        uint256 y;
        for (uint256 i = 0; i < 32; i++) {
            uint256 c = (uint256(x) >> (i * 8)) & 0xff;
            if (48 <= c && c <= 57)
                y += (c - 48) * 10 ** i;
            else
                break;
        }
        return y;
    }
    function toString(address account) public pure returns(string memory) {
        return toString(abi.encodePacked(account));
    }
    
    function toString(uint256 value) public pure returns(string memory) {
        return toString(abi.encodePacked(value));
    }
    
    function toString(bytes32 value) public pure returns(string memory) {
        return toString(abi.encodePacked(value));
    }
    
    function toString(bytes memory data) public pure returns(string memory) {
        bytes memory alphabet = "0123456789abcdef";
    
        bytes memory str = new bytes(2 + data.length * 2);
        str[0] = "0";
        str[1] = "x";
        for (uint i = 0; i < data.length; i++) {
            str[2+i*2] = alphabet[uint(uint8(data[i] >> 4))];
            str[3+i*2] = alphabet[uint(uint8(data[i] & 0x0f))];
        }
        return string(str);
    }
}
[{"inputs":[{"internalType":"address","name":"_nftAddress","type":"address"},{"internalType":"address","name":"_paymentAddress","type":"address"},{"internalType":"address","name":"_recipientAddress","type":"address"},{"internalType":"uint256","name":"_price","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"BridgeDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"BridgeWithdrawal","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerSet","type":"event"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"addChainId","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"addClaimAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"},{"internalType":"string","name":"_payload","type":"string"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"name":"addPreMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"name":"addPreTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_witness","type":"address"}],"name":"addWitness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"size","type":"uint256"}],"name":"adjustBlockWindow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"x","type":"bytes32"}],"name":"asciiToInteger","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"blacklisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_payload","type":"string"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"buyWithSignature","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_payload","type":"string"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"uint256","name":"signedBlock","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"buyWithSignature2","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"chainBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"chainIds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_uri","type":"string"}],"name":"changeMetadataBaseUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"}],"name":"changeName","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"changeNft","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payment","type":"address"}],"name":"changePayment","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"changePrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"}],"name":"changeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"image","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"name":"checkPreMintImage","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"string","name":"image","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"name":"checkPreTransferImage","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"claimOnChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"deletePreMint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"deletePreTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"string","name":"payload","type":"string"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"getAddressFromSignature","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"string","name":"payload","type":"string"},{"internalType":"uint256","name":"blockNumber","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"getAddressFromSignature","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"getAddressFromSignature","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"getAddressFromSignature","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_payload","type":"string"}],"name":"getHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPaymentDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getPreMint","outputs":[{"components":[{"internalType":"string","name":"payload","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"internalType":"struct VaultHandlerV7a.PreMint","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getPreMintByIndex","outputs":[{"components":[{"internalType":"string","name":"payload","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"}],"internalType":"struct VaultHandlerV7a.PreMint","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_for","type":"address"}],"name":"getPreMintCount","outputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getPreTransfer","outputs":[{"components":[{"internalType":"string","name":"payload","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"},{"internalType":"address","name":"_from","type":"address"}],"internalType":"struct VaultHandlerV7a.PreTransfer","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getPreTransferByIndex","outputs":[{"components":[{"internalType":"string","name":"payload","type":"string"},{"internalType":"bytes32","name":"preImage","type":"bytes32"},{"internalType":"address","name":"_from","type":"address"}],"internalType":"struct VaultHandlerV7a.PreTransfer","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getPreTransferCount","outputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"metadataBaseUri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_uri","type":"string"},{"internalType":"string","name":"_payload","type":"string"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nftAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paymentAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"recipientAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"removeChainId","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_witness","type":"address"}],"name":"removeWitness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shouldBurn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"toString","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"name":"toString","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"toString","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"value","type":"bytes32"}],"name":"toString","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"toggleBlacklist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"toggleShouldBurn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFromChain","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferNftOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address payable","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferPaymentOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferToChain","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"code","type":"string"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"transferWithCode","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"string","name":"_uri","type":"string"}],"name":"updateTokenUri","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"usedTokenIds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"witnesses","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]