MCPcopy Create free account
hub / github.com/ElementsProject/elements / CTransaction

Class CTransaction

test/functional/test_framework/messages.py:801–939  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

799
800
801class CTransaction:
802 __slots__ = ("hash", "nLockTime", "nVersion", "sha256", "vin", "vout",
803 "wit")
804
805 def __init__(self, tx=None):
806 if tx is None:
807 self.nVersion = 2
808 self.vin = []
809 self.vout = []
810 self.wit = CTxWitness()
811 self.nLockTime = 0
812 self.sha256 = None
813 self.hash = None
814 else:
815 self.nVersion = tx.nVersion
816 self.vin = copy.deepcopy(tx.vin)
817 self.vout = copy.deepcopy(tx.vout)
818 self.nLockTime = tx.nLockTime
819 self.sha256 = tx.sha256
820 self.hash = tx.hash
821 self.wit = copy.deepcopy(tx.wit)
822
823 def deserialize(self, f):
824 self.nVersion = struct.unpack("<i", f.read(4))[0]
825 flags = struct.unpack("<B", f.read(1))[0]
826 self.vin = deser_vector(f, CTxIn)
827 self.vout = deser_vector(f, CTxOut)
828 self.nLockTime = struct.unpack("<I", f.read(4))[0]
829 if flags & 1 > 0:
830 self.wit.vtxinwit = [CTxInWitness() for _ in range(len(self.vin))]
831 self.wit.vtxoutwit = [CTxOutWitness() for _ in range(len(self.vout))]
832 self.wit.deserialize(f)
833 else:
834 self.wit = CTxWitness()
835 if flags > 1:
836 raise TypeError('Extra witness flags:' + str(flags))
837 self.sha256 = None
838 self.hash = None
839
840 # Only applicable for non-CT, non-segwit transactions
841 def serialize_without_witness(self):
842 r = b""
843 r += struct.pack("<i", self.nVersion)
844 r += struct.pack("B", 0)
845 r += ser_vector(self.vin)
846 r += ser_vector(self.vout)
847 r += struct.pack("<I", self.nLockTime)
848 return r
849
850 # Only serialize with witness when explicitly called for
851 def serialize_with_witness(self):
852 flags = 0
853 if not self.wit.is_null():
854 flags |= 1
855 r = b""
856 r += struct.pack("<i", self.nVersion)
857 r += struct.pack("<B", flags)
858 r += ser_vector(self.vin)

Callers 15

run_testMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90
test_no_surjMethod · 0.90
test_no_rangeMethod · 0.90
run_testMethod · 0.90
run_testMethod · 0.90

Calls

no outgoing calls