Skip to content

Commit 9827a8c

Browse files
committed
add validation tests
1 parent e1834aa commit 9827a8c

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

electrum/gui/qt/main_window.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,10 +1683,8 @@ def on_failure(exc_info):
16831683
on_success = run_hook('tc_sign_wrapper', self.wallet, tx, on_success, on_failure) or on_success
16841684
if external_keypairs:
16851685
# can sign directly
1686-
print('\nexternal keys: ',external_keypairs)#
16871686
task = partial(tx.sign, external_keypairs)
16881687
else:
1689-
print('\nexternal keys2: ', external_keypairs) #
16901688
task = partial(self.wallet.sign_transaction, tx, password)
16911689
msg = _('Signing transaction...')
16921690
WaitingDialog(self, msg, task, on_success, on_failure)
@@ -1733,6 +1731,45 @@ def broadcast_done(result):
17331731
WaitingDialog(self, _('Broadcasting transaction...'),
17341732
broadcast_thread, broadcast_done, self.on_error)
17351733

1734+
<<<<<<< Updated upstream
1735+
=======
1736+
def exchange_psbt_http(self, payjoin):
1737+
""" """
1738+
import requests, copy
1739+
assert payjoin.is_complete()
1740+
1741+
print(payjoin.to_json())
1742+
print(payjoin.serialize_as_base64())
1743+
1744+
for txin in payjoin.inputs():
1745+
print(txin)
1746+
print(txin.utxo)
1747+
print(txin.utxo.outputs())
1748+
print
1749+
self.utxo.outputs()[self.prevout.out_idx]
1750+
1751+
1752+
1753+
1754+
url = 'https://testnet.demo.btcpayserver.org/BTC/pj'
1755+
payload = payjoin.serialize_as_base64()
1756+
headers = {'content-type': 'text/plain',
1757+
'content-length': str(len(payload))
1758+
}
1759+
print(headers)
1760+
"""
1761+
try:
1762+
r = requests.post(url, data=payload, headers=headers)
1763+
except:
1764+
pass
1765+
1766+
print(payload)
1767+
print(r.status_code)
1768+
print(r.headers)
1769+
print(r.text)
1770+
"""
1771+
1772+
>>>>>>> Stashed changes
17361773
def mktx_for_open_channel(self, funding_sat):
17371774
coins = self.get_coins(nonlocal_only=True)
17381775
make_tx = lambda fee_est: self.wallet.lnworker.mktx_for_open_channel(coins=coins,

electrum/gui/qt/transaction_dialog.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ def sign_done(success):
241241
_logger.info(f"Starting Payjoin Session")
242242
try:
243243
self.payjoin.set_tx(self.tx)
244+
print('tx1: ',self.tx.to_json())#
244245
self.payjoin.do_payjoin()
246+
print('tx2: ', self.payjoin.payjoin_proposal.to_json()) #
245247
self.payjoin.payjoin_proposal.add_info_from_wallet(self.wallet)
248+
print('tx3: ', self.payjoin.payjoin_proposal.to_json()) #
246249
self.payjoin.validate_payjoin_proposal()
247250
except (PayJoinProposalValidationException, PayJoinExchangeException) as e:
248251
_logger.warning(repr(e))

electrum/transaction.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ def witness_elements(self)-> Sequence[bytes]:
245245
n = vds.read_compact_size()
246246
return list(vds.read_bytes(vds.read_compact_size()) for i in range(n))
247247

248+
def is_segwit(self, *, guess_for_address=False) -> bool:
249+
if self.witness not in (b'\x00', b'', None):
250+
return True
251+
return False
252+
248253

249254
class BCDataStream(object):
250255
"""Workalike python implementation of Bitcoin's CDataStream class."""
@@ -1349,14 +1354,18 @@ def scriptpubkey(self) -> Optional[bytes]:
13491354
return None
13501355

13511356
def is_complete(self) -> bool:
1352-
if self.script_sig is not None or self.witness is not None:
1357+
if self.script_sig is not None and self.witness is not None:
13531358
return True
13541359
if self.is_coinbase_input():
13551360
return True
1356-
if self.script_sig is not None and not Transaction.is_segwit_input(self):
1361+
if self.script_sig is not None and not self.is_segwit():
1362+
return True
1363+
if self.witness is not None and self.is_segwit():
13571364
return True
1365+
"""
13581366
if self.witness is not None and Transaction.is_segwit_input(self):
13591367
return True
1368+
"""
13601369
signatures = list(self.part_sigs.values())
13611370
s = len(signatures)
13621371
# note: The 'script_type' field is currently only set by the wallet,
@@ -1457,6 +1466,20 @@ def calc_if_p2sh_segwit_now():
14571466
self._is_p2sh_segwit = calc_if_p2sh_segwit_now()
14581467
return self._is_p2sh_segwit
14591468

1469+
def is_segwit(self, *, guess_for_address=False) -> bool:
1470+
if super().is_segwit():
1471+
return True
1472+
if self.is_native_segwit() or self.is_p2sh_segwit():
1473+
return True
1474+
if self.is_native_segwit() is False and self.is_p2sh_segwit() is False:
1475+
return False
1476+
if self.witness_script:
1477+
return True
1478+
_type = self.script_type
1479+
if _type == 'address' and guess_for_address:
1480+
_type = Transaction.guess_txintype_from_address(self.address)
1481+
return is_segwit_script_type(_type)
1482+
14601483
def already_has_some_signatures(self) -> bool:
14611484
"""Returns whether progress has been made towards completing this input."""
14621485
return (self.part_sigs
@@ -1798,6 +1821,12 @@ def get_fee(self) -> Optional[int]:
17981821
except MissingTxInputAmount:
17991822
return None
18001823

1824+
def get_fee_rate(self) -> Optional[int]:
1825+
if self.get_fee() is None:
1826+
return None
1827+
return self.get_fee() / self.estimated_size()
1828+
1829+
18011830
def serialize_preimage(self, txin_index: int, *,
18021831
bip143_shared_txdigest_fields: BIP143SharedTxDigestFields = None) -> str:
18031832
nVersion = int_to_hex(self.version, 4)

0 commit comments

Comments
 (0)