From b1082ece1b19026dd9a1feb3cbf7fb5d24edf23a Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holgernahrstaedt@gmx.de>
Date: Tue, 22 Dec 2020 12:30:31 +0100
Subject: [PATCH] New release

* Fix bug in ecda (convert mpz into int when not supported)
---
 CHANGELOG.rst                |  6 ++++++
 beemgraphenebase/ecdsasig.py |  6 +++++-
 examples/blockactivity.py    | 35 +++++++++++++++++++++++++++--------
 3 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 0449525c..2e50b032 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,5 +1,11 @@
 Changelog
 ========
+0.24.21
+-------
+* Fix bug in ecda (convert mpz into int when not supported)
+* add coinactivity example script
+* PR #272: correct blockchain virtual op batch calls (thanks to @crokkon)
+
 0.24.20
 -------
 * New hive node has been added (https://hived.emre.sh)
diff --git a/beemgraphenebase/ecdsasig.py b/beemgraphenebase/ecdsasig.py
index d7deb97a..42bc7805 100644
--- a/beemgraphenebase/ecdsasig.py
+++ b/beemgraphenebase/ecdsasig.py
@@ -101,7 +101,11 @@ def recover_public_key(digest, signature, i, message=None):
             Q_point = Q.to_affine()
             public_key = ec.EllipticCurvePublicNumbers(Q_point.x(), Q_point.y(), ec.SECP256K1()).public_key(default_backend())
         except:
-            public_key = ec.EllipticCurvePublicNumbers(Q._Point__x, Q._Point__y, ec.SECP256K1()).public_key(default_backend())
+            try:
+                public_key = ec.EllipticCurvePublicNumbers(Q._Point__x, Q._Point__y, ec.SECP256K1()).public_key(default_backend())
+            except:
+                Q_point = Q.to_affine()
+                public_key = ec.EllipticCurvePublicNumbers(int(Q_point.x()), int(Q_point.y()), ec.SECP256K1()).public_key(default_backend())
         public_key.verify(sigder, message, ec.ECDSA(hashes.SHA256()))
         return public_key
     else:
diff --git a/examples/blockactivity.py b/examples/blockactivity.py
index ebff3af2..972a98f1 100644
--- a/examples/blockactivity.py
+++ b/examples/blockactivity.py
@@ -57,11 +57,13 @@ def main(args=None):
     print(blk_inst)
     block_count = 0
     total_ops = 0
+    total_virtual_ops = 0
     total_trx = 0
     blocksperday = 20 * 60 * 24
     
-    blockchain = Blockchain(blockchain_instance=blk_inst)
-    last_block_id = blockchain.get_current_block_num() - blocksperday
+    blockchain = Blockchain(blockchain_instance=blk_inst, )
+    current_block_num = blockchain.get_current_block_num()
+    last_block_id = current_block_num - blocksperday
 
     last_block = Block(last_block_id, blockchain_instance=blk_inst)
 
@@ -69,6 +71,12 @@ def main(args=None):
 
     start = timer()
     for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num):
+        if "block" in entry:
+            block_time = parse_time(entry["block"]["timestamp"])
+        else:
+            block_time = entry["timestamp"]
+        if block_time > stopTime:
+            break
         block_count += 1
         if "block" in entry:
             trxs = entry["block"]["transactions"]
@@ -78,20 +86,31 @@ def main(args=None):
             total_trx += 1
             for op in tx["operations"]:
                 total_ops += 1
-        if "block" in entry:
-            block_time = parse_time(entry["block"]["timestamp"])
-        else:
-            block_time = entry["timestamp"]
+
         ops_per_day = total_ops / block_count * blocksperday
         if block_count % (block_debug) == 0:
             print("%d blocks remaining... estimated ops per day: %.1f" % (blocksperday - block_count, ops_per_day))
-        if block_time > stopTime:
-            break
+
     duration = timer() - start
+    
+    stopTime = last_block.time() + timedelta(seconds=60 * 60 * 24)
+    start = timer()
+    for entry in blockchain.blocks(start=last_block_id, max_batch_size=max_batch_size, threading=threading, thread_num=thread_num, only_virtual_ops=True): 
+        block_time = entry["timestamp"]
+        if block_time > stopTime:
+            break        
+        for tx in entry["operations"]:
+            for op in tx["op"]:
+                total_virtual_ops += 1
+
+    duration = timer() - start    
+    
+    
     print("Received %.2f blocks/s." % (block_count / duration))
     print("Bocks: %d, duration %.3f s" % (block_count, duration))
     print("Operations per day: %d" % total_ops)
     print("Trx per day: %d" % total_trx)
+    print("Virtual Operations per day: %d" % total_virtual_ops)
 
 if __name__ == '__main__':
     sys.exit(main())
-- 
GitLab