CREATE TABLE IF NOT EXISTS ETH_wallets (
    address VARCHAR(255) PRIMARY KEY NOT NULL,
    queue_id VARCHAR(255) NOT NULL,
    timestamp BIGINT NOT NULL,
    sign VARCHAR(255) NOT NULL,
    status TINYINT DEFAULT 0
);

CREATE INDEX idx_queue_id ON ETH_wallets (queue_id);

CREATE TABLE IF NOT EXISTS ETH_balances (
    address VARCHAR(255) NOT NULL,
    symbol VARCHAR(32) DEFAULT "ETH",
    used_gas DECIMAL(40,16) DEFAULT 0,
    balance DECIMAL(40,16) DEFAULT 0,
    success_tx_hash TEXT DEFAULT NULL,
    failed_tx_hash TEXT DEFAULT NULL,
    PRIMARY KEY (address),
    FOREIGN KEY (address) REFERENCES ETH_wallets (address) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS USDT_balances (
    address VARCHAR(255) NOT NULL,
    symbol VARCHAR(32) DEFAULT "USDT",
    freeze_num DECIMAL(40,16) DEFAULT 0,
    balance DECIMAL(40,16) DEFAULT 0,
    success_tx_hash TEXT DEFAULT NULL,
    failed_tx_hash TEXT DEFAULT NULL,
    PRIMARY KEY (address),
    FOREIGN KEY (address) REFERENCES ETH_wallets (address) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS ETH_unconfirmed_tx (
    queue_id VARCHAR(255) NOT NULL,
    tx_type TINYINT NOT NULL,
    chain VARCHAR(32) DEFAULT "ETH",
    symbol VARCHAR(32),
    from_addr VARCHAR(255),
    to_addr VARCHAR(255),
    tx_hash VARCHAR(255),
    height BIGINT,
    amount DECIMAL(40,16),
    status TINYINT DEFAULT 2,
    FOREIGN KEY (queue_id) REFERENCES ETH_wallets (queue_id) ON DELETE CASCADE
);