Search in sources :

Example 1 with SigningException

use of bisq.core.btc.exceptions.SigningException in project bisq-core by bisq-network.

the class TradeWalletService method signInput.

private void signInput(Transaction transaction, TransactionInput input, int inputIndex) throws SigningException {
    checkNotNull(input.getConnectedOutput(), "input.getConnectedOutput() must not be null");
    Script scriptPubKey = input.getConnectedOutput().getScriptPubKey();
    checkNotNull(wallet);
    ECKey sigKey = input.getOutpoint().getConnectedKey(wallet);
    checkNotNull(sigKey, "signInput: sigKey must not be null. input.getOutpoint()=" + input.getOutpoint().toString());
    if (sigKey.isEncrypted())
        checkNotNull(aesKey);
    Sha256Hash hash = transaction.hashForSignature(inputIndex, scriptPubKey, Transaction.SigHash.ALL, false);
    ECKey.ECDSASignature signature = sigKey.sign(hash, aesKey);
    TransactionSignature txSig = new TransactionSignature(signature, Transaction.SigHash.ALL, false);
    if (scriptPubKey.isSentToRawPubKey()) {
        input.setScriptSig(ScriptBuilder.createInputScript(txSig));
    } else if (scriptPubKey.isSentToAddress()) {
        input.setScriptSig(ScriptBuilder.createInputScript(txSig, sigKey));
    } else {
        throw new SigningException("Don't know how to sign for this kind of scriptPubKey: " + scriptPubKey);
    }
}
Also used : Script(org.bitcoinj.script.Script) Sha256Hash(org.bitcoinj.core.Sha256Hash) SigningException(bisq.core.btc.exceptions.SigningException) ECKey(org.bitcoinj.core.ECKey) TransactionSignature(org.bitcoinj.crypto.TransactionSignature)

Aggregations

SigningException (bisq.core.btc.exceptions.SigningException)1 ECKey (org.bitcoinj.core.ECKey)1 Sha256Hash (org.bitcoinj.core.Sha256Hash)1 TransactionSignature (org.bitcoinj.crypto.TransactionSignature)1 Script (org.bitcoinj.script.Script)1