dkg 0.1.0b6__py3-none-any.whl → 1.1.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 +106 -28
- dkg/constants.py +18 -10
- dkg/data/interfaces/ContentAsset.json +133 -3
- dkg/data/interfaces/Paranet.json +821 -0
- dkg/data/interfaces/{Identity.json → ParanetIncentivesPoolFactory.json} +67 -86
- dkg/data/interfaces/ParanetKnowledgeMinersRegistry.json +919 -0
- dkg/data/interfaces/ParanetNeurowebIncentivesPool.json +1102 -0
- dkg/data/interfaces/{ServiceAgreementStorageV1.json → ParanetsRegistry.json} +331 -360
- dkg/dataclasses.py +28 -8
- dkg/exceptions.py +1 -1
- dkg/main.py +6 -3
- dkg/method.py +55 -39
- dkg/module.py +1 -0
- dkg/network.py +20 -10
- dkg/paranet.py +476 -0
- dkg/providers/blockchain.py +57 -26
- dkg/types/__init__.py +1 -0
- dkg/types/general.py +44 -0
- dkg/utils/blockchain_request.py +149 -4
- dkg/utils/node_request.py +77 -80
- {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/METADATA +3 -141
- dkg-1.1.0.dist-info/NOTICE +9 -0
- dkg-1.1.0.dist-info/RECORD +52 -0
- {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/WHEEL +1 -1
- dkg/data/interfaces/Assertion.json +0 -157
- dkg/data/interfaces/CommitManagerV1.json +0 -549
- dkg/data/interfaces/CommitManagerV1U1.json +0 -735
- dkg/data/interfaces/HashingProxy.json +0 -253
- dkg/data/interfaces/IdentityStorage.json +0 -342
- dkg/data/interfaces/ParametersStorage.json +0 -487
- dkg/data/interfaces/Profile.json +0 -318
- dkg/data/interfaces/ProfileStorage.json +0 -596
- dkg/data/interfaces/ProofManagerV1.json +0 -540
- dkg/data/interfaces/ProofManagerV1U1.json +0 -561
- dkg/data/interfaces/ScoringProxy.json +0 -268
- dkg/data/interfaces/ServiceAgreementStorageV1U1.json +0 -1097
- dkg/data/interfaces/ServiceAgreementV1.json +0 -745
- dkg/data/interfaces/ShardingTable.json +0 -294
- dkg/data/interfaces/ShardingTableStorage.json +0 -317
- dkg/data/interfaces/Staking.json +0 -482
- dkg/data/interfaces/StakingStorage.json +0 -407
- dkg/data/interfaces/WhitelistStorage.json +0 -124
- dkg-0.1.0b6.dist-info/RECORD +0 -64
- {dkg-0.1.0b6.dist-info → dkg-1.1.0.dist-info}/LICENSE +0 -0
dkg/dataclasses.py
CHANGED
@@ -15,10 +15,13 @@
|
|
15
15
|
# specific language governing permissions and limitations
|
16
16
|
# under the License.
|
17
17
|
|
18
|
-
from
|
18
|
+
from dataclasses import dataclass
|
19
|
+
from enum import auto, Enum
|
19
20
|
|
20
21
|
import pandas as pd
|
21
22
|
|
23
|
+
from dkg.types import AutoStrEnum, AutoStrEnumCapitalize, AutoStrEnumUpperCase
|
24
|
+
|
22
25
|
|
23
26
|
class BlockchainResponseDict(dict):
|
24
27
|
pass
|
@@ -34,12 +37,29 @@ class NodeResponseDict(dict):
|
|
34
37
|
return pd.DataFrame(self)
|
35
38
|
|
36
39
|
|
37
|
-
class
|
38
|
-
|
39
|
-
|
40
|
+
class BidSuggestionRange(AutoStrEnum):
|
41
|
+
LOW = auto()
|
42
|
+
MEDIUM = auto()
|
43
|
+
HIGH = auto()
|
44
|
+
ALL = auto()
|
45
|
+
|
46
|
+
|
47
|
+
class KnowledgeAssetEnumStates(AutoStrEnumUpperCase):
|
48
|
+
LATEST = auto()
|
49
|
+
LATEST_FINALIZED = auto()
|
50
|
+
|
51
|
+
|
52
|
+
class KnowledgeAssetContentVisibility(AutoStrEnumUpperCase):
|
53
|
+
ALL = auto()
|
54
|
+
PUBLIC = auto()
|
55
|
+
PRIVATE = auto()
|
56
|
+
|
57
|
+
|
58
|
+
class ParanetIncentivizationType(AutoStrEnumCapitalize):
|
59
|
+
NEUROWEB = auto()
|
40
60
|
|
41
61
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
62
|
+
@dataclass
|
63
|
+
class BaseIncentivesPoolParams:
|
64
|
+
def to_contract_args(self) -> dict:
|
65
|
+
raise NotImplementedError("This method should be overridden in subclasses")
|
dkg/exceptions.py
CHANGED
dkg/main.py
CHANGED
@@ -18,12 +18,13 @@
|
|
18
18
|
from functools import wraps
|
19
19
|
|
20
20
|
from dkg.assertion import Assertion
|
21
|
-
from dkg.asset import
|
21
|
+
from dkg.asset import KnowledgeAsset
|
22
22
|
from dkg.graph import Graph
|
23
23
|
from dkg.manager import DefaultRequestManager
|
24
24
|
from dkg.module import Module
|
25
25
|
from dkg.network import Network
|
26
26
|
from dkg.node import Node
|
27
|
+
from dkg.paranet import Paranet
|
27
28
|
from dkg.providers import BlockchainProvider, NodeHTTPProvider
|
28
29
|
from dkg.types import UAL, Address, ChecksumAddress
|
29
30
|
from dkg.utils.ual import format_ual, parse_ual
|
@@ -31,7 +32,8 @@ from dkg.utils.ual import format_ual, parse_ual
|
|
31
32
|
|
32
33
|
class DKG(Module):
|
33
34
|
assertion: Assertion
|
34
|
-
asset:
|
35
|
+
asset: KnowledgeAsset
|
36
|
+
paranet: Paranet
|
35
37
|
network: Network
|
36
38
|
node: Node
|
37
39
|
graph: Graph
|
@@ -56,7 +58,8 @@ class DKG(Module):
|
|
56
58
|
self.manager = DefaultRequestManager(node_provider, blockchain_provider)
|
57
59
|
modules = {
|
58
60
|
"assertion": Assertion(self.manager),
|
59
|
-
"asset":
|
61
|
+
"asset": KnowledgeAsset(self.manager),
|
62
|
+
"paranet": Paranet(self.manager),
|
60
63
|
"network": Network(self.manager),
|
61
64
|
"node": Node(self.manager),
|
62
65
|
"graph": Graph(self.manager),
|
dkg/method.py
CHANGED
@@ -21,8 +21,11 @@ from typing import TYPE_CHECKING, Any, Generic, Type
|
|
21
21
|
|
22
22
|
from dkg.exceptions import ValidationError
|
23
23
|
from dkg.types import TFunc
|
24
|
-
from dkg.utils.blockchain_request import (
|
25
|
-
|
24
|
+
from dkg.utils.blockchain_request import (
|
25
|
+
ContractInteraction,
|
26
|
+
ContractTransaction,
|
27
|
+
JSONRPCRequest,
|
28
|
+
)
|
26
29
|
from dkg.utils.node_request import NodeCall
|
27
30
|
from dkg.utils.string_transformations import snake_to_camel
|
28
31
|
|
@@ -50,48 +53,21 @@ class Method(Generic[TFunc]):
|
|
50
53
|
case JSONRPCRequest():
|
51
54
|
return {"args": self._validate_and_map(self.action.args, args, kwargs)}
|
52
55
|
case ContractInteraction():
|
56
|
+
contract = kwargs.pop("contract", None)
|
57
|
+
if not self.action.contract:
|
58
|
+
if contract:
|
59
|
+
self.action.contract = contract
|
60
|
+
else:
|
61
|
+
raise ValidationError(
|
62
|
+
"ContractInteraction requires a 'contract' to be provided"
|
63
|
+
)
|
64
|
+
|
53
65
|
return {
|
54
66
|
"args": self._validate_and_map(self.action.args, args, kwargs),
|
55
67
|
"state_changing": isinstance(self.action, ContractTransaction),
|
56
68
|
}
|
57
69
|
case NodeCall():
|
58
|
-
|
59
|
-
|
60
|
-
args_in_path = 0
|
61
|
-
path_args = []
|
62
|
-
path_kwargs = {}
|
63
|
-
if len(path_placeholders) > 0:
|
64
|
-
for placeholder in path_placeholders:
|
65
|
-
if (placeholder != "") and (placeholder in kwargs.keys()):
|
66
|
-
path_kwargs[placeholder] = kwargs.pop(placeholder)
|
67
|
-
else:
|
68
|
-
if len(args) <= args_in_path:
|
69
|
-
raise ValidationError(
|
70
|
-
"Number of given arguments can't be smaller than "
|
71
|
-
"number of path placeholders"
|
72
|
-
)
|
73
|
-
|
74
|
-
if placeholder == "":
|
75
|
-
path_args.append(args[args_in_path])
|
76
|
-
else:
|
77
|
-
path_kwargs[placeholder] = args[args_in_path]
|
78
|
-
|
79
|
-
args_in_path += 1
|
80
|
-
|
81
|
-
return {
|
82
|
-
"path": self.action.path.format(*path_args, **path_kwargs),
|
83
|
-
"params": self._validate_and_map(
|
84
|
-
self.action.params, args[args_in_path:], kwargs
|
85
|
-
)
|
86
|
-
if self.action.params
|
87
|
-
else {},
|
88
|
-
"data": self._validate_and_map(
|
89
|
-
self.action.data, args[args_in_path:], kwargs
|
90
|
-
)
|
91
|
-
if self.action.data
|
92
|
-
else {},
|
93
|
-
}
|
94
|
-
|
70
|
+
return self._process_node_call_args(args, kwargs)
|
95
71
|
case _:
|
96
72
|
return {}
|
97
73
|
|
@@ -129,3 +105,43 @@ class Method(Generic[TFunc]):
|
|
129
105
|
)
|
130
106
|
|
131
107
|
return processed_args
|
108
|
+
|
109
|
+
def _process_node_call_args(
|
110
|
+
self, args: list[Any], kwargs: dict[str, Any]
|
111
|
+
) -> dict[str, Any]:
|
112
|
+
path_placeholders = re.findall(r"\{([^{}]+)?\}", self.action.path)
|
113
|
+
|
114
|
+
args_in_path = 0
|
115
|
+
path_args = []
|
116
|
+
path_kwargs = {}
|
117
|
+
if len(path_placeholders) > 0:
|
118
|
+
for placeholder in path_placeholders:
|
119
|
+
if (placeholder != "") and (placeholder in kwargs.keys()):
|
120
|
+
path_kwargs[placeholder] = kwargs.pop(placeholder)
|
121
|
+
else:
|
122
|
+
if len(args) <= args_in_path:
|
123
|
+
raise ValidationError(
|
124
|
+
"Number of given arguments can't be smaller than "
|
125
|
+
"number of path placeholders"
|
126
|
+
)
|
127
|
+
|
128
|
+
if placeholder == "":
|
129
|
+
path_args.append(args[args_in_path])
|
130
|
+
else:
|
131
|
+
path_kwargs[placeholder] = args[args_in_path]
|
132
|
+
|
133
|
+
args_in_path += 1
|
134
|
+
|
135
|
+
return {
|
136
|
+
"path": self.action.path.format(*path_args, **path_kwargs),
|
137
|
+
"params": self._validate_and_map(
|
138
|
+
self.action.params, args[args_in_path:], kwargs
|
139
|
+
)
|
140
|
+
if self.action.params
|
141
|
+
else {},
|
142
|
+
"data": self._validate_and_map(
|
143
|
+
self.action.data, args[args_in_path:], kwargs
|
144
|
+
)
|
145
|
+
if self.action.data
|
146
|
+
else {},
|
147
|
+
}
|
dkg/module.py
CHANGED
dkg/network.py
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
# under the License.
|
17
17
|
|
18
18
|
from dkg.constants import DEFAULT_HASH_FUNCTION_ID
|
19
|
+
from dkg.dataclasses import BidSuggestionRange
|
19
20
|
from dkg.manager import DefaultRequestManager
|
20
21
|
from dkg.method import Method
|
21
22
|
from dkg.module import Module
|
@@ -33,19 +34,28 @@ class Network(Module):
|
|
33
34
|
_get_bid_suggestion = Method(NodeRequest.bid_suggestion)
|
34
35
|
|
35
36
|
def get_bid_suggestion(
|
36
|
-
self,
|
37
|
+
self,
|
38
|
+
public_assertion_id: DataHexStr,
|
39
|
+
size_in_bytes: int,
|
40
|
+
epochs_number: int,
|
41
|
+
range: BidSuggestionRange = BidSuggestionRange.LOW,
|
37
42
|
) -> int:
|
38
43
|
content_asset_storage_address = self._get_asset_storage_address(
|
39
44
|
"ContentAssetStorage"
|
40
45
|
)
|
41
46
|
|
42
|
-
|
43
|
-
self.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
response = self._get_bid_suggestion(
|
48
|
+
self.manager.blockchain_provider.blockchain_id,
|
49
|
+
epochs_number,
|
50
|
+
size_in_bytes,
|
51
|
+
content_asset_storage_address,
|
52
|
+
public_assertion_id,
|
53
|
+
DEFAULT_HASH_FUNCTION_ID,
|
54
|
+
range,
|
55
|
+
)
|
56
|
+
|
57
|
+
return (
|
58
|
+
int(response["bidSuggestion"])
|
59
|
+
if range != BidSuggestionRange.ALL
|
60
|
+
else response
|
51
61
|
)
|