dkg 1.1.1__py3-none-any.whl → 8.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dkg/asset.py +589 -683
- dkg/constants.py +106 -45
- dkg/data/interfaces/AskStorage.json +366 -0
- dkg/data/interfaces/Chronos.json +202 -0
- dkg/data/interfaces/Hub.json +294 -2
- dkg/data/interfaces/IdentityStorage.json +400 -0
- dkg/data/interfaces/KnowledgeCollection.json +610 -0
- dkg/data/interfaces/KnowledgeCollectionStorage.json +2312 -0
- dkg/data/interfaces/Paranet.json +656 -135
- dkg/data/interfaces/ParanetIncentivesPoolFactory.json +18 -2
- dkg/data/interfaces/ParanetKnowledgeMinersRegistry.json +20 -4
- dkg/data/interfaces/{ParanetNeurowebIncentivesPool.json → ParanetNeuroIncentivesPool.json} +7 -7
- dkg/data/interfaces/ParanetsRegistry.json +844 -36
- dkg/data/interfaces/Token.json +146 -17
- dkg/dataclasses.py +11 -1
- dkg/exceptions.py +1 -0
- dkg/graph.py +55 -24
- dkg/main.py +18 -2
- dkg/network.py +2 -2
- dkg/node.py +7 -0
- dkg/paranet.py +336 -33
- dkg/providers/blockchain.py +23 -24
- dkg/providers/node_http.py +11 -9
- dkg/services/input_service.py +183 -0
- dkg/services/node_service.py +164 -0
- dkg/types/__init__.py +15 -3
- dkg/types/general.py +15 -8
- dkg/utils/blockchain_request.py +189 -64
- dkg/utils/knowledge_asset_tools.py +5 -0
- dkg/utils/knowledge_collection_tools.py +236 -0
- dkg/utils/merkle.py +1 -1
- dkg/utils/node_request.py +33 -33
- dkg/utils/rdf.py +10 -6
- dkg/utils/string_transformations.py +1 -0
- {dkg-1.1.1.dist-info → dkg-8.0.0.dist-info}/METADATA +36 -26
- dkg-8.0.0.dist-info/RECORD +56 -0
- {dkg-1.1.1.dist-info → dkg-8.0.0.dist-info}/WHEEL +1 -1
- dkg/data/interfaces/AssertionStorage.json +0 -229
- dkg/data/interfaces/ContentAsset.json +0 -801
- dkg/data/interfaces/ContentAssetStorage.json +0 -782
- dkg/data/interfaces/ServiceAgreementStorageProxy.json +0 -1314
- dkg/data/interfaces/UnfinalizedStateStorage.json +0 -171
- dkg-1.1.1.dist-info/RECORD +0 -52
- {dkg-1.1.1.dist-info → dkg-8.0.0.dist-info}/LICENSE +0 -0
- {dkg-1.1.1.dist-info → dkg-8.0.0.dist-info}/NOTICE +0 -0
@@ -0,0 +1,183 @@
|
|
1
|
+
from dkg.constants import (
|
2
|
+
DefaultParameters,
|
3
|
+
ZERO_ADDRESS,
|
4
|
+
DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS,
|
5
|
+
)
|
6
|
+
|
7
|
+
|
8
|
+
class InputService:
|
9
|
+
def __init__(self, manager, config):
|
10
|
+
self.manager = manager
|
11
|
+
self.config = config
|
12
|
+
|
13
|
+
def get_asset_get_arguments(self, options):
|
14
|
+
return {
|
15
|
+
"max_number_of_retries": self.get_max_number_of_retries(options),
|
16
|
+
"frequency": self.get_frequency(options),
|
17
|
+
"state": self.get_state(options),
|
18
|
+
"include_metadata": self.get_include_metadata(options),
|
19
|
+
"content_type": self.get_content_type(options),
|
20
|
+
"validate": self.get_validate(options),
|
21
|
+
"output_format": self.get_output_format(options),
|
22
|
+
"hash_function_id": self.get_hash_function_id(options),
|
23
|
+
"paranet_ual": self.get_paranet_ual(options),
|
24
|
+
"subject_ual": self.get_subject_ual(options),
|
25
|
+
}
|
26
|
+
|
27
|
+
def get_asset_create_arguments(self, options):
|
28
|
+
return {
|
29
|
+
"max_number_of_retries": self.get_max_number_of_retries(options),
|
30
|
+
"frequency": self.get_frequency(options),
|
31
|
+
"epochs_num": self.get_epochs_num(options),
|
32
|
+
"hash_function_id": self.get_hash_function_id(options),
|
33
|
+
"score_function_id": self.get_score_function_id(options),
|
34
|
+
"immutable": self.get_immutable(options),
|
35
|
+
"token_amount": self.get_token_amount(options),
|
36
|
+
"payer": self.get_payer(options),
|
37
|
+
"minimum_number_of_finalization_confirmations": self.get_minimum_number_of_finalization_confirmations(
|
38
|
+
options
|
39
|
+
),
|
40
|
+
"minimum_number_of_node_replications": self.get_minimum_number_of_node_replications(
|
41
|
+
options
|
42
|
+
),
|
43
|
+
}
|
44
|
+
|
45
|
+
def get_query_arguments(self, options):
|
46
|
+
return {
|
47
|
+
"max_number_of_retries": self.get_max_number_of_retries(options),
|
48
|
+
"frequency": self.get_frequency(options),
|
49
|
+
"paranet_ual": self.get_paranet_ual(options),
|
50
|
+
"repository": self.get_repository(options),
|
51
|
+
}
|
52
|
+
|
53
|
+
def get_publish_finality_arguments(self, options):
|
54
|
+
return {
|
55
|
+
"max_number_of_retries": self.get_max_number_of_retries(options),
|
56
|
+
"frequency": self.get_frequency(options),
|
57
|
+
"minimum_number_of_finalization_confirmations": self.get_minimum_number_of_finalization_confirmations(
|
58
|
+
options
|
59
|
+
),
|
60
|
+
}
|
61
|
+
|
62
|
+
def get_max_number_of_retries(self, options):
|
63
|
+
return (
|
64
|
+
options.get("max_number_of_retries")
|
65
|
+
or self.config.get("max_number_of_retries")
|
66
|
+
or DefaultParameters.MAX_NUMBER_OF_RETRIES.value
|
67
|
+
)
|
68
|
+
|
69
|
+
def get_frequency(self, options):
|
70
|
+
return (
|
71
|
+
options.get("frequency")
|
72
|
+
or self.config.get("frequency")
|
73
|
+
or DefaultParameters.FREQUENCY.value
|
74
|
+
)
|
75
|
+
|
76
|
+
def get_state(self, options):
|
77
|
+
return (
|
78
|
+
options.get("state")
|
79
|
+
or self.config.get("state")
|
80
|
+
or DefaultParameters.STATE.value
|
81
|
+
)
|
82
|
+
|
83
|
+
def get_include_metadata(self, options):
|
84
|
+
return (
|
85
|
+
options.get("include_metadata")
|
86
|
+
or self.config.get("include_metadata")
|
87
|
+
or DefaultParameters.INCLUDE_METADATA.value
|
88
|
+
)
|
89
|
+
|
90
|
+
def get_content_type(self, options):
|
91
|
+
return (
|
92
|
+
options.get("content_type")
|
93
|
+
or self.config.get("content_type")
|
94
|
+
or DefaultParameters.CONTENT_TYPE.value
|
95
|
+
)
|
96
|
+
|
97
|
+
def get_validate(self, options):
|
98
|
+
return (
|
99
|
+
options.get("validate")
|
100
|
+
or self.config.get("validate")
|
101
|
+
or DefaultParameters.VALIDATE.value
|
102
|
+
)
|
103
|
+
|
104
|
+
def get_output_format(self, options):
|
105
|
+
return (
|
106
|
+
options.get("output_format")
|
107
|
+
or self.config.get("output_format")
|
108
|
+
or DefaultParameters.OUTPUT_FORMAT.value
|
109
|
+
)
|
110
|
+
|
111
|
+
def get_hash_function_id(self, options):
|
112
|
+
return (
|
113
|
+
options.get("hash_function_id")
|
114
|
+
or self.config.get("hash_function_id")
|
115
|
+
or DefaultParameters.HASH_FUNCTION_ID.value
|
116
|
+
)
|
117
|
+
|
118
|
+
def get_paranet_ual(self, options):
|
119
|
+
return (
|
120
|
+
options.get("paranet_ual")
|
121
|
+
or self.config.get("paranet_ual")
|
122
|
+
or DefaultParameters.PARANET_UAL.value
|
123
|
+
)
|
124
|
+
|
125
|
+
def get_subject_ual(self, options):
|
126
|
+
return (
|
127
|
+
options.get("subject_ual")
|
128
|
+
or self.config.get("subject_ual")
|
129
|
+
or DefaultParameters.GET_SUBJECT_UAL.value
|
130
|
+
)
|
131
|
+
|
132
|
+
def get_epochs_num(self, options):
|
133
|
+
return options.get("epochs_num") or self.config.get("epochs_num") or None
|
134
|
+
|
135
|
+
def get_immutable(self, options):
|
136
|
+
return (
|
137
|
+
options.get("immutable")
|
138
|
+
or self.config.get("immutable")
|
139
|
+
or DefaultParameters.IMMUTABLE.value
|
140
|
+
)
|
141
|
+
|
142
|
+
def get_token_amount(self, options):
|
143
|
+
return options.get("token_amount") or self.config.get("token_amount") or None
|
144
|
+
|
145
|
+
def get_payer(self, options):
|
146
|
+
return options.get("payer") or self.config.get("payer") or ZERO_ADDRESS
|
147
|
+
|
148
|
+
def get_minimum_number_of_finalization_confirmations(self, options):
|
149
|
+
return (
|
150
|
+
options.get("minimum_number_of_finalization_confirmations")
|
151
|
+
or self.config.get("minimum_number_of_finalization_confirmations")
|
152
|
+
or DefaultParameters.MIN_NUMBER_OF_FINALIZATION_CONFIRMATION.value
|
153
|
+
or None
|
154
|
+
)
|
155
|
+
|
156
|
+
def get_minimum_number_of_node_replications(self, options):
|
157
|
+
return (
|
158
|
+
options.get("minimum_number_of_node_replications")
|
159
|
+
or self.config.get("minimum_number_of_node_replications")
|
160
|
+
or None
|
161
|
+
)
|
162
|
+
|
163
|
+
def get_score_function_id(self, options):
|
164
|
+
environment = (
|
165
|
+
options.get("environment")
|
166
|
+
or self.config.get("environment")
|
167
|
+
or self.manager.blockchain_provider.environment
|
168
|
+
or DefaultParameters.ENVIRONMENT.value
|
169
|
+
)
|
170
|
+
blockchain_name = (
|
171
|
+
options.get("blockchain")
|
172
|
+
or self.config.get("blockchain")
|
173
|
+
or self.manager.blockchain_provider.blockchain_id
|
174
|
+
)
|
175
|
+
|
176
|
+
return DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[environment][blockchain_name]
|
177
|
+
|
178
|
+
def get_repository(self, options):
|
179
|
+
return (
|
180
|
+
options.get("repository")
|
181
|
+
or self.config.get("repository")
|
182
|
+
or DefaultParameters.REPOSITORY.value
|
183
|
+
)
|
@@ -0,0 +1,164 @@
|
|
1
|
+
from dkg.manager import DefaultRequestManager
|
2
|
+
from dkg.method import Method
|
3
|
+
from dkg.module import Module
|
4
|
+
import time
|
5
|
+
from dkg.utils.decorators import retry
|
6
|
+
from dkg.exceptions import (
|
7
|
+
OperationNotFinished,
|
8
|
+
)
|
9
|
+
from dkg.utils.node_request import (
|
10
|
+
NodeRequest,
|
11
|
+
validate_operation_status,
|
12
|
+
)
|
13
|
+
|
14
|
+
|
15
|
+
class NodeService(Module):
|
16
|
+
def __init__(self, manager: DefaultRequestManager):
|
17
|
+
self.manager = manager
|
18
|
+
|
19
|
+
_get_operation_result = Method(NodeRequest.get_operation_result)
|
20
|
+
_finality_status = Method(NodeRequest.finality_status)
|
21
|
+
_ask = Method(NodeRequest.ask)
|
22
|
+
_publish = Method(NodeRequest.publish)
|
23
|
+
_get = Method(NodeRequest.get)
|
24
|
+
_query = Method(NodeRequest.query)
|
25
|
+
|
26
|
+
def get_operation_result(
|
27
|
+
self, operation_id: str, operation: str, max_retries: int, frequency: int
|
28
|
+
):
|
29
|
+
@retry(
|
30
|
+
catch=OperationNotFinished,
|
31
|
+
max_retries=max_retries,
|
32
|
+
base_delay=frequency,
|
33
|
+
backoff=1,
|
34
|
+
)
|
35
|
+
def retry_get_operation_result():
|
36
|
+
operation_result = self._get_operation_result(
|
37
|
+
operation_id=operation_id,
|
38
|
+
operation=operation,
|
39
|
+
)
|
40
|
+
validate_operation_status(operation_result)
|
41
|
+
|
42
|
+
return operation_result
|
43
|
+
|
44
|
+
return retry_get_operation_result()
|
45
|
+
|
46
|
+
def finality_status(
|
47
|
+
self,
|
48
|
+
ual: str,
|
49
|
+
required_confirmations: int,
|
50
|
+
max_number_of_retries: int,
|
51
|
+
frequency: int,
|
52
|
+
):
|
53
|
+
retries = 0
|
54
|
+
finality = 0
|
55
|
+
|
56
|
+
while finality < required_confirmations and retries <= max_number_of_retries:
|
57
|
+
if retries > max_number_of_retries:
|
58
|
+
raise Exception(
|
59
|
+
f"Unable to achieve required confirmations. "
|
60
|
+
f"Max number of retries ({max_number_of_retries}) reached."
|
61
|
+
)
|
62
|
+
|
63
|
+
if retries > 0:
|
64
|
+
time.sleep(frequency)
|
65
|
+
|
66
|
+
retries += 1
|
67
|
+
|
68
|
+
try:
|
69
|
+
try:
|
70
|
+
response = self._finality_status(ual=ual)
|
71
|
+
except Exception as e:
|
72
|
+
response = None
|
73
|
+
print(f"failed: {e}")
|
74
|
+
|
75
|
+
if response is not None:
|
76
|
+
finality = response.get("finality", 0)
|
77
|
+
if finality >= required_confirmations:
|
78
|
+
break
|
79
|
+
|
80
|
+
except Exception:
|
81
|
+
finality = 0
|
82
|
+
|
83
|
+
return finality
|
84
|
+
|
85
|
+
def ask(self, ual, required_confirmations, max_number_of_retries, frequency):
|
86
|
+
ask = 0
|
87
|
+
retries = 0
|
88
|
+
|
89
|
+
while ask < required_confirmations and retries < max_number_of_retries:
|
90
|
+
if retries > max_number_of_retries:
|
91
|
+
raise Exception(
|
92
|
+
f"Unable to achieve required confirmations. "
|
93
|
+
f"Max number of retries ({max_number_of_retries}) reached."
|
94
|
+
)
|
95
|
+
|
96
|
+
if retries > 0:
|
97
|
+
time.sleep(frequency)
|
98
|
+
|
99
|
+
retries += 1
|
100
|
+
|
101
|
+
try:
|
102
|
+
try:
|
103
|
+
response = self._ask(
|
104
|
+
ual=ual, minimumNumberOfNodeReplications=required_confirmations
|
105
|
+
)
|
106
|
+
except Exception as e:
|
107
|
+
response = None
|
108
|
+
print(f"failed: {e}")
|
109
|
+
|
110
|
+
if response is not None:
|
111
|
+
number_of_confirmations = response.json().get(
|
112
|
+
"numberOfConfirmations", 0
|
113
|
+
)
|
114
|
+
if number_of_confirmations >= required_confirmations:
|
115
|
+
ask = number_of_confirmations
|
116
|
+
|
117
|
+
except Exception as e:
|
118
|
+
ask = 0
|
119
|
+
print(f"Retry {retries + 1}/{max_number_of_retries} failed: {e}")
|
120
|
+
|
121
|
+
return ask
|
122
|
+
|
123
|
+
def publish(
|
124
|
+
self,
|
125
|
+
dataset_root,
|
126
|
+
dataset,
|
127
|
+
blockchain_id,
|
128
|
+
hash_function_id,
|
129
|
+
minimum_number_of_node_replications,
|
130
|
+
):
|
131
|
+
return self._publish(
|
132
|
+
dataset_root,
|
133
|
+
dataset,
|
134
|
+
blockchain_id,
|
135
|
+
hash_function_id,
|
136
|
+
minimum_number_of_node_replications,
|
137
|
+
)
|
138
|
+
|
139
|
+
def get(
|
140
|
+
self,
|
141
|
+
ual_with_state,
|
142
|
+
content_type,
|
143
|
+
include_metadata,
|
144
|
+
hash_function_id,
|
145
|
+
paranet_ual,
|
146
|
+
subject_ual,
|
147
|
+
):
|
148
|
+
return self._get(
|
149
|
+
ual_with_state,
|
150
|
+
content_type,
|
151
|
+
include_metadata,
|
152
|
+
hash_function_id,
|
153
|
+
paranet_ual,
|
154
|
+
subject_ual,
|
155
|
+
)
|
156
|
+
|
157
|
+
def query(
|
158
|
+
self,
|
159
|
+
query,
|
160
|
+
query_type,
|
161
|
+
repository,
|
162
|
+
paranet_ual,
|
163
|
+
):
|
164
|
+
return self._query(query, query_type, repository, paranet_ual)
|
dkg/types/__init__.py
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
-
from .general import
|
2
|
-
|
3
|
-
|
1
|
+
from .general import (
|
2
|
+
AutoStrEnum, # NOQA: F401
|
3
|
+
AutoStrEnumCapitalize, # NOQA: F401
|
4
|
+
AutoStrEnumUpperCase, # NOQA: F401
|
5
|
+
)
|
6
|
+
from .blockchain import (
|
7
|
+
ABI, # NOQA: F401
|
8
|
+
ABIElement, # NOQA: F401
|
9
|
+
ABIError, # NOQA: F401
|
10
|
+
ABIEvent, # NOQA: F401
|
11
|
+
ABIFunction, # NOQA: F401
|
12
|
+
ABIParameter, # NOQA: F401
|
13
|
+
AgreementData, # NOQA: F401
|
14
|
+
Environment, # NOQA: F401
|
15
|
+
)
|
4
16
|
from .dkg_node import UAL # NOQA: F401
|
5
17
|
from .encoding import BytesLike, DataHexStr, HexStr # NOQA: F401
|
6
18
|
from .evm import Address, ChecksumAddress, Wei # NOQA: F401
|
dkg/types/general.py
CHANGED
@@ -17,28 +17,35 @@
|
|
17
17
|
|
18
18
|
from enum import Enum
|
19
19
|
|
20
|
+
|
20
21
|
class AutoStrEnum(str, Enum):
|
21
22
|
@staticmethod
|
22
|
-
def _generate_next_value_(
|
23
|
+
def _generate_next_value_(
|
24
|
+
name: str, start: int, count: int, last_values: list
|
25
|
+
) -> str:
|
23
26
|
return name.lower()
|
24
|
-
|
27
|
+
|
25
28
|
def __str__(self):
|
26
29
|
return str(self.value)
|
27
|
-
|
30
|
+
|
28
31
|
|
29
32
|
class AutoStrEnumCapitalize(str, Enum):
|
30
33
|
@staticmethod
|
31
|
-
def _generate_next_value_(
|
34
|
+
def _generate_next_value_(
|
35
|
+
name: str, start: int, count: int, last_values: list
|
36
|
+
) -> str:
|
32
37
|
return name.capitalize()
|
33
|
-
|
38
|
+
|
34
39
|
def __str__(self):
|
35
40
|
return str(self.value)
|
36
41
|
|
37
42
|
|
38
43
|
class AutoStrEnumUpperCase(str, Enum):
|
39
44
|
@staticmethod
|
40
|
-
def _generate_next_value_(
|
45
|
+
def _generate_next_value_(
|
46
|
+
name: str, start: int, count: int, last_values: list
|
47
|
+
) -> str:
|
41
48
|
return name
|
42
|
-
|
49
|
+
|
43
50
|
def __str__(self):
|
44
|
-
return str(self.value)
|
51
|
+
return str(self.value)
|