Exemplo n.º 1
0
    print_event('op', op)

print('\nGetting withdraw_vesting ops in block 9284729...')
for op in chainsync.get_ops_in_block(9284729, whitelist=['withdraw_vesting']):
    print_event('op', op)

print('\nGetting all ops in block 1000000, 5000000, and 2000000...')
for op in chainsync.get_ops_in_blocks([1000000, 5000000, 2000000]):
    print_event('op', op)

print('\nGetting producer_reward ops in block 1000000, 5000000, and 2000000...')
for op in chainsync.get_ops_in_blocks([1000000, 5000000, 2000000], whitelist=['producer_reward']):
    print_event('op', op)

print('\nStreaming blocks from head...')
for dataType, data in chainsync.stream(['blocks']):
    print_event(dataType, data)

print('\nStreaming blocks from the irreversible height...')
for dataType, data in chainsync.stream(['blocks'], mode='irreversible'):
    print_event(dataType, data)

print('\nStreaming status...')
for dataType, data in chainsync.stream(['status']):
    print_event(dataType, data)

print('\nStreaming ops_per_blocks...')
for dataType, data in chainsync.stream(['ops_per_blocks']):
    print_event(dataType, data)

print('\nStreaming blocks + status from head...')
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
    db.ops.update(model.query(), model.data(), upsert=True)
Exemplo n.º 3
0
print('\nGetting all ops in block 10000, 50000, and 20000...')
for op in chainsync.get_ops_in_blocks([10000, 50000, 20000]):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
                                    op['operation_type']))

print('\nGetting producer_reward ops in block 10000, 50000, and 20000...')
for op in chainsync.get_ops_in_blocks([10000, 50000, 20000],
                                      whitelist=['producer_reward']):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
                                    op['operation_type']))

print('\nStreaming blocks, 100 at a time, from the irreversible height...')
for dataType, block in chainsync.stream(['blocks'],
                                        batch_size=100,
                                        mode='irreversible'):
    print("{}: {} - {}".format(datetime.datetime.now(), block['block_num'],
                               block['miner']))

print('\nStreaming all ops...')
for dataType, op in chainsync.stream(['ops']):
    print("{}: {} [{}] - {}".format(datetime.datetime.now(), op['block_num'],
                                    op['transaction_id'],
                                    op['operation_type']))

print(
    '\nStreaming all blocks + ops + virtual ops + accurate counts of ops per block...'
)
for dataType, data in chainsync.stream(['blocks', 'ops', 'ops_per_blocks'],
                                       start_block=1045177):