Skip to content

Commit

Permalink
Merge pull request #233 from planetarium/release/0.10.0
Browse files Browse the repository at this point in the history
0.10.0
  • Loading branch information
U-lis authored Jan 31, 2024
2 parents 85e8230 + 07c3abb commit 6930dff
Show file tree
Hide file tree
Showing 27 changed files with 594 additions and 113 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
HEADLESS: ${{ vars.HEADLESS }}
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
Expand Down Expand Up @@ -163,6 +165,8 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
HEADLESS: ${{ vars.HEADLESS }}
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- development
- internal
- release/*
- main
pull_request:
Expand All @@ -16,7 +17,7 @@ jobs:
test:
uses: ./.github/workflows/test.yml
with:
environment: ${{ github.ref == 'refs/heads/main' && 'mainnet' || (startsWith(github.ref, 'refs/heads/release') && 'internal' || 'development') }}
environment: ${{ github.ref == 'refs/heads/main' && 'mainnet' || ((github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release')) && 'internal' || 'development') }}
secrets:
APPLE_CREDENTIAL: ${{ secrets.APPLE_CREDENTIAL }}
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
Expand All @@ -28,14 +29,14 @@ jobs:
build_frontend:
uses: ./.github/workflows/build_frontend.yml
with:
environment: ${{ github.ref == 'refs/heads/main' && 'mainnet' || (startsWith(github.ref, 'refs/heads/release') && 'internal' || 'development') }}
environment: ${{ github.ref == 'refs/heads/main' && 'mainnet' || ((github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release')) && 'internal' || 'development') }}
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

synth:
uses: ./.github/workflows/synth.yml
with:
environment: ${{ startsWith(github.ref, 'refs/heads/release') && 'internal' || 'development' }}
environment: ${{ github.ref == 'refs/heads/main' && 'mainnet' || ((github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release')) && 'internal' || 'development') }}
secrets:
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand All @@ -58,11 +59,11 @@ jobs:

deploy_without_approval:
# This is for development / internal deployment
if: ${{ github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/heads/release') }}
if: ${{ github.ref == 'refs/heads/development' || github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release') }}
needs: [ "test", "build_frontend", "synth" ]
uses: ./.github/workflows/deploy.yml
with:
environment: ${{ startsWith(github.ref, 'refs/heads/release') && 'internal' || 'development' }}
environment: ${{ (github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release')) && 'internal' || 'development' }}
secrets:
ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/synth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
HEADLESS: ${{ vars.HEADLESS }}
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
Expand Down
2 changes: 2 additions & 0 deletions common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Config:
account_id: str
region_name: str
cdn_host: str
odin_gql_url: str
heimdall_gql_url: str

# Multiplanetary
planet_url: str
Expand Down
22 changes: 22 additions & 0 deletions common/_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ def _unload_from_garage(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
result = self.execute(query)
return bytes.fromhex(result["actionTxQuery"]["unloadFromMyGarages"])

def _claim_items(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
ts = kwargs.get("timestamp", (datetime.datetime.utcnow()+datetime.timedelta(days=1)).isoformat())
claim_data = kwargs.get("claim_data")
memo = kwargs.get("memo")

query = dsl_gql(
DSLQuery(
self.ds.StandaloneQuery.actionTxQuery.args(
publicKey=pubkey.hex(),
nonce=nonce,
timestamp=ts,
).select(
self.ds.ActionTxQuery.claimItems.args(
claimData=claim_data,
memo=memo,
)
)
)
)
result = self.execute(query)
return bytes.fromhex(result["actionTxQuery"]["unloadFromMyGarages"])

def _transfer_asset(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
ts = kwargs.get("timestamp", (datetime.datetime.utcnow()+datetime.timedelta(days=1)).isoformat())
sender = kwargs.get("sender")
Expand Down
59 changes: 59 additions & 0 deletions common/alembic/versions/90ff6ac09fe5_add_required_level_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Add required_level column
Revision ID: 90ff6ac09fe5
Revises: a2df38682595
Create Date: 2024-01-22 12:31:38.823682
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '90ff6ac09fe5'
down_revision = 'a2df38682595'
branch_labels = None
depends_on = None

old_enum = ("INIT", "VALIDATION_REQUEST", "VALID", "REFUNDED_BY_ADMIN", "INVALID", "REFUNDED_BY_BUYER",
"PURCHASE_LIMIT_EXCEED", "TIME_LIMIT", "UNKNOWN")
new_enum = sorted(old_enum + ("REQUIRED_LEVEL",))

old_status = sa.Enum(*old_enum, name="receiptstatus")
new_status = sa.Enum(*new_enum, name="receiptstatus")
tmp_status = sa.Enum(*new_enum, name="_receiptstatus")

receipt_table = sa.sql.table(
"receipt",
sa.Column("status", new_status, nullable=False)
)


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
tmp_status.create(op.get_bind(), checkfirst=False)
op.execute("ALTER TABLE receipt ALTER COLUMN status TYPE _receiptstatus USING status::text::_receiptstatus")
old_status.drop(op.get_bind(), checkfirst=False)
new_status.create(op.get_bind(), checkfirst=False)
op.execute("ALTER TABLE receipt ALTER COLUMN status TYPE receiptstatus USING status::text::receiptstatus")
tmp_status.drop(op.get_bind(), checkfirst=False)

op.add_column('product', sa.Column('required_level', sa.Integer(), nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('product', 'required_level')

op.execute(receipt_table.update()
.where(receipt_table.c.status.in_(['REQUIRED_LEVEL']))
.values(status="INVALID")
)
tmp_status.create(op.get_bind(), checkfirst=False)
op.execute("ALTER TABLE receipt ALTER COLUMN status TYPE _receiptstatus USING status::text::_receiptstatus")
new_status.drop(op.get_bind(), checkfirst=False)
old_status.create(op.get_bind(), checkfirst=False)
op.execute("ALTER TABLE receipt ALTER COLUMN status TYPE receiptstatus USING status::text::receiptstatus")
tmp_status.drop(op.get_bind(), checkfirst=False)
# ### end Alembic commands ###
30 changes: 30 additions & 0 deletions common/alembic/versions/a2df38682595_add_is_free_column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Add is_free column
Revision ID: a2df38682595
Revises: 2822c456abc3
Create Date: 2024-01-18 13:55:23.731546
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'a2df38682595'
down_revision = '2822c456abc3'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('product', sa.Column('is_free', sa.Boolean(), nullable=True, default=False))
op.execute("UPDATE product SET is_free=FALSE")
op.alter_column("product", "is_free", nullable=False)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('product', 'is_free')
# ### end Alembic commands ###
5 changes: 5 additions & 0 deletions common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class ReceiptStatus(IntEnum):
Purchase timestamp is not between target product's open/close timestamp.
This purchase is executed in appstore, so admin should refund this purchase in manual.
- **95: `REQUIRED_LEVEL`**
Does not met required level to get this product.
- **99: `UNKNOWN`**
An unhandled error case. This is reserve to catch all other errors.
Expand All @@ -145,6 +149,7 @@ class ReceiptStatus(IntEnum):
REFUNDED_BY_BUYER = 92
PURCHASE_LIMIT_EXCEED = 93
TIME_LIMIT = 94
REQUIRED_LEVEL = 95
UNKNOWN = 99


Expand Down
31 changes: 0 additions & 31 deletions common/lib9c/currency.py

This file was deleted.

16 changes: 0 additions & 16 deletions common/lib9c/fungible_asset.py

This file was deleted.

24 changes: 24 additions & 0 deletions common/lib9c/models/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations


class Address:
def __init__(self, addr: str):
if addr.startswith("0x"):
if len(addr) != 42:
raise ValueError("Address with 0x prefix must have exact 42 chars.")
self.raw = bytes.fromhex(addr[2:])
else:
if len(addr) != 40:
raise ValueError("Address without 0x prefix must have exact 40 chars.")
self.raw = bytes.fromhex(addr)

@property
def long_format(self):
return f"0x{self.raw.hex()}"

@property
def short_format(self):
return self.raw.hex()

def __eq__(self, other: Address):
return self.raw == other.raw
62 changes: 62 additions & 0 deletions common/lib9c/models/currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from __future__ import annotations

from typing import Dict, List, Optional, Any

import bencodex

from common.lib9c.models.address import Address


class Currency:
"""
# Currency
---
Lib9c Currency model which has ticker, minters, decimal_places, total_supply_trackable.
`minters` will be automatically sanitized to `None` if empty list provided.
"""

def __init__(self, ticker: str, decimal_places: int, minters: Optional[List[str]] = None,
total_supply_trackable: bool = False):
self.ticker = ticker
self.minters = [Address(x) for x in minters] if minters else None
self.decimal_places = decimal_places
self.total_supply_trackable = total_supply_trackable

def __eq__(self, other: Currency):
return (
self.ticker == other.ticker and
self.minters == other.minters and
self.decimal_places == other.decimal_places and
self.total_supply_trackable == other.total_supply_trackable
)

@classmethod
def NCG(cls):
return cls(
ticker="NCG",
minters=["47d082a115c63e7b58b1532d20e631538eafadde"],
decimal_places=2
)

@classmethod
def CRYSTAL(cls):
return cls(
ticker="CRYSTAL",
minters=None,
decimal_places=18
)

@property
def plain_value(self) -> Dict[str, Any]:
value = {
"ticker": self.ticker,
"decimalPlaces": chr(self.decimal_places).encode(),
"minters": [x.short_format for x in self.minters] if self.minters else None
}
if self.total_supply_trackable:
value["totalSupplyTrackable"] = True
return value

@property
def serialized_plain_value(self) -> bytes:
return bencodex.dumps(self.plain_value)
36 changes: 36 additions & 0 deletions common/lib9c/models/fungible_asset_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from __future__ import annotations

from decimal import Decimal
from typing import Dict, List, Optional, Any

import bencodex

from common.lib9c.models.currency import Currency


class FungibleAssetValue:
def __init__(self, currency: Currency, amount: Decimal):
self.currency = currency
self.amount = amount

def __eq__(self, other: FungibleAssetValue):
return self.currency == other.currency and self.amount == other.amount

@classmethod
def from_raw_data(
cls,
ticker: str, decimal_places: int, minters: Optional[List[str]] = None, total_supply_trackable: bool = False,
amount: Decimal = Decimal("0")
):
return cls(
Currency(ticker, decimal_places, minters, total_supply_trackable),
amount=amount
)

@property
def plain_value(self) -> List[Dict[str, Any] | int]:
return [self.currency.plain_value, int(self.amount * max(1, 10 ** self.currency.decimal_places))]

@property
def serialized_plain_value(self) -> bytes:
return bencodex.dumps(self.plain_value)
Loading

0 comments on commit 6930dff

Please sign in to comment.