@Test public void testPaymentNull() { String result = BitcoinScriptPatternParser.getPaymentDestination(null); assertNull( result,"Null as script returns null"); }
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);  }