# -*- coding: utf-8 -*- # Copyright (c) 2019-2021 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. import struct import time import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base from enum import IntEnum, auto CURRENT_DB_VERSION = 8 Base = declarative_base() class DBKVInt(Base): __tablename__ = 'kv_int' key = sa.Column(sa.String, primary_key=True) value = sa.Column(sa.Integer) class DBKVString(Base): __tablename__ = 'kv_string' key = sa.Column(sa.String, primary_key=True) value = sa.Column(sa.String) class Offer(Base): __tablename__ = 'offers' offer_id = sa.Column(sa.LargeBinary, primary_key=True) active_ind = sa.Column(sa.Integer) coin_from = sa.Column(sa.Integer) coin_to = sa.Column(sa.Integer) amount_from = sa.Column(sa.BigInteger) rate = sa.Column(sa.BigInteger) min_bid_amount = sa.Column(sa.BigInteger) time_valid = sa.Column(sa.BigInteger) lock_type = sa.Column(sa.Integer) lock_value = sa.Column(sa.Integer) swap_type = sa.Column(sa.Integer) proof_address = sa.Column(sa.String) proof_signature = sa.Column(sa.LargeBinary) pkhash_seller = sa.Column(sa.LargeBinary) secret_hash = sa.Column(sa.LargeBinary) addr_from = sa.Column(sa.String) created_at = sa.Column(sa.BigInteger) expire_at = sa.Column(sa.BigInteger) was_sent = sa.Column(sa.Boolean) from_feerate = sa.Column(sa.BigInteger) to_feerate = sa.Column(sa.BigInteger) # Local fields auto_accept_bids = sa.Column(sa.Boolean) withdraw_to_addr = sa.Column(sa.String) # Address to spend lock tx to - address from wallet if empty TODO security_token = sa.Column(sa.LargeBinary) state = sa.Column(sa.Integer) states = sa.Column(sa.LargeBinary) # Packed states and times def setState(self, new_state): now = int(time.time()) self.state = new_state if self.states is None: self.states = struct.pack(' L coin_a_lock_refund_spend_tx_msg_id = sa.Column(sa.LargeBinary) # MSG4F L -> F contract_count = sa.Column(sa.Integer) dest_af = sa.Column(sa.LargeBinary) # Destination for coin A amount to follower when swap completes successfully pkal = sa.Column(sa.LargeBinary) pkasl = sa.Column(sa.LargeBinary) pkaf = sa.Column(sa.LargeBinary) pkasf = sa.Column(sa.LargeBinary) vkbvl = sa.Column(sa.LargeBinary) vkbsl = sa.Column(sa.LargeBinary) pkbvl = sa.Column(sa.LargeBinary) pkbsl = sa.Column(sa.LargeBinary) vkbvf = sa.Column(sa.LargeBinary) vkbsf = sa.Column(sa.LargeBinary) pkbvf = sa.Column(sa.LargeBinary) pkbsf = sa.Column(sa.LargeBinary) kbsl_dleag = sa.Column(sa.LargeBinary) kbsf_dleag = sa.Column(sa.LargeBinary) vkbv = sa.Column(sa.LargeBinary) pkbv = sa.Column(sa.LargeBinary) pkbs = sa.Column(sa.LargeBinary) a_lock_tx = sa.Column(sa.LargeBinary) a_lock_tx_script = sa.Column(sa.LargeBinary) a_lock_tx_id = sa.Column(sa.LargeBinary) a_lock_tx_vout = sa.Column(sa.Integer) a_lock_refund_tx = sa.Column(sa.LargeBinary) a_lock_refund_tx_script = sa.Column(sa.LargeBinary) a_lock_refund_tx_id = sa.Column(sa.LargeBinary) a_swap_refund_value = sa.Column(sa.BigInteger) al_lock_refund_tx_sig = sa.Column(sa.LargeBinary) af_lock_refund_tx_sig = sa.Column(sa.LargeBinary) a_lock_refund_spend_tx = sa.Column(sa.LargeBinary) a_lock_refund_spend_tx_id = sa.Column(sa.LargeBinary) af_lock_refund_spend_tx_esig = sa.Column(sa.LargeBinary) af_lock_refund_spend_tx_sig = sa.Column(sa.LargeBinary) a_lock_spend_tx = sa.Column(sa.LargeBinary) a_lock_spend_tx_id = sa.Column(sa.LargeBinary) al_lock_spend_tx_esig = sa.Column(sa.LargeBinary) kal_sig = sa.Column(sa.LargeBinary) a_lock_refund_swipe_tx = sa.Column(sa.LargeBinary) # Follower spends script coin lock refund tx b_lock_tx_id = sa.Column(sa.LargeBinary) start_chain_a_height = sa.Column(sa.Integer) # Height of script chain before the swap b_restore_height = sa.Column(sa.Integer) # Height of scriptless chain before the swap class XmrSplitData(Base): __tablename__ = 'xmr_split_data' record_id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) bid_id = sa.Column(sa.LargeBinary) msg_type = sa.Column(sa.Integer) msg_sequence = sa.Column(sa.Integer) dleag = sa.Column(sa.LargeBinary) created_at = sa.Column(sa.BigInteger) __table_args__ = (sa.UniqueConstraint('bid_id', 'msg_type', 'msg_sequence', name='uc_1'),) class RevokedMessage(Base): __tablename__ = 'revoked_messages' record_id = sa.Column(sa.Integer, primary_key=True, autoincrement=True) active_ind = sa.Column(sa.Integer) msg_id = sa.Column(sa.LargeBinary) created_at = sa.Column(sa.BigInteger) expires_at = sa.Column(sa.BigInteger) class TableTypes(IntEnum): OFFER = auto() BID = auto()