Skip to content

Commit

Permalink
add validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rage-proof committed Nov 5, 2020
1 parent e1834aa commit 9827a8c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
41 changes: 39 additions & 2 deletions electrum/gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,10 +1683,8 @@ def on_failure(exc_info):
on_success = run_hook('tc_sign_wrapper', self.wallet, tx, on_success, on_failure) or on_success
if external_keypairs:
# can sign directly
print('\nexternal keys: ',external_keypairs)#
task = partial(tx.sign, external_keypairs)
else:
print('\nexternal keys2: ', external_keypairs) #
task = partial(self.wallet.sign_transaction, tx, password)
msg = _('Signing transaction...')
WaitingDialog(self, msg, task, on_success, on_failure)
Expand Down Expand Up @@ -1733,6 +1731,45 @@ def broadcast_done(result):
WaitingDialog(self, _('Broadcasting transaction...'),
broadcast_thread, broadcast_done, self.on_error)

<<<<<<< Updated upstream
=======
def exchange_psbt_http(self, payjoin):
""" """
import requests, copy
assert payjoin.is_complete()

print(payjoin.to_json())
print(payjoin.serialize_as_base64())

for txin in payjoin.inputs():
print(txin)
print(txin.utxo)
print(txin.utxo.outputs())
print
self.utxo.outputs()[self.prevout.out_idx]




url = 'https://testnet.demo.btcpayserver.org/BTC/pj'
payload = payjoin.serialize_as_base64()
headers = {'content-type': 'text/plain',
'content-length': str(len(payload))
}
print(headers)
"""
try:
r = requests.post(url, data=payload, headers=headers)
except:
pass
print(payload)
print(r.status_code)
print(r.headers)
print(r.text)
"""

>>>>>>> Stashed changes
def mktx_for_open_channel(self, funding_sat):
coins = self.get_coins(nonlocal_only=True)
make_tx = lambda fee_est: self.wallet.lnworker.mktx_for_open_channel(coins=coins,
Expand Down
3 changes: 3 additions & 0 deletions electrum/gui/qt/transaction_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ def sign_done(success):
_logger.info(f"Starting Payjoin Session")
try:
self.payjoin.set_tx(self.tx)
print('tx1: ',self.tx.to_json())#
self.payjoin.do_payjoin()
print('tx2: ', self.payjoin.payjoin_proposal.to_json()) #
self.payjoin.payjoin_proposal.add_info_from_wallet(self.wallet)
print('tx3: ', self.payjoin.payjoin_proposal.to_json()) #
self.payjoin.validate_payjoin_proposal()
except (PayJoinProposalValidationException, PayJoinExchangeException) as e:
_logger.warning(repr(e))
Expand Down
33 changes: 31 additions & 2 deletions electrum/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def witness_elements(self)-> Sequence[bytes]:
n = vds.read_compact_size()
return list(vds.read_bytes(vds.read_compact_size()) for i in range(n))

def is_segwit(self, *, guess_for_address=False) -> bool:
if self.witness not in (b'\x00', b'', None):
return True
return False


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

def is_complete(self) -> bool:
if self.script_sig is not None or self.witness is not None:
if self.script_sig is not None and self.witness is not None:
return True
if self.is_coinbase_input():
return True
if self.script_sig is not None and not Transaction.is_segwit_input(self):
if self.script_sig is not None and not self.is_segwit():
return True
if self.witness is not None and self.is_segwit():
return True
"""
if self.witness is not None and Transaction.is_segwit_input(self):
return True
"""
signatures = list(self.part_sigs.values())
s = len(signatures)
# note: The 'script_type' field is currently only set by the wallet,
Expand Down Expand Up @@ -1457,6 +1466,20 @@ def calc_if_p2sh_segwit_now():
self._is_p2sh_segwit = calc_if_p2sh_segwit_now()
return self._is_p2sh_segwit

def is_segwit(self, *, guess_for_address=False) -> bool:
if super().is_segwit():
return True
if self.is_native_segwit() or self.is_p2sh_segwit():
return True
if self.is_native_segwit() is False and self.is_p2sh_segwit() is False:
return False
if self.witness_script:
return True
_type = self.script_type
if _type == 'address' and guess_for_address:
_type = Transaction.guess_txintype_from_address(self.address)
return is_segwit_script_type(_type)

def already_has_some_signatures(self) -> bool:
"""Returns whether progress has been made towards completing this input."""
return (self.part_sigs
Expand Down Expand Up @@ -1798,6 +1821,12 @@ def get_fee(self) -> Optional[int]:
except MissingTxInputAmount:
return None

def get_fee_rate(self) -> Optional[int]:
if self.get_fee() is None:
return None
return self.get_fee() / self.estimated_size()


def serialize_preimage(self, txin_index: int, *,
bip143_shared_txdigest_fields: BIP143SharedTxDigestFields = None) -> str:
nVersion = int_to_hex(self.version, 4)
Expand Down

0 comments on commit 9827a8c

Please sign in to comment.