From 76077630aa7cec20176d7199a123a0d7e30cdf5a Mon Sep 17 00:00:00 2001 From: Sai Raj <39055732+sairajzero@users.noreply.github.com> Date: Sun, 6 Jun 2021 03:04:46 +0530 Subject: [PATCH] Replace getwork call with getblocktemplate --- lib/bitcoin_rpc.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/bitcoin_rpc.py b/lib/bitcoin_rpc.py index 58035b6..1351856 100644 --- a/lib/bitcoin_rpc.py +++ b/lib/bitcoin_rpc.py @@ -141,12 +141,16 @@ class BitcoinRPC(object): @defer.inlineCallbacks def prevhash(self): - resp = (yield self._call('getwork', [])) try: - defer.returnValue(json.loads(resp)['result']['data'][8:72]) + resp = (yield self._call('getblocktemplate', [{}])) + defer.returnValue(json.loads(resp)['result']['previousblockhash']) except Exception as e: - log.exception("Cannot decode prevhash %s" % str(e)) - raise + if (str(e) == "500 Internal Server Error"): + resp = (yield self._call('getblocktemplate', [])) + defer.returnValue(json.loads(resp)['result']['previousblockhash']) + else: + log.exception("Cannot decode prevhash %s" % str(e)) + raise @defer.inlineCallbacks def validateaddress(self, address):