Skip to content
Snippets Groups Projects
Commit 29dab265 authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Add support for new operation structure

Set use_condenser to True
Add unit test for hash_op
parent ae465d54
No related branches found
No related tags found
No related merge requests found
......@@ -149,7 +149,13 @@ class Block(BlockchainObject):
trxs = self["transactions"]
for tx in trxs:
for op in tx["operations"]:
ops_stat[op[0]] += 1
if isinstance(op, dict) and 'type' in op:
op_type = op["type"]
if len(op_type) > 10 and op_type[len(op_type)-10:] == "_operation":
op_type = op_type[:-10]
ops_stat[op_type] += 1
else:
ops_stat[op[0]] += 1
return ops_stat
......
......@@ -459,6 +459,15 @@ class Blockchain(object):
block_num = block.get("id")
_id = self.hash_op(event)
timestamp = formatTimeString(block.get("timestamp"))
elif isinstance(event, dict) and "type" in event and "value" in event:
op_type = event["type"]
if len(op_type) > 10 and op_type[len(op_type)-10:] == "_operation":
op_type = op_type[:-10]
op = event["value"]
trx_id = event.get("trx_id")
block_num = event.get("block")
_id = self.hash_op(event)
timestamp = formatTimeString(event.get("timestamp"))
else:
op_type, op = event["op"]
trx_id = event.get("trx_id")
......@@ -510,6 +519,12 @@ class Blockchain(object):
@staticmethod
def hash_op(event):
""" This method generates a hash of blockchain operation. """
if isinstance(event, dict) and "type" in event and "value" in event:
op_type = event["type"]
if len(op_type) > 10 and op_type[len(op_type)-10:] == "_operation":
op_type = op_type[:-10]
op = event["value"]
event = [op_type, op]
data = json.dumps(event, sort_keys=True)
return hashlib.sha1(py23_bytes(data, 'utf-8')).hexdigest()
......
......@@ -267,8 +267,9 @@ def get_node_list(appbase=False, testing=False):
node_list = ["https://api.steemitdev.com", "https://api.steemitstage.com"] + node_list
return node_list
else:
return ["wss://steemd.privex.io", "wss://steemd.pevo.science", "wss://rpc.buildteam.io", "wss://rpc.steemliberator.com", "wss://gtg.steem.house:8090",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://steemd.steemgigs.org", "wss://steemd.minnowsupportproject.org", "https://rpc.buildteam.io",
return ["wss://steemd.privex.io", "wss://rpc.buildteam.io", "https://steemd.privex.io", "https://rpc.buildteam.io", "wss://steemd.pevo.science",
"wss://rpc.steemliberator.com", "wss://gtg.steem.house:8090",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://steemd.steemgigs.org", "wss://steemd.minnowsupportproject.org",
"https://steemd.minnowsupportproject.org", "https://steemd.pevo.science", "https://rpc.steemviz.com", "https://seed.bitcoiner.me",
"https://rpc.steemliberator.com", "https://steemd.privex.io", "https://gtg.steem.house:8090",
"https://rpc.steemliberator.com", "https://gtg.steem.house:8090",
"https://rpc.curiesteem.com", "https://steemd.steemgigs.org"]
......@@ -24,6 +24,8 @@ class SteemNodeRPC(GrapheneRPC):
:param int num_retries: Try x times to num_retries to a node on disconnect, -1 for indefinitely
:param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5)
:param int timeout: Timeout setting for https nodes (default is 60)
:param bool use_condenser: Use the old condenser_api rpc protocol on nodes with version
0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower.
"""
......
......@@ -92,6 +92,8 @@ class GrapheneRPC(object):
:param int num_retries_call: Repeat num_retries_call times a rpc call on node error (default is 5)
:param int timeout: Timeout setting for https nodes (default is 60)
:param bool autoconnect: When set to false, connection is performed on the first rpc call (default is True)
:param bool use_condenser: Use the old condenser_api rpc protocol on nodes with version
0.19.4 or higher. The settings has no effect on nodes with version of 0.19.3 or lower.
Available APIs:
......@@ -146,7 +148,7 @@ class GrapheneRPC(object):
self.rpc_queue = []
self.timeout = kwargs.get('timeout', 60)
self.num_retries = kwargs.get("num_retries", -1)
self.use_condenser = kwargs.get("use_condenser", False)
self.use_condenser = kwargs.get("use_condenser", True)
self.error_cnt = {}
self.num_retries_call = kwargs.get("num_retries_call", 5)
self.error_cnt_call = 0
......
......@@ -13,7 +13,7 @@ from beem.instance import set_shared_steem_instance
from beem.utils import get_node_list
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
nodes_appbase = ["https://api.steem.house", "https://api.steemit.com"]
nodes_appbase = [ "https://api.steemitstage.com", "https://api.steem.house", "https://api.steemit.com"]
class Testcases(unittest.TestCase):
......
......@@ -16,7 +16,7 @@ from beem.instance import set_shared_steem_instance
from beem.utils import get_node_list
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
nodes_appbase = ["https://api.steem.house", "https://api.steemit.com"]
nodes_appbase = ["https://api.steemitstage.com", "https://api.steem.house", "https://api.steemit.com"]
class Testcases(unittest.TestCase):
......@@ -233,3 +233,12 @@ class Testcases(unittest.TestCase):
last_fetched_block_num = block.block_num
blocknum = last_fetched_block_num + 2
self.assertEqual(last_fetched_block_num, start_num + 4)
def test_hash_op(self):
bts = self.bts
b = Blockchain(steem_instance=bts)
op1 = {'type': 'vote_operation', 'value': {'voter': 'ubg', 'author': 'yesslife', 'permlink': 'steemit-sandwich-contest-week-25-2da-entry', 'weight': 100}}
op2 = ['vote', {'voter': 'ubg', 'author': 'yesslife', 'permlink': 'steemit-sandwich-contest-week-25-2da-entry', 'weight': 100}]
hash1 = b.hash_op(op1)
hash2 = b.hash_op(op2)
self.assertEqual(hash1, hash2)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment