URI: 
       tMerge pull request #5039 from SomberNight/tx_version_bump_to_2 - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit f846d1d59aa0a6eac4c3f21a966524e759dfade9
   DIR parent f05aabd8028e74b62eb63ad32e17cec679c3b38d
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Fri,  1 Feb 2019 20:48:18 +0100
       
       Merge pull request #5039 from SomberNight/tx_version_bump_to_2
       
       ttransaction: change default version to 2
       Diffstat:
         M electrum/tests/test_wallet_vertica… |      37 +++++++++++++++++++++++--------
         M electrum/transaction.py             |       6 ++++--
         M electrum/wallet.py                  |       8 +++++---
       
       3 files changed, 37 insertions(+), 14 deletions(-)
       ---
   DIR diff --git a/electrum/tests/test_wallet_vertical.py b/electrum/tests/test_wallet_vertical.py
       t@@ -570,7 +570,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet1 -> wallet2
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet2.get_receiving_address(), 250000)]
       -        tx = wallet1.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet1.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
        
                self.assertTrue(tx.is_complete())
                self.assertTrue(tx.is_segwit())
       t@@ -590,7 +590,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet2 -> wallet1
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet1.get_receiving_address(), 100000)]
       -        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
        
                self.assertTrue(tx.is_complete())
                self.assertFalse(tx.is_segwit())
       t@@ -643,7 +643,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet1 -> wallet2
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet2.get_receiving_address(), 370000)]
       -        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
                tx = Transaction(tx.serialize())  # simulates moving partial txn between cosigners
                self.assertFalse(tx.is_complete())
                wallet1b.sign_transaction(tx, password=None)
       t@@ -666,7 +666,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet2 -> wallet1
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet1a.get_receiving_address(), 100000)]
       -        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
        
                self.assertTrue(tx.is_complete())
                self.assertFalse(tx.is_segwit())
       t@@ -734,7 +734,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet1 -> wallet2
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet2a.get_receiving_address(), 165000)]
       -        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
                txid = tx.txid()
                tx = Transaction(tx.serialize())  # simulates moving partial txn between cosigners
                self.assertEqual(txid, tx.txid())
       t@@ -760,7 +760,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet2 -> wallet1
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet1a.get_receiving_address(), 100000)]
       -        tx = wallet2a.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet2a.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
                txid = tx.txid()
                tx = Transaction(tx.serialize())  # simulates moving partial txn between cosigners
                self.assertEqual(txid, tx.txid())
       t@@ -814,7 +814,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet1 -> wallet2
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet2.get_receiving_address(), 1000000)]
       -        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet1a.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
        
                self.assertTrue(tx.is_complete())
                self.assertFalse(tx.is_segwit())
       t@@ -834,7 +834,7 @@ class TestWalletSending(TestCaseForTestnet):
        
                # wallet2 -> wallet1
                outputs = [TxOutput(bitcoin.TYPE_ADDRESS, wallet1a.get_receiving_address(), 300000)]
       -        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
       +        tx = wallet2.mktx(outputs=outputs, password=None, config=self.config, fee=5000, tx_version=1)
        
                self.assertTrue(tx.is_complete())
                self.assertTrue(tx.is_segwit())
       t@@ -874,6 +874,7 @@ class TestWalletSending(TestCaseForTestnet):
                tx = wallet.make_unsigned_transaction(coins, outputs, config=self.config, fixed_fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325501
       +        tx.version = 1
                wallet.sign_transaction(tx, password=None)
        
                self.assertTrue(tx.is_complete())
       t@@ -895,6 +896,7 @@ class TestWalletSending(TestCaseForTestnet):
                # bump tx
                tx = wallet.bump_fee(tx=Transaction(tx.serialize()), delta=5000)
                tx.locktime = 1325501
       +        tx.version = 1
                self.assertFalse(tx.is_complete())
        
                wallet.sign_transaction(tx, password=None)
       t@@ -925,6 +927,7 @@ class TestWalletSending(TestCaseForTestnet):
                tx = wallet.cpfp(funding_tx, fee=50000)
                tx.set_rbf(True)
                tx.locktime = 1325502
       +        tx.version = 1
                wallet.sign_transaction(tx, password=None)
        
                self.assertTrue(tx.is_complete())
       t@@ -960,6 +963,7 @@ class TestWalletSending(TestCaseForTestnet):
                tx = wallet.make_unsigned_transaction(coins, outputs, config=self.config, fixed_fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325499
       +        tx.version = 1
                wallet.sign_transaction(tx, password=None)
        
                self.assertTrue(tx.is_complete())
       t@@ -981,6 +985,7 @@ class TestWalletSending(TestCaseForTestnet):
                # bump tx
                tx = wallet.bump_fee(tx=Transaction(tx.serialize()), delta=5000)
                tx.locktime = 1325500
       +        tx.version = 1
                self.assertFalse(tx.is_complete())
        
                wallet.sign_transaction(tx, password=None)
       t@@ -1011,6 +1016,7 @@ class TestWalletSending(TestCaseForTestnet):
                tx = wallet.cpfp(funding_tx, fee=50000)
                tx.set_rbf(True)
                tx.locktime = 1325501
       +        tx.version = 1
                wallet.sign_transaction(tx, password=None)
        
                self.assertTrue(tx.is_complete())
       t@@ -1045,7 +1051,7 @@ class TestWalletSending(TestCaseForTestnet):
                privkeys = ['93NQ7CFbwTPyKDJLXe97jczw33fiLijam2SCZL3Uinz1NSbHrTu', ]
                network = NetworkMock()
                dest_addr = 'tb1q3ws2p0qjk5vrravv065xqlnkckvzcpclk79eu2'
       -        tx = sweep(privkeys, network, config=None, recipient=dest_addr, fee=5000, locktime=1325785)
       +        tx = sweep(privkeys, network, config=None, recipient=dest_addr, fee=5000, locktime=1325785, tx_version=1)
        
                tx_copy = Transaction(tx.serialize())
                self.assertEqual('010000000129349e5641d79915e9d0282fdbaee8c3df0b6731bab9d70bf626e8588bde24ac010000004847304402206bf0d0a93abae0d5873a62ebf277a5dd2f33837821e8b93e74d04e19d71b578002201a6d729bc159941ef5c4c9e5fe13ece9fc544351ba531b00f68ba549c8b38a9a01fdffffff01b82e0f00000000001600148ba0a0bc12b51831f58c7ea8607e76c5982c071fd93a1400',
       t@@ -1090,6 +1096,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1446655
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertFalse(tx.is_segwit())
       t@@ -1132,6 +1139,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertFalse(tx.is_segwit())
       t@@ -1172,6 +1180,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325341
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertTrue(tx.is_segwit())
       t@@ -1213,6 +1222,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325341
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertTrue(tx.is_segwit())
       t@@ -1249,6 +1259,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1283,6 +1294,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1317,6 +1329,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1354,6 +1367,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1391,6 +1405,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1428,6 +1443,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325340
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1477,6 +1493,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325503
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1534,6 +1551,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325504
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
       t@@ -1593,6 +1611,7 @@ class TestWalletOfflineSigning(TestCaseForTestnet):
                tx = wallet_online.mktx(outputs=outputs, password=None, config=self.config, fee=5000)
                tx.set_rbf(True)
                tx.locktime = 1325505
       +        tx.version = 1
        
                self.assertFalse(tx.is_complete())
                self.assertEqual(1, len(tx.inputs()))
   DIR diff --git a/electrum/transaction.py b/electrum/transaction.py
       t@@ -679,7 +679,7 @@ class Transaction:
                self._inputs = None
                self._outputs = None  # type: List[TxOutput]
                self.locktime = 0
       -        self.version = 1
       +        self.version = 2
                # by default we assume this is a partial txn;
                # this value will get properly set when deserializing
                self.is_partial_originally = True
       t@@ -787,11 +787,13 @@ class Transaction:
                return d
        
            @classmethod
       -    def from_io(klass, inputs, outputs, locktime=0):
       +    def from_io(klass, inputs, outputs, locktime=0, version=None):
                self = klass(None)
                self._inputs = inputs
                self._outputs = outputs
                self.locktime = locktime
       +        if version is not None:
       +            self.version = version
                self.BIP69_sort()
                return self
        
   DIR diff --git a/electrum/wallet.py b/electrum/wallet.py
       t@@ -126,7 +126,7 @@ def sweep_preparations(privkeys, network: 'Network', imax=100):
        
        
        def sweep(privkeys, network: 'Network', config: 'SimpleConfig', recipient, fee=None, imax=100,
       -          *, locktime=None):
       +          *, locktime=None, tx_version=None):
            inputs, keypairs = sweep_preparations(privkeys, network, imax)
            total = sum(i.get('value') for i in inputs)
            if fee is None:
       t@@ -142,7 +142,7 @@ def sweep(privkeys, network: 'Network', config: 'SimpleConfig', recipient, fee=N
            if locktime is None:
                locktime = get_locktime_for_new_transaction(network)
        
       -    tx = Transaction.from_io(inputs, outputs, locktime=locktime)
       +    tx = Transaction.from_io(inputs, outputs, locktime=locktime, version=tx_version)
            tx.set_rbf(True)
            tx.sign(keypairs)
            return tx
       t@@ -719,10 +719,12 @@ class Abstract_Wallet(AddressSynchronizer):
                return tx
        
            def mktx(self, outputs, password, config, fee=None, change_addr=None,
       -             domain=None, rbf=False, nonlocal_only=False):
       +             domain=None, rbf=False, nonlocal_only=False, *, tx_version=None):
                coins = self.get_spendable_coins(domain, config, nonlocal_only=nonlocal_only)
                tx = self.make_unsigned_transaction(coins, outputs, config, fee, change_addr)
                tx.set_rbf(rbf)
       +        if tx_version is not None:
       +            tx.version = tx_version
                self.sign_transaction(tx, password)
                return tx