@ Nullable public RedeemData getConnectedRedeemData ( KeyBag keyBag ) throws ScriptException { TransactionOutput connectedOutput = getConnectedOutput ( ) ; checkNotNull ( connectedOutput , "Input is not connected so cannot retrieve key" ) ; Script connectedScript = connectedOutput . getScriptPubKey ( ) ; if ( ScriptPattern . isP2PKH ( connectedScript ) ) { byte [ ] addressBytes = ScriptPattern . extractHashFromP2PKH ( connectedScript ) ; return RedeemData . of ( keyBag . findKeyFromPubKeyHash ( addressBytes , Script . ScriptType . P2PKH ) , connectedScript ) ; } else if ( ScriptPattern . isP2WPKH ( connectedScript ) ) { byte [ ] addressBytes = ScriptPattern . extractHashFromP2WH ( connectedScript ) ; return RedeemData . of ( keyBag . findKeyFromPubKeyHash ( addressBytes , Script . ScriptType . P2WPKH ) , connectedScript ) ; } else if ( ScriptPattern . isP2PK ( connectedScript ) ) { byte [ ] pubkeyBytes = ScriptPattern . extractKeyFromP2PK ( connectedScript ) ; return RedeemData . of ( keyBag . findKeyFromPubKey ( pubkeyBytes ) , connectedScript ) ; } else if ( ScriptPattern . isP2SH ( connectedScript ) ) { byte [ ] scriptHash = ScriptPattern . extractHashFromP2SH ( connectedScript ) ; return keyBag . findRedeemDataFromScriptHash ( scriptHash ) ; } else { throw new ScriptException ( ScriptError . SCRIPT_ERR_UNKNOWN_ERROR , "Could not understand form of connected output script: " + connectedScript ) ; } }
Returns the RedeemData identified in the connected output for either P2PKH P2WPKH P2PK or P2SH scripts . If the script forms cannot be understood throws ScriptException .