def send_ether(from_wallet: Wallet, to_address: str, amount: int) -> AttributeDict: if not Web3.isChecksumAddress(to_address): to_address = Web3.toChecksumAddress(to_address) web3 = from_wallet.web3 chain_id = web3.eth.chain_id tx = { "from": from_wallet.address, "to": to_address, "value": amount, "chainId": chain_id, "gasPrice": get_gas_price(web3), } tx["gas"] = web3.eth.estimate_gas(tx) raw_tx = from_wallet.sign_tx(tx) tx_hash = web3.eth.send_raw_transaction(raw_tx) block_confirmations = from_wallet.block_confirmations.value block_number_poll_interval = BLOCK_NUMBER_POLL_INTERVAL[chain_id] transaction_timeout = from_wallet.transaction_timeout.value wait_for_transaction_receipt_and_block_confirmations( web3, tx_hash, block_confirmations, block_number_poll_interval, transaction_timeout, ) return web3.eth.get_transaction_receipt(tx_hash)
async def get_token_owner(self, network: str, tokenId: int) -> str: contract = self.get_contract(network=network) ownerIdResponse = await self._call_function( contract=contract, methodName=contract.ownerOfMethodName, arguments={'tokenId': int(tokenId)}) ownerId = Web3.toChecksumAddress(ownerIdResponse[0].strip()) return ownerId
async def get_migration_target(self, network: str) -> str: contract = self.get_contract(network=network) if not contract.migrationTargetMethodName: raise BadRequestException( 'Contract does not have a migrationTargetMethodName') ownerIdResponse = await self._call_function( contract=contract, methodName=contract.migrationTargetMethodName) migrationTarget = Web3.toChecksumAddress(ownerIdResponse[0].strip()) return migrationTarget
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
def get_number_orders_price(token_address, last_sync_block, chain_id): try: client = get_client(chain_id) last_block = get_last_block(client) while last_block < last_sync_block: logger.debug( f"Waiting for sync with subgraph, currently at last block {last_block}." ) last_block = get_last_block(client) time.sleep(2) query = gql( '{tokens(where:{nft:"' + token_address.lower() + '"}){orderCount, fixedRateExchanges{ price, baseToken {symbol, address} }, dispensers{id}}}' ) tokens_result = client.execute(query) logger.debug(f"Got result for did query: {tokens_result}.") order_count = tokens_result["tokens"][0]["orderCount"] price = None fres = tokens_result["tokens"][0].get("fixedRateExchanges", None) dispensers = tokens_result["tokens"][0].get("dispensers", None) if fres and "price" in fres[0]: price = Price(fres[0]["price"]) if "baseToken" in fres[0]: price.token_address = Web3.toChecksumAddress( fres[0]["baseToken"].get("address")) price.token_symbol = fres[0]["baseToken"].get("symbol") elif dispensers: price = Price(0) price_obj = price.as_dict() if price else {} return int(order_count), price_obj except Exception: logger.exception( f"Can not get number of orders for subgraph {get_network_name()} token address {token_address}" ) return -1, {}