def run(self, port, height_window_index): HEIGHT_WINDOW_SIZE = 100000 start_height = height_window_index * HEIGHT_WINDOW_SIZE end_height = start_height + HEIGHT_WINDOW_SIZE daemon = Daemon(port=port) res_info = daemon.get_info() if res_info['height'] < end_height: end_height = res_info['height'] assert start_height < end_height print('var chartData_%d = [' % height_window_index) for i in range(start_height, end_height): while True: try: res_blk = daemon.getblock(i) break except requests.exceptions.RequestException as e: continue block_header = res_blk['block_header'] timestamp = block_header['timestamp'] nonce = block_header['nonce'] difficulty = block_header['difficulty'] reward = block_header['reward'] block_size = block_header['block_size'] num_txes = block_header['num_txes'] blob_size = len(res_blk['blob']) / 2 # print(res_blk) # print('====================================================') res_txs = daemon.gettransactions( res_blk['tx_hashes']) if num_txes > 0 else None txs_str = '' for j in range(num_txes): tx_json = res_txs['txs'][j]['as_json'] tx = json.loads(tx_json) unlock_time = tx['unlock_time'] ins = len(tx['vin']) outs = len(tx['vout']) ring_size = len(tx['vin'][0]['key']['key_offsets']) ins_total = 0 for k in range(ins): ins_total += tx['vin'][k]['key']['amount'] outs_total = 0 for k in range(outs): outs_total += tx['vout'][k]['amount'] fee = tx['rct_signatures']['txnFee'] if ( tx['version'] & 0xff) > 1 else ins_total - outs_total extra_size = len(tx['extra']) tx_size = len(res_txs['txs'][j]['as_hex']) / 2 if j > 0: txs_str += ',' txs_str += "[%d,%d,%d,%d,%d,%d,%d,%d]" % ( unlock_time, ins, outs, ring_size, fee, extra_size, ins_total, tx_size) print('[%d,%d,%d,%d,%d,%d,[%s]],' % (timestamp, nonce, difficulty, reward, block_size, blob_size, txs_str)) print(']')
def _test_get_info(self): print('Test get_info') daemon = Daemon() res = daemon.get_info() # difficulty should be set to 1 for this test assert 'difficulty' in res.keys() assert res['difficulty'] == 1 # nettype should not be TESTNET assert 'testnet' in res.keys() assert res['testnet'] == False # nettype should not be STAGENET assert 'stagenet' in res.keys() assert res['stagenet'] == False # nettype should be FAKECHAIN assert 'nettype' in res.keys() assert res['nettype'] == "fakechain" # free_space should be > 0 assert 'free_space' in res.keys() assert res['free_space'] > 0 # height should be greater or equal to 1 assert 'height' in res.keys() assert res['height'] >= 1
def _test_get_info(self): print('Test get_info') daemon = Daemon() res = daemon.get_info() # difficulty should be set to 1 for this test assert 'difficulty' in res.keys() assert res['difficulty'] == 1; # nettype should not be TESTNET assert 'testnet' in res.keys() assert res['testnet'] == False; # nettype should not be STAGENET assert 'stagenet' in res.keys() assert res['stagenet'] == False; # nettype should be FAKECHAIN assert 'nettype' in res.keys() assert res['nettype'] == "fakechain"; # free_space should be > 0 assert 'free_space' in res.keys() assert res['free_space'] > 0 # height should be greater or equal to 1 assert 'height' in res.keys() assert res['height'] >= 1
def _test_generateblocks(self, blocks): print("Test generating", blocks, 'blocks') daemon = Daemon() res = daemon.get_info() height = res['height'] res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', blocks) assert res['height'] == height + blocks - 1
def _test_generateblocks(self, blocks): print("Test generating", blocks, 'blocks') daemon = Daemon() res = daemon.get_info() height = res['height'] res = daemon.generateblocks(mainnet_address, blocks) assert res['height'] == height + blocks - 1
def _test_generateblocks(self, blocks): print("Test generating", blocks, 'blocks') daemon = Daemon() res = daemon.get_info() height = res['height'] res = daemon.generateblocks( 'WmsAX8KpL3NADH2pu4VKVE2mi7f4WS53W8ywgQWPWGcieuyAoNPa3F1JpT9772RTBBAo9vLfYKTzbVA5GR48bBf1263W9Tijy', blocks) assert res['height'] == height + blocks - 1