Skip to content
Snippets Groups Projects
Commit 48493602 authored by Krzysztof Mochocki's avatar Krzysztof Mochocki Committed by Mateusz Żebrak
Browse files

UpdateNodeData returns dynamic global properties

parent eeec79ed
No related branches found
No related tags found
3 merge requests!186V1.27.5.0 release,!174RELEASE: 1,!102Redesign header
...@@ -5,10 +5,11 @@ from datetime import datetime, timedelta, timezone ...@@ -5,10 +5,11 @@ from datetime import datetime, timedelta, timezone
from math import ceil from math import ceil
from typing import TYPE_CHECKING, Final, cast from typing import TYPE_CHECKING, Final, cast
from clive.__private.core.commands.abc.command import Command from clive.__private.core.commands.abc.command_with_result import CommandWithResult
from clive.__private.core.iwax import calculate_current_manabar_value, calculate_manabar_full_regeneration_time from clive.__private.core.iwax import calculate_current_manabar_value, calculate_manabar_full_regeneration_time
from clive.exceptions import CommunicationError from clive.exceptions import CommunicationError
from clive.models import Asset from clive.models import Asset
from schemas.database_api.response_schemas import GetDynamicGlobalProperties
if TYPE_CHECKING: if TYPE_CHECKING:
from types import TracebackType from types import TracebackType
...@@ -18,10 +19,9 @@ if TYPE_CHECKING: ...@@ -18,10 +19,9 @@ if TYPE_CHECKING:
from clive.__private.storage.mock_database import Account from clive.__private.storage.mock_database import Account
from schemas.__private.hive_fields_custom_schemas import Manabar from schemas.__private.hive_fields_custom_schemas import Manabar
from schemas.database_api.fundaments_of_reponses import AccountItemFundament from schemas.database_api.fundaments_of_reponses import AccountItemFundament
from schemas.database_api.response_schemas import GetDynamicGlobalProperties
from schemas.rc_api.fundaments_of_responses import RcAccount from schemas.rc_api.fundaments_of_responses import RcAccount
GDPOT = GetDynamicGlobalProperties[Asset.Hive, Asset.Hbd, Asset.Vests] DynamicGlobalPropertiesT = GetDynamicGlobalProperties[Asset.Hive, Asset.Hbd, Asset.Vests]
class SuppressNotExistingApi: class SuppressNotExistingApi:
...@@ -39,7 +39,7 @@ class SuppressNotExistingApi: ...@@ -39,7 +39,7 @@ class SuppressNotExistingApi:
@dataclass @dataclass
class UpdateNodeData(Command): class UpdateNodeData(CommandWithResult[DynamicGlobalPropertiesT]):
accounts: list[Account] accounts: list[Account]
node: Node node: Node
...@@ -56,6 +56,7 @@ class UpdateNodeData(Command): ...@@ -56,6 +56,7 @@ class UpdateNodeData(Command):
api_accounts = self.__harvest_data_from_api() api_accounts = self.__harvest_data_from_api()
gdpo = self.node.api.database_api.get_dynamic_global_properties() gdpo = self.node.api.database_api.get_dynamic_global_properties()
self._result = gdpo
for account, info in api_accounts.items(): for account, info in api_accounts.items():
account.data.reputation = info.reputation account.data.reputation = info.reputation
...@@ -189,7 +190,7 @@ class UpdateNodeData(Command): ...@@ -189,7 +190,7 @@ class UpdateNodeData(Command):
def __calculate_hive_power( def __calculate_hive_power(
self, self,
gdpo: GDPOT, gdpo: DynamicGlobalPropertiesT,
account: AccountItemFundament[Asset.Hive, Asset.Hbd, Asset.Vests], account: AccountItemFundament[Asset.Hive, Asset.Hbd, Asset.Vests],
) -> int: ) -> int:
account_vesting_shares = ( account_vesting_shares = (
...@@ -205,7 +206,9 @@ class UpdateNodeData(Command): ...@@ -205,7 +206,9 @@ class UpdateNodeData(Command):
), ),
) )
def __update_manabar(self, gdpo: GDPOT, max_mana: int, manabar: Manabar, dest: mock_database.Manabar) -> None: def __update_manabar(
self, gdpo: DynamicGlobalPropertiesT, max_mana: int, manabar: Manabar, dest: mock_database.Manabar
) -> None:
power_from_api = int(manabar.current_mana) power_from_api = int(manabar.current_mana)
last_update = int(manabar.last_update_time) last_update = int(manabar.last_update_time)
dest.max_value = int(self.__vests_to_hive(max_mana, gdpo).amount) dest.max_value = int(self.__vests_to_hive(max_mana, gdpo).amount)
...@@ -231,7 +234,7 @@ class UpdateNodeData(Command): ...@@ -231,7 +234,7 @@ class UpdateNodeData(Command):
- gdpo.time - gdpo.time
) )
def __vests_to_hive(self, amount: int | Asset.Vests, gdpo: GDPOT) -> Asset.Hive: def __vests_to_hive(self, amount: int | Asset.Vests, gdpo: DynamicGlobalPropertiesT) -> Asset.Hive:
if isinstance(amount, Asset.Vests): if isinstance(amount, Asset.Vests):
amount = int(amount.amount) amount = int(amount.amount)
return Asset.Hive( return Asset.Hive(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment