class ChainSyncGetTransactionTestCase(ChainSyncBaseTestCase): def setUp(self): adapter = SteemAdapter(endpoints='https://steemd.pevo.science', retry=False) self.chainsync = ChainSync(adapter=adapter, retry=False) def test_get_transaction(self): tx_id = 'c68435a34a7afc701771eb090f96526ed4c2a37b' result = self.chainsync.get_transaction(tx_id) self.assertEqual(result['block_num'], 20905025) def test_get_transaction_exception_no_transaction_id(self): with self.assertRaises(TypeError) as context: self.chainsync.get_transaction() def test_get_transaction_exception_invalid_transaction_id(self): with self.assertRaises(Exception) as context: self.chainsync.get_transaction( '0000000000000000000000000000000000000000')
def test_txopdata_format(self): # Specify custom node since api.steemit.com doesn't have these endpoints enabled adapter = SteemAdapter(endpoints='https://steemd.pevo.science', retry=False) chainsync = ChainSync(adapter=adapter, retry=False) # Load a transaction by ID transaction = chainsync.get_transaction( '04008551461adb9a48c5c9eac8be6f63f9c840d9') for opIndex, op in enumerate(transaction['operations']): formatted = adapter.format_op_from_get_transaction(transaction, op, opIndex=opIndex) self.assertEqual(formatted['block_num'], 4042653) self.assertTrue(formatted['op_in_trx'] >= 0) self.assertTrue(formatted['trx_in_block'] >= 0) self.assertTrue('operation_type' in formatted and formatted['operation_type'] is not False) self.assertTrue('transaction_id' in formatted and formatted['transaction_id'] is not False)
if dataType == "op": print("[{}]: {} [{}] - {}".format(datetime.datetime.now(), dataType, data['transaction_id'], data['operation_type'])) if dataType == "ops_per_block": for height in data: print("[{}]: {} - #{} had {} ops".format(datetime.datetime.now(), dataType, height, data[height])) if dataType == 'tx': print("[{}]: {} [{}] - {} ops".format(datetime.datetime.now(), dataType, data['transaction_id'], len(data['operations']))) if dataType == 'status': print("[{}]: {} - {} h:{} / i:{}".format(datetime.datetime.now(), dataType, data['time'], data['last_irreversible_block_num'], data['head_block_number'])) print('\nGetting block 1') block = chainsync.get_block(1) print_event('block', block) print('\nGetting transaction c68435a34a7afc701771eb090f96526ed4c2a37b') tx = chainsync.get_transaction('c68435a34a7afc701771eb090f96526ed4c2a37b') print_event('tx', tx) print('\nGetting multiple transactions') transactions = [ '62f68c45f67ecbe4ac6eb8348bce44e73e46611c', '2f58f00e70b8d0f88e90350043e17ed6ea2eb223', 'c68435a34a7afc701771eb090f96526ed4c2a37b', ] for tx in chainsync.get_transactions(transactions): print_event('tx', tx) print('\nGetting ops in transaction c68435a34a7afc701771eb090f96526ed4c2a37b') for op in chainsync.get_ops_in_transaction('c68435a34a7afc701771eb090f96526ed4c2a37b'): print_event('op', op)