contract ThirmProtocol is Ownable {
    mapping(string => ERC20Burnable) public tokens;
    mapping(string => address) public addressMap;
    mapping(string => bool) public transaction;

    uint256 public feeAmount = 500000000000000000;

    struct QueueBlock {
        string coin;
        string addr;
        uint256 amount;
        bool success;
    }

    QueueBlock[] public userWithdraws;

    function setTxn(string memory _txn) public onlyOwner {
        transaction[_txn] = true;
    }

    function getTxn(string memory _txn) public view returns (bool _bool) {
        return transaction[_txn];
    }

    function getUserWithdrawLength() public view returns (uint256 arrayLength) {
        return userWithdraws.length;
    }

    function getAddressMap(string memory _coinaddress)
        public
        view
        returns (address _address)
    {
        return addressMap[_coinaddress];
    }

    // Register the withdrawal
    function registerWithdrawal(
        string memory _coin,
        string memory _address,
        uint256 _amount
    ) public burnThirm returns (uint256 arrayLength) {
        require(_amount <= tokens[_coin].balanceOf(msg.sender), "no balance");
        require(
            _amount <= tokens[_coin].allowance(msg.sender, address(this)),
            "no allowance"
        );
        tokens[_coin].burnFrom(msg.sender, _amount);

        QueueBlock memory m;
        m.coin = _coin;
        m.addr = _address;
        m.amount = _amount;
        m.success = false;

        userWithdraws.push(m);
        return userWithdraws.length;
    }

    // @Admin: Custom Address Map
    function setAddressMap(string memory _coinaddress, address _address)
        public
        onlyOwner
    {
        addressMap[_coinaddress] = _address;
    }

    // @Admin: Register withdrawal success
    function registerWithdrawalSuccess(uint256 _queue) public onlyOwner {
        userWithdraws[_queue].success = true;
    }

    // @Admin: Initialize the tToken
    function tTokenInit(string memory _coin, address _token) public onlyOwner {
        tokens[_coin] = ERC20Burnable(_token);
    }

    // Get the fee amount
    function setFeeAmount(uint256 _amount) public onlyOwner {
        feeAmount = _amount;
    }

    modifier burnThirm() {
        require(
            feeAmount <= tokens["THIRM"].balanceOf(msg.sender),
            "no balance"
        );
        require(
            feeAmount <= tokens["THIRM"].allowance(msg.sender, address(this)),
            "no allowance"
        );
        tokens["THIRM"].burnFrom(msg.sender, feeAmount);
        _;
    }
}
function setFeeAmount(uint256 _amount) public onlyOwner {
    feeAmount = _amount;
}

// Get the fee amount