mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-07 03:08:10 +01:00
Set bid and offer states when expired.
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2019-2023 tecnovert
|
||||
# Copyright (c) 2019-2024 tecnovert
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import time
|
||||
import struct
|
||||
import sqlalchemy as sa
|
||||
|
||||
from enum import IntEnum, auto
|
||||
@@ -34,6 +33,10 @@ def strConcepts(state):
|
||||
return 'Unknown'
|
||||
|
||||
|
||||
def pack_state(new_state: int, now: int) -> bytes:
|
||||
return int(new_state).to_bytes(4, 'little') + now.to_bytes(8, 'little')
|
||||
|
||||
|
||||
class DBKVInt(Base):
|
||||
__tablename__ = 'kv_int'
|
||||
|
||||
@@ -96,9 +99,9 @@ class Offer(Base):
|
||||
now = int(time.time())
|
||||
self.state = new_state
|
||||
if self.states is None:
|
||||
self.states = struct.pack('<iq', new_state, now)
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += struct.pack('<iq', new_state, now)
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class Bid(Base):
|
||||
@@ -183,9 +186,9 @@ class Bid(Base):
|
||||
if state_note is not None:
|
||||
self.state_note = state_note
|
||||
if self.states is None:
|
||||
self.states = struct.pack('<iq', new_state, now)
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += struct.pack('<iq', new_state, now)
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class SwapTx(Base):
|
||||
@@ -222,7 +225,11 @@ class SwapTx(Base):
|
||||
if self.state == new_state:
|
||||
return
|
||||
self.state = new_state
|
||||
self.states = (self.states if self.states is not None else bytes()) + struct.pack('<iq', new_state, int(time.time()))
|
||||
now: int = int(time.time())
|
||||
if self.states is None:
|
||||
self.states = pack_state(new_state, now)
|
||||
else:
|
||||
self.states += pack_state(new_state, now)
|
||||
|
||||
|
||||
class PrefundedTx(Base):
|
||||
|
||||
Reference in New Issue
Block a user