diff --git a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java index 04fe11a..91e9f6b 100644 --- a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java +++ b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java @@ -60,7 +60,6 @@ public class PSBT { private final List psbtOutputs = new ArrayList<>(); private static final Logger log = LoggerFactory.getLogger(PSBT.class); - private boolean verifyPrevTxids = true; public PSBT(Transaction transaction) { this.transaction = transaction; @@ -203,12 +202,7 @@ public class PSBT { } public PSBT(byte[] psbt, boolean verifySignatures) throws PSBTParseException { - this(psbt, verifySignatures, true); - } - - public PSBT(byte[] psbt, boolean verifySignatures, boolean verifyPrevTxids) throws PSBTParseException { this.psbtBytes = psbt; - this.verifyPrevTxids = verifyPrevTxids; parse(verifySignatures); } @@ -998,10 +992,6 @@ public class PSBT { return maxHeightLocktime.orElse(maxTimeLocktime.orElse(fallback)); } - boolean isVerifyPrevTxids() { - return verifyPrevTxids; - } - public static boolean isPSBT(byte[] b) { try { ByteBuffer buffer = ByteBuffer.wrap(b); @@ -1033,10 +1023,6 @@ public class PSBT { } public static PSBT fromString(String strPSBT, boolean verifySignatures) throws PSBTParseException { - return fromString(strPSBT, verifySignatures, true); - } - - static PSBT fromString(String strPSBT, boolean verifySignatures, boolean verifyPrevTxids) throws PSBTParseException { if (!isPSBT(strPSBT)) { throw new PSBTParseException("Provided string is not a PSBT"); } @@ -1046,6 +1032,6 @@ public class PSBT { } byte[] psbtBytes = Utils.hexToBytes(strPSBT); - return new PSBT(psbtBytes, verifySignatures, verifyPrevTxids); + return new PSBT(psbtBytes, verifySignatures); } } diff --git a/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java b/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java index 716a960..d6dc72e 100644 --- a/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java +++ b/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java @@ -124,17 +124,14 @@ public class PSBTInput { entry.checkOneByteKey(); Transaction nonWitnessTx = new Transaction(entry.getData()); nonWitnessTx.verify(); - if(psbt.isVerifyPrevTxids()) { - Sha256Hash inputHash = nonWitnessTx.calculateTxId(false); - Sha256Hash outpointHash = getPrevTxid(); - if(outpointHash == null) { - throw new PSBTParseException("Outpoint hash not present for input " + index); - } - if(!outpointHash.equals(inputHash)) { - throw new PSBTParseException("Hash of provided non witness utxo transaction " + inputHash + " does not match transaction input outpoint hash " + outpointHash + " at index " + index); - } + Sha256Hash inputHash = nonWitnessTx.calculateTxId(false); + Sha256Hash outpointHash = getPrevTxid(); + if(outpointHash == null) { + throw new PSBTParseException("Outpoint hash not present for input " + index); + } + if(!outpointHash.equals(inputHash)) { + throw new PSBTParseException("Hash of provided non witness utxo transaction " + inputHash + " does not match transaction input outpoint hash " + outpointHash + " at index " + index); } - this.nonWitnessUtxo = nonWitnessTx; log.debug("Found input non witness utxo with txid: " + nonWitnessTx.getTxId() + " version " + nonWitnessTx.getVersion() + " size " + nonWitnessTx.getMessageSize() + " locktime " + nonWitnessTx.getLocktime()); for(TransactionInput input: nonWitnessTx.getInputs()) { @@ -282,7 +279,7 @@ public class PSBTInput { break; case PSBT_IN_PREVIOUS_TXID: entry.checkOneByteKey(); - this.prevTxid = Sha256Hash.wrap(entry.getData()); + this.prevTxid = Sha256Hash.wrap(Utils.reverseBytes(entry.getData())); log.debug("Found input previous txid " + Utils.bytesToHex(entry.getData())); break; case PSBT_IN_OUTPUT_INDEX: @@ -394,7 +391,7 @@ public class PSBTInput { if(psbtVersion >= 2) { if(prevTxid != null) { - entries.add(populateEntry(PSBT_IN_PREVIOUS_TXID, null, prevTxid.getBytes())); + entries.add(populateEntry(PSBT_IN_PREVIOUS_TXID, null, Utils.reverseBytes(prevTxid.getBytes()))); } if(prevIndex != null) { byte[] prevIndexBytes = new byte[4]; diff --git a/src/test/java/com/sparrowwallet/drongo/psbt/PSBTTest.java b/src/test/java/com/sparrowwallet/drongo/psbt/PSBTTest.java index 016c80e..75bc9bb 100644 --- a/src/test/java/com/sparrowwallet/drongo/psbt/PSBTTest.java +++ b/src/test/java/com/sparrowwallet/drongo/psbt/PSBTTest.java @@ -514,42 +514,42 @@ public class PSBTTest { @Test public void testPSBTv2MissingPrevTxid() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEPBAAAAAABEAT+////ACICAtYB+EhGpnVfd2vgDj2d6PsQrMk1+4PEX7AWLUytWreSGPadhz5UAACAAQAAgAAAAIAAAAAAKgAAAAEDCAAIry8AAAAAAQQWABTEMPZMR1baMQ29GghVcu8pmSYnLAAiAgLjb7/1PdU0Bwz4/TlmFGgPNXqbhdtzQL8c+nRdKtezQBj2nYc+VAAAgAEAAIAAAACAAQAAAGQAAAABAwiLvesLAAAAAAEEFgAUTdGTrJZKVqwbnhzKhFT+L0dPhRMA"; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); - Assertions.assertEquals("PSBT_IN_PREV_TXID is required in PSBTv2", e.getMessage()); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); + Assertions.assertEquals("Outpoint hash not present for input 0", e.getMessage()); } @Test public void testPSBTv2MissingOutputIndex() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IARAE/v///wAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); Assertions.assertEquals("PSBT_IN_OUTPUT_INDEX is required in PSBTv2", e.getMessage()); } @Test public void testPSBTv2MissingOutputAmount() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAEQBP7///8AIgIC1gH4SEamdV93a+AOPZ3o+xCsyTX7g8RfsBYtTK1at5IY9p2HPlQAAIABAACAAAAAgAAAAAAqAAAAAQQWABTEMPZMR1baMQ29GghVcu8pmSYnLAAiAgLjb7/1PdU0Bwz4/TlmFGgPNXqbhdtzQL8c+nRdKtezQBj2nYc+VAAAgAEAAIAAAACAAQAAAGQAAAABAwiLvesLAAAAAAEEFgAUTdGTrJZKVqwbnhzKhFT+L0dPhRMA"; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); Assertions.assertEquals("PSBT_OUT_AMOUNT is required in PSBTv2", e.getMessage()); } @Test public void testPSBTv2MissingOutputScript() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAEQBP7///8AIgIC1gH4SEamdV93a+AOPZ3o+xCsyTX7g8RfsBYtTK1at5IY9p2HPlQAAIABAACAAAAAgAAAAAAqAAAAAQMIAAivLwAAAAAAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); Assertions.assertEquals("PSBT_OUT_SCRIPT is required in PSBTv2", e.getMessage()); } @Test public void testPSBTv2SmallTimeLocktime() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIB+wQCAAAAAAEAUgIAAAABwaolbiFLlqGCL5PeQr/ztfP/jQUZMG41FddRWl6AWxIAAAAAAP////8BGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgAAAAABAR8Yxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAQ4gCwrZIUGcHIcZc11y3HOfnqngY40f5MHu8PmUQISBX8gBDwQAAAAAAREE/2TNHQAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); Assertions.assertEquals("Required time locktime is less than 500000000", e.getMessage()); } @Test public void testPSBTv2LargeHeightLocktime() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIB+wQCAAAAAAEAUgIAAAABwaolbiFLlqGCL5PeQr/ztfP/jQUZMG41FddRWl6AWxIAAAAAAP////8BGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgAAAAABAR8Yxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAQ4gCwrZIUGcHIcZc11y3HOfnqngY40f5MHu8PmUQISBX8gBDwQAAAAAARIEAGXNHQAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt, true, false)); + Exception e = Assertions.assertThrows(PSBTParseException.class, () -> PSBT.fromString(strPsbt)); Assertions.assertEquals("Required time locktime is greater than or equal to 500000000", e.getMessage()); } @@ -564,7 +564,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsUpdated() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIB+wQCAAAAAAEAUgIAAAABwaolbiFLlqGCL5PeQr/ztfP/jQUZMG41FddRWl6AWxIAAAAAAP////8BGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgAAAAABAR8Yxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAQ4gCwrZIUGcHIcZc11y3HOfnqngY40f5MHu8PmUQISBX8gBDwQAAAAAACICAtYB+EhGpnVfd2vgDj2d6PsQrMk1+4PEX7AWLUytWreSGPadhz5UAACAAQAAgAAAAIAAAAAAKgAAAAEDCAAIry8AAAAAAQQWABTEMPZMR1baMQ29GghVcu8pmSYnLAAiAgLjb7/1PdU0Bwz4/TlmFGgPNXqbhdtzQL8c+nRdKtezQBj2nYc+VAAAgAEAAIAAAACAAQAAAGQAAAABAwiLvesLAAAAAAEEFgAUTdGTrJZKVqwbnhzKhFT+L0dPhRMA"; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); } @@ -572,7 +572,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsSequence() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIB+wQCAAAAAAEAUgIAAAABwaolbiFLlqGCL5PeQr/ztfP/jQUZMG41FddRWl6AWxIAAAAAAP////8BGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgAAAAABAR8Yxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAQ4gCwrZIUGcHIcZc11y3HOfnqngY40f5MHu8PmUQISBX8gBDwQAAAAAARAE/v///wAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals(4294967294L, psbt.getPsbtInputs().get(0).getSequence()); @@ -581,7 +581,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsSequenceLocktimes() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAEQBP7///8BEQSMjcRiARIEECcAAAAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals(4294967294L, psbt.getPsbtInputs().get(0).getSequence()); @@ -592,7 +592,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsModifiableBit0() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIBBgEBAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals((byte)0x01, psbt.getModifiable()); @@ -601,7 +601,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsModifiableBit1() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIBBgECAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals((byte)0x02, psbt.getModifiable()); @@ -610,7 +610,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsModifiableAllBits() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIBBgEHAfsEAgAAAAABAFICAAAAAcGqJW4hS5ahgi+T3kK/87Xz/40FGTBuNRXXUVpegFsSAAAAAAD/////ARjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4AAAAAAQEfGMaaOwAAAAAWABSwo68UQghBJpPKfRZoUrUtsK7wbgEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAAiAgLWAfhIRqZ1X3dr4A49nej7EKzJNfuDxF+wFi1MrVq3khj2nYc+VAAAgAEAAIAAAACAAAAAACoAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAIgIC42+/9T3VNAcM+P05ZhRoDzV6m4Xbc0C/HPp0XSrXs0AY9p2HPlQAAIABAACAAAAAgAEAAABkAAAAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals((byte)0x07, psbt.getModifiable()); @@ -619,7 +619,7 @@ public class PSBTTest { @Test public void testPSBTv21Input2OutputsAllFields() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAQYBBwH7BAIAAAAAAQBSAgAAAAHBqiVuIUuWoYIvk95Cv/O18/+NBRkwbjUV11FaXoBbEgAAAAAA/////wEYxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAAAAAAEBHxjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4BDiALCtkhQZwchxlzXXLcc5+eqeBjjR/kwe7w+ZRAhIFfyAEPBAAAAAABEAT+////AREEjI3EYgESBBAnAAAAIgIC1gH4SEamdV93a+AOPZ3o+xCsyTX7g8RfsBYtTK1at5IY9p2HPlQAAIABAACAAAAAgAAAAAAqAAAAAQMIAAivLwAAAAABBBYAFMQw9kxHVtoxDb0aCFVy7ymZJicsACICAuNvv/U91TQHDPj9OWYUaA81epuF23NAvxz6dF0q17NAGPadhz5UAACAAQAAgAAAAIABAAAAZAAAAAEDCIu96wsAAAAAAQQWABRN0ZOslkpWrBueHMqEVP4vR0+FEwA="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1, psbt.getInputCount()); Assertions.assertEquals(2, psbt.getOutputCount()); Assertions.assertEquals((byte)0x07, psbt.getModifiable()); @@ -635,14 +635,14 @@ public class PSBTTest { @Test public void testPSBTv2NoLocktime() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQQBAQEFAQIB+wQCAAAAAAEOIAsK2SFBnByHGXNdctxzn56p4GONH+TB7vD5lECEgV/IAQ8EAAAAAAABAwgACK8vAAAAAAEEFgAUxDD2TEdW2jENvRoIVXLvKZkmJywAAQMIi73rCwAAAAABBBYAFE3Rk6yWSlasG54cyoRU/i9HT4UTAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(0, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv2ZeroFallbackLocktime() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAAAAQ4gOhs7PIN9ZInqejHY5sfdUDwAG+8+BpWOdXSAjWjKeKUBDwQAAAAAAAEDCE+TNXcAAAAAAQQWABQLE1LKzQPPaqG388jWOIZxs0peEQA="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(0, psbt.getFallbackLocktime()); Assertions.assertEquals(0, psbt.getTransaction().getLocktime()); } @@ -650,49 +650,49 @@ public class PSBTTest { @Test public void testPSBTv21InputLocktime() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEgQQJwAAAAEOIDobOzyDfWSJ6nox2ObH3VA8ABvvPgaVjnV0gI1oynilAQ8EAAAAAAABAwhPkzV3AAAAAAEEFgAUCxNSys0Dz2qht/PI1jiGcbNKXhEA"; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(10000, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeHeight() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEgQQJwAAAAEOIDobOzyDfWSJ6nox2ObH3VA8ABvvPgaVjnV0gI1oynilAQ8EAAAAAAESBCgjAAAAAQMIT5M1dwAAAAABBBYAFAsTUsrNA89qobfzyNY4hnGzSl4RAA=="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(10000, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeMixed() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEgQQJwAAAAEOIDobOzyDfWSJ6nox2ObH3VA8ABvvPgaVjnV0gI1oynilAQ8EAAAAAAERBIyNxGIBEgQoIwAAAAEDCE+TNXcAAAAAAQQWABQLE1LKzQPPaqG388jWOIZxs0peEQA="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(10000, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeMixed2() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEQSLjcRiARIEECcAAAABDiA6Gzs8g31kiep6Mdjmx91QPAAb7z4GlY51dICNaMp4pQEPBAAAAAABEQSMjcRiARIEKCMAAAABAwhPkzV3AAAAAAEEFgAUCxNSys0Dz2qht/PI1jiGcbNKXhEA"; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(10000, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeTimeMixed() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEQSLjcRiAAEOIDobOzyDfWSJ6nox2ObH3VA8ABvvPgaVjnV0gI1oynilAQ8EAAAAAAERBIyNxGIBEgQoIwAAAAEDCE+TNXcAAAAAAQQWABQLE1LKzQPPaqG388jWOIZxs0peEQA="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1657048460, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeTimeMixed2() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAABEQSLjcRiARIEECcAAAABDiA6Gzs8g31kiep6Mdjmx91QPAAb7z4GlY51dICNaMp4pQEPBAAAAAABEQSMjcRiAAEDCE+TNXcAAAAAAQQWABQLE1LKzQPPaqG388jWOIZxs0peEQA="; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1657048460, psbt.getTransaction().getLocktime()); } @Test public void testPSBTv22InputsLocktimeTimeMixed3() throws PSBTParseException { String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQIBBQEBAfsEAgAAAAABDiAPdY2/vU2nwWyKMwnDyB4RAPVh6mRttbAXUsSF4b3enwEPBAEAAAAAAQ4gOhs7PIN9ZInqejHY5sfdUDwAG+8+BpWOdXSAjWjKeKUBDwQAAAAAAREEjI3EYgABAwhPkzV3AAAAAAEEFgAUCxNSys0Dz2qht/PI1jiGcbNKXhEA"; - PSBT psbt = PSBT.fromString(strPsbt, true, false); + PSBT psbt = PSBT.fromString(strPsbt); Assertions.assertEquals(1657048460, psbt.getTransaction().getLocktime()); } @@ -711,10 +711,10 @@ public class PSBTTest { public void convertPSBTv2ToPSBTv0() throws PSBTParseException { Network.set(Network.TESTNET); String strPsbt = "cHNidP8BAgQCAAAAAQMEAAAAAAEEAQEBBQECAQYBBwH7BAIAAAAAAQBSAgAAAAHBqiVuIUuWoYIvk95Cv/O18/+NBRkwbjUV11FaXoBbEgAAAAAA/////wEYxpo7AAAAABYAFLCjrxRCCEEmk8p9FmhStS2wrvBuAAAAAAEBHxjGmjsAAAAAFgAUsKOvFEIIQSaTyn0WaFK1LbCu8G4BDiALCtkhQZwchxlzXXLcc5+eqeBjjR/kwe7w+ZRAhIFfyAEPBAAAAAABEAT+////AREEjI3EYgESBBAnAAAAIgIC1gH4SEamdV93a+AOPZ3o+xCsyTX7g8RfsBYtTK1at5IY9p2HPlQAAIABAACAAAAAgAAAAAAqAAAAAQMIAAivLwAAAAABBBYAFMQw9kxHVtoxDb0aCFVy7ymZJicsACICAuNvv/U91TQHDPj9OWYUaA81epuF23NAvxz6dF0q17NAGPadhz5UAACAAQAAgAAAAIABAAAAZAAAAAEDCIu96wsAAAAAAQQWABRN0ZOslkpWrBueHMqEVP4vR0+FEwA="; - PSBT origPsbtv2 = PSBT.fromString(strPsbt, true, false); - PSBT psbtv2 = PSBT.fromString(strPsbt, true, false); + PSBT origPsbtv2 = PSBT.fromString(strPsbt); + PSBT psbtv2 = PSBT.fromString(strPsbt); psbtv2.convertVersion(0); - PSBT psbtv0 = PSBT.fromString(psbtv2.toBase64String(), true, false); + PSBT psbtv0 = PSBT.fromString(psbtv2.toBase64String()); Assertions.assertEquals(origPsbtv2.getTransaction().getTxId(), psbtv0.getTransaction().getTxId()); }