def serialize_with_witness(self):
    flags = 0
    if (not self.wit.is_null()):
        flags |= 1
    r = b''
    r += struct.pack('<i', self.nVersion)
    if flags:
        dummy = []
        r += ser_vector(dummy)
        r += struct.pack('<B', flags)
    r += ser_vector(self.vin)
    r += ser_vector(self.vout)
    if (flags & 1):
        if (len(self.wit.vtxinwit) != len(self.vin)):
            self.wit.vtxinwit = self.wit.vtxinwit[:len(self.vin)]
            for _ in range(len(self.wit.vtxinwit), len(self.vin)):
                self.wit.vtxinwit.append(CTxInWitness())
        r += self.wit.serialize()
    r += struct.pack('<I', self.nLockTime)
    return r
def serialize_with_witness(self):
    flags = 0
    if (not self.wit.is_null()):
        flags |= 1
    r = b
    r += struct.pack('<i', self.nVersion)
    if flags:
        dummy = []
        r += ser_vector(dummy)
        r += struct.pack('<B', flags)
    r += ser_vector(self.vin)
    r += ser_vector(self.vout)
    if (flags & 1):
        if (len(self.wit.vtxinwit) != len(self.vin)):
            self.wit.vtxinwit = self.wit.vtxinwit[:len(self.vin)]
            for _ in range(len(self.wit.vtxinwit), len(self.vin)):
                self.wit.vtxinwit.append(CTxInWitness())
        r += self.wit.serialize()
    r += struct.pack('<I', self.nLockTime)
    return r