# -*- coding: utf-8 -*- # Copyright (c) 2019 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE.txt or http://www.opensource.org/licenses/mit-license.php. import struct import time import sqlalchemy as sa from sqlalchemy.ext.declarative import declarative_base CURRENT_DB_VERSION = 2 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) 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) auto_accept_bids = sa.Column(sa.Boolean) 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('