Esempio n. 1
0
 def get_status(self):
     try:
         state = self.mongo_cli.get_one(table=FLAGS.chain_status,
                                        cond={FLAGS.block_height: 0})
     except Exception as e:
         raise exception.DBError(e)
     return None if state is None else state
Esempio n. 2
0
    def get_tx_by_hash(self, txhash):
        try:
            tx = self.mongo_cli.get_one(table=FLAGS.transaction_info,
                                        cond={FLAGS.tx_id: txhash})

        except Exception, e:
            raise exception.DBError(e)
Esempio n. 3
0
 def select_txout_by_hash(self, txhash):
     try:
         tx = self.mongo_cli.get_one(table=FLAGS.transaction_info,
                                     cond={FLAGS.tx_id: txhash})
         txouts = tx.get[FLAGS.transaction_out]
     except Exception, e:
         raise exception.DBError(e)
Esempio n. 4
0
 def get_latest_block_miner(self):
     height = self.get_recent_height()
     try:
         miner = self.mongo_cli.get_one(table=FLAGS.block_info, cond={FLAGS.block_height: height}, fields={'miner': 1, '_id': 0})
     except Exception as e:
         raise exception.DBError(e)
     return miner.get('miner')
Esempio n. 5
0
 def get_difficulty(self):
     try:
         height = self.get_recent_height()
         difficulty = self.mongo_cli.get_one(FLAGS.block_info, {'height': height}, fields={'difficulty': 1, '_id': 0})
     except Exception as e:
         raise exception.DBError(e)
     return difficulty.get('difficulty')
Esempio n. 6
0
 def request_node_status(self):
     try:
         stats = self.mongo_cli.get_many(table=FLAGS.node_status,
                                         n=1,
                                         sort_key=FLAGS.timestamp,
                                         ascend=False)
     except Exception as e:
         raise exception.DBError(e)
     return stats
Esempio n. 7
0
 def get_block_latest_in_range(self, start, end):
     try:
         blocks = self.mongo_cli.get_many(table=FLAGS.block_info,
                                          n=end - start,
                                          sort_key=FLAGS.block_height,
                                          ascend=False,
                                          skip=start)
     except Exception as e:
         raise exception.DBError(e)
     return blocks
Esempio n. 8
0
 def get_transactions_in_range(self, low, high):
     try:
         coinbase = self.mongo_cli.get_many(
             table=FLAGS.block_info,
             items={"transactions": 1, "_id": 0},
             n=high - low,
             skip=low)
     except Exception as e:
         raise exception.DBError(e)
     return coinbase
Esempio n. 9
0
 def get_timestamps_in_range(self, start, end):
     try:
         timestamps = self.mongo_cli.get_many(
             table=FLAGS.block_info,
             items={"timestamp": 1, "_id": 0},
             n=end-start,
             skip=start)
     except Exception as e:
         raise exception.DBError(e)
     return timestamps
Esempio n. 10
0
 def get_hash_rate_in_range(self, start, end):
     try:
         hash_rates = self.mongo_cli.get_many(
             table=FLAGS.block_info,
             items={"hash_rate": 1, "_id": 0},
             n=end-start,
             skip=start)
     except Exception as e:
         raise exception.DBError(e)
     return hash_rates
Esempio n. 11
0
 def get_last_block_interval(self):
     height = self.get_recent_height()
     if height < 1:
         return None
     last_height = height - 1
     try:
         time = self.mongo_cli.get_one(table=FLAGS.block_info, cond={FLAGS.block_height: height}, fields={'timestamp': 1, '_id': 0})
         last_time = self.mongo_cli.get_one(table=FLAGS.block_info, cond={FLAGS.block_height: last_height}, fields={'timestamp': 1, '_id': 0})
         interval = time.get('timestamp') - last_time.get('timestamp')
     except Exception as e:
         raise exception.DBError(e)
     return interval
Esempio n. 12
0
 def get_block_by_hash(self, blockhash):
     try:
         if not is_hash_prefix(blockhash):
             raise Exception("Block hash is wrong!")
         block = self.mongo_cli.get_one(table=FLAGS.block_info,
                                        cond={FLAGS.block_id: blockhash})
         if block is None:
             raise Exception("Block not found!")
         block_info = self._show_block(block)
     except Exception as e:
         raise exception.DBError(e)
     return block_info
Esempio n. 13
0
 def select_txout_by_id(self, txout_id):
     try:
         txout = self.mongo_cli.get_one(table=FLAGS.transaction_info,
                                        cond={FLAGS.txout_id: txout_id})
     except Exception, e:
         raise exception.DBError(e)
Esempio n. 14
0
 def save_node(self, status):
     try:
         self.mongo_cli.insert(flags.FLAGS.node_status, status)
     except Exception as e:
         raise exception.DBError(e)
Esempio n. 15
0
 def save_chain_patch(self, status_list):
     try:
         self.mongo_cli.insert_many(flags.FLAGS.chain_status, status_list)
     except Exception as e:
         raise exception.DBError(e)
Esempio n. 16
0
 def get_node_stats_list(self):
     try:
         stats = self.mongo_cli.get_many(table=FLAGS.node_status)
     except Exception as e:
         raise exception.DBError(e)
     return None if stats is None else stats
Esempio n. 17
0
 def get_recent_height(self):
     try:
         state = self.mongo_cli.get(flags.FLAGS.db_status)
     except Exception as e:
         raise exception.DBError(e)
     return None if state is None else state[flags.FLAGS.block_height]
Esempio n. 18
0
 def get_total_addr_num(self):
     try:
         total_num = self.mongo_cli.count(FLAGS.address_info)
     except Exception as e:
         raise exception.DBError(e)
     return total_num
Esempio n. 19
0
 def get_total_tx_num(self):
     try:
         total_num = self.mongo_cli.count(FLAGS.transaction_info)
     except Exception as e:
         raise exception.DBError(e)
     return total_num