meshtensor-cli 9.18.1__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.
- meshtensor_cli/__init__.py +22 -0
- meshtensor_cli/cli.py +10742 -0
- meshtensor_cli/doc_generation_helper.py +4 -0
- meshtensor_cli/src/__init__.py +1085 -0
- meshtensor_cli/src/commands/__init__.py +0 -0
- meshtensor_cli/src/commands/axon/__init__.py +0 -0
- meshtensor_cli/src/commands/axon/axon.py +132 -0
- meshtensor_cli/src/commands/crowd/__init__.py +0 -0
- meshtensor_cli/src/commands/crowd/contribute.py +621 -0
- meshtensor_cli/src/commands/crowd/contributors.py +200 -0
- meshtensor_cli/src/commands/crowd/create.py +783 -0
- meshtensor_cli/src/commands/crowd/dissolve.py +219 -0
- meshtensor_cli/src/commands/crowd/refund.py +233 -0
- meshtensor_cli/src/commands/crowd/update.py +418 -0
- meshtensor_cli/src/commands/crowd/utils.py +124 -0
- meshtensor_cli/src/commands/crowd/view.py +991 -0
- meshtensor_cli/src/commands/governance/__init__.py +0 -0
- meshtensor_cli/src/commands/governance/governance.py +794 -0
- meshtensor_cli/src/commands/liquidity/__init__.py +0 -0
- meshtensor_cli/src/commands/liquidity/liquidity.py +699 -0
- meshtensor_cli/src/commands/liquidity/utils.py +202 -0
- meshtensor_cli/src/commands/proxy.py +700 -0
- meshtensor_cli/src/commands/stake/__init__.py +0 -0
- meshtensor_cli/src/commands/stake/add.py +799 -0
- meshtensor_cli/src/commands/stake/auto_staking.py +306 -0
- meshtensor_cli/src/commands/stake/children_hotkeys.py +865 -0
- meshtensor_cli/src/commands/stake/claim.py +770 -0
- meshtensor_cli/src/commands/stake/list.py +738 -0
- meshtensor_cli/src/commands/stake/move.py +1211 -0
- meshtensor_cli/src/commands/stake/remove.py +1466 -0
- meshtensor_cli/src/commands/stake/wizard.py +323 -0
- meshtensor_cli/src/commands/subnets/__init__.py +0 -0
- meshtensor_cli/src/commands/subnets/mechanisms.py +515 -0
- meshtensor_cli/src/commands/subnets/price.py +733 -0
- meshtensor_cli/src/commands/subnets/subnets.py +2908 -0
- meshtensor_cli/src/commands/sudo.py +1294 -0
- meshtensor_cli/src/commands/tc/__init__.py +0 -0
- meshtensor_cli/src/commands/tc/tc.py +190 -0
- meshtensor_cli/src/commands/treasury/__init__.py +0 -0
- meshtensor_cli/src/commands/treasury/treasury.py +194 -0
- meshtensor_cli/src/commands/view.py +354 -0
- meshtensor_cli/src/commands/wallets.py +2311 -0
- meshtensor_cli/src/commands/weights.py +467 -0
- meshtensor_cli/src/meshtensor/__init__.py +0 -0
- meshtensor_cli/src/meshtensor/balances.py +313 -0
- meshtensor_cli/src/meshtensor/chain_data.py +1263 -0
- meshtensor_cli/src/meshtensor/extrinsics/__init__.py +0 -0
- meshtensor_cli/src/meshtensor/extrinsics/mev_shield.py +174 -0
- meshtensor_cli/src/meshtensor/extrinsics/registration.py +1861 -0
- meshtensor_cli/src/meshtensor/extrinsics/root.py +550 -0
- meshtensor_cli/src/meshtensor/extrinsics/serving.py +255 -0
- meshtensor_cli/src/meshtensor/extrinsics/transfer.py +239 -0
- meshtensor_cli/src/meshtensor/meshtensor_interface.py +2598 -0
- meshtensor_cli/src/meshtensor/minigraph.py +254 -0
- meshtensor_cli/src/meshtensor/networking.py +12 -0
- meshtensor_cli/src/meshtensor/templates/main-filters.j2 +24 -0
- meshtensor_cli/src/meshtensor/templates/main-header.j2 +36 -0
- meshtensor_cli/src/meshtensor/templates/neuron-details.j2 +111 -0
- meshtensor_cli/src/meshtensor/templates/price-multi.j2 +113 -0
- meshtensor_cli/src/meshtensor/templates/price-single.j2 +99 -0
- meshtensor_cli/src/meshtensor/templates/subnet-details-header.j2 +49 -0
- meshtensor_cli/src/meshtensor/templates/subnet-details.j2 +32 -0
- meshtensor_cli/src/meshtensor/templates/subnet-metrics.j2 +57 -0
- meshtensor_cli/src/meshtensor/templates/subnets-table.j2 +28 -0
- meshtensor_cli/src/meshtensor/templates/table.j2 +267 -0
- meshtensor_cli/src/meshtensor/templates/view.css +1058 -0
- meshtensor_cli/src/meshtensor/templates/view.j2 +43 -0
- meshtensor_cli/src/meshtensor/templates/view.js +1053 -0
- meshtensor_cli/src/meshtensor/utils.py +2007 -0
- meshtensor_cli/version.py +23 -0
- meshtensor_cli-9.18.1.dist-info/METADATA +261 -0
- meshtensor_cli-9.18.1.dist-info/RECORD +74 -0
- meshtensor_cli-9.18.1.dist-info/WHEEL +4 -0
- meshtensor_cli-9.18.1.dist-info/entry_points.txt +3 -0
|
File without changes
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
from typing import TYPE_CHECKING, Optional
|
|
3
|
+
|
|
4
|
+
from async_substrate_interface import AsyncExtrinsicReceipt
|
|
5
|
+
from meshtensor_drand import encrypt_mlkem768
|
|
6
|
+
from meshtensor_cli.src.meshtensor.utils import format_error_message
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from scalecodec import GenericCall, GenericExtrinsic
|
|
10
|
+
from meshtensor_cli.src.meshtensor.meshtensor_interface import MeshtensorInterface
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def encrypt_extrinsic(
|
|
14
|
+
meshtensor: "MeshtensorInterface",
|
|
15
|
+
signed_extrinsic: "GenericExtrinsic",
|
|
16
|
+
) -> "GenericCall":
|
|
17
|
+
"""
|
|
18
|
+
Encrypt a signed extrinsic using MEV Shield.
|
|
19
|
+
|
|
20
|
+
Takes a pre-signed extrinsic and returns a MevShield.submit_encrypted call.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
meshtensor: The MeshtensorInterface instance for chain queries.
|
|
24
|
+
signed_extrinsic: The signed extrinsic to encrypt.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
A MevShield.submit_encrypted call to be signed with the current nonce.
|
|
28
|
+
|
|
29
|
+
Raises:
|
|
30
|
+
ValueError: If MEV Shield NextKey is not available on chain.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
ml_kem_768_public_key = await meshtensor.get_mev_shield_next_key()
|
|
34
|
+
if ml_kem_768_public_key is None:
|
|
35
|
+
raise ValueError("MEV Shield NextKey not available on chain")
|
|
36
|
+
|
|
37
|
+
plaintext = bytes(signed_extrinsic.data.data)
|
|
38
|
+
|
|
39
|
+
# Encrypt using ML-KEM-768
|
|
40
|
+
ciphertext = encrypt_mlkem768(ml_kem_768_public_key, plaintext)
|
|
41
|
+
|
|
42
|
+
# Commitment: blake2_256(payload_core)
|
|
43
|
+
commitment_hash = hashlib.blake2b(plaintext, digest_size=32).digest()
|
|
44
|
+
commitment_hex = "0x" + commitment_hash.hex()
|
|
45
|
+
|
|
46
|
+
# Create the MevShield.submit_encrypted call
|
|
47
|
+
encrypted_call = await meshtensor.substrate.compose_call(
|
|
48
|
+
call_module="MevShield",
|
|
49
|
+
call_function="submit_encrypted",
|
|
50
|
+
call_params={
|
|
51
|
+
"commitment": commitment_hex,
|
|
52
|
+
"ciphertext": ciphertext,
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return encrypted_call
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def extract_mev_shield_id(response: "AsyncExtrinsicReceipt") -> Optional[str]:
|
|
60
|
+
"""
|
|
61
|
+
Extract the MEV Shield wrapper ID from an extrinsic response.
|
|
62
|
+
|
|
63
|
+
After submitting a MEV Shield encrypted call, the EncryptedSubmitted event
|
|
64
|
+
contains the wrapper ID needed to track execution.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
response: The extrinsic receipt from submit_extrinsic.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
The wrapper ID (hex string) or None if not found.
|
|
71
|
+
"""
|
|
72
|
+
for event in await response.triggered_events:
|
|
73
|
+
if event["event_id"] == "EncryptedSubmitted":
|
|
74
|
+
return event["attributes"]["id"]
|
|
75
|
+
return None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def wait_for_extrinsic_by_hash(
|
|
79
|
+
meshtensor: "MeshtensorInterface",
|
|
80
|
+
extrinsic_hash: str,
|
|
81
|
+
shield_id: str,
|
|
82
|
+
submit_block_hash: str,
|
|
83
|
+
timeout_blocks: int = 2,
|
|
84
|
+
status=None,
|
|
85
|
+
) -> tuple[bool, Optional[str], Optional[AsyncExtrinsicReceipt]]:
|
|
86
|
+
"""
|
|
87
|
+
Wait for the result of a MeV Shield encrypted extrinsic.
|
|
88
|
+
|
|
89
|
+
After submit_encrypted succeeds, the block author will decrypt and submit
|
|
90
|
+
the inner extrinsic directly. This function polls subsequent blocks looking
|
|
91
|
+
for either:
|
|
92
|
+
- an extrinsic matching the provided hash (success)
|
|
93
|
+
OR
|
|
94
|
+
- a markDecryptionFailed extrinsic with matching shield ID (failure)
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
meshtensor: MeshtensorInterface instance.
|
|
98
|
+
extrinsic_hash: The hash of the inner extrinsic to find.
|
|
99
|
+
shield_id: The wrapper ID from EncryptedSubmitted event (for detecting decryption failures).
|
|
100
|
+
submit_block_hash: Block hash where submit_encrypted was included.
|
|
101
|
+
timeout_blocks: Max blocks to wait (default 2).
|
|
102
|
+
status: Optional rich.Status object for progress updates.
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
Tuple of (success: bool, error: Optional[str], receipt: Optional[AsyncExtrinsicReceipt]).
|
|
106
|
+
- (True, None, receipt) if extrinsic was found and succeeded.
|
|
107
|
+
- (False, error_message, receipt) if extrinsic was found but failed.
|
|
108
|
+
- (False, "Timeout...", None) if not found within timeout.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
async def _noop(_):
|
|
112
|
+
return True
|
|
113
|
+
|
|
114
|
+
starting_block = await meshtensor.substrate.get_block_number(submit_block_hash)
|
|
115
|
+
current_block = starting_block + 1
|
|
116
|
+
|
|
117
|
+
while current_block - starting_block <= timeout_blocks:
|
|
118
|
+
if status:
|
|
119
|
+
status.update(
|
|
120
|
+
f"Waiting for :shield: MEV Protection "
|
|
121
|
+
f"(checking block {current_block - starting_block} of {timeout_blocks})..."
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
await meshtensor.substrate.wait_for_block(
|
|
125
|
+
current_block,
|
|
126
|
+
result_handler=_noop,
|
|
127
|
+
task_return=False,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
block_hash = await meshtensor.substrate.get_block_hash(current_block)
|
|
131
|
+
extrinsics = await meshtensor.substrate.get_extrinsics(block_hash)
|
|
132
|
+
|
|
133
|
+
result_idx = None
|
|
134
|
+
for idx, extrinsic in enumerate(extrinsics):
|
|
135
|
+
# Success: Inner extrinsic executed
|
|
136
|
+
if f"0x{extrinsic.extrinsic_hash.hex()}" == extrinsic_hash:
|
|
137
|
+
result_idx = idx
|
|
138
|
+
break
|
|
139
|
+
|
|
140
|
+
# Failure: Decryption failed
|
|
141
|
+
call = extrinsic.value.get("call", {})
|
|
142
|
+
if (
|
|
143
|
+
call.get("call_module") == "MevShield"
|
|
144
|
+
and call.get("call_function") == "mark_decryption_failed"
|
|
145
|
+
):
|
|
146
|
+
call_args = call.get("call_args", [])
|
|
147
|
+
for arg in call_args:
|
|
148
|
+
if arg.get("name") == "id" and arg.get("value") == shield_id:
|
|
149
|
+
result_idx = idx
|
|
150
|
+
break
|
|
151
|
+
if result_idx is not None:
|
|
152
|
+
break
|
|
153
|
+
|
|
154
|
+
if result_idx is not None:
|
|
155
|
+
receipt = AsyncExtrinsicReceipt(
|
|
156
|
+
substrate=meshtensor.substrate,
|
|
157
|
+
block_hash=block_hash,
|
|
158
|
+
block_number=current_block,
|
|
159
|
+
extrinsic_idx=result_idx,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
if not await receipt.is_success:
|
|
163
|
+
error_msg = format_error_message(await receipt.error_message)
|
|
164
|
+
return False, error_msg, receipt
|
|
165
|
+
|
|
166
|
+
return True, None, receipt
|
|
167
|
+
|
|
168
|
+
current_block += 1
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
False,
|
|
172
|
+
"Failed to find outcome of the shield extrinsic (The protected extrinsic wasn't decrypted)",
|
|
173
|
+
None,
|
|
174
|
+
)
|