@Test public void testPaymentPuzzle() { byte[] txOutScriptPuzzle= new byte[]{(byte)0xAA,(byte)0x20,(byte)0x6f,(byte)0xe2,(byte)0x8c,(byte)0x0a,(byte)0xb6,(byte)0xf1,(byte)0xb3,(byte)0x72,(byte)0xc1,(byte)0xa6,(byte)0xa2,(byte)0x46,(byte)0xae,(byte)0x63,(byte)0xf7,(byte)0x4f,(byte)0x93,(byte)0x1e,(byte)0x83,(byte)0x65,(byte)0xe1,(byte)0x5a,(byte)0x08,(byte)0x9c,(byte)0x68,(byte)0xd6,(byte)0x19,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x87}; String result = BitcoinScriptPatternParser.getPaymentDestination(txOutScriptPuzzle); String comparatorText = "puzzle_206FE28C0AB6F1B372C1A6A246AE63F74F931E8365E15A089C68D61900000000"; assertEquals( comparatorText, result,"Payment destination of script should be puzzle"); }
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);  }