-- mysql
CREATE TABLE IF NOT EXISTS topup_req_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	address VARCHAR(255) NOT NULL,
	timestamp BIGINT,
	sign VARCHAR(255),
	status TINYINT DEFAULT 1,
	PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS topup_resp_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	from_addr VARCHAR(255) NOT NULL,
	to_addr VARCHAR(255) NOT NULL,
	amount DECIMAL(30,16) NOT NULL,
	tx_hash VARCHAR(255) DEFAULT NULL,
	height BIGINT DEFAULT NULL, 
	status TINYINT DEFAULT 5, --遵循constant模块的定义
	FOREIGN KEY (queue_id) REFERENCES topup_req_msg(queue_id)
);

CREATE TABLE IF NOT EXISTS withdraw_req_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	from_addr VARCHAR(255) NOT NULL,
	to_addr VARCHAR(255) NOT NULL,
    amount DECIMAL(30,16) NOT NULL,
    fee DECIMAL(30,16) NOT NULL,
    timestamp BIGINT,
	sign VARCHAR(255),
	status TINYINT DEFAULT 5, --遵循constant模块的定义
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS withdraw_resp_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	from_addr VARCHAR(255) NOT NULL,
	to_addr VARCHAR(255) NOT NULL,
    tx_hash VARCHAR(255) DEFAULT NULL,
    amount DECIMAL(30,16) DEFAULT NULL,
    fee DECIMAL(30,16) DEFAULT NULL,
    height BIGINT DEFAULT NULL,
	status TINYINT DEFAULT 5, --遵循constant模块的定义
    FOREIGN KEY (queue_id) REFERENCES withdraw_req_msg(queue_id)
);

CREATE TABLE IF NOT EXISTS pay_req_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	from_addr VARCHAR(255) NOT NULL,
	to_addr VARCHAR(255) NOT NULL,
    amount DECIMAL(30,16) NOT NULL,
    fee DECIMAL(30,16) NOT NULL,
    timestamp BIGINT,
	sign VARCHAR(255),
	status TINYINT DEFAULT 5, --遵循constant模块的定义
    PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS pay_resp_msg (
	queue_id VARCHAR(255) NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	from_addr VARCHAR(255) NOT NULL,
	to_addr VARCHAR(255) NOT NULL,
    tx_hash VARCHAR(255) DEFAULT NULL,
    amount DECIMAL(30,16) DEFAULT NULL,
    fee DECIMAL(30,16) DEFAULT NULL,
    height BIGINT DEFAULT NULL,
	status TINYINT DEFAULT 5, --遵循constant模块的定义
    FOREIGN KEY (queue_id) REFERENCES pay_req_msg(queue_id)
);

-- pay_msg的交易
-- CREATE TABLE IF NOT EXISTS pay_msg_tx (
--     queue_id VARCHAR(255) NOT NULL,
--     tx_hash VARCHAR(255) DEFAULT NULL,
-- 	to_addr VARCHAR(255) NOT NULL,
--     amount DECIMAL(30,16) DEFAULT NULL,
--     fee DECIMAL(30,16),
--     height BIGINT DEFAULT 0,
--     status TINYINT DEFAULT 5, --遵循constant模块的定义
--     FOREIGN KEY (queue_id) REFERENCES pay_req_msg(queue_id)  
-- );

CREATE TABLE IF NOT EXISTS remove_req_msg(
    queue_id VARCHAR(255) NOT NULL,
	msg_type TINYINT NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	address VARCHAR(255) NOT NULL,
	timestamp BIGINT,
	sign VARCHAR(255),
	status TINYINT DEFAULT 2,
	PRIMARY KEY (queue_id)
);

CREATE TABLE IF NOT EXISTS remove_resp_msg(
    queue_id VARCHAR(255) NOT NULL,
	msg_type TINYINT NOT NULL,
	chain VARCHAR(32) NOT NULL,
	symbol VARCHAR(32) NOT NULL,
	address VARCHAR(255) NOT NULL,
	status TINYINT DEFAULT 2,
    FOREIGN KEY (queue_id) REFERENCES remove_req_msg(queue_id)  
);