def get_token_info(queryWord): length_of_query_word = len(queryWord) if length_of_query_word == 42 or length_of_query_word == 40: queryWord = queryWord if length_of_query_word == 42 else "0x" + queryWord query_res = Token.query_token(address=queryWord) else: queryWord = queryWord.upper() query_res = Token.query_token(symbol=queryWord) if query_res: return [query_res.toJson()] return []
def get_token_holding(address): holding_list = [ holding.contract for holding in TokenHolding.query_token_holding(address) ] holding_list = get_balance_2(address, holding_list) res = deque([]) for holding in holding_list: query_res = Token.query_token(address=holding.get("assetId")) if query_res: tmp_dict = query_res.toJson() tmp_dict["balance"] = holding.get("balance") if tmp_dict.get("tokenIcon"): res.appendleft(tmp_dict) else: res.append(tmp_dict) balances = _get_global_asset(address) for balance in balances: if balance.get("asset") == setting.NEO_ASSETID: neo_balance = balance.get("value") if balance.get("asset") == setting.GAS_ASSETID: gas_balance = str(Decimal(balance.get("value")) * (10**8)) try: neo_balance = neo_balance except: neo_balance = "0" try: gas_balance = gas_balance except: gas_balance = "0" res.appendleft( dict( balance=gas_balance, tokenAddress= "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7", tokenDecimal="8", tokenIcon=None, tokenName="GAS", tokenSynbol="GAS", tokenType="GAS")) res.appendleft( dict( balance=neo_balance, tokenAddress= "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tokenDecimal="0", tokenIcon=None, tokenName="NEO", tokenSynbol="NEO", tokenType="NEO")) return list(res)
def get_transaction_by_address(address, asset, page=1): query_tx = [] if asset == setting.NEO_ASSETID or asset == setting.GAS_ASSETID: try: query_tx_ids = ContractTxMapping.query.filter( ContractTxMapping.address == address, ContractTxMapping.asset == asset).order_by( ContractTxMapping.block_height.desc()).paginate( page=page, per_page=8).items except: query_tx_ids = [] decimal = 0 for tx in query_tx_ids: exist_instance = ContractTxDetail.query.filter( ContractTxDetail.tx_id == tx.tx_id).first() if exist_instance: query_tx.append(exist_instance) else: try: query_tx = InvokeTx.query.filter( or_(InvokeTx.address_from == address, InvokeTx.address_to == address), InvokeTx.contract == asset).order_by( InvokeTx.block_timestamp.desc()).paginate(page=page, per_page=8).items except Exception as e: runserver_logger.error(e) query_tx = [] if query_tx: exist_instance = Token.query_token(address=asset) if exist_instance: decimal = int(exist_instance.decimal) else: decimal = 0 txs = [ handle_invoke_tx_decimal(item.to_json(), decimal) for item in query_tx ] txs = [ utxo_to_account(tx, address, asset) if "inputs" in tx.keys() and "outputs" in tx.keys() else tx for tx in txs ] return txs
def get_transaction_by_address(address, asset, page=1): if asset == setting.NEO_ASSETID or asset == setting.GAS_ASSETID: try: query_tx = ContractTx.query.filter( or_(ContractTx.address_from == address, ContractTx.address_to == address), ContractTx.asset == asset, ).order_by(ContractTx.block_timestamp.desc()).paginate( page=page, per_page=8).items except: query_tx = [] decimal = 0 else: try: query_tx = InvokeTx.query.filter( or_(InvokeTx.address_from == address, InvokeTx.address_to == address), InvokeTx.contract == asset).order_by( InvokeTx.block_timestamp.desc()).paginate(page=page, per_page=8).items except Exception as e: runserver_logger.error(e) query_tx = [] if query_tx: exist_instance = Token.query_token(address=asset) if exist_instance: decimal = int(exist_instance.decimal) else: decimal = 0 txs = [ handle_invoke_tx_decimal(item.to_json(), decimal) for item in query_tx ] return txs