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

Class CTxOut

bitcoin/core/__init__.py:214–260  ·  view source on GitHub ↗

An output of a transaction Contains the public key that the next input must be able to sign with to claim it.

Source from the content-addressed store, hash-verified

212
213
214class CTxOut(ImmutableSerializable):
215 """An output of a transaction
216
217 Contains the public key that the next input must be able to sign with to
218 claim it.
219 """
220 __slots__ = ['nValue', 'scriptPubKey']
221
222 def __init__(self, nValue=-1, scriptPubKey=script.CScript()):
223 object.__setattr__(self, 'nValue', int(nValue))
224 object.__setattr__(self, 'scriptPubKey', scriptPubKey)
225
226 @classmethod
227 def stream_deserialize(cls, f):
228 nValue = struct.unpack(b"<q", ser_read(f,8))[0]
229 scriptPubKey = script.CScript(BytesSerializer.stream_deserialize(f))
230 return cls(nValue, scriptPubKey)
231
232 def stream_serialize(self, f):
233 f.write(struct.pack(b"<q", self.nValue))
234 BytesSerializer.stream_serialize(self.scriptPubKey, f)
235
236 def is_valid(self):
237 if not MoneyRange(self.nValue):
238 return False
239 if not self.scriptPubKey.is_valid():
240 return False
241 return True
242
243 def __repr__(self):
244 if self.nValue >= 0:
245 return "CTxOut(%s*COIN, %r)" % (str_money_value(self.nValue), self.scriptPubKey)
246 else:
247 return "CTxOut(%d, %r)" % (self.nValue, self.scriptPubKey)
248
249 @classmethod
250 def from_txout(cls, txout):
251 """Create an immutable copy of an existing TxOut
252
253 If txout is already immutable (txout.__class__ is CTxOut) then it will
254 be returned directly.
255 """
256 if txout.__class__ is CTxOut:
257 return txout
258
259 else:
260 return cls(txout.nValue, txout.scriptPubKey)
261
262@__make_mutable
263class CMutableTxOut(CTxOut):

Callers 5

gettxoutMethod · 0.90
spend-p2wpkh.pyFile · 0.90
test_checkblockMethod · 0.85
create_test_txsMethod · 0.85
publish-text.pyFile · 0.85

Calls

no outgoing calls

Tested by 2

test_checkblockMethod · 0.68
create_test_txsMethod · 0.68