I am playing around with Bitcoin-qt. I want to iterate all blocks and all their transactions.
So far I've been able to get a list of all tx's in the blocks I want to. Now I want to get information about the transaction: Amount, confirmations and so forth.
However, when I use the gettransaction
method of the Bitcoin-qt API, it seems I can only get transactions from my own wallet.
For instance, I cannot say, because I get the error "Invalid or non-wallet transaction id (code -5)
":
gettransaction 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098
However, when I have a TX of one of my own transactions, I get a correct response.
My code
public void AddBtcTransaction(string hash)
{
List<string> parameters = new List<string>();
parameters.Add(hash);
var data = RequestServer("gettransaction", parameters);
int i = 0;
}
public string RequestServer(string methodName, List<string> parameters)
{
string respVal = string.Empty;
var rawRequest = GetRawRequest();
JObject joe = new JObject();
joe.Add(new JProperty("jsonrpc", "1.0"));
joe.Add(new JProperty("id", "1"));
joe.Add(new JProperty("method", methodName));
JArray props = new JArray();
foreach (var parameter in parameters)
{
props.Add(parameter);
}
joe.Add(new JProperty("params", props));
// serialize json for the request
string s = JsonConvert.SerializeObject(joe);
byte[] byteArray = Encoding.UTF8.GetBytes(s);
rawRequest.ContentLength = byteArray.Length;
Stream dataStream = rawRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
StreamReader streamReader = null;
try
{
WebResponse webResponse = rawRequest.GetResponse();
streamReader = new StreamReader(webResponse.GetResponseStream(), true);
respVal = streamReader.ReadToEnd();
var data = JsonConvert.DeserializeObject(respVal).ToString();
return data;
}
catch (Exception exp)
{
}
finally
{
if (streamReader != null)
{
streamReader.Close();
}
}
return string.Empty;
}
private HttpWebRequest GetRawRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(ServerIp);
webRequest.Credentials = new NetworkCredential(UserName, Password);
/// important, otherwise the service can't desirialse your request properly
webRequest.ContentType = "application/json-rpc";
webRequest.Method = "POST";
return webRequest;
}
Any idea about how I would get information about transactions outside my wallet?