Skip to content

Commit bf3e212

Browse files
committed
Minor: fix formatting
1 parent 70c8ea1 commit bf3e212

File tree

2 files changed

+45
-38
lines changed

2 files changed

+45
-38
lines changed

bitcoin/core/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def from_txout(cls, txout):
313313

314314

315315
class CTxInWitness(ImmutableSerializable):
316-
"""Witness data for a single transaction input. """
316+
"""Witness data for a single transaction input"""
317317
__slots__ = ['scriptWitness']
318318

319319
def __init__(self, scriptWitness=CScriptWitness()):
@@ -347,7 +347,7 @@ def from_txinwitness(cls, txinwitness):
347347
return cls(txinwitness.scriptWitness)
348348

349349
class CTxWitness(ImmutableSerializable):
350-
"""Witness data for all inputs to a transaction."""
350+
"""Witness data for all inputs to a transaction"""
351351
__slots__ = ['vtxinwit']
352352

353353
def __init__(self, vtxinwit=()):
@@ -406,14 +406,18 @@ def __init__(self, vin=(), vout=(), nLockTime=0, nVersion=1, witness=CTxWitness(
406406

407407
@classmethod
408408
def stream_deserialize(cls, f):
409-
"""Deserialize a transaction. This implementation corresponds to
410-
Bitcoin's SerializeTransaction() and consensus behavior. Note that
411-
Bitcoin's DecodeHexTx() also has the option to attempt deserializing
412-
as a non-witness transaction first, falling back to the consensus
413-
behavior if it fails. The difference lies in transactions which
414-
have zero inputs: they are invalid but may be (de-)serialized anyway
415-
for the purpose of signing them and adding inputs. If the behavior
416-
of DecodeHexTx() is needed it could be added, but not here. """
409+
"""Deserialize transaction
410+
411+
This implementation corresponds to Bitcoin's SerializeTransaction() and
412+
consensus behavior. Note that Bitcoin's DecodeHexTx() also has the
413+
option to attempt deserializing as a non-witness transaction first,
414+
falling back to the consensus behavior if it fails. The difference lies
415+
in transactions which have zero inputs: they are invalid but may be
416+
(de)serialized anyway for the purpose of signing them and adding
417+
inputs. If the behavior of DecodeHexTx() is needed it could be added,
418+
but not here.
419+
"""
420+
# FIXME can't assume f is seekable
417421
nVersion = struct.unpack(b"<i", ser_read(f,4))[0]
418422
pos = f.tell()
419423
markerbyte = struct.unpack(b'B', ser_read(f, 1))[0]
@@ -650,7 +654,10 @@ def calc_witness_merkle_root(self):
650654
return self.build_witness_merkle_tree_from_txs(self.vtx)[-1]
651655

652656
def get_witness_commitment_index(self):
653-
"""Return None or an index"""
657+
"""Find txout # of witness commitment in coinbase
658+
659+
Return None or an index
660+
"""
654661
if not len(self.vtx):
655662
raise ValueError('Block contains no transactions')
656663
commit_pos = None

bitcoin/tests/test_segwit.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def test_p2wpkh_signaturehash(self):
3737
value = int(6*COIN)
3838

3939
address = CBitcoinAddress.from_scriptPubKey(scriptpubkey)
40-
self.assertEqual(SignatureHash(address.to_scriptPubKey(), CTransaction.deserialize(unsigned_tx),
41-
1, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
40+
self.assertEqual(SignatureHash(address.to_scriptPubKey(), CTransaction.deserialize(unsigned_tx),
41+
1, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
4242
x('c37af31116d1b27caf68aae9e3ac82f1477929014d5b917657d0eb49478cb670'))
4343

4444
def test_p2sh_p2wpkh_signaturehash(self):
@@ -48,8 +48,8 @@ def test_p2sh_p2wpkh_signaturehash(self):
4848
value = int(10*COIN)
4949

5050
address = CBitcoinAddress.from_scriptPubKey(redeemscript)
51-
self.assertEqual(SignatureHash(address.to_scriptPubKey(), CTransaction.deserialize(unsigned_tx),
52-
0, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
51+
self.assertEqual(SignatureHash(address.to_scriptPubKey(), CTransaction.deserialize(unsigned_tx),
52+
0, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
5353
x('64f3b0f4dd2bb3aa1ce8566d220cc74dda9df97d8490cc81d89d735c92e59fb6'))
5454

5555
def test_p2wsh_signaturehash1(self):
@@ -63,14 +63,14 @@ def test_p2wsh_signaturehash1(self):
6363
# OP_CODESEPARATOR removed
6464
scriptcode2 = CScript(x('210255a9626aebf5e29c0e6538428ba0d1dcf6ca98ffdf086aa8ced5e0d0215ea465ac'))
6565

66-
self.assertEqual(SignatureHash(scriptcode1, CTransaction.deserialize(unsigned_tx),
67-
1, SIGHASH_SINGLE, value2, SIGVERSION_WITNESS_V0),
66+
self.assertEqual(SignatureHash(scriptcode1, CTransaction.deserialize(unsigned_tx),
67+
1, SIGHASH_SINGLE, value2, SIGVERSION_WITNESS_V0),
6868
x('82dde6e4f1e94d02c2b7ad03d2115d691f48d064e9d52f58194a6637e4194391'))
69-
self.assertEqual(SignatureHash(scriptcode2, CTransaction.deserialize(unsigned_tx),
70-
1, SIGHASH_SINGLE, value2, SIGVERSION_WITNESS_V0),
69+
self.assertEqual(SignatureHash(scriptcode2, CTransaction.deserialize(unsigned_tx),
70+
1, SIGHASH_SINGLE, value2, SIGVERSION_WITNESS_V0),
7171
x('fef7bd749cce710c5c052bd796df1af0d935e59cea63736268bcbe2d2134fc47'))
7272

73-
def test_p2wsh_signaturehash2(self):
73+
def test_p2wsh_signaturehash2(self):
7474
unsigned_tx = x('0100000002e9b542c5176808107ff1df906f46bb1f2583b16112b95ee5380665ba7fcfc0010000000000ffffffff80e68831516392fcd100d186b3c2c7b95c80b53c77e77c35ba03a66b429a2a1b0000000000ffffffff0280969800000000001976a914de4b231626ef508c9a74a8517e6783c0546d6b2888ac80969800000000001976a9146648a8cd4531e1ec47f35916de8e259237294d1e88ac00000000')
7575
scriptpubkey1 = CScript(x('0020ba468eea561b26301e4cf69fa34bde4ad60c81e70f059f045ca9a79931004a4d'))
7676
value1 = int(0.16777215*COIN)
@@ -81,40 +81,40 @@ def test_p2wsh_signaturehash2(self):
8181
witnessscript2= CScript(x('5163ab68210392972e2eb617b2388771abe27235fd5ac44af8e61693261550447a4c3e39da98ac'))
8282
scriptcode2 = CScript(x('68210392972e2eb617b2388771abe27235fd5ac44af8e61693261550447a4c3e39da98ac'))
8383

84-
self.assertEqual(SignatureHash(scriptcode1, CTransaction.deserialize(unsigned_tx),
85-
0, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value1, SIGVERSION_WITNESS_V0),
84+
self.assertEqual(SignatureHash(scriptcode1, CTransaction.deserialize(unsigned_tx),
85+
0, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value1, SIGVERSION_WITNESS_V0),
8686
x('e9071e75e25b8a1e298a72f0d2e9f4f95a0f5cdf86a533cda597eb402ed13b3a'))
87-
self.assertEqual(SignatureHash(scriptcode2, CTransaction.deserialize(unsigned_tx),
88-
1, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value2, SIGVERSION_WITNESS_V0),
87+
self.assertEqual(SignatureHash(scriptcode2, CTransaction.deserialize(unsigned_tx),
88+
1, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value2, SIGVERSION_WITNESS_V0),
8989
x('cd72f1f1a433ee9df816857fad88d8ebd97e09a75cd481583eb841c330275e54'))
9090

91-
def test_p2sh_p2wsh_signaturehash(self):
91+
def test_p2sh_p2wsh_signaturehash(self):
9292
unsigned_tx = x('010000000136641869ca081e70f394c6948e8af409e18b619df2ed74aa106c1ca29787b96e0100000000ffffffff0200e9a435000000001976a914389ffce9cd9ae88dcc0631e88a821ffdbe9bfe2688acc0832f05000000001976a9147480a33f950689af511e6e84c138dbbd3c3ee41588ac00000000')
9393

9494
scriptPubKey = CScript(x('a9149993a429037b5d912407a71c252019287b8d27a587'))
9595
value = int(9.87654321*COIN)
9696
redeemScript = CScript(x('0020a16b5755f7f6f96dbd65f5f0d6ab9418b89af4b1f14a1bb8a09062c35f0dcb54'))
9797
witnessscript= CScript(x('56210307b8ae49ac90a048e9b53357a2354b3334e9c8bee813ecb98e99a7e07e8c3ba32103b28f0c28bfab54554ae8c658ac5c3e0ce6e79ad336331f78c428dd43eea8449b21034b8113d703413d57761b8b9781957b8c0ac1dfe69f492580ca4195f50376ba4a21033400f6afecb833092a9a21cfdf1ed1376e58c5d1f47de74683123987e967a8f42103a6d48b1131e94ba04d9737d61acdaa1322008af9602b3b14862c07a1789aac162102d8b661b0b3302ee2f162b09e07a55ad5dfbe673a9f01d9f0c19617681024306b56ae'))
9898

99-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
100-
0, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
99+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
100+
0, SIGHASH_ALL, value, SIGVERSION_WITNESS_V0),
101101
x('185c0be5263dce5b4bb50a047973c1b6272bfbd0103a89444597dc40b248ee7c'))
102-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
103-
0, SIGHASH_NONE, value, SIGVERSION_WITNESS_V0),
102+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
103+
0, SIGHASH_NONE, value, SIGVERSION_WITNESS_V0),
104104
x('e9733bc60ea13c95c6527066bb975a2ff29a925e80aa14c213f686cbae5d2f36'))
105-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
106-
0, SIGHASH_SINGLE, value, SIGVERSION_WITNESS_V0),
105+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
106+
0, SIGHASH_SINGLE, value, SIGVERSION_WITNESS_V0),
107107
x('1e1f1c303dc025bd664acb72e583e933fae4cff9148bf78c157d1e8f78530aea'))
108-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
109-
0, SIGHASH_ALL|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
108+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
109+
0, SIGHASH_ALL|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
110110
x('2a67f03e63a6a422125878b40b82da593be8d4efaafe88ee528af6e5a9955c6e'))
111-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
112-
0, SIGHASH_NONE|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
111+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
112+
0, SIGHASH_NONE|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
113113
x('781ba15f3779d5542ce8ecb5c18716733a5ee42a6f51488ec96154934e2c890a'))
114-
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
115-
0, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
114+
self.assertEqual(SignatureHash(witnessscript, CTransaction.deserialize(unsigned_tx),
115+
0, SIGHASH_SINGLE|SIGHASH_ANYONECANPAY, value, SIGVERSION_WITNESS_V0),
116116
x('511e8e52ed574121fc1b654970395502128263f62662e076dc6baf05c2e6a99b'))
117-
117+
118118
def test_checkblock(self):
119119
# (No witness) coinbase generated by Bitcoin Core
120120
str_coinbase = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03520101ffffffff0100f2052a01000000232102960c90bc04a631cb17922e4f5d80ac75fd590a88b8baaa5a3d5086ac85e4d788ac00000000'

0 commit comments

Comments
 (0)