Browse Source

swapserver: remove config option LIGHTNING_SWAP_HTLC_FIRST; read it from get_pairs instead.

master
ThomasV 2 years ago
parent
commit
dfa0dd47b7
  1. 1
      electrum/plugins/swapserver/server.py
  2. 1
      electrum/simple_config.py
  3. 8
      electrum/submarine_swaps.py

1
electrum/plugins/swapserver/server.py

@ -51,6 +51,7 @@ class SwapServer(Logger, EventListener):
pairs = { pairs = {
"info": [], "info": [],
"warnings": [], "warnings": [],
"htlcFirst": True,
"pairs": { "pairs": {
"BTC/BTC": { "BTC/BTC": {
"rate": 1, "rate": 1,

1
electrum/simple_config.py

@ -890,7 +890,6 @@ class SimpleConfig(Logger):
LIGHTNING_USE_GOSSIP = ConfigVar('use_gossip', default=False, type_=bool) LIGHTNING_USE_GOSSIP = ConfigVar('use_gossip', default=False, type_=bool)
LIGHTNING_USE_RECOVERABLE_CHANNELS = ConfigVar('use_recoverable_channels', default=True, type_=bool) LIGHTNING_USE_RECOVERABLE_CHANNELS = ConfigVar('use_recoverable_channels', default=True, type_=bool)
LIGHTNING_ALLOW_INSTANT_SWAPS = ConfigVar('allow_instant_swaps', default=False, type_=bool) LIGHTNING_ALLOW_INSTANT_SWAPS = ConfigVar('allow_instant_swaps', default=False, type_=bool)
LIGHTNING_SWAP_HTLC_FIRST = ConfigVar('swap_htlc_first', default=False, type_=bool)
LIGHTNING_TO_SELF_DELAY_CSV = ConfigVar('lightning_to_self_delay', default=7 * 144, type_=int) LIGHTNING_TO_SELF_DELAY_CSV = ConfigVar('lightning_to_self_delay', default=7 * 144, type_=int)
LIGHTNING_MAX_FUNDING_SAT = ConfigVar('lightning_max_funding_sat', default=LN_MAX_FUNDING_SAT_LEGACY, type_=int) LIGHTNING_MAX_FUNDING_SAT = ConfigVar('lightning_max_funding_sat', default=LN_MAX_FUNDING_SAT_LEGACY, type_=int)

8
electrum/submarine_swaps.py

@ -181,6 +181,7 @@ class SwapManager(Logger):
self.percentage = 0 self.percentage = 0
self._min_amount = None self._min_amount = None
self._max_amount = None self._max_amount = None
self.server_supports_htlc_first = False
self.wallet = wallet self.wallet = wallet
self.lnworker = lnworker self.lnworker = lnworker
@ -531,7 +532,7 @@ class SwapManager(Logger):
refund_privkey = os.urandom(32) refund_privkey = os.urandom(32)
refund_pubkey = ECPrivkey(refund_privkey).get_public_key_bytes(compressed=True) refund_pubkey = ECPrivkey(refund_privkey).get_public_key_bytes(compressed=True)
if self.wallet.config.LIGHTNING_SWAP_HTLC_FIRST: if self.server_supports_htlc_first:
self.logger.info('requesting preimage hash for swap') self.logger.info('requesting preimage hash for swap')
request_data = { request_data = {
"invoiceAmount": lightning_amount_sat, "invoiceAmount": lightning_amount_sat,
@ -580,7 +581,7 @@ class SwapManager(Logger):
lockup_address = data["address"] lockup_address = data["address"]
redeem_script = data["redeemScript"] redeem_script = data["redeemScript"]
# verify redeem_script is built with our pubkey and preimage # verify redeem_script is built with our pubkey and preimage
if self.wallet.config.LIGHTNING_SWAP_HTLC_FIRST: if self.server_supports_htlc_first:
claim_pubkey, _ = check_reverse_redeem_script(redeem_script, lockup_address, payment_hash, locktime, refund_pubkey=refund_pubkey) claim_pubkey, _ = check_reverse_redeem_script(redeem_script, lockup_address, payment_hash, locktime, refund_pubkey=refund_pubkey)
else: else:
claim_pubkey, _ = check_normal_redeem_script(redeem_script, lockup_address, payment_hash, locktime, refund_pubkey=refund_pubkey) claim_pubkey, _ = check_normal_redeem_script(redeem_script, lockup_address, payment_hash, locktime, refund_pubkey=refund_pubkey)
@ -605,7 +606,7 @@ class SwapManager(Logger):
prepay=False) prepay=False)
tx = self.create_funding_tx(swap, tx, password) tx = self.create_funding_tx(swap, tx, password)
if self.wallet.config.LIGHTNING_SWAP_HTLC_FIRST: if self.server_supports_htlc_first:
# send invoice to server and wait for htlcs # send invoice to server and wait for htlcs
request_data = { request_data = {
"preimageHash": payment_hash.hex(), "preimageHash": payment_hash.hex(),
@ -780,6 +781,7 @@ class SwapManager(Logger):
limits = pairs['pairs']['BTC/BTC']['limits'] limits = pairs['pairs']['BTC/BTC']['limits']
self._min_amount = limits['minimal'] self._min_amount = limits['minimal']
self._max_amount = limits['maximal'] self._max_amount = limits['maximal']
self.server_supports_htlc_first = pairs.get('htlcFirst', False)
def pairs_filename(self): def pairs_filename(self):
return os.path.join(self.wallet.config.path, 'swap_pairs') return os.path.join(self.wallet.config.path, 'swap_pairs')

Loading…
Cancel
Save