Exemplo n.º 1
0
 def fill_psbt(self, b64psbt, non_witness: bool = True, xpubs: bool = True):
     psbt = PSBT()
     psbt.deserialize(b64psbt)
     if non_witness:
         for i, inp in enumerate(psbt.tx.vin):
             txid = inp.prevout.hash.to_bytes(32, 'big').hex()
             try:
                 res = self.cli.gettransaction(txid)
             except:
                 raise SpecterError(
                     "Can't find previous transaction in the wallet.")
             stream = BytesIO(bytes.fromhex(res["hex"]))
             prevtx = CTransaction()
             prevtx.deserialize(stream)
             psbt.inputs[i].non_witness_utxo = prevtx
     if xpubs:
         # for multisig add xpub fields
         if len(self.keys) > 1:
             for k in self.keys:
                 key = b'\x01' + decode_base58(k.xpub)
                 if k.fingerprint != '':
                     fingerprint = bytes.fromhex(k.fingerprint)
                 else:
                     fingerprint = get_xpub_fingerprint(k.xpub)
                 if k.derivation != '':
                     der = der_to_bytes(k.derivation)
                 else:
                     der = b''
                 value = fingerprint + der
                 psbt.unknown[key] = value
     return psbt.serialize()
Exemplo n.º 2
0
def get_txid(tx):
    b = BytesIO(bytes.fromhex(tx))
    t = CTransaction()
    t.deserialize(b)
    for inp in t.vin:
        inp.scriptSig = b""
    t.rehash()
    return t.hash
Exemplo n.º 3
0
 def fill_psbt(self, b64psbt):
     psbt = PSBT()
     psbt.deserialize(b64psbt)
     for i, inp in enumerate(psbt.tx.vin):
         txid = inp.prevout.hash.to_bytes(32,'big').hex()
         try:
             res = self.cli.gettransaction(txid)
         except:
             raise SpecterError("Can't find previous transaction in the wallet.")
         stream = BytesIO(bytes.fromhex(res["hex"]))
         prevtx = CTransaction()
         prevtx.deserialize(stream)
         psbt.inputs[i].non_witness_utxo = prevtx
     return psbt.serialize()
Exemplo n.º 4
0
    def fill_psbt(self, b64psbt, non_witness: bool = True, xpubs: bool = True):
        psbt = PSBT()
        psbt.deserialize(b64psbt)
        if non_witness:
            for i, inp in enumerate(psbt.tx.vin):
                txid = inp.prevout.hash.to_bytes(32, "big").hex()
                try:
                    res = self.gettransaction(txid)
                    stream = BytesIO(bytes.fromhex(res["hex"]))
                    prevtx = CTransaction()
                    prevtx.deserialize(stream)
                    psbt.inputs[i].non_witness_utxo = prevtx
                except:
                    logger.error(
                        "Can't find previous transaction in the wallet. Signing might not be possible for certain devices..."
                    )
        else:
            # remove non_witness_utxo if we don't want them
            for inp in psbt.inputs:
                if inp.witness_utxo is not None:
                    inp.non_witness_utxo = None

        if xpubs:
            # for multisig add xpub fields
            if len(self.keys) > 1:
                for k in self.keys:
                    key = b"\x01" + decode_base58(k.xpub)
                    if k.fingerprint != "":
                        fingerprint = bytes.fromhex(k.fingerprint)
                    else:
                        fingerprint = get_xpub_fingerprint(k.xpub)
                    if k.derivation != "":
                        der = der_to_bytes(k.derivation)
                    else:
                        der = b""
                    value = fingerprint + der
                    psbt.unknown[key] = value
        return psbt.serialize()