@Test public void testPaymentSegwitP2WSHSynthetic() { byte[] txOutScriptP2Hash= new byte[]{(byte)0x00,(byte)0x20,(byte)0x00,(byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08,(byte)0x09,(byte)0x0A,(byte)0x0B,(byte)0x0C,(byte)0x0D,(byte)0x0E,(byte)0x0F,(byte)0x10,(byte)0x11,(byte)0x12,(byte)0x13,(byte)0x14,(byte)0x15,(byte)0x16,(byte)0x17,(byte)0x18,(byte)0x19,(byte)0x1A,(byte)0x1B,(byte)0x1C,(byte)0x1D,(byte)0x1E,(byte)0x1F}; String result = BitcoinScriptPatternParser.getPaymentDestination(txOutScriptP2Hash); String comparatorText = "P2WSH_000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"; assertEquals( comparatorText, result,"Payment destination of script should be P2WSH"); }
public static String getPaymentDestination(byte[] scriptPubKey) { if (scriptPubKey==null) { return null; } if (scriptPubKey.length==0) { return "anyone"; } String payToHashSegwit = checkP2WPKHP2SH(scriptPubKey); if (payToHashSegwit!=null) { return payToHashSegwit; } String payToP2WSHSegwit = checkP2WSH(scriptPubKey); if (payToP2WSHSegwit!=null) { return payToP2WSHSegwit; } String payToPubKeySegwit = checkP2WPKH(scriptPubKey); if (payToPubKeySegwit!=null) { return payToPubKeySegwit; } String payToHash = checkPayToHash(scriptPubKey); if (payToHash!=null) { return payToHash; } String payToPubKey = checkPayToPubKey(scriptPubKey); if (payToPubKey!=null) { return payToPubKey; } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0xAA) && ((scriptPubKey[scriptPubKey.length-1] & 0xFF)==0x87)) { byte[] puzzle = Arrays.copyOfRange(scriptPubKey, 1, scriptPubKey.length-2); return "puzzle_"+BitcoinUtil.convertByteArrayToHexString(puzzle); } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0x6a)) { return "unspendable"; } return null; }
BitcoinScriptPatternParser { public static String getPaymentDestination(byte[] scriptPubKey) { if (scriptPubKey==null) { return null; } if (scriptPubKey.length==0) { return "anyone"; } String payToHashSegwit = checkP2WPKHP2SH(scriptPubKey); if (payToHashSegwit!=null) { return payToHashSegwit; } String payToP2WSHSegwit = checkP2WSH(scriptPubKey); if (payToP2WSHSegwit!=null) { return payToP2WSHSegwit; } String payToPubKeySegwit = checkP2WPKH(scriptPubKey); if (payToPubKeySegwit!=null) { return payToPubKeySegwit; } String payToHash = checkPayToHash(scriptPubKey); if (payToHash!=null) { return payToHash; } String payToPubKey = checkPayToPubKey(scriptPubKey); if (payToPubKey!=null) { return payToPubKey; } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0xAA) && ((scriptPubKey[scriptPubKey.length-1] & 0xFF)==0x87)) { byte[] puzzle = Arrays.copyOfRange(scriptPubKey, 1, scriptPubKey.length-2); return "puzzle_"+BitcoinUtil.convertByteArrayToHexString(puzzle); } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0x6a)) { return "unspendable"; } return null; } }
BitcoinScriptPatternParser { public static String getPaymentDestination(byte[] scriptPubKey) { if (scriptPubKey==null) { return null; } if (scriptPubKey.length==0) { return "anyone"; } String payToHashSegwit = checkP2WPKHP2SH(scriptPubKey); if (payToHashSegwit!=null) { return payToHashSegwit; } String payToP2WSHSegwit = checkP2WSH(scriptPubKey); if (payToP2WSHSegwit!=null) { return payToP2WSHSegwit; } String payToPubKeySegwit = checkP2WPKH(scriptPubKey); if (payToPubKeySegwit!=null) { return payToPubKeySegwit; } String payToHash = checkPayToHash(scriptPubKey); if (payToHash!=null) { return payToHash; } String payToPubKey = checkPayToPubKey(scriptPubKey); if (payToPubKey!=null) { return payToPubKey; } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0xAA) && ((scriptPubKey[scriptPubKey.length-1] & 0xFF)==0x87)) { byte[] puzzle = Arrays.copyOfRange(scriptPubKey, 1, scriptPubKey.length-2); return "puzzle_"+BitcoinUtil.convertByteArrayToHexString(puzzle); } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0x6a)) { return "unspendable"; } return null; } private  BitcoinScriptPatternParser(); }
BitcoinScriptPatternParser { public static String getPaymentDestination(byte[] scriptPubKey) { if (scriptPubKey==null) { return null; } if (scriptPubKey.length==0) { return "anyone"; } String payToHashSegwit = checkP2WPKHP2SH(scriptPubKey); if (payToHashSegwit!=null) { return payToHashSegwit; } String payToP2WSHSegwit = checkP2WSH(scriptPubKey); if (payToP2WSHSegwit!=null) { return payToP2WSHSegwit; } String payToPubKeySegwit = checkP2WPKH(scriptPubKey); if (payToPubKeySegwit!=null) { return payToPubKeySegwit; } String payToHash = checkPayToHash(scriptPubKey); if (payToHash!=null) { return payToHash; } String payToPubKey = checkPayToPubKey(scriptPubKey); if (payToPubKey!=null) { return payToPubKey; } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0xAA) && ((scriptPubKey[scriptPubKey.length-1] & 0xFF)==0x87)) { byte[] puzzle = Arrays.copyOfRange(scriptPubKey, 1, scriptPubKey.length-2); return "puzzle_"+BitcoinUtil.convertByteArrayToHexString(puzzle); } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0x6a)) { return "unspendable"; } return null; } private  BitcoinScriptPatternParser(); static String getPaymentDestination(byte[] scriptPubKey); }
BitcoinScriptPatternParser { public static String getPaymentDestination(byte[] scriptPubKey) { if (scriptPubKey==null) { return null; } if (scriptPubKey.length==0) { return "anyone"; } String payToHashSegwit = checkP2WPKHP2SH(scriptPubKey); if (payToHashSegwit!=null) { return payToHashSegwit; } String payToP2WSHSegwit = checkP2WSH(scriptPubKey); if (payToP2WSHSegwit!=null) { return payToP2WSHSegwit; } String payToPubKeySegwit = checkP2WPKH(scriptPubKey); if (payToPubKeySegwit!=null) { return payToPubKeySegwit; } String payToHash = checkPayToHash(scriptPubKey); if (payToHash!=null) { return payToHash; } String payToPubKey = checkPayToPubKey(scriptPubKey); if (payToPubKey!=null) { return payToPubKey; } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0xAA) && ((scriptPubKey[scriptPubKey.length-1] & 0xFF)==0x87)) { byte[] puzzle = Arrays.copyOfRange(scriptPubKey, 1, scriptPubKey.length-2); return "puzzle_"+BitcoinUtil.convertByteArrayToHexString(puzzle); } if ((scriptPubKey.length>0) && ((scriptPubKey[0] & 0xFF)==0x6a)) { return "unspendable"; } return null; } private  BitcoinScriptPatternParser(); static String getPaymentDestination(byte[] scriptPubKey);  }