CREATE TABLE IF NOT EXISTS topup_req_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    address TEXT NOT NULL,
    timestamp INTEGER,
    sign TEXT,
    status INTEGER DEFAULT 1,
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS topup_resp_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    from_addr TEXT DEFAULT NULL,
    to_addr TEXT NOT NULL,
    amount TEXT NOT NULL,  -- 改为 TEXT 类型
    tx_hash TEXT DEFAULT NULL,
    height INTEGER DEFAULT NULL, 
    status INTEGER DEFAULT 5, 
    FOREIGN KEY (queue_id) REFERENCES topup_req_msg(queue_id)
);

CREATE TABLE IF NOT EXISTS withdraw_req_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    from_addr TEXT NOT NULL,
    to_addr TEXT NOT NULL,
    amount TEXT NOT NULL,  -- 改为 TEXT 类型
    fee TEXT NOT NULL,    -- 改为 TEXT 类型
    timestamp INTEGER,
    sign TEXT,
    status INTEGER DEFAULT 5,
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS withdraw_resp_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    from_addr TEXT NOT NULL,
    to_addr TEXT NOT NULL,
    tx_hash TEXT DEFAULT NULL,
    amount TEXT DEFAULT NULL,  -- 改为 TEXT 类型
    fee TEXT DEFAULT NULL,     -- 改为 TEXT 类型
    height INTEGER DEFAULT NULL,
    status INTEGER DEFAULT 5,
    FOREIGN KEY (queue_id) REFERENCES withdraw_req_msg(queue_id)
);

CREATE TABLE IF NOT EXISTS pay_req_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    from_addr TEXT NOT NULL,
    to_addr TEXT NOT NULL,
    total_amount TEXT NOT NULL,  -- 改为 TEXT 类型
    total_fee TEXT NOT NULL,    -- 改为 TEXT 类型
    timestamp INTEGER,
    sign TEXT,
    status INTEGER DEFAULT 5,
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS pay_resp_msg (
    queue_id TEXT NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    from_addr TEXT NOT NULL,
    pay_status INTEGER DEFAULT 5, 
    FOREIGN KEY (queue_id) REFERENCES pay_req_msg(queue_id)  
);

-- pay_msg的交易
CREATE TABLE IF NOT EXISTS pay_msg_tx (
    queue_id TEXT NOT NULL,
    tx_hash TEXT DEFAULT NULL,
    to_addr TEXT NOT NULL,
    amount TEXT DEFAULT NULL,  -- 改为 TEXT 类型
    fee TEXT,                  -- 改为 TEXT 类型
    height INTEGER DEFAULT 0,
    status INTEGER DEFAULT 5,
    FOREIGN KEY (queue_id) REFERENCES pay_req_msg(queue_id)  
);

CREATE TABLE IF NOT EXISTS remove_req_msg(
    queue_id TEXT NOT NULL,
    msg_type INTEGER NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    address TEXT NOT NULL,
    timestamp INTEGER,
    sign TEXT,
    status INTEGER DEFAULT 2,
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS remove_resp_msg(
    queue_id TEXT NOT NULL,
    msg_type INTEGER NOT NULL,
    chain TEXT NOT NULL,
    symbol TEXT NOT NULL,
    address TEXT NOT NULL,
    status INTEGER DEFAULT 2,
    FOREIGN KEY (queue_id) REFERENCES remove_req_msg(queue_id)  
);