MCPcopy
hub / github.com/petertodd/python-bitcoinlib / COutPoint

Class COutPoint

bitcoin/core/__init__.py:87–133  ·  view source on GitHub ↗

The combination of a transaction hash and an index n into its vout

Source from the content-addressed store, hash-verified

85
86
87class COutPoint(ImmutableSerializable):
88 """The combination of a transaction hash and an index n into its vout"""
89 __slots__ = ['hash', 'n']
90
91 def __init__(self, hash=b'\x00'*32, n=0xffffffff):
92 if not len(hash) == 32:
93 raise ValueError('COutPoint: hash must be exactly 32 bytes; got %d bytes' % len(hash))
94 object.__setattr__(self, 'hash', hash)
95 if not (0 <= n <= 0xffffffff):
96 raise ValueError('COutPoint: n must be in range 0x0 to 0xffffffff; got %x' % n)
97 object.__setattr__(self, 'n', n)
98
99 @classmethod
100 def stream_deserialize(cls, f):
101 hash = ser_read(f,32)
102 n = struct.unpack(b"<I", ser_read(f,4))[0]
103 return cls(hash, n)
104
105 def stream_serialize(self, f):
106 assert len(self.hash) == 32
107 f.write(self.hash)
108 f.write(struct.pack(b"<I", self.n))
109
110 def is_null(self):
111 return ((self.hash == b'\x00'*32) and (self.n == 0xffffffff))
112
113 def __repr__(self):
114 if self.is_null():
115 return 'COutPoint()'
116 else:
117 return 'COutPoint(lx(%r), %i)' % (b2lx(self.hash), self.n)
118
119 def __str__(self):
120 return '%s:%i' % (b2lx(self.hash), self.n)
121
122 @classmethod
123 def from_outpoint(cls, outpoint):
124 """Create an immutable copy of an existing OutPoint
125
126 If outpoint is already immutable (outpoint.__class__ is COutPoint) it is
127 returned directly.
128 """
129 if outpoint.__class__ is COutPoint:
130 return outpoint
131
132 else:
133 return cls(outpoint.hash, outpoint.n)
134
135@__make_mutable
136class CMutableOutPoint(COutPoint):

Callers 13

listunspentMethod · 0.90
fundrawtransactionMethod · 0.90
spend-p2wpkh.pyFile · 0.90
__init__Method · 0.85
create_test_txsMethod · 0.85
load_test_vectorsFunction · 0.85
test_is_nullMethod · 0.85
test_reprMethod · 0.85
test_strMethod · 0.85

Calls

no outgoing calls

Tested by 5

create_test_txsMethod · 0.68
load_test_vectorsFunction · 0.68
test_is_nullMethod · 0.68
test_reprMethod · 0.68
test_strMethod · 0.68