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();
}
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);
}
}
Aggregations