Skip to content

Commit

Permalink
Merge pull request #102 from HathorNetwork/dev
Browse files Browse the repository at this point in the history
Release v0.1.12
  • Loading branch information
r4mmer authored Nov 25, 2021
2 parents 2a3457e + 894a764 commit 0f4cfb1
Show file tree
Hide file tree
Showing 15 changed files with 815 additions and 28 deletions.
9 changes: 7 additions & 2 deletions gateways/clients/hathor_core_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@

logger = get_logger()

STATUS_ENDPOINT = '/v1a/status'
TOKEN_ENDPOINT = '/v1a/thin_wallet/token'
ADDRESS_BALANCE_ENDPOINT = '/v1a/thin_wallet/address_balance'
ADDRESS_SEARCH_ENDPOINT = '/v1a/thin_wallet/address_search'
DASHBOARD_TX_ENDPOINT = '/v1a/dashboard_tx'
STATUS_ENDPOINT = '/v1a/status'
TOKEN_ENDPOINT = '/v1a/thin_wallet/token'
TOKEN_HISTORY_ENDPOINT = '/v1a/thin_wallet/token_history'
TRANSACTION_ENDPOINT = '/v1a/transaction'
TX_ACC_WEIGHT_ENDPOINT = '/v1a/transaction_acc_weight'
VERSION_ENDPOINT = '/v1a/version'


class HathorCoreAsyncClient:
Expand Down
81 changes: 80 additions & 1 deletion gateways/node_api_gateway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
from typing import Optional

from gateways.clients.cache_client import ADDRESS_BLACKLIST_COLLECTION_NAME, CacheClient
from gateways.clients.hathor_core_client import ADDRESS_BALANCE_ENDPOINT, ADDRESS_SEARCH_ENDPOINT, HathorCoreClient
from gateways.clients.hathor_core_client import (
ADDRESS_BALANCE_ENDPOINT,
ADDRESS_SEARCH_ENDPOINT,
DASHBOARD_TX_ENDPOINT,
TOKEN_ENDPOINT,
TOKEN_HISTORY_ENDPOINT,
TRANSACTION_ENDPOINT,
TX_ACC_WEIGHT_ENDPOINT,
VERSION_ENDPOINT,
HathorCoreClient,
)


class NodeApiGateway:
Expand Down Expand Up @@ -74,3 +84,72 @@ def get_address_search(
params=params,
timeout=10,
)

def get_version(self) -> Optional[dict]:
"""Retrieve version information
"""

return self.hathor_core_client.get(VERSION_ENDPOINT)

def get_dashboard_tx(self, block: int, tx: int) -> Optional[dict]:
"""Retrieve info on blocks and transaction to show on dashboard
"""

return self.hathor_core_client.get(DASHBOARD_TX_ENDPOINT, params={'tx': tx, 'block': block})

def get_transaction_acc_weight(self, id: str) -> Optional[dict]:
"""Retrieve acc weight for a tx
"""

return self.hathor_core_client.get(TX_ACC_WEIGHT_ENDPOINT, params={'id': id})

def get_token_history(
self,
id: str,
count: int,
hash: Optional[str] = None,
page: Optional[str] = None,
timestamp: Optional[int] = None) -> Optional[dict]:
"""Retrieve token history
"""

params = {'id': id, 'count': count}
if hash:
params['hash'] = hash
params['page'] = page
params['timestamp'] = timestamp

return self.hathor_core_client.get(TOKEN_HISTORY_ENDPOINT, params=params)

def get_transaction(self, id: str) -> Optional[dict]:
"""Retrieve transaction by id
"""
return self.hathor_core_client.get(TRANSACTION_ENDPOINT, params={'id': id})

def list_transactions(
self,
type: str,
count: int,
hash: Optional[str] = None,
page: Optional[str] = None,
timestamp: Optional[int] = None) -> Optional[dict]:
"""Retrieve list of transactions
"""

params = {'type': type, 'count': count}
if hash:
params['hash'] = hash
params['page'] = page
params['timestamp'] = timestamp

return self.hathor_core_client.get(TRANSACTION_ENDPOINT, params=params)

def get_token(self, id: str) -> Optional[dict]:
"""Retrieve token by id
"""
return self.hathor_core_client.get(TOKEN_ENDPOINT, params={'id': id})

def list_tokens(self) -> Optional[dict]:
"""Retrieve list of tokens
"""
return self.hathor_core_client.get(TOKEN_ENDPOINT)
Loading

0 comments on commit 0f4cfb1

Please sign in to comment.