예제 #1
0
        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;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public JsonRpcResponse <string> Ping()
 {
     return(_rpcConnector.MakeRequest <string>(KodiMethods.Ping, new object(), timeout: 2000));
 }