JSON-RPC signrawtransaction returns false when using private keys I've been working with BitcoinLib testing various parameters on the signrawtransaction rpc call. 

It's been mostly successful, however there seems to be a persisting problem when using only private keys to sign a transaction. (second optional argument of signrawtransaction call). The server replies false and returns the failed hex. I have tested the same transaction on the qt console using the same keys, and it returns true. 

The wrapper employs a SignRawTransactionRequest class matching the four arguments of the rpc call.

public SignRawTransactionRequest(String rawTransactionHex)
    {
        RawTransactionHex = rawTransactionHex;
        Inputs = new List&lt;SignRawTransactionInput&gt;();
        PrivateKeys = new List&lt;String&gt;();
        SigHashType = SignRawTransaction.SigHashType.All;
    }


It allows for 'inputs' and 'privatekeys' to be null, following the signrawtransaction syntax, while assuming 'sighashtype=all' unless explicitly specified otherwise.

The implementation also includes a SignRawTransactionInput class corresponding to the first optional argument of the rpc call. ([{"txid":txid,"vout":n, "scriptPubKey":hex, "redeemScript":hex } ,...])

public class SignRawTransactionInput
{
    [JsonProperty(PropertyName = "txid", Order = 0)]
    public String TransactionId { get; set; }

    [JsonProperty(PropertyName = "vout", Order = 1)]
    public Int32 Output { get; set; }

    [JsonProperty(PropertyName = "scriptPubKey", Order = 2)]
    public String ScriptPubKey { get; set; }

    [JsonProperty(PropertyName = "redeemScript", Order = 3)]
    public String RedeemScript { get; set; }
}


The request if fed to the wrapper method RpcServer.SignRawTransaction and returns a SignRawTransactionResponse containing the result and the hex as returned by the server.

public class SignRawTransactionResponse
    {
        public String Hex { get; set; }
        public Boolean Complete { get; set; }
    }


So far, signings using just the hex (no other arguments), inputs, different sighashtypes and various combinations of those have been successful. The server replies TRUE and returns the hex of the signed transaction when called with plain hex




or when called with some arguments





However, it returns false when the second optional argument(list of private keys) is used. It has been tested with one, all, and various combinations of the available private keys of the wallet. 

 

I suspect it might be a JSON error and that the wrapper is not constructing that part of the JSON properly, however that usually leads to a parsing error and not the false reply I get here.

The same combinations return true when signrawtransaction is called from the console.



Any ideas on what might be wrong with the private keys argument?
This was not a case of BitcoinLib malfunctioning in any way. It was simply a case of using wrong privkeys to sign the unspent outputs.