def _parse_block(self, block_doc, txid): """ Parse a block :param duniterpy.documents.Block block_doc: The block :param int txid: Latest tx id :return: The list of transfers sent """ transfers_changed = [] new_transfers = {} for tx in [t for t in self._transactions_processor.awaiting(self.currency)]: if self._transactions_processor.run_state_transitions(tx, block_doc): transfers_changed.append(tx) self._logger.debug("New transaction validated : {0}".format(tx.sha_hash)) connections = self._connections_processor.connections_to(self.currency) for conn in connections: new_transactions = [t for t in block_doc.transactions if not self._transactions_processor.find_by_hash(conn.pubkey, t.sha_hash) and SimpleTransaction.is_simple(t)] new_transfers[conn] = [] for (i, tx_doc) in enumerate(new_transactions): tx = parse_transaction_doc(tx_doc, conn.pubkey, block_doc.blockUID.number, block_doc.mediantime, txid+i) if tx: new_transfers[conn].append(tx) self._transactions_processor.commit(tx) else: logging.debug("Error during transfer parsing") return transfers_changed, new_transfers
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
def parse_sent_transaction(self, pubkey, transaction): """ Parse a block :param sakia.data.entities.Transaction transaction: The transaction to parse :return: The list of transfers sent """ if not self._transactions_processor.find_by_hash(pubkey, transaction.sha_hash): txid = self._transactions_processor.next_txid(transaction.currency, -1) tx = parse_transaction_doc(transaction.txdoc(), pubkey, transaction.blockstamp.number, transaction.timestamp, txid+1) tx.state = Transaction.AWAITING if tx: self._transactions_processor.commit(tx) return tx else: logging.debug("Error during transfer parsing")
def parse_sent_transaction(self, pubkey, transaction): """ Parse a block :param sakia.data.entities.Transaction transaction: The transaction to parse :return: The list of transfers sent """ if not self._transactions_processor.find_by_hash(pubkey, transaction.sha_hash): txid = self._transactions_processor.next_txid(transaction.currency, -1) tx = parse_transaction_doc(transaction.txdoc(), pubkey, transaction.blockstamp.number, transaction.timestamp, txid+1) if tx: tx.state = Transaction.AWAITING self._transactions_processor.commit(tx) return tx else: logging.debug("Error during transfer parsing")
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