dkg 0.1.0b6__py3-none-any.whl → 1.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.
Files changed (43) hide show
  1. dkg/asset.py +106 -28
  2. dkg/constants.py +13 -9
  3. dkg/data/interfaces/ContentAsset.json +133 -3
  4. dkg/data/interfaces/Paranet.json +821 -0
  5. dkg/data/interfaces/{Identity.json → ParanetIncentivesPoolFactory.json} +67 -86
  6. dkg/data/interfaces/ParanetKnowledgeMinersRegistry.json +919 -0
  7. dkg/data/interfaces/ParanetNeurowebIncentivesPool.json +1102 -0
  8. dkg/data/interfaces/{ServiceAgreementStorageV1.json → ParanetsRegistry.json} +331 -360
  9. dkg/dataclasses.py +28 -8
  10. dkg/main.py +6 -3
  11. dkg/method.py +55 -39
  12. dkg/module.py +1 -0
  13. dkg/network.py +20 -10
  14. dkg/paranet.py +477 -0
  15. dkg/providers/blockchain.py +57 -26
  16. dkg/types/__init__.py +1 -0
  17. dkg/types/general.py +44 -0
  18. dkg/utils/blockchain_request.py +149 -4
  19. dkg/utils/node_request.py +77 -80
  20. {dkg-0.1.0b6.dist-info → dkg-1.0.0.dist-info}/METADATA +3 -141
  21. dkg-1.0.0.dist-info/NOTICE +9 -0
  22. dkg-1.0.0.dist-info/RECORD +52 -0
  23. {dkg-0.1.0b6.dist-info → dkg-1.0.0.dist-info}/WHEEL +1 -1
  24. dkg/data/interfaces/Assertion.json +0 -157
  25. dkg/data/interfaces/CommitManagerV1.json +0 -549
  26. dkg/data/interfaces/CommitManagerV1U1.json +0 -735
  27. dkg/data/interfaces/HashingProxy.json +0 -253
  28. dkg/data/interfaces/IdentityStorage.json +0 -342
  29. dkg/data/interfaces/ParametersStorage.json +0 -487
  30. dkg/data/interfaces/Profile.json +0 -318
  31. dkg/data/interfaces/ProfileStorage.json +0 -596
  32. dkg/data/interfaces/ProofManagerV1.json +0 -540
  33. dkg/data/interfaces/ProofManagerV1U1.json +0 -561
  34. dkg/data/interfaces/ScoringProxy.json +0 -268
  35. dkg/data/interfaces/ServiceAgreementStorageV1U1.json +0 -1097
  36. dkg/data/interfaces/ServiceAgreementV1.json +0 -745
  37. dkg/data/interfaces/ShardingTable.json +0 -294
  38. dkg/data/interfaces/ShardingTableStorage.json +0 -317
  39. dkg/data/interfaces/Staking.json +0 -482
  40. dkg/data/interfaces/StakingStorage.json +0 -407
  41. dkg/data/interfaces/WhitelistStorage.json +0 -124
  42. dkg-0.1.0b6.dist-info/RECORD +0 -64
  43. {dkg-0.1.0b6.dist-info → dkg-1.0.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 enum import Enum
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 KnowledgeAssetEnumStates(Enum):
38
- LATEST = "LATEST"
39
- LATEST_FINALIZED = "LATEST_FINALIZED"
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
- class KnowledgeAssetContentVisibility(Enum):
43
- ALL = "ALL"
44
- PUBLIC = "PUBLIC"
45
- PRIVATE = "PRIVATE"
62
+ @dataclass
63
+ class BaseIncentivesPoolParams:
64
+ def to_contract_args(self) -> dict:
65
+ raise NotImplementedError("This method should be overridden in subclasses")
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 ContentAsset
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: ContentAsset
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": ContentAsset(self.manager),
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 (ContractInteraction,
25
- ContractTransaction, JSONRPCRequest)
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
- path_placeholders = re.findall(r"\{([^{}]+)?\}", self.action.path)
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
@@ -34,6 +34,7 @@ class Module:
34
34
  processed_args = method.process_args(*args, **kwargs)
35
35
  request_params = asdict(method.action)
36
36
  request_params.update(processed_args)
37
+
37
38
  return self.manager.blocking_request(type(method.action), request_params)
38
39
 
39
40
  return caller
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, public_assertion_id: DataHexStr, size_in_bytes: int, epochs_number: int,
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
- return int(
43
- self._get_bid_suggestion(
44
- self.manager.blockchain_provider.blockchain_id,
45
- epochs_number,
46
- size_in_bytes,
47
- content_asset_storage_address,
48
- public_assertion_id,
49
- DEFAULT_HASH_FUNCTION_ID,
50
- )["bidSuggestion"]
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
  )