mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 16:01:30 +00:00
swaps: mapping of prepay_hash to payment_hash
This commit is contained in:
parent
c8506eaa39
commit
a1e8f9e2aa
3 changed files with 15 additions and 14 deletions
|
@ -632,8 +632,6 @@ class LNWallet(LNWorker):
|
||||||
}
|
}
|
||||||
# add txid to merge item with onchain item
|
# add txid to merge item with onchain item
|
||||||
swap = self.swap_manager.get_swap(payment_hash)
|
swap = self.swap_manager.get_swap(payment_hash)
|
||||||
if swap is None:
|
|
||||||
swap = self.swap_manager.get_swap_by_prepay(payment_hash)
|
|
||||||
if swap:
|
if swap:
|
||||||
if swap.is_reverse:
|
if swap.is_reverse:
|
||||||
item['txid'] = swap.spending_txid
|
item['txid'] = swap.spending_txid
|
||||||
|
|
|
@ -68,7 +68,7 @@ class SwapData(StoredObject):
|
||||||
lightning_amount = attr.ib(type=int)
|
lightning_amount = attr.ib(type=int)
|
||||||
redeem_script = attr.ib(type=bytes, converter=hex_to_bytes)
|
redeem_script = attr.ib(type=bytes, converter=hex_to_bytes)
|
||||||
preimage = attr.ib(type=bytes, converter=hex_to_bytes)
|
preimage = attr.ib(type=bytes, converter=hex_to_bytes)
|
||||||
fee_preimage = attr.ib(type=bytes, converter=hex_to_bytes)
|
prepay_hash = attr.ib(type=bytes, converter=hex_to_bytes)
|
||||||
privkey = attr.ib(type=bytes, converter=hex_to_bytes)
|
privkey = attr.ib(type=bytes, converter=hex_to_bytes)
|
||||||
lockup_address = attr.ib(type=str)
|
lockup_address = attr.ib(type=str)
|
||||||
funding_txid = attr.ib(type=str)
|
funding_txid = attr.ib(type=str)
|
||||||
|
@ -109,8 +109,10 @@ class SwapManager(Logger):
|
||||||
self.lnworker = wallet.lnworker
|
self.lnworker = wallet.lnworker
|
||||||
self.lnwatcher = self.wallet.lnworker.lnwatcher
|
self.lnwatcher = self.wallet.lnworker.lnwatcher
|
||||||
self.swaps = self.wallet.db.get_dict('submarine_swaps')
|
self.swaps = self.wallet.db.get_dict('submarine_swaps')
|
||||||
self.prepayments = {}
|
self.prepayments = {} # fee_preimage -> preimage
|
||||||
for swap in self.swaps.values():
|
for k, swap in self.swaps.items():
|
||||||
|
if swap.is_reverse and swap.prepay_hash is not None:
|
||||||
|
self.prepayments[swap.prepay_hash] = bytes.fromhex(k)
|
||||||
if swap.is_redeemed:
|
if swap.is_redeemed:
|
||||||
continue
|
continue
|
||||||
self.add_lnwatcher_callback(swap)
|
self.add_lnwatcher_callback(swap)
|
||||||
|
@ -154,12 +156,10 @@ class SwapManager(Logger):
|
||||||
return self.lnwatcher.config.estimate_fee(136, allow_fallback_to_static_rates=True)
|
return self.lnwatcher.config.estimate_fee(136, allow_fallback_to_static_rates=True)
|
||||||
|
|
||||||
def get_swap(self, payment_hash):
|
def get_swap(self, payment_hash):
|
||||||
return self.swaps.get(payment_hash.hex())
|
# for history
|
||||||
|
swap = self.swaps.get(payment_hash.hex())
|
||||||
def get_swap_by_prepay(self, prepay_payment_hash):
|
if swap:
|
||||||
payment_hash = self.prepayments.get(prepay_payment_hash)
|
return swap
|
||||||
if payment_hash:
|
|
||||||
return self.swaps.get(payment_hash.hex())
|
|
||||||
|
|
||||||
def add_lnwatcher_callback(self, swap):
|
def add_lnwatcher_callback(self, swap):
|
||||||
callback = lambda: self._claim_swap(swap)
|
callback = lambda: self._claim_swap(swap)
|
||||||
|
@ -222,6 +222,7 @@ class SwapManager(Logger):
|
||||||
locktime = locktime,
|
locktime = locktime,
|
||||||
privkey = privkey,
|
privkey = privkey,
|
||||||
preimage = preimage,
|
preimage = preimage,
|
||||||
|
prepay_hash = None,
|
||||||
lockup_address = lockup_address,
|
lockup_address = lockup_address,
|
||||||
onchain_amount = onchain_amount,
|
onchain_amount = onchain_amount,
|
||||||
lightning_amount = lightning_amount,
|
lightning_amount = lightning_amount,
|
||||||
|
@ -282,9 +283,9 @@ class SwapManager(Logger):
|
||||||
if fee_invoice:
|
if fee_invoice:
|
||||||
fee_lnaddr = self.lnworker._check_invoice(fee_invoice)
|
fee_lnaddr = self.lnworker._check_invoice(fee_invoice)
|
||||||
invoice_amount += fee_lnaddr.get_amount_sat()
|
invoice_amount += fee_lnaddr.get_amount_sat()
|
||||||
fee_preimage = fee_lnaddr.paymenthash
|
prepay_hash = fee_lnaddr.paymenthash
|
||||||
else:
|
else:
|
||||||
fee_preimage = None
|
prepay_hash = None
|
||||||
assert int(invoice_amount) == amount_sat, (invoice_amount, amount_sat)
|
assert int(invoice_amount) == amount_sat, (invoice_amount, amount_sat)
|
||||||
# save swap data to wallet file
|
# save swap data to wallet file
|
||||||
swap = SwapData(
|
swap = SwapData(
|
||||||
|
@ -292,7 +293,7 @@ class SwapManager(Logger):
|
||||||
locktime = locktime,
|
locktime = locktime,
|
||||||
privkey = privkey,
|
privkey = privkey,
|
||||||
preimage = preimage,
|
preimage = preimage,
|
||||||
fee_preimage = fee_preimage,
|
prepay_hash = prepay_hash,
|
||||||
lockup_address = lockup_address,
|
lockup_address = lockup_address,
|
||||||
onchain_amount = onchain_amount,
|
onchain_amount = onchain_amount,
|
||||||
lightning_amount = amount_sat,
|
lightning_amount = amount_sat,
|
||||||
|
|
|
@ -841,6 +841,8 @@ class Abstract_Wallet(AddressSynchronizer, ABC):
|
||||||
item = transactions_tmp[txid]
|
item = transactions_tmp[txid]
|
||||||
item['label'] = tx_item['label']
|
item['label'] = tx_item['label']
|
||||||
item['type'] = tx_item['type'] # fixme: do we need this?
|
item['type'] = tx_item['type'] # fixme: do we need this?
|
||||||
|
if 'ln_value' not in item:
|
||||||
|
item['ln_value'] = 0
|
||||||
item['ln_value'] = Satoshis(ln_value) # fixme: we need to add value
|
item['ln_value'] = Satoshis(ln_value) # fixme: we need to add value
|
||||||
item['amount_msat'] = tx_item['amount_msat']
|
item['amount_msat'] = tx_item['amount_msat']
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Reference in a new issue