Пример #1
0
class PostStream:
    log = logging.getLogger(__name__)
    last_shown_no = 0

    def __init__(self, block_pointer):
        self.bp = block_pointer
        self.start_stream()
        self.steem = Steem()

    def start_stream(self):
        self.log.info('Start new block chain and stream %s' % self.bp.last())

    def get(self):
        try:
            block = self.steem.get_block(self.bp.last())
            if block == None:
                return None
            output = []
            for trans in block['transactions']:
                if trans['operations'][0][0] == 'comment':
                    post = trans['operations'][0][1]
                    post['block_num'] = self.bp.last()
                    post['timestamp'] = trans['expiration']
                    output.append(post)
            if self.bp.last() > (self.last_shown_no + 100):
                self.last_shown_no = self.bp.last()
                self.log.info('Processing block: %s' % self.last_shown_no)
            self.bp.update(self.bp.last() + 1)
            return output
        except Exception as e:
            self.log.error('Failed receiving from the stream: ' + str(e))
            raise
Пример #2
0
class TransferStream:
    log = logging.getLogger(__name__)
    last_shown_no = 0

    def __init__(self, block_pointer, config):
        self.bp = block_pointer
        self.start_stream()
        self.steem = Steem()
        self.filter_account = config['receiving_account']
        self.config = config

    def start_stream(self):
        self.log.info('Start new block chain and stream %s' % self.bp.last())

    def get(self):
        try:
            if not self.bp.last():
                self.bp.update(self.steem.head_block_number)
            block_no = self.bp.last()
            block = self.steem.get_block(block_no)
            if block == None:
                return None
            output = []
            for index, trans in enumerate(block['transactions']):
                if trans['operations'][0][0] == 'transfer':
                    transfer = trans['operations'][0][1]
                    if transfer['to'] == self.filter_account:
                        memo = transfer['memo'].split(' ')
                        timestamp = time.mktime(
                            datetime.datetime.strptime(
                                block['timestamp'],
                                "%Y-%m-%dT%H:%M:%S").timetuple()) * 1000
                        transfer_detail = {
                            'block_num': block_no,
                            'tx_id': block['transaction_ids'][index],
                            'timestamp': block['timestamp'],
                            'from': transfer['from'],
                            'to': transfer['to'],
                            'amount': transfer['amount'],
                            'invoiceId': memo[0],
                            'memo': memo[1]
                        }
                        output.append(transfer_detail)
            if block_no > (self.last_shown_no + 100):
                self.last_shown_no = block_no
                self.log.info('Processing block: %s' % self.last_shown_no)
            self.bp.update(block_no + 1)
            return output
        except Exception as e:
            self.log.error('Failed receiving from the stream: ' + str(e))
            raise
Пример #3
0
 global_process_start_time = time.clock()
 # Update the Queue
 update_queue()
 # Process New Blocks
 props = rpc.get_dynamic_global_properties()
 block_number = props['last_irreversible_block_num']
 while (block_number - last_block) > 0:
     last_block += 1
     total_start_time = time.clock()
     pprint("[STEEM] - Starting Block #" + str(last_block))
     flush_start_time1 = time.clock()
     sys.stdout.flush()
     flush_time1 = time.clock() - flush_start_time1
     # Get full block
     get_block_start_time = time.clock()
     block = rpc.get_block(last_block)
     get_block_time = time.clock() - get_block_start_time
     # Process block
     process_block_start_time = time.clock()
     process_block(block, last_block)
     process_block_time = time.clock() - process_block_start_time
     # Update our block height
     db.status.update({'_id': 'height'},
                      {"$set": {
                          'value': last_block
                      }},
                      upsert=True)
     # if last_block % 100 == 0:
     pprint("[STEEM] - Processed up to Block #" + str(last_block))
     flush_start_time2 = time.clock()
     sys.stdout.flush()