dkg 8.0.11__py3-none-any.whl → 8.0.13__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/constants.py CHANGED
@@ -75,19 +75,9 @@ class OutputTypes(Enum):
75
75
  JSONLD: str = "JSON-LD"
76
76
 
77
77
 
78
- class Environments(Enum):
79
- DEVELOPMENT: str = "development"
80
- DEVNET: str = "devnet"
81
- TESTNET: str = "testnet"
82
- MAINNET: str = "mainnet"
83
-
84
-
85
78
  class BlockchainIds(Enum):
86
79
  HARDHAT_1: str = "hardhat1:31337"
87
80
  HARDHAT_2: str = "hardhat2:31337"
88
- BASE_DEVNET: str = "base:84532"
89
- GNOSIS_DEVNET: str = "gnosis:10200"
90
- NEUROWEB_DEVNET: str = "otp:2160"
91
81
  BASE_TESTNET: str = "base:84532"
92
82
  GNOSIS_TESTNET: str = "gnosis:10200"
93
83
  NEUROWEB_TESTNET: str = "otp:20430"
@@ -114,12 +104,6 @@ BLOCKCHAINS = {
114
104
  "rpc": "http://localhost:9545",
115
105
  },
116
106
  },
117
- "devnet": {
118
- "base:84532": {
119
- "hub": "0xE043daF4cC8ae2c720ef95fc82574a37a429c40A",
120
- "rpc": "https://sepolia.base.org",
121
- }
122
- },
123
107
  "testnet": {
124
108
  "base:84532": {
125
109
  "hub": "0xf21CE8f8b01548D97DCFb36869f1ccB0814a4e05",
@@ -152,11 +136,6 @@ BLOCKCHAINS = {
152
136
 
153
137
  DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
154
138
  "development": {"hardhat1:31337": 2, "hardhat2:31337": 2, "otp:2043": 2},
155
- "devnet": {
156
- "otp:2160": 2,
157
- "gnosis:10200": 2,
158
- "base:84532": 2,
159
- },
160
139
  "testnet": {
161
140
  "otp:20430": 2,
162
141
  "gnosis:10200": 2,
@@ -27,7 +27,7 @@ from dkg.exceptions import (
27
27
  AccountMissing,
28
28
  NetworkNotSupported,
29
29
  )
30
- from dkg.types import URI, Address, Environment, Wei
30
+ from dkg.types import URI, Address, Wei
31
31
  from web3.contract import Contract
32
32
  from web3.contract.contract import ContractFunction
33
33
  from web3.types import TxReceipt
@@ -39,13 +39,12 @@ from dkg.providers.blockchain.base_blockchain import BaseBlockchainProvider
39
39
  class AsyncBlockchainProvider(BaseBlockchainProvider):
40
40
  def __init__(
41
41
  self,
42
- environment: Environment,
43
42
  blockchain_id: str,
44
43
  rpc_uri: URI | None = None,
45
44
  gas_price: Wei | None = None,
46
45
  verify: bool = True,
47
46
  ):
48
- super().__init__(environment, blockchain_id, rpc_uri, gas_price)
47
+ super().__init__(blockchain_id, rpc_uri, gas_price)
49
48
 
50
49
  ssl_context = None if verify else False
51
50
  self.w3 = AsyncWeb3(
@@ -8,7 +8,7 @@ from dkg.exceptions import (
8
8
  EnvironmentNotSupported,
9
9
  RPCURINotDefined,
10
10
  )
11
- from dkg.types import URI, DataHexStr, Environment, Wei
11
+ from dkg.types import URI, DataHexStr, Wei
12
12
  from eth_account.signers.local import LocalAccount
13
13
  from eth_typing import ABI, ABIFunction
14
14
  from web3.logs import DISCARD
@@ -21,27 +21,26 @@ class BaseBlockchainProvider:
21
21
 
22
22
  def __init__(
23
23
  self,
24
- environment: Environment,
25
24
  blockchain_id: str,
26
25
  rpc_uri: URI | None = None,
27
26
  gas_price: Wei | None = None,
28
27
  ):
29
- if environment not in BLOCKCHAINS.keys():
30
- raise EnvironmentNotSupported(f"Environment {environment} isn't supported!")
31
-
32
- self.environment = environment
33
- self.rpc_uri = rpc_uri
34
- self.blockchain_id = (
35
- blockchain_id
36
- if blockchain_id in BLOCKCHAINS[self.environment].keys()
37
- else None
38
- )
28
+ self.environment = None
29
+ for env_name, chains_in_env in BLOCKCHAINS.items():
30
+ if blockchain_id in chains_in_env:
31
+ self.environment = env_name
32
+ break
33
+
34
+ if self.environment is None:
35
+ raise EnvironmentNotSupported(
36
+ f"Could not derive environment for blockchain_id: {blockchain_id}. "
37
+ "Ensure it's defined in BLOCKCHAINS constant."
38
+ )
39
39
 
40
- if self.rpc_uri is None and self.blockchain_id is not None:
41
- self.blockchain_id = blockchain_id
42
- self.rpc_uri = self.rpc_uri or BLOCKCHAINS[self.environment][
43
- self.blockchain_id
44
- ].get("rpc", None)
40
+ self.blockchain_id = blockchain_id
41
+ self.rpc_uri = rpc_uri or BLOCKCHAINS[self.environment][self.blockchain_id].get(
42
+ "rpc", None
43
+ )
45
44
 
46
45
  if self.rpc_uri is None:
47
46
  raise RPCURINotDefined(
@@ -26,7 +26,7 @@ from dkg.exceptions import (
26
26
  AccountMissing,
27
27
  NetworkNotSupported,
28
28
  )
29
- from dkg.types import URI, Address, Environment, Wei
29
+ from dkg.types import URI, Address, Wei
30
30
  from web3 import Web3
31
31
  from web3.contract import Contract
32
32
  from web3.contract.contract import ContractFunction
@@ -37,13 +37,12 @@ from dkg.providers.blockchain.base_blockchain import BaseBlockchainProvider
37
37
  class BlockchainProvider(BaseBlockchainProvider):
38
38
  def __init__(
39
39
  self,
40
- environment: Environment,
41
40
  blockchain_id: str,
42
41
  rpc_uri: URI | None = None,
43
42
  gas_price: Wei | None = None,
44
43
  verify: bool = True,
45
44
  ):
46
- super().__init__(environment, blockchain_id, rpc_uri, gas_price)
45
+ super().__init__(blockchain_id, rpc_uri, gas_price)
47
46
 
48
47
  self.w3 = Web3(
49
48
  Web3.HTTPProvider(self.rpc_uri, request_kwargs={"verify": verify})
dkg/types/blockchain.py CHANGED
@@ -50,7 +50,7 @@ ABIElement = ABIFunction | ABIEvent | ABIError
50
50
  ABI = list[ABIElement]
51
51
 
52
52
 
53
- Environment = Literal["development", "devnet", "testnet", "mainnet"]
53
+ Environment = Literal["development", "testnet", "mainnet"]
54
54
 
55
55
 
56
56
  class AgreementData(NamedTuple):
@@ -6,6 +6,7 @@ from dkg.types import JSONLD, NQuads
6
6
  from pyld import jsonld
7
7
  from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM, ESCAPE_MAP
8
8
  from rdflib import Graph, BNode, URIRef, Literal as RDFLiteral
9
+ from rdflib.exceptions import ParserError as RDFParserError
9
10
  from uuid import uuid4
10
11
  from web3 import Web3
11
12
  import math
@@ -154,29 +155,26 @@ def generate_missing_ids_for_blank_nodes(nquads_list: list[str] | None) -> list[
154
155
 
155
156
  return term # Return IRIs or Literals unchanged
156
157
 
157
- # Create a temporary graph for parsing individual quads
158
- result = []
159
-
160
- # Process each N-Quad string individually to maintain order
161
- for nquad in nquads_list:
162
- if not nquad.strip():
163
- continue
158
+ all_nquads = "\n".join(nquad for nquad in nquads_list if nquad.strip())
164
159
 
165
- # Parse single N-Quad
166
- g = Graph()
167
- g.parse(data=nquad, format="nquads")
160
+ # Create a single Dataset
161
+ g = Graph()
162
+ try:
163
+ g.parse(data=all_nquads, format="nt")
164
+ except RDFParserError:
165
+ raise UnsupportedJSONLD(nquads_list)
168
166
 
169
- # Get the triple and replace blank nodes
170
- for s, p, o in g:
171
- updated_quad = (
172
- replace_blank_node(s),
173
- replace_blank_node(p),
174
- replace_blank_node(o),
175
- )
176
- # Format as N-Quad string
177
- result.append(
178
- f"{updated_quad[0].n3()} {updated_quad[1].n3()} {updated_quad[2].n3()} ."
179
- )
167
+ # Process all quads
168
+ result = []
169
+ for s, p, o in g:
170
+ updated_quad = (
171
+ replace_blank_node(s),
172
+ replace_blank_node(p),
173
+ replace_blank_node(o),
174
+ )
175
+ result.append(
176
+ f"{updated_quad[0].n3()} {updated_quad[1].n3()} {updated_quad[2].n3()} ."
177
+ )
180
178
 
181
179
  return result
182
180
 
@@ -266,3 +264,44 @@ def escape_literal_dict(obj):
266
264
  return escape_literal_string(s=obj)
267
265
  else:
268
266
  return obj
267
+
268
+
269
+ # Used when JSON-LD parsing fails due to quads being passed instead of triples
270
+ class UnsupportedJSONLD(Exception):
271
+ def __init__(self, nquads_list):
272
+ self.nquads_list = nquads_list
273
+ self.message = f"""
274
+ Unsupported JSON-LD input detected
275
+
276
+ After parsing the JSON-LD input, the parser detected creation of new named graphs.
277
+ The DKG does not support custom named graphs.
278
+
279
+ Problematic Quads:
280
+
281
+ {self.find_problematic_quads()}
282
+
283
+ Full Parsed N-Quads Array:
284
+
285
+ {self.format_nquads_list()}
286
+
287
+ """
288
+ super().__init__(self.message)
289
+
290
+ def __str__(self):
291
+ return f"{self.__class__.__name__}: {self.message}"
292
+
293
+ def format_nquads_list(self):
294
+ return "\n".join(nquad.strip() for nquad in self.nquads_list)
295
+
296
+ def find_problematic_quads(self):
297
+ problematic = []
298
+ g = Graph()
299
+ for quad in self.nquads_list:
300
+ if not quad.strip():
301
+ continue
302
+ try:
303
+ g.parse(data=quad, format="nt")
304
+ except RDFParserError:
305
+ problematic.append(quad)
306
+
307
+ return "\n".join(f"{i + 1}. {quad}" for i, quad in enumerate(problematic))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dkg
3
- Version: 8.0.11
3
+ Version: 8.0.13
4
4
  Summary: Python library for interacting with the OriginTrail Decentralized Knowledge Graph
5
5
  License: Apache-2.0
6
6
  Author: Uladzislau Hubar
@@ -3,7 +3,7 @@ dkg/assertion.py,sha256=-KIVT3LHlOHegGg68_KceC5O2r8B_povbofRjmLguVQ,2507
3
3
  dkg/clients/__init__.py,sha256=qKQ8TIbst7UZpJEpEJOZslgEX5EB0PU_H7cwk5-UDso,84
4
4
  dkg/clients/async_dkg.py,sha256=PM0suu8BFUhhS8_K_zoPTxKEXn5J1AFCwyB-JP-hLmc,4013
5
5
  dkg/clients/dkg.py,sha256=QTLm5nfeW0gx_t2e8JMO5gcIJaPvmy1L7ZOy7dSfhkc,3786
6
- dkg/constants.py,sha256=Zjr7N4cQr-9Kcut3KyYWiITXgsYyAM13TvKdDNbu4lY,5307
6
+ dkg/constants.py,sha256=PBX3AEK0bBeiG7sHBY65cZllo74q-H8hclqNbl4fj90,4776
7
7
  dkg/data/interfaces/AskStorage.json,sha256=hHWq3e0Kx8Cs3PKD4HL2xYRQ8DXRTxTL06QXqFyqlns,6773
8
8
  dkg/data/interfaces/Chronos.json,sha256=aIpCUgJ8omHidyt0GPkj02COT1LW8Tu66qDm7iquQJk,3595
9
9
  dkg/data/interfaces/Hub.json,sha256=ZcaePz10ff2Vm7VP-vWP63xLOuE0EE8jNruWvWmMjLw,12611
@@ -40,9 +40,9 @@ dkg/modules/paranet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSu
40
40
  dkg/modules/paranet/paranet.py,sha256=YulI-sP65sOlBYyUVbA008JByvy-bqnOnWt7vXsf5Kk,26959
41
41
  dkg/providers/__init__.py,sha256=mOHuyl44mpuLnXv920CJ1lsbSTlxNLCwK4xXeQsfv3s,251
42
42
  dkg/providers/blockchain/__init__.py,sha256=Vg5XQ9Fw5m0CQvpMTH5atgPIKKcnknX9peShsmOOtGg,158
43
- dkg/providers/blockchain/async_blockchain.py,sha256=c32RaNP7Qpo7aqP7ZVigkRiKKhb1B57Y4pwItzs9Md0,8766
44
- dkg/providers/blockchain/base_blockchain.py,sha256=VOF3qfwsfJJ3ykBEXDF6yOkKqWG0m-cLFsNC3K3pdPI,3647
45
- dkg/providers/blockchain/blockchain.py,sha256=HxLXkkK1vT_EsMfeIUZUubz6oktMECN19FUdsOAyArk,7906
43
+ dkg/providers/blockchain/async_blockchain.py,sha256=GpMTGKhsqB_m2f6InUAwiRJNisKQErgVSot869TnTV0,8706
44
+ dkg/providers/blockchain/base_blockchain.py,sha256=AW3PlcgfEthvHxxCcv0USXtnOmIixnjK9rg-HpfHuxA,3591
45
+ dkg/providers/blockchain/blockchain.py,sha256=-CoUpc1lRLiVpCWmYVI7dUOn_goreSqSkz0DZq66GAI,7846
46
46
  dkg/providers/node/__init__.py,sha256=Nx2m3bbwDa4y0gAR1WUKhxmw36F-TscKaZj1CKqlEF4,148
47
47
  dkg/providers/node/async_node_http.py,sha256=dBge8pS9Pnk8N4TTgKeewmWWJnSOgU48rQVbm5ZKKsc,2804
48
48
  dkg/providers/node/base_node_http.py,sha256=CCkVwyr_iQKCbknVmEpUDXZlQb8C-Z5ndqQdW-fQR0E,763
@@ -56,7 +56,7 @@ dkg/services/node_services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
56
56
  dkg/services/node_services/async_node_service.py,sha256=AGwpEIbL6HbqcL1Y8FjIwNynQyvvhQaBZdwZtu9X-BQ,5478
57
57
  dkg/services/node_services/node_service.py,sha256=gqCm-PXB0dWwqWw6OxD3AZ3oiS-z6dhxG_l4LDXv3OA,4811
58
58
  dkg/types/__init__.py,sha256=YewW48fOBq-FtecY12Tlr_0vGDuNc2uzpIiM-WERzBU,704
59
- dkg/types/blockchain.py,sha256=hsBpFLgpcEmgODLK0g_cUW1AB69ZZYeX4AcW6wpAMtA,1682
59
+ dkg/types/blockchain.py,sha256=T-A7PEa7v99RuCcmwzkOubQPJG4TXZHHjCgYr09lM7U,1672
60
60
  dkg/types/dkg_node.py,sha256=uGjaYUO4D55sHJrL_3aOL3Nul3RlAo_aL4HLoSrQxr0,838
61
61
  dkg/types/encoding.py,sha256=gOtt9XLoxs6TE7rOCrAx-aCOdsDdaTVn3bxu9HPavxc,915
62
62
  dkg/types/evm.py,sha256=gN2hSq4MQzobWE3YAiTZPcv5b65AVyUEQut8hWPnx68,971
@@ -68,15 +68,15 @@ dkg/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
68
68
  dkg/utils/blockchain_request.py,sha256=CMz3sNRhfmYirm0-VUK2HTpbRfgc1gtG2SoPIuRYKb0,12446
69
69
  dkg/utils/decorators.py,sha256=uUh0xI9wv1gE6JF44eYEfUPGSFEBLR6Ua5D9Dhc3s10,1566
70
70
  dkg/utils/knowledge_asset_tools.py,sha256=uehOshzaYg03hDU8RSIV_k2mNaASVgqyyErzj6GwBxw,81
71
- dkg/utils/knowledge_collection_tools.py,sha256=hPCFcIdyWDCgfbo5uPQizvfin0hHvEElAYpvKYVDIBs,7951
71
+ dkg/utils/knowledge_collection_tools.py,sha256=6U9lLjoXfsayH_AmicNWtmsQ5xdllhTs-L9DsbPYvlU,8994
72
72
  dkg/utils/merkle.py,sha256=924kloBAnCXydteVtWMj_QLP5CRJf2GbHMZ-lbIK0KE,5141
73
73
  dkg/utils/metadata.py,sha256=483OroYwGNfZ_cCXfH3-xUrZgiR4mjjo9iU_Ie5RYRs,1658
74
74
  dkg/utils/node_request.py,sha256=wppF8Xf0RkuAAcURcYgyjGAdMsXm0L5YEem8wFGE2g8,6517
75
75
  dkg/utils/rdf.py,sha256=AvlcxZEeP58UbaGGvPX_ss69O-tgTXOJ9y9COZqVgkw,2973
76
76
  dkg/utils/string_transformations.py,sha256=eR51fVwTF9QKxEqXo9_1Bfw_k8iQajdXD6rKuTvhs70,972
77
77
  dkg/utils/ual.py,sha256=g7PFyS4Sbwjmwkq-eB20uRULEC2wlPGZr31BVQjs5OQ,1569
78
- dkg-8.0.11.dist-info/LICENSE,sha256=Dr70w2zcW8-jrPGlpTTTlJPL8lR4j2zpDD32tdEFgjY,11375
79
- dkg-8.0.11.dist-info/METADATA,sha256=gIDVZmuZ6j9G-UKdH1IUcsT4tGDDhmSPEIAwRUV-d6U,10821
80
- dkg-8.0.11.dist-info/NOTICE,sha256=Rk5toFR2ZqPwVZ3P_P4wE6U1xCnWR9KD3rNBqfPY7h8,368
81
- dkg-8.0.11.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
82
- dkg-8.0.11.dist-info/RECORD,,
78
+ dkg-8.0.13.dist-info/LICENSE,sha256=Dr70w2zcW8-jrPGlpTTTlJPL8lR4j2zpDD32tdEFgjY,11375
79
+ dkg-8.0.13.dist-info/METADATA,sha256=p4WHsfUDVtn17p--zUboDCgjn2iuEoOPwRfSUc-9xEg,10821
80
+ dkg-8.0.13.dist-info/NOTICE,sha256=Rk5toFR2ZqPwVZ3P_P4wE6U1xCnWR9KD3rNBqfPY7h8,368
81
+ dkg-8.0.13.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
82
+ dkg-8.0.13.dist-info/RECORD,,
File without changes
File without changes
File without changes