'Add new signatures to a transaction'

def update_signatures(self, raw):

    d = deserialize(raw)
    for (i, txin) in enumerate(self.inputs()):
        (pubkeys, x_pubkeys) = self.get_sorted_pubkeys(txin)
        sigs1 = txin.get('signatures')
        sigs2 = d['inputs'][i].get('signatures')
        for sig in sigs2:
            if (sig in sigs1):
                continue
            pre_hash = Hash(self.serialize_preimage(i).decode('hex'))
            order = ecdsa.ecdsa.generator_secp256k1.order()
            (r, s) = ecdsa.util.sigdecode_der(sig.decode('hex')[:(-1)], order)
            sig_string = ecdsa.util.sigencode_string(r, s, order)
            compressed = True
            for recid in range(4):
                public_key = MyVerifyingKey.from_signature(sig_string, recid, pre_hash, curve=SECP256k1)
                pubkey = point_to_ser(public_key.pubkey.point, compressed).encode('hex')
                if (pubkey in pubkeys):
                    public_key.verify_digest(sig_string, pre_hash, sigdecode=ecdsa.util.sigdecode_string)
                    j = pubkeys.index(pubkey)
                    print_error('adding    sig', i, j, pubkey, sig)
                    self._inputs[i]['signatures'][j] = sig
                    self._inputs[i]['x_pubkeys'][j] = pubkey
                    break
    self.raw = self.serialize()
