kopia lustrzana https://github.com/bugout-dev/moonstream
Rmoce user token from workflow.
rodzic
d4c3ebd84d
commit
799353b39a
|
@ -458,7 +458,7 @@ def upload_abi_to_s3(
|
|||
|
||||
|
||||
def get_all_entries_from_search(
|
||||
journal_id: str, search_query: str, limit: int, token: str
|
||||
journal_id: str, search_query: str, limit: int, token: str, content: bool = False
|
||||
) -> List[BugoutSearchResult]:
|
||||
"""
|
||||
Get all required entries from journal using search interface
|
||||
|
@ -472,7 +472,7 @@ def get_all_entries_from_search(
|
|||
token=token,
|
||||
journal_id=journal_id,
|
||||
query=search_query,
|
||||
content=False,
|
||||
content=content,
|
||||
timeout=10.0,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
|
@ -488,7 +488,7 @@ def get_all_entries_from_search(
|
|||
token=token,
|
||||
journal_id=journal_id,
|
||||
query=search_query,
|
||||
content=False,
|
||||
content=content,
|
||||
timeout=10.0,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
|
|
|
@ -11,11 +11,14 @@ from ..settings import bugout_client as bc
|
|||
from ..settings import (
|
||||
MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||
MOONSTREAM_PUBLIC_QUERIES_TOKEN,
|
||||
MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID,
|
||||
)
|
||||
from ..data import BUGOUT_RESOURCE_QUERY_RESOLVER
|
||||
|
||||
from web3 import Web3
|
||||
|
||||
from bugout.data import BugoutResourceHolders, ResourcePermissions, HolderType
|
||||
from web3 import Web3
|
||||
from moonstream.client import (
|
||||
Moonstream,
|
||||
ENDPOINT_QUERIES,
|
||||
|
@ -95,46 +98,41 @@ def generate_leaderboard_owners(
|
|||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Get list of all leaderboard and add owners to it.
|
||||
|
||||
{
|
||||
"resources": [
|
||||
{
|
||||
"id": "ff90a1eb-6552-4bba-9d2b-f54cf2ab0103",
|
||||
"application_id": "e1b6321a-5e68-4f9d-ba0c-d87e37d9e7a9",
|
||||
"resource_data": {
|
||||
"type": "leaderboard",
|
||||
"leaderboard_id": "0b112383-c7d2-4734-818b-1600d5f096f8"
|
||||
},
|
||||
"created_at": "2023-08-09T11:49:06.992161+00:00",
|
||||
"updated_at": "2023-08-09T11:49:06.992161+00:00"
|
||||
}
|
||||
"""
|
||||
|
||||
leaderboard_owners = []
|
||||
|
||||
for leaderboard in leaderboards:
|
||||
leaderboard_id = leaderboard["resource_data"]["leaderboard_id"]
|
||||
resource_id = leaderboard["resource_id"]
|
||||
# breakpoint()
|
||||
leaderboard_id = leaderboard.resource_data["leaderboard_id"]
|
||||
resource_id = leaderboard.id
|
||||
|
||||
holders = bc.get_resource_holders(
|
||||
holders: BugoutResourceHolders = bc.get_resource_holders(
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
resource_id=resource_id,
|
||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||
)
|
||||
|
||||
owner = [
|
||||
holder["id"]
|
||||
for holder in holders.holders
|
||||
if holder["holder_type"] == "user" and "admin" in holder["permissions"]
|
||||
][0]
|
||||
print(holders.holders)
|
||||
try:
|
||||
owner = [
|
||||
holder.id
|
||||
for holder in holders.holders
|
||||
if holder.holder_type == HolderType.user
|
||||
and ResourcePermissions.ADMIN in holder.permissions
|
||||
][0]
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
breakpoint()
|
||||
continue
|
||||
|
||||
leaderboard_owners.append(
|
||||
{
|
||||
"leaderboard_id": leaderboard_id,
|
||||
"owner": owner,
|
||||
"resource_id": resource_id,
|
||||
"created_at": leaderboard["created_at"],
|
||||
"updated_at": leaderboard["updated_at"],
|
||||
"owner": str(owner),
|
||||
"resource_id": str(resource_id),
|
||||
"created_at": str(leaderboard.created_at),
|
||||
"updated_at": str(leaderboard.updated_at),
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -162,8 +160,6 @@ def collect_billing_information(
|
|||
- moonstream contracts
|
||||
"""
|
||||
|
||||
# Get user_id
|
||||
|
||||
subscription_resources = bc.list_resources(
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, # type: ignore
|
||||
params={
|
||||
|
@ -204,10 +200,12 @@ def collect_billing_information(
|
|||
|
||||
query_amount = len(query_resources.resources)
|
||||
|
||||
# MOONSTREAM_ADMIN_ACCESS_TOKEN = "ad7a7364-c535-4c9f-9d2d-20d7b6ade18d"
|
||||
|
||||
### Get user's leaderboards resources
|
||||
leaderboard_resources = bc.list_resources(
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, # type: ignore
|
||||
params={"user_id": user_id, "type": "leaderboard"},
|
||||
params={"type": "leaderboard"},
|
||||
timeout=BUGOUT_REQUEST_TIMEOUT_SECONDS,
|
||||
)
|
||||
|
||||
|
@ -223,65 +221,12 @@ def collect_billing_information(
|
|||
|
||||
leaderboard_configs = get_all_entries_from_search(
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN,
|
||||
journal_id="a75b4538-3323-4f1c-a57a-6fd858f0c424",
|
||||
journal_id=MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID,
|
||||
search_query="",
|
||||
content=True,
|
||||
limit=1000,
|
||||
)
|
||||
|
||||
"""
|
||||
class BugoutSearchResult(BaseModel):
|
||||
entry_url: str
|
||||
content_url: str
|
||||
title: str
|
||||
content: Optional[str]
|
||||
tags: List[str]
|
||||
created_at: str
|
||||
updated_at: str
|
||||
score: float
|
||||
context_type: Optional[str] = None
|
||||
context_url: Optional[str] = None
|
||||
context_id: Optional[str] = None
|
||||
|
||||
{
|
||||
"leaderboard_id":"258a9042-c8c5-48d2-bf33-3e516afc6c03",
|
||||
"query_name":"leaderboard_258a9042_c8c5_48d2_bf33_3e516afc6c03",
|
||||
"params":{
|
||||
"shards_common": 0,
|
||||
"shards_uncommon": 2,
|
||||
"shards_rare": 3,
|
||||
"shards_epic": 5,
|
||||
"shards_legendary": 10,
|
||||
"equipments_common": 0,
|
||||
"equipments_uncommon": 70,
|
||||
"equipments_rare": 100,
|
||||
"equipments_epic": 180,
|
||||
"equipments_legendary": 350,
|
||||
"artifacts_common": 0,
|
||||
"artifacts_uncommon": 30,
|
||||
"artifacts_rare": 40,
|
||||
"artifacts_epic": 80,
|
||||
"artifacts_legendary": 160,
|
||||
"common_upgrade_points": 0,
|
||||
"uncommon_upgrade_points": 65,
|
||||
"rare_upgrade_points": 95,
|
||||
"epic_upgrade_points": 155,
|
||||
"legendary_upgrade_points": 300,
|
||||
"gold_chest_points": 1,
|
||||
"magical_chest_points": 10,
|
||||
"legendary_chest_points": 35,
|
||||
"ultra_chest_points": 120,
|
||||
"wooden_chest_points": 0,
|
||||
"silver_chest_points": 0,
|
||||
"since_timestamp": 1698796800,
|
||||
"until_timestamp": 1701388800
|
||||
},
|
||||
"normalize_addresses": true
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
|
||||
leaderboard_configs_mapper = {}
|
||||
|
||||
for leaderboard_entry in leaderboard_configs:
|
||||
|
@ -305,7 +250,7 @@ def collect_billing_information(
|
|||
for blockchain, addresses in contracts.items():
|
||||
contracts_events = recive_S3_data_from_query(
|
||||
client=client,
|
||||
token=MOONSTREAM_ADMIN_ACCESS_TOKEN, # type: ignore
|
||||
token=MOONSTREAM_PUBLIC_QUERIES_TOKEN, # type: ignore
|
||||
query_name="template_contract_events_per_month",
|
||||
params={},
|
||||
time_await=2,
|
||||
|
@ -323,33 +268,28 @@ def collect_billing_information(
|
|||
|
||||
contract_data[blockchain] = contracts_events
|
||||
|
||||
"""
|
||||
{
|
||||
"id": "258a9042-c8c5-48d2-bf33-3e516afc6c03",
|
||||
"title": "Boomland: Hunter League - Season 3",
|
||||
"description": "U2NvcmluZzoKKiBVcGdyYWRlLCBkZXBlbmRpbmcgb24gcmFyaXR5ICh1bmNvbW1vbiB1cGdyYWRlcyB3b3J0aCA2NSBwb2ludHMsIHJhcmUgOTUsIGVwaWMgMTU1LCBsZWdlbmRhcnkgMzAwKQoqIE9wZW5pbmcgY2hlc3QKICAgICogR29sZCA9IDFwCiAgICAqIE1hZ2ljYWwgPSAxMHAKICAgICogTGVnZW5kYXJ5IFJveWFsID0gMzVwCiAgICAqIFVsdHJhIFN1cHJlbWUgPSAxMjBwCiogR2V0dGluZyBhIHNoYXJkLCAyIHBvaW50IGZvciB1bmNvbW1vbiwgMyBwb2ludCBmb3IgcmFyZSwgNSBwb2ludCBmb3IgZXBpYywgMTAgcG9pbnQgZm9yIGxlZ2VuZGFyeS4KKiBHZXR0aW5nIGVxdWlwbWVudCwgNzAgcG9pbnQgZm9yIHVuY29tbW9uLCAxMDAgcG9pbnQgZm9yIHJhcmUsIDE4MCBwb2ludCBmb3IgZXBpYywgMzUwIHBvaW50IGZvciBsZWdlbmRhcnkuCiogR2V0dGluZyBhbiBhcnRpZmFjdCwgMzAgcG9pbnQgZm9yIHVuY29tbW9uLCA0MCBwb2ludCBmb3IgcmFyZSwgODAgcG9pbnQgZm9yIGVwaWMsIDE2MCBwb2ludCBmb3IgbGVnZW5kYXJ5Lg==",
|
||||
"resource_id": "380316e7-475d-4778-bab3-55cc37d5bd31",
|
||||
"created_at": "2023-11-01T13:50:39.211766+00:00",
|
||||
"updated_at": "2023-11-01T14:25:27.953960+00:00"
|
||||
}
|
||||
"""
|
||||
for leaderboard in leaderboards:
|
||||
if leaderboard["id"] in leaderboard_configs_mapper:
|
||||
leaderboard["query_name"] = leaderboard_configs_mapper[leaderboard["id"]][
|
||||
"query_name"
|
||||
]
|
||||
if leaderboard["leaderboard_id"] in leaderboard_configs_mapper:
|
||||
leaderboard["query_name"] = leaderboard_configs_mapper[
|
||||
leaderboard["leaderboard_id"]
|
||||
]["query_name"]
|
||||
leaderboard["update_activated"] = leaderboard_configs_mapper[
|
||||
leaderboard["id"]
|
||||
leaderboard["leaderboard_id"]
|
||||
]["update_activated"]
|
||||
|
||||
# get leaderboard info
|
||||
|
||||
leaderboard_info = requests.get(
|
||||
f"https://engineapi.moonstream.to/leaderboard/info?leaderboard_id={leaderboard['id']}",
|
||||
f"https://engineapi.moonstream.to/leaderboard/info?leaderboard_id={leaderboard['leaderboard_id']}",
|
||||
).json()
|
||||
|
||||
leaderboard["users_count"] = leaderboard_info["users_count"]
|
||||
leaderboard["last_updated_at"] = leaderboard_info["last_updated_at"]
|
||||
try:
|
||||
leaderboard["users_count"] = leaderboard_info["users_count"]
|
||||
leaderboard["last_updated_at"] = leaderboard_info["last_updated_at"]
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
leaderboard["users_count"] = 0
|
||||
leaderboard["last_updated_at"] = None
|
||||
continue
|
||||
|
||||
return {
|
||||
"subscriptions": subscription_amount,
|
||||
|
|
|
@ -538,13 +538,6 @@ This CLI is configured to work with the following API URLs:
|
|||
help="Month for which to generate billing in YYYY-MM format (e.g. 2021-10)",
|
||||
)
|
||||
|
||||
generate_billing_parser.add_argument(
|
||||
"--user-token",
|
||||
required=False,
|
||||
type=str,
|
||||
help="User token for which to generate billing (currently works)",
|
||||
)
|
||||
|
||||
generate_billing_parser.add_argument(
|
||||
"--user-id",
|
||||
required=False,
|
||||
|
|
|
@ -133,3 +133,17 @@ BUGOUT_RESOURCE_TYPE_DASHBOARD = "dashboards"
|
|||
### Moonstream queries
|
||||
|
||||
MOONSTREAM_QUERY_TEMPLATE_CONTEXT_TYPE = "moonstream_query_template"
|
||||
|
||||
|
||||
MOONSTREAM_PUBLIC_QUERIES_TOKEN = os.environ.get("MOONSTREAM_PUBLIC_QUERIES_TOKEN", "")
|
||||
if MOONSTREAM_PUBLIC_QUERIES_TOKEN == "":
|
||||
raise ValueError("MOONSTREAM_PUBLIC_QUERIES_TOKEN environment variable must be set")
|
||||
|
||||
|
||||
MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID = os.environ.get(
|
||||
"MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID", ""
|
||||
)
|
||||
if MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID == "":
|
||||
raise ValueError(
|
||||
"MOONSTREAM_LEADERBOARD_GENERATOR_JOURNAL_ID environment variable must be set"
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue