def wait_for_transaction_receipt(self, txid): LOG.info("Waiting for transaction receipt from the DID sidechain...") try: w3 = Web3(Web3.HTTPProvider(self.sidechain_rpc)) tx_receipt = w3.eth.wait_for_transaction_receipt(txid, timeout=30, poll_latency=0.1) return { "tx_receipt": json.loads(Web3.toJSON(tx_receipt)), "err_type": None, "err_message": None } except TimeExhausted as e: LOG.info( f"Timed out while sending transactions to the DID sidechain: {str(e)}" ) return { "tx_receipt": {}, "err_type": "TimeExhausted", "err_message": str(e) } except Exception as e: LOG.info( f"Error while sending transactions to the DID sidechain: {str(e)}" ) return { "tx_receipt": {}, "err_type": "Exception", "err_message": str(e) }
def get_block_count(self) -> int: LOG.info("Get block count...") try: w3 = Web3(Web3.HTTPProvider(self.sidechain_rpc)) currentBlock = w3.eth.get_block_number() LOG.info("Actual block number: " + str(currentBlock)) return currentBlock except Exception as e: LOG.info(f"Error while getting block count: {str(e)}") return None
def get_raw_transaction(self, txid): LOG.info(f"Retrieving transaction {txid} from the DID sidechain...") try: w3 = Web3(Web3.HTTPProvider(self.sidechain_rpc)) tx = w3.eth.get_transaction_receipt(txid) return json.loads(Web3.toJSON(tx)) except Exception as e: LOG.info( f"Error while getting raw transaction for a txid: {str(e)}") return None
def send_raw_transaction(self, signed_transaction): LOG.info("Sending transaction to the DID sidechain...") try: w3 = Web3(Web3.HTTPProvider(self.sidechain_rpc)) tx = w3.eth.send_raw_transaction(signed_transaction.rawTransaction) return {"tx_id": tx.hex(), "error": None} except Exception as e: LOG.info( f"Error while sending transactions to the DID sidechain: {str(e)}" ) return {"tx_id": None, "error": str(e)}
def get_balance(self, address): LOG.info( f"Retrieving current balance on DID sidechain for address {address}" ) balance = 0 try: w3 = Web3(Web3.HTTPProvider(self.sidechain_rpc)) balance = float(w3.eth.get_balance( Web3.toChecksumAddress(address))) balance = balance / 1000000000000000000.0 except Exception as e: LOG.info(f"Error while retrieving balance for an address: {e}") return balance