CREATE TABLE IF NOT EXISTS ETH_wallets (
    address TEXT PRIMARY KEY NOT NULL,
    queue_id TEXT NOT NULL,
    timestamp INTEGER NOT NULL,
    sign TEXT NOT NULL,
    status INTEGER DEFAULT 0 -- 0未在监听 1正在监听
);

CREATE TABLE IF NOT EXISTS ETH_balances (
    address TEXT NOT NULL,
    symbol TEXT DEFAULT "ETH",
    used_gas TEXT DEFAULT "0",
    balance TEXT 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 TEXT NOT NULL,
    symbol TEXT DEFAULT "USDT",
    freeze_num TEXT DEFAULT "0",
    balance TEXT 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 TEXT NOT NULL, -- 关联的msg queue_id
    tx_type INTEGER NOT NULL, --0充值，1提现，2支付
    chain TEXT DEFALUT "ETH",
    symbol TEXT,
	from_addr TEXT,
	to_addr TEXT,
    tx_hash TEXT,
	height INTEGER,
    amount TEXT,
	status INTEGER DEFAULT 2, --0充值失败，1充值成功，2充值待确认
    PRIMARY KEY (tx_hash),
    FOREIGN KEY (queue_id) REFERENCES eth_wallets (queue_id) ON DELETE CASCADE
);