public long GetLatestBlock() { int sleep = 1; for (int retry = 0;; retry++) { try { return(_conn.MakeRequest <long>(RpcMethods.getblockcount)); } catch { if (retry == 5) { throw; } } Log.Warn($"Exception caught. Sleeping for {sleep} seconds and retrying..."); Thread.Sleep(sleep * 1000); sleep *= 2; } }
static void Main(string[] args) { var btc = new BitcoinService("http://gethfull:8332", "coinfabrik", "0oOI078hIwho6nyWyeUJBz6YvKFmlm8t", "", 10); var conn = new RpcConnector(btc); long last = -1; while (true) { var latestBlock = conn.MakeRequest <long>(RpcMethods.getblockcount); if (latestBlock == last) { Thread.Sleep(1000); continue; } var latestBlockHash = conn.MakeRequest <string>(RpcMethods.getblockhash, new object[] { latestBlock }); var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Console.WriteLine($"{now} - New block: {latestBlockHash}"); last = latestBlock; } //var block = conn.MakeRequest<string>(RpcMethods.getblock, new object[]{ latestBlockHash, 0 }); //Console.WriteLine(block); }
public JsonRpcResponse <string> Ping() { return(_rpcConnector.MakeRequest <string>(KodiMethods.Ping, new object(), timeout: 2000)); }