mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-11-02 18:26:43 +00:00
add creator, combiner, extractor psbt tests and fix issues
This commit is contained in:
parent
5cd203d366
commit
70d0b7afcd
6 changed files with 134 additions and 6 deletions
|
@ -115,7 +115,7 @@ public class TransactionInput extends ChildMessage {
|
|||
}
|
||||
|
||||
public boolean hasWitness() {
|
||||
return witness != null && witness.getPushCount() != 0;
|
||||
return witness != null;
|
||||
}
|
||||
|
||||
public TransactionOutPoint getOutpoint() {
|
||||
|
|
|
@ -151,7 +151,7 @@ public class TransactionWitness extends ChildMessage {
|
|||
|
||||
public Script getWitnessScript() {
|
||||
List<ScriptChunk> scriptChunks = this.asScriptChunks();
|
||||
if(scriptChunks.get(scriptChunks.size() - 1).isScript()) {
|
||||
if(!scriptChunks.isEmpty() && scriptChunks.get(scriptChunks.size() - 1).isScript()) {
|
||||
return scriptChunks.get(scriptChunks.size() - 1).getScript();
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,18 @@ public class PSBT {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(PSBT.class);
|
||||
|
||||
public PSBT(Transaction transaction) {
|
||||
this.transaction = transaction;
|
||||
|
||||
for(int i = 0; i < transaction.getInputs().size(); i++) {
|
||||
psbtInputs.add(new PSBTInput(transaction, i));
|
||||
}
|
||||
|
||||
for(int i = 0; i < transaction.getOutputs().size(); i++) {
|
||||
psbtOutputs.add(new PSBTOutput());
|
||||
}
|
||||
}
|
||||
|
||||
public PSBT(WalletTransaction walletTransaction) {
|
||||
Wallet wallet = walletTransaction.getWallet();
|
||||
|
||||
|
@ -449,17 +461,32 @@ public class PSBT {
|
|||
}
|
||||
|
||||
public Transaction extractTransaction() {
|
||||
boolean hasWitness = false;
|
||||
for(PSBTInput psbtInput : getPsbtInputs()) {
|
||||
if(psbtInput.getFinalScriptSig() == null) {
|
||||
return null;
|
||||
}
|
||||
if(psbtInput.getFinalScriptWitness() != null) {
|
||||
hasWitness = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(hasWitness && !transaction.isSegwit()) {
|
||||
transaction.setSegwitVersion(1);
|
||||
}
|
||||
|
||||
for(int i = 0; i < transaction.getInputs().size(); i++) {
|
||||
TransactionInput txInput = transaction.getInputs().get(i);
|
||||
PSBTInput psbtInput = getPsbtInputs().get(i);
|
||||
txInput.setScriptBytes(psbtInput.getFinalScriptSig().getProgram());
|
||||
txInput.setWitness(psbtInput.getFinalScriptWitness());
|
||||
|
||||
if(hasWitness) {
|
||||
if(psbtInput.getFinalScriptWitness() != null) {
|
||||
txInput.setWitness(psbtInput.getFinalScriptWitness());
|
||||
} else {
|
||||
txInput.setWitness(new TransactionWitness(transaction, Collections.emptyList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return transaction;
|
||||
|
|
|
@ -43,9 +43,13 @@ public class PSBTInput {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(PSBTInput.class);
|
||||
|
||||
PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map<ECKey, KeyDerivation> derivedPublicKeys, Map<String, String> proprietary) {
|
||||
PSBTInput(Transaction transaction, int index) {
|
||||
this.transaction = transaction;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map<ECKey, KeyDerivation> derivedPublicKeys, Map<String, String> proprietary) {
|
||||
this(transaction, index);
|
||||
sigHash = SigHash.ALL;
|
||||
|
||||
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(scriptType)) {
|
||||
|
@ -286,10 +290,18 @@ public class PSBTInput {
|
|||
return nonWitnessUtxo;
|
||||
}
|
||||
|
||||
public void setNonWitnessUtxo(Transaction nonWitnessUtxo) {
|
||||
this.nonWitnessUtxo = nonWitnessUtxo;
|
||||
}
|
||||
|
||||
public TransactionOutput getWitnessUtxo() {
|
||||
return witnessUtxo;
|
||||
}
|
||||
|
||||
public void setWitnessUtxo(TransactionOutput witnessUtxo) {
|
||||
this.witnessUtxo = witnessUtxo;
|
||||
}
|
||||
|
||||
public TransactionSignature getPartialSignature(ECKey publicKey) {
|
||||
return partialSignatures.get(publicKey);
|
||||
}
|
||||
|
@ -306,10 +318,18 @@ public class PSBTInput {
|
|||
return redeemScript;
|
||||
}
|
||||
|
||||
public void setRedeemScript(Script redeemScript) {
|
||||
this.redeemScript = redeemScript;
|
||||
}
|
||||
|
||||
public Script getWitnessScript() {
|
||||
return witnessScript;
|
||||
}
|
||||
|
||||
public void setWitnessScript(Script witnessScript) {
|
||||
this.witnessScript = witnessScript;
|
||||
}
|
||||
|
||||
public KeyDerivation getKeyDerivation(ECKey publicKey) {
|
||||
return derivedPublicKeys.get(publicKey);
|
||||
}
|
||||
|
@ -334,6 +354,10 @@ public class PSBTInput {
|
|||
return porCommitment;
|
||||
}
|
||||
|
||||
public void setPorCommitment(String porCommitment) {
|
||||
this.porCommitment = porCommitment;
|
||||
}
|
||||
|
||||
public Map<ECKey, TransactionSignature> getPartialSignatures() {
|
||||
return partialSignatures;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,10 @@ public class PSBTOutput {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(PSBTOutput.class);
|
||||
|
||||
PSBTOutput() {
|
||||
//empty constructor
|
||||
}
|
||||
|
||||
PSBTOutput(Script redeemScript, Script witnessScript, Map<ECKey, KeyDerivation> derivedPublicKeys, Map<String, String> proprietary) {
|
||||
this.redeemScript = redeemScript;
|
||||
this.witnessScript = witnessScript;
|
||||
|
@ -105,10 +109,18 @@ public class PSBTOutput {
|
|||
return redeemScript;
|
||||
}
|
||||
|
||||
public void setRedeemScript(Script redeemScript) {
|
||||
this.redeemScript = redeemScript;
|
||||
}
|
||||
|
||||
public Script getWitnessScript() {
|
||||
return witnessScript;
|
||||
}
|
||||
|
||||
public void setWitnessScript(Script witnessScript) {
|
||||
this.witnessScript = witnessScript;
|
||||
}
|
||||
|
||||
public KeyDerivation getKeyDerivation(ECKey publicKey) {
|
||||
return derivedPublicKeys.get(publicKey);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ package com.sparrowwallet.drongo.psbt;
|
|||
|
||||
import com.sparrowwallet.drongo.ExtendedKey;
|
||||
import com.sparrowwallet.drongo.KeyDerivation;
|
||||
import com.sparrowwallet.drongo.protocol.NonStandardScriptException;
|
||||
import com.sparrowwallet.drongo.protocol.SigHash;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.crypto.ECKey;
|
||||
import com.sparrowwallet.drongo.protocol.*;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -309,4 +310,68 @@ public class PSBTTest {
|
|||
PSBT psbt4 = PSBT.fromString(psbtStr4);
|
||||
Assert.assertEquals(psbtStr4, psbt4.toBase64String());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void creatorBip() throws PSBTParseException {
|
||||
Transaction transaction = new Transaction();
|
||||
transaction.setVersion(2);
|
||||
transaction.addOutput(149990000L, new Script(Utils.hexToBytes("0014d85c2b71d0060b09c9886aeb815e50991dda124d")));
|
||||
transaction.addOutput(100000000L, new Script(Utils.hexToBytes("001400aea9a2e5f0f876a588df5546e8742d1d87008f")));
|
||||
transaction.addInput(Sha256Hash.wrap("75ddabb27b8845f5247975c8a5ba7c6f336c4570708ebe230caf6db5217ae858"), 0, new Script(new byte[0]));
|
||||
transaction.addInput(Sha256Hash.wrap("1dea7cd05979072a3578cab271c02244ea8a090bbb46aa680a65ecd027048d83"), 1, new Script(new byte[0]));
|
||||
|
||||
PSBT psbt = new PSBT(transaction);
|
||||
Assert.assertEquals("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000000000000000000", psbt.toString());
|
||||
|
||||
psbt.getPsbtInputs().get(0).setRedeemScript(new Script(Utils.hexToBytes("5221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae")));
|
||||
psbt.getPsbtInputs().get(1).setRedeemScript(new Script(Utils.hexToBytes("00208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903")));
|
||||
psbt.getPsbtInputs().get(1).setWitnessScript(new Script(Utils.hexToBytes("522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae")));
|
||||
|
||||
Transaction utxo1 = new Transaction(Utils.hexToBytes("0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000"));
|
||||
psbt.getPsbtInputs().get(0).setNonWitnessUtxo(utxo1);
|
||||
|
||||
Transaction utxo2 = new Transaction(Utils.hexToBytes("0200000000010158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88702483045022100a22edcc6e5bc511af4cc4ae0de0fcd75c7e04d8c1c3a8aa9d820ed4b967384ec02200642963597b9b1bc22c75e9f3e117284a962188bf5e8a74c895089046a20ad770121035509a48eb623e10aace8bfd0212fdb8a8e5af3c94b0b133b95e114cab89e4f7965000000"));
|
||||
psbt.getPsbtInputs().get(1).setWitnessUtxo(utxo2.getOutputs().get(1));
|
||||
|
||||
psbt.getPsbtInputs().get(0).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f")), new KeyDerivation("d90c6a4f", "m/0'/0'/0'"));
|
||||
psbt.getPsbtInputs().get(0).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("02dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7")), new KeyDerivation("d90c6a4f", "m/0'/0'/1'"));
|
||||
|
||||
psbt.getPsbtInputs().get(1).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73")), new KeyDerivation("d90c6a4f", "m/0'/0'/3'"));
|
||||
psbt.getPsbtInputs().get(1).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("03089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc")), new KeyDerivation("d90c6a4f", "m/0'/0'/2'"));
|
||||
psbt.getPsbtOutputs().get(0).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("03a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca58771")), new KeyDerivation("d90c6a4f", "m/0'/0'/4'"));
|
||||
psbt.getPsbtOutputs().get(1).getDerivedPublicKeys().put(ECKey.fromPublicOnly(Utils.hexToBytes("027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b50051096")), new KeyDerivation("d90c6a4f", "m/0'/0'/5'"));
|
||||
|
||||
Assert.assertEquals("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000", psbt.toString());
|
||||
|
||||
PSBT testPSBT = new PSBT(Utils.hexToBytes("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000"));
|
||||
System.out.println(testPSBT.getExtendedPublicKeys());
|
||||
|
||||
for(PSBTInput psbtInput : psbt.getPsbtInputs()) {
|
||||
psbtInput.setSigHash(SigHash.ALL);
|
||||
}
|
||||
|
||||
Assert.assertEquals("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f618765000000010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8870103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000", psbt.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combinerBip() throws PSBTParseException {
|
||||
String strPsbt1 = "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAEAuwIAAAABqtc5MQGL0l+ErkALaISL4J23BurCrBgpi6vucatlb4sAAAAASEcwRAIgWPb8fGoz4bMVSNSByCbAFb0wE1qtQs1neQ2rZtKtJDsCIEoc7SYExnNbY5PltBaR3XiwDwxZQvufdRhW+qk4FX26Af7///8CgPD6AgAAAAAXqRQPuUY0IWlrgsgzryQceMF9295JNIfQ8gonAQAAABepFCnKdPigj4GZlCgYXJe12FLkBj9hh2UAAAAiAgKVg785rgpgl0etGZrd1jT6YQhVnWxc05tMIYPxq5bgf0cwRAIgdAGK1BgAl7hzMjwAFXILNoTMgSOJEEjn282bVa1nnJkCIHPTabdA4+tT3O+jOCPIBwUUylWn3ZVE8VfBZ5EyYRGMAQEDBAEAAAABBEdSIQKVg785rgpgl0etGZrd1jT6YQhVnWxc05tMIYPxq5bgfyEC2rYf9JoU22p9ArDNH7t4/EsYMStbTlTa5Nui+/71NtdSriIGApWDvzmuCmCXR60Zmt3WNPphCFWdbFzTm0whg/GrluB/ENkMak8AAACAAAAAgAAAAIAiBgLath/0mhTban0CsM0fu3j8SxgxK1tOVNrk26L7/vU21xDZDGpPAAAAgAAAAIABAACAAAEBIADC6wsAAAAAF6kUt/X69A49QKWkWbHbNTXyty+pIeiHIgIDCJ3BDHrG21T5EymvYXMz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|
||||
Assert.assertEquals("70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000002202029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01220202dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d7483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01010304010000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e887220203089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f012202023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d2010103040100000001042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000", psbt1.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractorBip() throws PSBTParseException {
|
||||
String strPsbt = "cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWABTYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFgAUAK6pouXw+HaliN9VRuh0LR2HAI8AAAAAAAEAuwIAAAABqtc5MQGL0l+ErkALaISL4J23BurCrBgpi6vucatlb4sAAAAASEcwRAIgWPb8fGoz4bMVSNSByCbAFb0wE1qtQs1neQ2rZtKtJDsCIEoc7SYExnNbY5PltBaR3XiwDwxZQvufdRhW+qk4FX26Af7///8CgPD6AgAAAAAXqRQPuUY0IWlrgsgzryQceMF9295JNIfQ8gonAQAAABepFCnKdPigj4GZlCgYXJe12FLkBj9hh2UAAAABB9oARzBEAiB0AYrUGACXuHMyPAAVcgs2hMyBI4kQSOfbzZtVrWecmQIgc9Npt0Dj61Pc76M4I8gHBRTKVafdlUTxV8FnkTJhEYwBSDBFAiEA9hA4swjcHahlo0hSdG8BV3KTQgjG0kRUOTzZm98iF3cCIAVuZ1pnWm0KArhbFOXikHTYolqbV2C+ooFvZhkQoAbqAUdSIQKVg785rgpgl0etGZrd1jT6YQhVnWxc05tMIYPxq5bgfyEC2rYf9JoU22p9ArDNH7t4/EsYMStbTlTa5Nui+/71NtdSrgABASAAwusLAAAAABepFLf1+vQOPUClpFmx2zU18rcvqSHohwEHIyIAIIwjUxc3Q7WV37Sge3K6jkLjeX2nTof+fZ10l+OyAokDAQjaBABHMEQCIGLrelVhB6fHP0WsSrWh3d9vcHX7EnWWmn84Pv/3hLyyAiAMBdu3Rw2/LwhVfdNWxzJcHtMJE+mWzThAlF2xIijaXwFHMEQCIGX0W6WZi1mif/4ae+0BavHx+Q1Us6qPdFCqX1aiUQO9AiB/ckcDrR7blmgLKEtW1P/LiPf7dZ6rvgiqMPKbhROD0gFHUiEDCJ3BDHrG21T5EymvYXMz2ziM6tDCMfcjN50bmQMLAtwhAjrdkE89bc9Z3bkGsN7iNSm3/7ntUOXoYVGSaGAiHw5zUq4AIgIDqaTDf1mW06ol26xrVwrwZQOUSSlCRgs1R1Ptnuylh3EQ2QxqTwAAAIAAAACABAAAgAAiAgJ/Y5l1fS7/VaE2rQLGhLGDi2VW5fG2s0KCqUtrUAUQlhDZDGpPAAAAgAAAAIAFAACAAA==";
|
||||
PSBT psbt = PSBT.fromString(strPsbt);
|
||||
Transaction transaction = psbt.extractTransaction();
|
||||
|
||||
Assert.assertEquals("0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7500000000da00473044022074018ad4180097b873323c0015720b3684cc8123891048e7dbcd9b55ad679c99022073d369b740e3eb53dcefa33823c8070514ca55a7dd9544f157c167913261118c01483045022100f61038b308dc1da865a34852746f015772934208c6d24454393cd99bdf2217770220056e675a675a6d0a02b85b14e5e29074d8a25a9b5760bea2816f661910a006ea01475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752aeffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d01000000232200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f000400473044022062eb7a556107a7c73f45ac4ab5a1dddf6f7075fb1275969a7f383efff784bcb202200c05dbb7470dbf2f08557dd356c7325c1ed30913e996cd3840945db12228da5f01473044022065f45ba5998b59a27ffe1a7bed016af1f1f90d54b3aa8f7450aa5f56a25103bd02207f724703ad1edb96680b284b56d4ffcb88f7fb759eabbe08aa30f29b851383d20147522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae00000000", Utils.bytesToHex(transaction.bitcoinSerialize()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue