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

Class CTxIn

bitcoin/core/__init__.py:145–190  ·  view source on GitHub ↗

An input of a transaction Contains the location of the previous transaction's output that it claims, and a signature that matches the output's public key.

Source from the content-addressed store, hash-verified

143 return cls(outpoint.hash, outpoint.n)
144
145class CTxIn(ImmutableSerializable):
146 """An input of a transaction
147
148 Contains the location of the previous transaction's output that it claims,
149 and a signature that matches the output's public key.
150 """
151 __slots__ = ['prevout', 'scriptSig', 'nSequence']
152
153 def __init__(self, prevout=COutPoint(), scriptSig=CScript(), nSequence = 0xffffffff):
154 if not (0 <= nSequence <= 0xffffffff):
155 raise ValueError('CTxIn: nSequence must be an integer between 0x0 and 0xffffffff; got %x' % nSequence)
156 object.__setattr__(self, 'nSequence', nSequence)
157
158 object.__setattr__(self, 'prevout', prevout)
159 object.__setattr__(self, 'scriptSig', scriptSig)
160
161 @classmethod
162 def stream_deserialize(cls, f):
163 prevout = COutPoint.stream_deserialize(f)
164 scriptSig = script.CScript(BytesSerializer.stream_deserialize(f))
165 nSequence = struct.unpack(b"<I", ser_read(f,4))[0]
166 return cls(prevout, scriptSig, nSequence)
167
168 def stream_serialize(self, f):
169 COutPoint.stream_serialize(self.prevout, f)
170 BytesSerializer.stream_serialize(self.scriptSig, f)
171 f.write(struct.pack(b"<I", self.nSequence))
172
173 def is_final(self):
174 return (self.nSequence == 0xffffffff)
175
176 def __repr__(self):
177 return "CTxIn(%s, %s, 0x%x)" % (repr(self.prevout), repr(self.scriptSig), self.nSequence)
178
179 @classmethod
180 def from_txin(cls, txin):
181 """Create an immutable copy of an existing TxIn
182
183 If txin is already immutable (txin.__class__ is CTxIn) it is returned
184 directly.
185 """
186 if txin.__class__ is CTxIn:
187 return txin
188
189 else:
190 return cls(COutPoint.from_outpoint(txin.prevout), txin.scriptSig, txin.nSequence)
191
192@__make_mutable
193class CMutableTxIn(CTxIn):

Callers 7

spend-p2wpkh.pyFile · 0.90
create_test_txsMethod · 0.85
test_is_finalMethod · 0.85
test_reprMethod · 0.85
test_is_coinbaseMethod · 0.85
publish-text.pyFile · 0.85

Calls

no outgoing calls

Tested by 4

create_test_txsMethod · 0.68
test_is_finalMethod · 0.68
test_reprMethod · 0.68
test_is_coinbaseMethod · 0.68