合约代码如下: // SPDX-License-Identifier: MIT pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract DexContract {
address private owner;
mapping(address => uint256) public balances;
mapping(string => bool) private txHashExists;
string[] private txHashList;
event transferTokenLog(address from ,address to ,uint256 amount);
event transferoutTokenLog(address addr, uint256 amount,string txhash);
event OwnershipTransferred(address oldOwner,address newOwner);
event transferoutTokenStart(address addr);
event transferoutTokenEnd(address addr);
event transferoutTokenLog(address addr);
ERC20 private _tokenContract;
constructor(address tokenAddress) {
owner = payable(msg.sender);
_tokenContract = ERC20(tokenAddress);
}
function deposit() external payable {
balances[address(this)] += msg.value;
}
function transferToken(uint256 amount) public {
_tokenContract.transferFrom(msg.sender, address(this), amount);
emit transferTokenLog(msg.sender, address(this), amount);
}
function transferoutToken(address addr, uint256 amount,string memory txHash) public {
emit transferoutTokenStart(addr);
require(!txHashExists[txHash], "Transaction hash already exists");
emit transferoutTokenLog(addr);
require(owner == msg.sender, "transfer failed.");
_tokenContract.transfer(addr, amount);
emit transferoutTokenEnd(addr);
txHashExists[txHash] = true;
txHashList.push(txHash);
emit transferoutTokenLog(addr, amount, txHash);
}
function transferOwnership(address newOwner) public virtual {
require(owner == msg.sender, "Insufficient permissions.");
require(newOwner != address(0), "Invalid address.");
address oldOwner = owner;
owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}