Beispiel #1
0
class ChainSyncGetTransactionsTestCase(ChainSyncBaseTestCase):
    def setUp(self):
        adapter = SteemAdapter(endpoints='https://steemd.pevo.science',
                               retry=False)
        self.chainsync = ChainSync(adapter=adapter, retry=False)

    def test_get_transactions(self):
        txs = [
            'a3815d4a17f1331481ec6bf89ba0844ce16175bc',
            'c68435a34a7afc701771eb090f96526ed4c2a37b',
        ]
        result = self.chainsync.get_transactions(txs)
        for tx in result:
            self.assertTrue(tx['transaction_id'] in txs)

    def test_get_transactions_exception_no_transaction_id(self):
        with self.assertRaises(TypeError) as context:
            self.chainsync.get_transactions()

    def test_get_transactions_exception_invalid_transaction_id(self):
        with self.assertRaises(Exception) as context:
            txs = [
                'a3815d4a17f1331481ec6bf89ba0844ce16175bc',
                '0000000000000000000000000000000000000000',
            ]
            result = self.chainsync.get_transactions(txs)
            for tx in result:
                self.assertTrue(tx['transaction_id'] in txs)
Beispiel #2
0
 def test_yield_event_plugin(self):
     # configure with adapter + plugin
     chainsync = ChainSync(adapter=SteemAdapter(),
                           plugins=[SamplePlugin1()])
     # sample 'what' and 'data' for the event
     what = 'block'
     data = {'timestamp': '2018-02-19T23:54:09'}
     # yield the data in an event
     tupled = chainsync.yield_event(what, data)
     eventType, eventData = tupled
     # they should still match
     self.assertEqual(eventType, what)
     self.assertEqual(eventData, data)
     # ensure a datetime is returned
     self.assertIsInstance(eventData['timestamp'], datetime)
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)
Beispiel #5
0
 def setUp(self):
     adapter = SteemAdapter(
         endpoints='https://rpc.buildteam.io',
         retry=False
     )
     self.chainsync = ChainSync(adapter=adapter, retry=False)
Beispiel #6
0
 def setUp(self):
     self.chainsync = ChainSync(adapter=self.adapter, retry=False)
Beispiel #7
0
import datetime

from chainsync import ChainSync
from chainsync.adapters.steem import SteemAdapter

adapter = SteemAdapter(endpoints=['https://direct.steemd.privex.io'], debug=False)
chainsync = ChainSync(adapter)

def print_event(dataType, data):
    if dataType == "block":
        print("[{}]: {} [{}] - #{}, previous: {}".format(datetime.datetime.now(), dataType, data['block_id'], data['block_num'], data['previous']))
    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 = [
Beispiel #8
0
import os
import signal
import time
import datetime

from chainsync import ChainSync
from chainsync.adapters.steem import SteemAdapter

from chainmodel import ChainModel
from chainmodel.models.steem.schema import Schema

from pymongo import MongoClient

# Setup ChainSync + Steem adapter
adapter = SteemAdapter(endpoints=['https://api.steemit.com/'])
chainsync = ChainSync(adapter)

# establish models with schema
chainmodel = ChainModel(schema=Schema())


class Example():
    def __init__(self):
        # Handling KeyboardInterrupt so the pool doesn't override
        # https://stackoverflow.com/questions/11312525/catch-ctrlc-sigint-and-exit-multiprocesses-gracefully-in-python
        original_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)

        self.requests = multiprocessing.Queue()
        self.responses = multiprocessing.Queue()

        self.requests_pool = multiprocessing.Pool(None, self.worker,
 def test_main_debug_flag_set_true_from_main_false_for_adapter(self):
     adapter = SteemAdapter(debug=False)
     # main debug flag should override adapter
     custom = ChainSync(adapter, debug=True)
     self.assertEqual(custom.debug, True)
     self.assertEqual(custom.adapter.debug, True)
 def test_main_debug_flag_set_false_from_adapter(self):
     adapter = SteemAdapter(debug=True)
     custom = ChainSync(adapter)
     self.assertEqual(custom.debug, False)
 def test_main_debug_flag_set_true(self):
     adapter = SteemAdapter()
     custom = ChainSync(adapter, debug=True)
     self.assertEqual(custom.debug, True)
Beispiel #12
0
 def setUp(self):
     adapter = SteemAdapter(endpoints='https://steemd.pevo.science',
                            retry=False)
     self.chainsync = ChainSync(adapter=adapter, retry=False)
Beispiel #13
0
import datetime
from chainsync import ChainSync
from chainsync.adapters.decent import DecentAdapter

adapter = DecentAdapter(endpoints=['http://api.decent-db.com:8090/'])
chainsync = ChainSync(adapter)

print('\nGetting block 1')
block = chainsync.get_block(1)
print(block)

print('\nGetting blocks 1, 10, 50, 250, 500')
blocks = chainsync.get_blocks([1, 10, 50, 250, 500])
for block in blocks:
    print(block)

print('\nGetting blocks 1000-1005')
blocks = chainsync.get_block_sequence(1000, 5)
for block in blocks:
    print(block)

print('\nGetting all ops in block 92847...')
for op in chainsync.get_ops_in_block(92847):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
                                    op['operation_type']))

print('\nGetting withdraw_vesting ops in block 92847...')
for op in chainsync.get_ops_in_block(92847, whitelist=['withdraw_vesting']):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
 def setUp(self):
     self.chainsync = ChainSync(adapter=SteemAdapter)
 def test_adapter_debug_flag_set_true(self):
     adapter = SteemAdapter(debug=True)
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.debug, True)
 def test_adapter_init_custom_adapter_custom_endpoint_list(self):
     endpoints = ['http://localhost:8091', 'http://localhost:8090']
     adapter = SteemAdapter(endpoints=endpoints)
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.endpoint, 'http://localhost:8091')
     self.assertEqual(custom.adapter.endpoints, endpoints)
 def test_adapter_init_custom_adapter_custom_endpoint_string(self):
     adapter = SteemAdapter(endpoints='http://localhost:8091')
     custom = ChainSync(adapter)
     self.assertEqual(custom.adapter.endpoint, 'http://localhost:8091')
from chainsync import ChainSync
from chainsync.adapters.steem import SteemAdapter

from chainmodel import ChainModel
from chainmodel.models.steem.schema import Schema

# define endpoints
endpoints = [
    'https://api.steemit.com/',
    'https://rpc.buildteam.io/',
    'https://steemd.privex.io/',
]

# setup adapter + chainsync
adapter = SteemAdapter(endpoints=endpoints)
chainsync = ChainSync(adapter)

# establish models with schema
chainmodel = ChainModel(schema=Schema())

# connect to database
mongo = MongoClient('mongodb://localhost', connect=False)
db = mongo['steem']

# stream all operations
for dataType, opData in chainsync.stream(['ops']):

    # model data based on schema
    model = chainmodel.get(opData)

    # insert in database
Beispiel #19
0
import datetime

from chainsync import ChainSync
from chainsync.adapters.muse import MuseAdapter

adapter = MuseAdapter(endpoints=['http://45.79.206.79:8090/'], debug=False)
chainsync = ChainSync(adapter)

print('\nGetting block 1')
block = chainsync.get_block(1)
print(block)

print('\nGetting blocks 1, 10, 50, 250, 500')
blocks = chainsync.get_blocks([1, 10, 50, 250, 500])
for block in blocks:
    print(block)

print('\nGetting blocks 1000-1005')
blocks = chainsync.get_block_sequence(1000, 5)
for block in blocks:
    print(block)

print('\nGetting all ops in block 6274087...')
for op in chainsync.get_ops_in_block(6274087):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
                                    op['operation_type']))

print('\nGetting withdraw_vesting ops in block 6274087...')
for op in chainsync.get_ops_in_block(6274087, whitelist=['feed_publish']):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],