diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 7fd46de..7935f50 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -2165,6 +2165,24 @@ class BasicSwap(BaseApp): msg_buf.fee_rate_to ) # Unused: TODO - Set priority? + # Set auto-accept type + automation_id = extra_options.get("automation_id", -1) + if automation_id == -1 and auto_accept_bids: + automation_id = 1 # Default strategy + + if automation_id != -1: + strategy = self.queryOne( + AutomationStrategy, + cursor, + {"active_ind": 1, "record_id": automation_id}, + ) + if strategy: + msg_buf.auto_accept_type = ( + 2 if strategy.only_known_identities else 1 + ) + else: + msg_buf.auto_accept_type = 0 + # If a prefunded txn is not used, check that the wallet balance can cover the tx fee. if "prefunded_itx" not in extra_options: # TODO: Better tx size estimate, xmr_swap_b_lock_tx_vsize could be larger than xmr_swap_b_lock_spend_tx_vsize @@ -2217,6 +2235,7 @@ class BasicSwap(BaseApp): security_token=security_token, from_feerate=msg_buf.fee_rate_from, to_feerate=msg_buf.fee_rate_to, + auto_accept_type=msg_buf.auto_accept_type, ) offer.setState(OfferStates.OFFER_SENT) @@ -7054,6 +7073,11 @@ class BasicSwap(BaseApp): expire_at=msg["sent"] + offer_data.time_valid, was_sent=False, bid_reversed=bid_reversed, + auto_accept_type=( + offer_data.auto_accept_type + if b"\xa0\x01" in offer_bytes + else None + ), ) offer.setState(OfferStates.OFFER_RECEIVED) self.add(offer, cursor) diff --git a/basicswap/db.py b/basicswap/db.py index bb583f2..1cea42d 100644 --- a/basicswap/db.py +++ b/basicswap/db.py @@ -13,7 +13,7 @@ from enum import IntEnum, auto from typing import Optional -CURRENT_DB_VERSION = 26 +CURRENT_DB_VERSION = 27 CURRENT_DB_DATA_VERSION = 6 @@ -183,6 +183,7 @@ class Offer(Table): amount_negotiable = Column("bool") rate_negotiable = Column("bool") + auto_accept_type = Column("integer") # Local fields auto_accept_bids = Column("bool") diff --git a/basicswap/db_upgrades.py b/basicswap/db_upgrades.py index 5208d0f..16da49a 100644 --- a/basicswap/db_upgrades.py +++ b/basicswap/db_upgrades.py @@ -425,6 +425,9 @@ def upgradeDatabase(self, db_version): last_updated INTEGER, PRIMARY KEY (record_id))""" ) + elif current_version == 26: + db_version += 1 + cursor.execute("ALTER TABLE offers ADD COLUMN auto_accept_type INTEGER") if current_version != db_version: self.db_version = db_version self.setIntKV("db_version", db_version, cursor) diff --git a/basicswap/messages_npb.py b/basicswap/messages_npb.py index fa3ac14..ef2c98e 100644 --- a/basicswap/messages_npb.py +++ b/basicswap/messages_npb.py @@ -136,6 +136,7 @@ class OfferMessage(NonProtobufClass): 17: ("amount_negotiable", 0, 2), 18: ("rate_negotiable", 0, 2), 19: ("proof_utxos", 2, 0), + 20: ("auto_accept_type", 0, 0), } diff --git a/basicswap/templates/offer.html b/basicswap/templates/offer.html index e34979c..0d18c5b 100644 --- a/basicswap/templates/offer.html +++ b/basicswap/templates/offer.html @@ -219,16 +219,17 @@ Revoked {{ data.was_revoked }} - {% if data.sent %} - Auto Accept Strategy + Auto Accept Type - {% if data.automation_strat_id == -1 %} None {% else %} - {{ data.automation_strat_label }} + {% if data.auto_accept_type is none %} Unknown + {% elif data.auto_accept_type == 0 %} Bids are accepted manually + {% elif data.auto_accept_type == 1 %} Bids are accepted automatically + {% elif data.auto_accept_type == 2 %} Bids are accepted automatically from known identities + {% else %} Unknown ({{ data.auto_accept_type }}) {% endif %} - {% endif %} {% if data.xmr_type == true %} Chain A offer fee rate @@ -482,7 +483,7 @@ if (document.readyState === 'loading') { name="bid_amount_send" value="" max="{{ data.amt_to }}" - onchange="validateMaxAmount(this, {{ data.amt_to }}); updateBidParams('sending');"> + onchange="validateMaxAmount(this, parseFloat('{{ data.amt_to }}')); updateBidParams('sending');">
max {{ data.amt_to }} ({{ data.tla_to }})
@@ -505,7 +506,7 @@ if (document.readyState === 'loading') { name="bid_amount" value="" max="{{ data.amt_from }}" - onchange="validateMaxAmount(this, {{ data.amt_from }}); updateBidParams('receiving');"> + onchange="validateMaxAmount(this, parseFloat('{{ data.amt_from }}')); updateBidParams('receiving');">
max {{ data.amt_from }} ({{ data.tla_from }})
diff --git a/basicswap/ui/page_offers.py b/basicswap/ui/page_offers.py index 859e7f6..1c00d79 100644 --- a/basicswap/ui/page_offers.py +++ b/basicswap/ui/page_offers.py @@ -733,6 +733,9 @@ def page_offer(self, url_split, post_string): "swap_type": strSwapDesc(offer.swap_type), "reverse": reverse_bid, "form_id": get_data_entry_or(form_data, "formid", "") if form_data else "", + "auto_accept_type": ( + offer.auto_accept_type if hasattr(offer, "auto_accept_type") else 0 + ), } data.update(extend_data)