electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 6e51b7d60e3ca50142912810bc309d048ff7197b
parent b2332af77b2edfd22ba7b951d589546f7cc40c22
Author: ThomasV <thomasv@electrum.org>
Date:   Tue, 30 May 2017 19:32:23 +0200

Merge pull request #2468 from bauerj/issue-2462

Parse transaction version field
Diffstat:
Mlib/tests/test_transaction.py | 6+++++-
Mlib/transaction.py | 6++++--
2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/tests/test_transaction.py b/lib/tests/test_transaction.py @@ -7,7 +7,7 @@ from lib.keystore import xpubkey_to_address unsigned_blob = '01000000012a5c9a94fcde98f5581cd00162c60a13936ceb75389ea65bf38633b424eb4031000000005701ff4c53ff0488b21e03ef2afea18000000089689bff23e1e7fb2f161daa37270a97a3d8c2e537584b2d304ecb47b86d21fc021b010d3bd425f8cf2e04824bfdf1f1f5ff1d51fadd9a41f9e3fb8dd3403b1bfe00000000ffffffff0140420f00000000001976a914230ac37834073a42146f11ef8414ae929feaafc388ac00000000' signed_blob = '01000000012a5c9a94fcde98f5581cd00162c60a13936ceb75389ea65bf38633b424eb4031000000006c493046022100a82bbc57a0136751e5433f41cf000b3f1a99c6744775e76ec764fb78c54ee100022100f9e80b7de89de861dc6fb0c1429d5da72c2b6b2ee2406bc9bfb1beedd729d985012102e61d176da16edd1d258a200ad9759ef63adf8e14cd97f53227bae35cdb84d2f6ffffffff0140420f00000000001976a914230ac37834073a42146f11ef8414ae929feaafc388ac00000000' - +v2_blob = "0200000001191601a44a81e061502b7bfbc6eaa1cef6d1e6af5308ef96c9342f71dbf4b9b5000000006b483045022100a6d44d0a651790a477e75334adfb8aae94d6612d01187b2c02526e340a7fd6c8022028bdf7a64a54906b13b145cd5dab21a26bd4b85d6044e9b97bceab5be44c2a9201210253e8e0254b0c95776786e40984c1aa32a7d03efa6bdacdea5f421b774917d346feffffff026b20fa04000000001976a914024db2e87dd7cfd0e5f266c5f212e21a31d805a588aca0860100000000001976a91421919b94ae5cefcdf0271191459157cdb41c4cbf88aca6240700" class TestBCDataStream(unittest.TestCase): @@ -141,6 +141,10 @@ class TestTransaction(unittest.TestCase): res = xpubkey_to_address('fd007d260305ef27224bbcf6cf5238d2b3638b5a78d5') self.assertEquals(res, ('fd007d260305ef27224bbcf6cf5238d2b3638b5a78d5', '1CQj15y1N7LDHp7wTt28eoD1QhHgFgxECH')) + def test_version_field(self): + tx = transaction.Transaction(v2_blob) + self.assertEquals(tx.txid(), "b97f9180173ab141b61b9f944d841e60feec691d6daab4d4d932b24dd36606fe") + class NetworkMock(object): diff --git a/lib/transaction.py b/lib/transaction.py @@ -515,6 +515,7 @@ class Transaction: self._inputs = None self._outputs = None self.locktime = 0 + self.version = 1 def update(self, raw): self.raw = raw @@ -583,6 +584,7 @@ class Transaction: self._inputs = d['inputs'] self._outputs = [(x['type'], x['address'], x['value']) for x in d['outputs']] self.locktime = d['lockTime'] + self.version = d['version'] return d @classmethod @@ -708,7 +710,7 @@ class Transaction: return s def serialize_preimage(self, i): - nVersion = int_to_hex(1, 4) + nVersion = int_to_hex(self.version, 4) nHashType = int_to_hex(1, 4) nLocktime = int_to_hex(self.locktime, 4) inputs = self.inputs() @@ -733,7 +735,7 @@ class Transaction: return any(self.is_segwit_input(x) for x in self.inputs()) def serialize(self, estimate_size=False, witness=True): - nVersion = int_to_hex(1, 4) + nVersion = int_to_hex(self.version, 4) nLocktime = int_to_hex(self.locktime, 4) inputs = self.inputs() outputs = self.outputs()