Configurable reader
This commit is contained in:
parent
fd9ccb48fa
commit
8dff57c4e3
|
@ -13,11 +13,8 @@ from frozendict import frozendict
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# mainnet: https://reader.partisiablockchain.com
|
HOSTNAME_MAINNET = 'reader.partisiablockchain.com'
|
||||||
# testnet: https://node1.testnet.partisiablockchain.com
|
HOSTNAME_TESTNET = 'node1.testnet.partisiablockchain.com'
|
||||||
|
|
||||||
|
|
||||||
HOSTNAME = 'reader.partisiablockchain.com'
|
|
||||||
|
|
||||||
URL_ACCOUNT_PLUGIN = 'https://{hostname}/{shard}blockchain/accountPlugin/local'
|
URL_ACCOUNT_PLUGIN = 'https://{hostname}/{shard}blockchain/accountPlugin/local'
|
||||||
URL_ACCOUNT_PLUGIN_GLOBAL = 'https://{hostname}/{shard}blockchain/accountPlugin/global'
|
URL_ACCOUNT_PLUGIN_GLOBAL = 'https://{hostname}/{shard}blockchain/accountPlugin/global'
|
||||||
|
@ -49,6 +46,7 @@ class Balances:
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class PbcClient:
|
class PbcClient:
|
||||||
session: requests.Session
|
session: requests.Session
|
||||||
|
hostname: str = HOSTNAME_MAINNET
|
||||||
|
|
||||||
def get_json(
|
def get_json(
|
||||||
self,
|
self,
|
||||||
|
@ -82,7 +80,7 @@ class PbcClient:
|
||||||
data: dict = {'path': []}
|
data: dict = {'path': []}
|
||||||
|
|
||||||
url: str = URL_ACCOUNT_PLUGIN_GLOBAL.format(
|
url: str = URL_ACCOUNT_PLUGIN_GLOBAL.format(
|
||||||
hostname=HOSTNAME,
|
hostname=self.hostname,
|
||||||
shard='',
|
shard='',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,7 +91,7 @@ class PbcClient:
|
||||||
coins = self.determine_coins()
|
coins = self.determine_coins()
|
||||||
|
|
||||||
url = URL_ACCOUNT_PLUGIN.format(
|
url = URL_ACCOUNT_PLUGIN.format(
|
||||||
hostname=HOSTNAME,
|
hostname=self.hostname,
|
||||||
shard=shard_id_for_address(address),
|
shard=shard_id_for_address(address),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -120,10 +118,9 @@ class PbcClient:
|
||||||
|
|
||||||
def get_contract_state(self, address: str) -> tuple[dict, datetime.datetime]:
|
def get_contract_state(self, address: str) -> tuple[dict, datetime.datetime]:
|
||||||
url = URL_CONTRACT_STATE.format(
|
url = URL_CONTRACT_STATE.format(
|
||||||
hostname=HOSTNAME,
|
hostname=self.hostname,
|
||||||
shard=shard_id_for_address(address),
|
shard=shard_id_for_address(address),
|
||||||
address=address,
|
address=address,
|
||||||
)
|
)
|
||||||
data: dict = {'path': []}
|
data: dict = {'path': []}
|
||||||
return self.get_json(url, data=data)
|
return self.get_json(url, data=data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user