@Test public void testPaymentPubKeyGenesis() { byte[] txOutScriptGenesis= new byte[]{(byte)0x41,(byte)0x04,(byte)0x67,(byte)0x8A,(byte)0xFD,(byte)0xB0,(byte)0xFE,(byte)0x55,(byte)0x48,(byte)0x27,(byte)0x19,(byte)0x67,(byte)0xF1,(byte)0xA6,(byte)0x71,(byte)0x30,(byte)0xB7,(byte)0x10,(byte)0x5C,(byte)0xD6,(byte)0xA8,(byte)0x28,(byte)0xE0,(byte)0x39,(byte)0x09,(byte)0xA6,(byte)0x79,(byte)0x62,(byte)0xE0,(byte)0xEA,(byte)0x1F,(byte)0x61,(byte)0xDE,(byte)0xB6,(byte)0x49,(byte)0xF6,(byte)0xBC,(byte)0x3F,(byte)0x4C,(byte)0xEF,(byte)0x38,(byte)0xC4,(byte)0xF3,(byte)0x55,(byte)0x04,(byte)0xE5,(byte)0x1E,(byte)0xC1,(byte)0x12,(byte)0xDE,(byte)0x5C,(byte)0x38,(byte)0x4D,(byte)0xF7,(byte)0xBA,(byte)0x0B,(byte)0x8D,(byte)0x57,(byte)0x8A,(byte)0x4C,(byte)0x70,(byte)0x2B,(byte)0x6B,(byte)0xF1,(byte)0x1D,(byte)0x5F,(byte)0xAC}; String result = BitcoinScriptPatternParser.getPaymentDestination(txOutScriptGenesis); String comparatorText = "bitcoinpubkey_4104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5F"; assertEquals( comparatorText,result,"TxOutScript from Genesis should be payment to a pubkey address"); }
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);  }