Skip to content

Commit abeba75

Browse files
committed
Make str(<COutPoint>) return hash:n format
Previously was the same as repr(), ugly.
1 parent 0586aa7 commit abeba75

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

bitcoin/core/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ def __repr__(self):
153153
else:
154154
return 'COutPoint(lx(%r), %i)' % (b2lx(self.hash), self.n)
155155

156+
def __str__(self):
157+
return '%s:%i' % (b2lx(self.hash), self.n)
158+
156159
@classmethod
157160
def from_outpoint(cls, outpoint):
158161
"""Create an immutable copy of an existing OutPoint

bitcoin/tests/test_transactions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ def T(outpoint, expected):
5858
T( COutPoint(lx('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'), 0),
5959
"COutPoint(lx('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'), 0)")
6060

61+
def test_str(self):
62+
def T(outpoint, expected):
63+
actual = str(outpoint)
64+
self.assertEqual(actual, expected)
65+
T(COutPoint(),
66+
'0000000000000000000000000000000000000000000000000000000000000000:4294967295')
67+
T(COutPoint(lx('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'), 0),
68+
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:0')
69+
T(COutPoint(lx('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'), 10),
70+
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b:10')
71+
6172
class Test_CMutableOutPoint(unittest.TestCase):
6273
def test_GetHash(self):
6374
"""CMutableOutPoint.GetHash() is not cached"""

0 commit comments

Comments
 (0)