Commit Graph

129 Commits

Author SHA1 Message Date
SomberNight
373db76ac9 util: kill bh2u
no longer useful, and the name is so confusing...
2023-02-17 11:43:11 +00:00
SomberNight
1ce37c8bb1 transaction: rm hardcoded sighash magic numbers 2023-02-17 11:40:12 +00:00
SomberNight
845f4aee4d transaction.py: move Tx.serialize_input -> TxInput.serialize_to_network 2023-02-17 11:37:22 +00:00
Sebastian Falbesoner
ede9b2b372 transaction: cache address determination from output script
In order to avoid repeatedly calling get_addr_from_output_script() on
every read of the "TxOutput.address" property, determine and cache it
only whenever the output script is created/changed.
2023-02-08 00:41:44 +00:00
SomberNight
04a5aaeddc transaction: (trivial) add comment about is_cb_input vs is_cb_output
follow-up d6febb5c12, 96ac199f5c
2023-02-03 14:49:16 +00:00
ThomasV
d6febb5c12 Display mined tx outputs as ShortIDs instead of full transaction outpoints.
ShortIDs were originally designed for lightning channels, and are now
understood by some block explorers.

This allows to remove one column in the UTXO tab (height is redundant).

In the transaction dialog, the space saving ensures that all inputs fit
into one line (it was not the case previously with p2wsh addresses).
For clarity and consistency, the ShortID is displayed for both inputs
and outputs in the transaction dialog.
2023-01-26 10:48:28 +01:00
SomberNight
d3227d7489 transaction: for witness v0 txins, put both UTXO and WIT_UTXO in psbt
Until now we have been only putting PSBT_IN_NON_WITNESS_UTXO (="UTXO", full tx)
in segwit witness v0 txins, as signers wanted the full tx anyway due to
bip-143 sighash issue [0], and as WITNESS_UTXO can be calculated from UTXO.

My reading of bip-174 is that either behaviour is correct, but
achow101 said bip-174 expects PSBT_IN_WITNESS_UTXO for segwit inputs.
Regardless, including both fields does not increase the tx size too much
(UTXO can be very large ofc but we were already including that, WIT_UTXO is small).
This also might increase compatibility with some other software - I've found
some issues where this might have been the culprit [1][2][3].

closes https://github.com/spesmilo/electrum/issues/8039

related:
[0] https://github.com/spesmilo/electrum/pull/6198
[1] https://github.com/cryptoadvance/specter-desktop/issues/868
[2] https://github.com/cryptoadvance/specter-desktop/issues/1046
[3] https://github.com/cryptoadvance/specter-desktop/issues/1544
2022-10-31 17:14:21 +00:00
SomberNight
01b5e3f8e0 flake8: enable more mandatory tests 2022-10-31 16:13:22 +00:00
SomberNight
45a939c146 tests: add test to check if we include xpubs in psbts
related: https://github.com/spesmilo/electrum/issues/8036
2022-10-27 15:55:01 +00:00
ThomasV
47c480be49 check_scriptpubkey_template_and_dust: support anysegwit. fix #8012 2022-10-12 10:06:56 +02:00
SomberNight
c71f00cc8e transaction.deserialize: only set self._inputs after parsing witness
re multi-threaded sanity...
(see lazy deserialization in Transaction.inputs)
2022-07-05 18:56:52 +02:00
ThomasV
44f29331bf lnwatcher: in inspect_tx_candidate, match witness scripts against HTLC templates
fixes #7781
2022-04-28 13:21:10 +02:00
SomberNight
207600e00c transaction.py: TxOutpoint: nicer __str__ and __repr__
useful e.g. when TxOutpoint is used as key in a dict (and the dict is printed)
2022-04-01 21:31:50 +02:00
SomberNight
e36d7fed7d swaps: more precise tx size estimation for claim tx when RBF-ing 2022-03-31 20:55:11 +02:00
ThomasV
1364e7538a bump fee of swap claim transactions
Note: This adds a new field, spent_txid, to PartialTxOutput
2022-03-30 13:44:10 +02:00
SomberNight
e00c998df3 transaction: TxInput.witness_elements() to return [] if not segwit
Previously it would raise:
```
>>> import electrum
>>> tx = electrum.transaction.tx_from_any("0200000001d945b6b076ad7858f7a2227374a42ada71582b1d558fde9ece4bf6c9395c67ca000000006a473044022034867c61623a147dbe7e8541da1086ec8691d4f39181deeba4be70559e26734d02205c0288c96ae6950a0687c0d8c06f9cd343362e6a174cd4c66cfc2abd2278aed801210330fb51ac7b556a599a05c2b8670e79008406e4c0b7e46d4a522ad01804f25dbbfdffffff02389d0700000000001976a9146d687bece6d502519ce5317e25f48da60a52ca8f88ac20a1070000000000220020a948d7fa6abbb97e31779ae54383012b413d53821c7fd394900f6b443c61deeee82a1800")
>>> tx.inputs()[0].witness_elements()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/wspace/electrum/electrum/transaction.py", line 257, in witness_elements
    vds.write(self.witness)
  File "/home/user/wspace/electrum/electrum/transaction.py", line 279, in write
    assert isinstance(_bytes, (bytes, bytearray))
AssertionError
```
2022-03-20 16:55:36 +01:00
SomberNight
4f9e4c520f ecc: API changes: verify_message_hash to return bool instead of raising
verify_message_hash and verify_message_for_address now return bool
instead of raising Exceptions on bad signatures.
2022-02-16 19:24:38 +01:00
bitromortac
947693c90d check dust limits
* on channel opening we verify that the peer's dust limit is above 354
  sat, the limit for unknown segwit versions
* we constrain the allowed scriptpubkey types for channel closing
* we check that the remote's output is above the relay dust limit for
  the collaborative close case
2021-10-27 16:27:15 +02:00
bitromortac
f2f8c4533b implement option_shutdown_anysegwit
https://github.com/lightningnetwork/lightning-rfc/pull/672

We check the received shutdown script against higher segwit versions and
accept closing to that script if option_shutdown_anysegwit has been
negotiated.
2021-10-26 14:51:09 +02:00
SomberNight
0b05edc705 wallet payreqs: trivial clean-up 2021-09-19 17:25:57 +02:00
SomberNight
acbb363240 follow-up prev: some clean-ups
re https://github.com/spesmilo/electrum/pull/7492
2021-09-15 16:41:41 +02:00
djboi
604cba8fb6 Added different Sighash_Types (#7453)
Implements signing for sighash types other than `ALL` for segwit inputs.

fixes https://github.com/spesmilo/electrum/issues/7408
2021-09-07 14:41:50 +00:00
Benoit Verret
f731c38293 Minor style changes 2021-03-21 00:36:23 -04:00
SomberNight
4315fa4371 BIP-0350: use bech32m for witness version 1+ addresses
We have supported sending to any witness version since Electrum 3.0, using
addresses as specified in BIP-0173 (bech32 encoding).
BIP-0350 makes a breaking change in address encoding, and recommends using
(and using only) a new encoding (bech32m) for sending to witness version 1
and later. The address encoding for currently in use witness v0 addresses
remains the same, as in BIP-0173; following the BIP-0350 spec.

closes https://github.com/spesmilo/electrum/issues/6949

related:
cd3885c0fb/bip-0350.mediawiki
https://github.com/bitcoin/bitcoin/pull/20861
2021-03-17 18:11:55 +01:00
SomberNight
e25602ab3b wallet: don't put partial tx as UTXO into psbt
if there is a chain of unsigned txs, we cannot populate NON_WITNESS_UTXO

closes #7080
closes #7009
closes #6482
2021-03-04 13:20:49 +01:00
SomberNight
6094f2751e kivy channel dialog: fix unit of displayed feerate
The amount shown was in sat/kw, incorrectly labeled as sat/kbyte.
Show sat/vbyte instead.
2021-03-01 17:09:04 +01:00
SomberNight
058d9ab6bb wallet.bump_fee: add new strategy: decrease payment amounts
- Rename bump_fee "methods" to "strategies".
- Refactor strategies so that bump_fee can use any subset of them in any permutation.
- Adds a new strategy which decreases the payment outputs (instead of change).
2021-02-25 15:32:07 +01:00
SomberNight
914eb9989d wallet: minor clean-up of tx.set_rbf() calls
Better to always call it, to make sure inputs have identical sequence numbers.
2021-02-12 04:59:40 +01:00
rage-proof
cb3977798c add function to determine script-type for all inputs in a psbt (#6984)
* Add functions to determine the script type from a psbt.

* add a function inside PartialTransaction

* P2wsh uses the witness-script field to save the script.

* Limit the detection of script-types that are not multisig.
2021-02-04 02:52:40 +00:00
SomberNight
bc6f2926f4 commands: add 'freeze_utxo' cmd; to expose this to CLI/RPC 2021-01-22 21:56:11 +01:00
ThomasV
f130cb53ce bump_dee and dscancel: call tx.estimated_size() after add_input_info().
This is a workaround, see the FIXME. PartialTxInput.is_segwit() should
return the correct value, or raise if information is missing.
2021-01-17 17:26:44 +01:00
SomberNight
21f13e21b1 wallet: fix bump_fee and dscancel for "not all inputs ismine" case
we fetch the missing prev txs over network

fixes #6551
fixes #6864
2020-12-20 15:29:41 +01:00
SomberNight
bb41ef3450 wallet: (fix) bump_fee sometimes created invalid tx that spent orig out
When replacing non-segwit tx, bump_fee in some circumstances created
a tx that tried to spend from the tx-to-be-replaced. There is
explicit logic to avoid this but it only worked for segwit txs.

The change in transaction.py is a no-op, just tried to make it clearer
that the scriptSigs, witnesses are being reset by from_tx().
2020-12-18 19:35:22 +01:00
SomberNight
c81551299e transaction: put full derivation paths into PSBT by default
There are three export options for exporting a PSBT.
The default option previously only put derivation path suffixes for pubkeys
(paths relative to the intermediate xpub), now it puts the full path
(if is known by the keystore).

The "export for hardware device; include xpubs" option works same as before:
it puts both full paths and also global xpubs into the PSBT.
Hence the difference between the default option and the "include xpubs" option
is now only that the latter puts global xpubs into the PSBT.

This change is largely made for user-convenient in mind.
Now exporting a PSBT should be less error-prone: particularly for the
single-signer coldcard with sdcard usage, the default option will now work.

closes #5969
related #5955
2020-12-10 17:39:12 +01:00
SomberNight
03bdb4f1b7 Transaction.get_preimage_script: support custom legacy-p2sh inputs
tests based on
- 8ca383c9e0/python/elec-p2sh-hodl.py
- 8ca383c9e0/python/elec-p2wsh-hodl.py

note: I could not reproduce the signature for the p2wsh cltv spend linked above,
so I have created a new testnet output and spent that for that test (to make sure
our behaviour is consensus-valid).
2020-10-24 08:26:11 +02:00
SomberNight
eefb68c82b transaction: change Transaction.is_segwit_input(txin) to txin.is_segwit() 2020-10-24 08:03:13 +02:00
SomberNight
4c7a92f39c bitcoin: implement construct_script and use it 2020-10-24 07:49:06 +02:00
SomberNight
89bd520185 bitcoin: move construct_witness from transaction.py to bitcoin.py 2020-10-24 05:18:16 +02:00
zebra-lucky
546c0e1bb6 tx: add deserialize to locktime/version properties (#6633) 2020-10-06 15:10:46 +00:00
SomberNight
364fca6a58 transaction: fix regression: witness_utxo was not included in QR code
fixes #6600
2020-09-23 15:11:53 +02:00
SomberNight
c4c22312c4 transaction: impl tx.to_qr_data(): move logic from GUI to tx class 2020-09-23 14:57:46 +02:00
SomberNight
7b91da9966 Qt tx dialog: handle "empty" locktime field
fix https://github.com/spesmilo/electrum/issues/5486#issuecomment-696276020
2020-09-23 13:31:39 +02:00
SomberNight
13fe8e466d transaction: simply PartialTransaction constructor
rm footgun (see prev commit)
2020-08-26 19:55:05 +02:00
SomberNight
73cf007048 transaction: allow PSBT input to have both UTXO and WITNESS_UTXO
- make sure they are consistent
- only keep one of them internally (UTXO), and only serialise with UTXO (not both)

fixes #6429
2020-07-22 02:44:33 +02:00
SomberNight
1849206394 submarine_swaps: small clean-up 2020-06-18 18:18:33 +02:00
ghost43
947af92126 tx dialog: show various warnings if input amounts cannot be verified (#6217)
see #5749
2020-06-08 14:24:41 +00:00
matejcik
e058ee2957 psbt: always include full prev tx (#6198)
* enable streaming full UTXOs for all types of inputs

Co-authored-by: SomberNight <somber.night@protonmail.com>
2020-06-03 18:03:12 +00:00
SomberNight
62be1cc367 small clean-up re "extract preimage from on-chain htlc_tx"
related: #6122
2020-05-06 03:15:20 +02:00
ThomasV
8ba7e68064 fix #6122: extract preimage from on-chain htlc_tx 2020-05-03 16:03:27 +02:00
ThomasV
8f41aeb783 Replace wallet backup with channel backups
- channels can be backed up individually
 - backups are added to lnwatcher
 - AbstractChannel ancestor class
2020-04-10 14:45:23 +02:00