From f2c6d310aeb4d6b6ed92ea1ec2988d6fe58ff2d7 Mon Sep 17 00:00:00 2001 From: Chris Kleeschulte Date: Tue, 11 Aug 2015 12:31:54 -0400 Subject: [PATCH] GetProgress - uses the same routine as the log reporter in bitcoin - essentially divides the chainParams checkpoints by the current tip --- src/libbitcoind.cc | 13 +++++++++++++ src/libbitcoind.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index 6aaec133..f2e6befd 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -216,6 +216,18 @@ NAN_METHOD(VerifyScript) { static bool set_cooked(void); +/** + * GetProgress() + * bitcoind.getProgress() + * provides a float value >= indicating the progress of the blockchain sync + */ +NAN_METHOD(GetProgress) { + const CChainParams& chainParams = Params(); + float progress = 0; + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + NanReturnValue(progress); +}; + NAN_METHOD(StartTxMon) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); @@ -1670,6 +1682,7 @@ init(Handle target) { NODE_SET_METHOD(target, "sendTransaction", SendTransaction); NODE_SET_METHOD(target, "estimateFee", EstimateFee); NODE_SET_METHOD(target, "startTxMon", StartTxMon); + NODE_SET_METHOD(target, "getProgress", GetProgress); } diff --git a/src/libbitcoind.h b/src/libbitcoind.h index 307f5968..8bd4836d 100644 --- a/src/libbitcoind.h +++ b/src/libbitcoind.h @@ -31,3 +31,4 @@ NAN_METHOD(VerifyScript); NAN_METHOD(SendTransaction); NAN_METHOD(EstimateFee); NAN_METHOD(StartTxMon); +NAN_METHOD(GetProgress);