def query_exchange_rate_for_height(currency, height): if height <= last_height[currency]: res = gm.ExchangeRate(all_exchange_rates[currency][height]) else: res = gm.ExchangeRate( all_exchange_rates[currency][last_height[currency]]) return res
def query_cluster_outgoing_relations(currency, page_state, cluster, pagesize, limit): set_keyspace(session, currency) if limit is None: query = cluster_outgoing_relations_without_limit_query params = [cluster] else: query = cluster_outgoing_relations_query params = [cluster, limit] if pagesize is not None: query[currency].fetch_size = pagesize if page_state is not None: page_state = bytes.fromhex(page_state) rows = session.execute(query[currency], params, paging_state=page_state) else: rows = session.execute(query[currency], params) page_state = rows.paging_state exchange_rate = gm.ExchangeRate( all_exchange_rates[currency][last_height[currency]]) relations = [ gm.ClusterOutgoingRelations(row, exchange_rate) for row in rows.current_rows ] return page_state, relations
def query_cluster_addresses(currency, cluster, page, pagesize, limit): set_keyspace(session, currency) if limit is None: query = cluster_addresses_without_limit_query params = [int(cluster)] else: query = cluster_addresses_query params = [int(cluster), limit] if pagesize is not None: query[currency].fetch_size = pagesize if page is not None: page = bytes.fromhex(page) rows = session.execute(query[currency], params, paging_state=page) else: rows = session.execute(query[currency], params) clusteraddresses = [ gm.ClusterAddresses( row, gm.ExchangeRate( all_exchange_rates[currency][last_height[currency]])).__dict__ for row in rows.current_rows ] page = rows.paging_state return page, clusteraddresses
def query_cluster(currency, cluster): set_keyspace(session, currency) rows = session.execute(cluster_query[currency], [int(cluster)]) return gm.Cluster( rows.current_rows[0], gm.ExchangeRate(all_exchange_rates[currency][ last_height[currency]])) if rows else None
def query_address(currency, address): set_keyspace(session, currency) rows = session.execute(address_query[currency], [address, address[0:5]]) return gm.Address( rows[0], gm.ExchangeRate(all_exchange_rates[currency][ last_height[currency]])) if rows else None
def query_address_outgoing_relations(currency, page_state, address, pagesize, limit): set_keyspace(session, currency) if limit is None: query = address_outgoing_relations_without_limit_query params = [address[0:5], address] else: query = address_outgoing_relations_query params = [address[0:5], address, limit] if pagesize is not None: query[currency].fetch_size = pagesize if page_state is not None: rows = session.execute(query[currency], params, paging_state=page_state) else: rows = session.execute(query[currency], params) page_state = rows.paging_state exchange_rate = gm.ExchangeRate( all_exchange_rates[currency][last_height[currency]]) relations = [ gm.AddressOutgoingRelations(row, exchange_rate) for row in rows.current_rows ] return page_state, relations
def query_exchange_rates(currency, offset, limit): if not offset: offset = 0 if not limit: limit = 100 start = last_height[currency] - limit * offset end = last_height[currency] - limit * (offset + 1) exchange_rates = [ gm.ExchangeRate(all_exchange_rates[currency][height]).__dict__ for height in range(start, end, -1) ] return exchange_rates