diff --git a/basicswap/__init__.py b/basicswap/__init__.py index 18d9033..2a724a2 100644 --- a/basicswap/__init__.py +++ b/basicswap/__init__.py @@ -1,3 +1,3 @@ name = "basicswap" -__version__ = "0.11.58" +__version__ = "0.11.59" diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index bd87c6b..83b1413 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -4273,7 +4273,7 @@ class BasicSwap(BaseApp): except AutomationConstraint as e: self.log.info('Not auto accepting bid {}, {}'.format(bid.bid_id.hex(), str(e))) if self.debug: - self.logEvent(Concepts.AUTOMATION, + self.logEvent(Concepts.BID, bid.bid_id, EventLogTypes.AUTOMATION_CONSTRAINT, str(e), @@ -5814,7 +5814,7 @@ class BasicSwap(BaseApp): session.remove() self.mxDB.release() - def updateWalletInfo(self, coin): + def updateWalletInfo(self, coin) -> None: # Store wallet info to db so it's available after startup try: bi = self.getBlockchainInfo(coin) @@ -6141,15 +6141,22 @@ class BasicSwap(BaseApp): session.remove() self.mxDB.release() - def getAutomationStrategy(self, strategy_id): - self.mxDB.acquire() + def getAutomationStrategy(self, strategy_id: int): try: - session = scoped_session(self.session_factory) + session = self.openSession() return session.query(AutomationStrategy).filter_by(record_id=strategy_id).first() finally: - session.close() - session.remove() - self.mxDB.release() + self.closeSession(session, commit=False) + + def updateAutomationStrategy(self, strategy_id: int, data, note: str) -> None: + try: + session = self.openSession() + strategy = session.query(AutomationStrategy).filter_by(record_id=strategy_id).first() + strategy.data = json.dumps(data).encode('utf-8') + strategy.note = note + session.add(strategy) + finally: + self.closeSession(session) def getLinkedStrategy(self, linked_type, linked_id): self.mxDB.acquire() @@ -6211,7 +6218,7 @@ class BasicSwap(BaseApp): if session is None: self.closeSession(use_session) - def addSMSGAddress(self, pubkey_hex, addressnote=None): + def addSMSGAddress(self, pubkey_hex: str, addressnote: str = None) -> None: self.mxDB.acquire() try: session = scoped_session(self.session_factory) @@ -6229,7 +6236,7 @@ class BasicSwap(BaseApp): session.remove() self.mxDB.release() - def editSMSGAddress(self, address, active_ind, addressnote): + def editSMSGAddress(self, address: str, active_ind: int, addressnote: str) -> None: self.mxDB.acquire() try: session = scoped_session(self.session_factory) diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index 391a799..ca79478 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Copyright (c) 2020-2022 tecnovert +# Copyright (c) 2020-2023 tecnovert # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -260,7 +260,7 @@ class BTCInterface(CoinInterface): last_block_header = prev_block_header raise ValueError(f'Block header not found at time: {time}') - def initialiseWallet(self, key_bytes: bytes): + def initialiseWallet(self, key_bytes: bytes) -> None: key_wif = self.encodeKey(key_bytes) self.rpc_callback('sethdseed', [True, key_wif]) @@ -388,11 +388,11 @@ class BTCInterface(CoinInterface): def getPubkey(self, privkey): return PublicKey.from_secret(privkey).format() - def getAddressHashFromKey(self, key) -> bytes: + def getAddressHashFromKey(self, key: bytes) -> bytes: pk = self.getPubkey(key) return hash160(pk) - def getSeedHash(self, seed): + def getSeedHash(self, seed) -> bytes: return self.getAddressHashFromKey(seed)[::-1] def verifyKey(self, k: bytes) -> bool: diff --git a/basicswap/interface/firo.py b/basicswap/interface/firo.py index b4feb40..260ca03 100644 --- a/basicswap/interface/firo.py +++ b/basicswap/interface/firo.py @@ -163,7 +163,7 @@ class FIROInterface(BTCInterface): return CScript([OP_HASH160, script_hash_hash, OP_EQUAL]) - def getSeedHash(self, seed): + def getSeedHash(self, seed) -> bytes: return hash160(seed)[::-1] def encodeScriptDest(self, script): diff --git a/basicswap/interface/xmr.py b/basicswap/interface/xmr.py index 2180630..31a3fd0 100644 --- a/basicswap/interface/xmr.py +++ b/basicswap/interface/xmr.py @@ -127,7 +127,7 @@ class XMRInterface(CoinInterface): self.createWallet(params) self.openWallet(self._wallet_filename) - def ensureWalletExists(self): + def ensureWalletExists(self) -> None: with self._mx_wallet: self.openWallet(self._wallet_filename) @@ -190,12 +190,12 @@ class XMRInterface(CoinInterface): def walletRestoreHeight(self): return self._restore_height - def getMainWalletAddress(self): + def getMainWalletAddress(self) -> str: with self._mx_wallet: self.openWallet(self._wallet_filename) return self.rpc_wallet_cb('get_address')['address'] - def getNewAddress(self, placeholder): + def getNewAddress(self, placeholder) -> str: with self._mx_wallet: self.openWallet(self._wallet_filename) return self.rpc_wallet_cb('create_address', {'account_index': 0})['address'] @@ -204,19 +204,19 @@ class XMRInterface(CoinInterface): self._log.warning('TODO - estimate fee rate?') return 0.0, 'unused' - def getNewSecretKey(self): + def getNewSecretKey(self) -> bytes: return edu.get_secret() - def pubkey(self, key): + def pubkey(self, key: bytes) -> bytes: return edf.scalarmult_B(key) - def encodeKey(self, vk): + def encodeKey(self, vk: bytes) -> str: return vk[::-1].hex() - def decodeKey(self, k_hex): + def decodeKey(self, k_hex: str) -> bytes: return bytes.fromhex(k_hex)[::-1] - def encodePubkey(self, pk): + def encodePubkey(self, pk: bytes) -> str: return edu.encodepoint(pk) def decodePubkey(self, pke): @@ -225,12 +225,12 @@ class XMRInterface(CoinInterface): def getPubkey(self, privkey): return ed25519_get_pubkey(privkey) - def getAddressFromKeys(self, key_view, key_spend): + def getAddressFromKeys(self, key_view: bytes, key_spend: bytes) -> str: pk_view = self.getPubkey(key_view) pk_spend = self.getPubkey(key_spend) return xmr_util.encode_address(pk_view, pk_spend) - def verifyKey(self, k): + def verifyKey(self, k: int) -> bool: i = b2i(k) return (i < edf.l and i > 8) @@ -239,23 +239,23 @@ class XMRInterface(CoinInterface): # Checks for small order return verify_ed25519_point(pubkey_bytes) - def proveDLEAG(self, key): + def proveDLEAG(self, key: bytes) -> bytes: privkey = PrivateKey(key) return dleag_prove(privkey) - def verifyDLEAG(self, dleag_bytes): + def verifyDLEAG(self, dleag_bytes: bytes) -> bool: return dleag_verify(dleag_bytes) - def lengthDLEAG(self): + def lengthDLEAG(self) -> int: return dleag_proof_len() - def sumKeys(self, ka, kb): + def sumKeys(self, ka: bytes, kb: bytes) -> bytes: return ed25519_scalar_add(ka, kb) - def sumPubkeys(self, Ka, Kb): + def sumPubkeys(self, Ka: bytes, Kb: bytes) -> bytes: return ed25519_add(Ka, Kb) - def encodeSharedAddress(self, Kbv, Kbs): + def encodeSharedAddress(self, Kbv: bytes, Kbs: bytes) -> str: return xmr_util.encode_address(Kbv, Kbs) def publishBLockTx(self, kbv, Kbs, output_amount, feerate, delay_for: int = 10, unlock_time: int = 0) -> bytes: @@ -494,14 +494,14 @@ class XMRInterface(CoinInterface): self._wallet_password = orig_password raise e - def unlockWallet(self, password): + def unlockWallet(self, password: str) -> None: self._log.info('unlockWallet - {}'.format(self.ticker())) self._wallet_password = password if not self._have_checked_seed: self._sc.checkWalletSeed(self.coin_type()) - def lockWallet(self): + def lockWallet(self) -> None: self._log.info('lockWallet - {}'.format(self.ticker())) self._wallet_password = None diff --git a/basicswap/js_server.py b/basicswap/js_server.py index 7664889..87f01fc 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -551,10 +551,17 @@ def js_getcoinseed(self, url_split, post_string, is_json) -> bytes: raise ValueError('Particl wallet seed is set from the Basicswap mnemonic.') ci = swap_client.ci(coin) - seed = swap_client.getWalletKey(coin, 1) + if coin == Coins.XMR: + key_view = swap_client.getWalletKey(coin, 1, for_ed25519=True) + key_spend = swap_client.getWalletKey(coin, 2, for_ed25519=True) + address = ci.getAddressFromKeys(key_view, key_spend) + return bytes(json.dumps({'coin': ci.ticker(), 'key_view': ci.encodeKey(key_view), 'key_spend': ci.encodeKey(key_spend), 'address': address}), 'UTF-8') + + seed_key = swap_client.getWalletKey(coin, 1) if coin == Coins.DASH: - return bytes(json.dumps({'coin': ci.ticker(), 'seed': seed.hex(), 'mnemonic': ci.seedToMnemonic(seed)}), 'UTF-8') - return bytes(json.dumps({'coin': ci.ticker(), 'seed': seed.hex()}), 'UTF-8') + return bytes(json.dumps({'coin': ci.ticker(), 'seed': seed_key.hex(), 'mnemonic': ci.seedToMnemonic(seed_key)}), 'UTF-8') + seed_id = ci.getSeedHash(seed_key) + return bytes(json.dumps({'coin': ci.ticker(), 'seed': seed_key.hex(), 'seed_id': seed_id.hex()}), 'UTF-8') def js_setpassword(self, url_split, post_string, is_json) -> bytes: diff --git a/basicswap/templates/automation_strategy.html b/basicswap/templates/automation_strategy.html index 404c126..e09f4ba 100644 --- a/basicswap/templates/automation_strategy.html +++ b/basicswap/templates/automation_strategy.html @@ -44,6 +44,7 @@