示例#1
0
 async def initialize_transactions(self, connection, log_stream):
     """
     Request transactions from the network to initialize data for a given pubkey
     :param sakia.data.entities.Connection connection:
     :param function log_stream:
     """
     history_data = await self._bma_connector.get(
         connection.currency,
         bma.tx.history,
         req_args={'pubkey': connection.pubkey})
     txid = 0
     nb_tx = len(history_data["history"]["sent"]) + len(
         history_data["history"]["received"])
     log_stream("Found {0} transactions".format(nb_tx))
     transactions = []
     for sent_data in history_data["history"]["sent"] + history_data[
             "history"]["received"]:
         sent = TransactionDoc.from_bma_history(history_data["currency"],
                                                sent_data)
         log_stream("{0}/{1} transactions".format(txid, nb_tx))
         try:
             tx = parse_transaction_doc(sent, connection.pubkey,
                                        sent_data["block_number"],
                                        sent_data["time"], txid)
             transactions.append(tx)
             self._repo.insert(tx)
         except sqlite3.IntegrityError:
             log_stream("Transaction already registered in database")
         await asyncio.sleep(0)
         txid += 1
     return transactions
示例#2
0
 async def parse_transactions_history(self, connections, start, end):
     """
     Request transactions from the network to initialize data for a given pubkey
     :param List[sakia.data.entities.Connection] connections: the list of connections found by tx parsing
     :param int start: the first block
     :param int end: the last block
     """
     transfers_changed = []
     new_transfers = {}
     for connection in connections:
         txid = 0
         new_transfers[connection] = []
         history_data = await self._bma_connector.get(self.currency, bma.tx.blocks,
                                                      req_args={'pubkey': connection.pubkey,
                                                                'start': start,
                                                                'end': end})
         for tx_data in history_data["history"]["sent"]:
             for tx in [t for t in self._transactions_processor.awaiting(self.currency)]:
                 if self._transactions_processor.run_state_transitions(tx, tx_data["hash"], tx_data["block_number"]):
                     transfers_changed.append(tx)
                     self._logger.debug("New transaction validated : {0}".format(tx.sha_hash))
         for tx_data in history_data["history"]["received"]:
             tx_doc = TransactionDoc.from_bma_history(history_data["currency"], tx_data)
             if not self._transactions_processor.find_by_hash(connection.pubkey, tx_doc.sha_hash) \
                 and SimpleTransaction.is_simple(tx_doc):
                 tx = parse_transaction_doc(tx_doc, connection.pubkey, tx_data["block_number"],
                                            tx_data["time"], txid)
                 if tx:
                     new_transfers[connection].append(tx)
                     self._transactions_processor.commit(tx)
                 else:
                     logging.debug("Error during transfer parsing")
     return transfers_changed, new_transfers
示例#3
0
 async def initialize_transactions(self, connection, log_stream, progress):
     """
     Request transactions from the network to initialize data for a given pubkey
     :param sakia.data.entities.Connection connection:
     :param function log_stream:
     :param function progress: progress callback
     """
     blockchain = self._blockchain_repo.get_one(
         currency=connection.currency)
     avg_blocks_per_month = int(30 * 24 * 3600 /
                                blockchain.parameters.avg_gen_time)
     start = blockchain.current_buid.number - avg_blocks_per_month
     end = blockchain.current_buid.number
     history_data = await self._bma_connector.get(connection.currency,
                                                  bma.tx.blocks,
                                                  req_args={
                                                      'pubkey':
                                                      connection.pubkey,
                                                      'start': start,
                                                      'end': end
                                                  })
     txid = 0
     nb_tx = len(history_data["history"]["sent"]) + len(
         history_data["history"]["received"])
     log_stream("Found {0} transactions".format(nb_tx))
     transactions = []
     for sent_data in history_data["history"]["sent"] + history_data[
             "history"]["received"]:
         sent = TransactionDoc.from_bma_history(history_data["currency"],
                                                sent_data)
         log_stream("{0}/{1} transactions".format(txid, nb_tx))
         progress(1 / nb_tx)
         try:
             tx = parse_transaction_doc(sent, connection.pubkey,
                                        sent_data["block_number"],
                                        sent_data["time"], txid)
             if tx:
                 transactions.append(tx)
                 self._repo.insert(tx)
             else:
                 log_stream("ERROR : Could not parse transaction")
         except sqlite3.IntegrityError:
             log_stream("Transaction already registered in database")
         await asyncio.sleep(0)
         txid += 1
     return transactions
示例#4
0
 async def parse_transactions_history(self, connections, start, end):
     """
     Request transactions from the network to initialize data for a given pubkey
     :param List[sakia.data.entities.Connection] connections: the list of connections found by tx parsing
     :param int start: the first block
     :param int end: the last block
     """
     transfers_changed = []
     new_transfers = {}
     for connection in connections:
         txid = 0
         new_transfers[connection] = []
         history_data = await self._bma_connector.get(self.currency,
                                                      bma.tx.blocks,
                                                      req_args={
                                                          'pubkey':
                                                          connection.pubkey,
                                                          'start': start,
                                                          'end': end
                                                      })
         for tx_data in history_data["history"]["sent"]:
             for tx in [
                     t for t in self._transactions_processor.awaiting(
                         self.currency)
             ]:
                 if self._transactions_processor.run_state_transitions(
                         tx, tx_data["hash"], tx_data["block_number"]):
                     transfers_changed.append(tx)
                     self._logger.debug(
                         "New transaction validated : {0}".format(
                             tx.sha_hash))
         for tx_data in history_data["history"]["received"]:
             tx_doc = TransactionDoc.from_bma_history(
                 history_data["currency"], tx_data)
             if not self._transactions_processor.find_by_hash(connection.pubkey, tx_doc.sha_hash) \
                 and SimpleTransaction.is_simple(tx_doc):
                 tx = parse_transaction_doc(tx_doc, connection.pubkey,
                                            tx_data["block_number"],
                                            tx_data["time"], txid)
                 if tx:
                     new_transfers[connection].append(tx)
                     self._transactions_processor.commit(tx)
                 else:
                     logging.debug("Error during transfer parsing")
     return transfers_changed, new_transfers
示例#5
0
 async def initialize_transactions(self, connection, log_stream, progress):
     """
     Request transactions from the network to initialize data for a given pubkey
     :param sakia.data.entities.Connection connection:
     :param function log_stream:
     :param function progress: progress callback
     """
     blockchain = self._blockchain_repo.get_one(currency=connection.currency)
     avg_blocks_per_month = int(30 * 24 * 3600 / blockchain.parameters.avg_gen_time)
     start = blockchain.current_buid.number - avg_blocks_per_month
     end = blockchain.current_buid.number
     history_data = await self._bma_connector.get(connection.currency, bma.tx.blocks,
                                                  req_args={'pubkey': connection.pubkey,
                                                            'start': start,
                                                            'end': end})
     txid = 0
     nb_tx = len(history_data["history"]["sent"]) + len(history_data["history"]["received"])
     log_stream("Found {0} transactions".format(nb_tx))
     transactions = []
     for sent_data in history_data["history"]["sent"] + history_data["history"]["received"]:
         sent = TransactionDoc.from_bma_history(history_data["currency"], sent_data)
         log_stream("{0}/{1} transactions".format(txid, nb_tx))
         progress(1 / nb_tx)
         try:
             tx = parse_transaction_doc(sent, connection.pubkey, sent_data["block_number"],
                                        sent_data["time"], txid)
             if tx:
                 transactions.append(tx)
                 self._repo.insert(tx)
             else:
                 log_stream("ERROR : Could not parse transaction")
         except sqlite3.IntegrityError:
             log_stream("Transaction already registered in database")
         await asyncio.sleep(0)
         txid += 1
     return transactions