Skip to content

Commit

Permalink
Moved few parameters to global constants
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed Oct 3, 2023
1 parent 0ec1cc3 commit fc0ad5d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
31 changes: 15 additions & 16 deletions dkg/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
from web3.constants import HASH_ZERO
from web3.exceptions import ContractLogicError

from dkg.constants import BLOCKCHAINS, PRIVATE_ASSERTION_PREDICATE
from dkg.constants import (BLOCKCHAINS, DEFAULT_HASH_FUNCTION_ID,
DEFAULT_SCORE_FUNCTION_ID,
PRIVATE_ASSERTION_PREDICATE,
PRIVATE_CURRENT_REPOSITORY,
PRIVATE_HISTORICAL_REPOSITORY)
from dkg.dataclasses import (KnowledgeAssetContentVisibility,
KnowledgeAssetEnumStates, NodeResponseDict)
from dkg.exceptions import (DatasetOutputFormatNotSupported,
Expand All @@ -47,11 +51,6 @@


class ContentAsset(Module):
DEFAULT_HASH_FUNCTION_ID = 1
DEFAULT_SCORE_FUNCTION_ID = 1
PRIVATE_HISTORICAL_REPOSITORY = "privateHistory"
PRIVATE_CURRENT_REPOSITORY = "privateCurrent"

def __init__(self, manager: DefaultRequestManager):
self.manager = manager

Expand Down Expand Up @@ -149,7 +148,7 @@ def create(
public_assertion_metadata["size"],
content_asset_storage_address,
public_assertion_id,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
)

Expand All @@ -166,7 +165,7 @@ def create(
"chunksNumber": public_assertion_metadata["chunks_number"],
"tokenAmount": token_amount,
"epochsNumber": epochs_number,
"scoreFunctionId": self.DEFAULT_SCORE_FUNCTION_ID,
"scoreFunctionId": DEFAULT_SCORE_FUNCTION_ID,
"immutable_": immutable,
}
)
Expand Down Expand Up @@ -217,7 +216,7 @@ def create(
chain_name,
content_asset_storage_address,
token_id,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["operationId"]
operation_result = self.get_operation_result(operation_id, "publish")

Expand Down Expand Up @@ -303,7 +302,7 @@ def update(
public_assertion_metadata["size"],
content_asset_storage_address,
public_assertion_id,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
)

Expand Down Expand Up @@ -363,7 +362,7 @@ def update(
chain_name,
content_asset_storage_address,
token_id,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["operationId"]
operation_result = self.get_operation_result(operation_id, "update")

Expand Down Expand Up @@ -568,9 +567,9 @@ def handle_latest_finalized_state(token_id: int) -> tuple[HexStr, bool]:
query_private_operation_id = self._query(
query,
"CONSTRUCT",
self.PRIVATE_CURRENT_REPOSITORY
PRIVATE_CURRENT_REPOSITORY
if is_state_finalized
else self.PRIVATE_HISTORICAL_REPOSITORY,
else PRIVATE_HISTORICAL_REPOSITORY,
)["operationId"]

query_private_operation_result = self.get_operation_result(
Expand Down Expand Up @@ -659,7 +658,7 @@ def extend_storing_period(
latest_finalized_state_size,
content_asset_storage_address,
latest_finalized_state,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
)

Expand Down Expand Up @@ -713,7 +712,7 @@ def add_tokens(
latest_finalized_state_size,
content_asset_storage_address,
latest_finalized_state,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
) - sum(agreement_data.tokensInfo)

Expand Down Expand Up @@ -771,7 +770,7 @@ def add_update_tokens(
unfinalized_state_size,
content_asset_storage_address,
unfinalized_state,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
) - sum(agreement_data.tokensInfo)

Expand Down
6 changes: 6 additions & 0 deletions dkg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@
"hubAddress": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
},
}

DEFAULT_HASH_FUNCTION_ID = 1
DEFAULT_SCORE_FUNCTION_ID = 1

PRIVATE_HISTORICAL_REPOSITORY = "privateHistory"
PRIVATE_CURRENT_REPOSITORY = "privateCurrent"
6 changes: 2 additions & 4 deletions dkg/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from dkg.constants import BLOCKCHAINS
from dkg.constants import BLOCKCHAINS, DEFAULT_HASH_FUNCTION_ID
from dkg.manager import DefaultRequestManager
from dkg.method import Method
from dkg.module import Module
Expand All @@ -25,8 +25,6 @@


class Network(Module):
DEFAULT_HASH_FUNCTION_ID = 1

def __init__(self, manager: DefaultRequestManager):
self.manager = manager

Expand All @@ -50,6 +48,6 @@ def get_bid_suggestion(
size_in_bytes,
content_asset_storage_address,
public_assertion_id,
self.DEFAULT_HASH_FUNCTION_ID,
DEFAULT_HASH_FUNCTION_ID,
)["bidSuggestion"]
)

0 comments on commit fc0ad5d

Please sign in to comment.