Search in sources :

Example 6 with PSBTOutput

use of com.sparrowwallet.drongo.psbt.PSBTOutput in project drongo by sparrowwallet.

the class PSBT method serialize.

public byte[] serialize(boolean includeXpubs) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.writeBytes(Utils.hexToBytes(PSBT_MAGIC_HEX));
    baos.writeBytes(new byte[] { (byte) 0xff });
    List<PSBTEntry> globalEntries = getGlobalEntries();
    for (PSBTEntry entry : globalEntries) {
        if (includeXpubs || (entry.getKeyType() != PSBT_GLOBAL_BIP32_PUBKEY && entry.getKeyType() != PSBT_GLOBAL_PROPRIETARY)) {
            entry.serializeToStream(baos);
        }
    }
    baos.writeBytes(new byte[] { (byte) 0x00 });
    for (PSBTInput psbtInput : getPsbtInputs()) {
        List<PSBTEntry> inputEntries = psbtInput.getInputEntries();
        for (PSBTEntry entry : inputEntries) {
            if (includeXpubs || (entry.getKeyType() != PSBT_IN_BIP32_DERIVATION && entry.getKeyType() != PSBT_IN_PROPRIETARY && entry.getKeyType() != PSBT_IN_TAP_INTERNAL_KEY && entry.getKeyType() != PSBT_IN_TAP_BIP32_DERIVATION)) {
                entry.serializeToStream(baos);
            }
        }
        baos.writeBytes(new byte[] { (byte) 0x00 });
    }
    for (PSBTOutput psbtOutput : getPsbtOutputs()) {
        List<PSBTEntry> outputEntries = psbtOutput.getOutputEntries();
        for (PSBTEntry entry : outputEntries) {
            if (includeXpubs || (entry.getKeyType() != PSBT_OUT_REDEEM_SCRIPT && entry.getKeyType() != PSBT_OUT_WITNESS_SCRIPT && entry.getKeyType() != PSBT_OUT_BIP32_DERIVATION && entry.getKeyType() != PSBT_OUT_PROPRIETARY && entry.getKeyType() != PSBT_OUT_TAP_INTERNAL_KEY && entry.getKeyType() != PSBT_OUT_TAP_BIP32_DERIVATION)) {
                entry.serializeToStream(baos);
            }
        }
        baos.writeBytes(new byte[] { (byte) 0x00 });
    }
    return baos.toByteArray();
}
Also used : PSBTOutput(com.sparrowwallet.drongo.psbt.PSBTOutput) PSBTEntry(com.sparrowwallet.drongo.psbt.PSBTEntry) PSBTInput(com.sparrowwallet.drongo.psbt.PSBTInput)

Example 7 with PSBTOutput

use of com.sparrowwallet.drongo.psbt.PSBTOutput in project drongo by sparrowwallet.

the class PSBT method combine.

public void combine(PSBT psbt) {
    byte[] txBytes = transaction.bitcoinSerialize();
    byte[] psbtTxBytes = psbt.getTransaction().bitcoinSerialize();
    if (!Arrays.equals(txBytes, psbtTxBytes)) {
        throw new IllegalArgumentException("Provided PSBT does contain a matching global transaction");
    }
    if (isFinalized() || psbt.isFinalized()) {
        throw new IllegalArgumentException("Cannot combine an already finalised PSBT");
    }
    if (psbt.getVersion() != null) {
        version = psbt.getVersion();
    }
    extendedPublicKeys.putAll(psbt.extendedPublicKeys);
    globalProprietary.putAll(psbt.globalProprietary);
    for (int i = 0; i < getPsbtInputs().size(); i++) {
        PSBTInput thisInput = getPsbtInputs().get(i);
        PSBTInput otherInput = psbt.getPsbtInputs().get(i);
        thisInput.combine(otherInput);
    }
    for (int i = 0; i < getPsbtOutputs().size(); i++) {
        PSBTOutput thisOutput = getPsbtOutputs().get(i);
        PSBTOutput otherOutput = psbt.getPsbtOutputs().get(i);
        thisOutput.combine(otherOutput);
    }
}
Also used : PSBTOutput(com.sparrowwallet.drongo.psbt.PSBTOutput) PSBTInput(com.sparrowwallet.drongo.psbt.PSBTInput)

Aggregations

PSBTOutput (com.sparrowwallet.drongo.psbt.PSBTOutput)7 PSBTInput (com.sparrowwallet.drongo.psbt.PSBTInput)5 PSBTEntry (com.sparrowwallet.drongo.psbt.PSBTEntry)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ECKey (com.sparrowwallet.drongo.crypto.ECKey)1 Transaction (com.sparrowwallet.drongo.protocol.Transaction)1 TransactionInput (com.sparrowwallet.drongo.protocol.TransactionInput)1 TransactionOutput (com.sparrowwallet.drongo.protocol.TransactionOutput)1 TreeItem (javafx.scene.control.TreeItem)1