Skip to content

Commit

Permalink
fix: proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Supremesource committed Apr 27, 2024
1 parent a3175e2 commit f886e72
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
5 changes: 1 addition & 4 deletions src/communex/cli/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ def add_custom_proposal(
# _ = resolve_key_ss58(founder)
resolved_key = classic_load_key(key)

proposal = {
"data": cid
}

with context.progress_status("Adding a proposal..."):
client.add_custom_proposal(resolved_key, proposal)
client.add_custom_proposal(resolved_key, cid)
9 changes: 3 additions & 6 deletions src/communex/cli/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def propose_on_subnet(
@subnet_app.command()
def add_custom_proposal(
ctx: Context,
netuid: int,
key: str,
cid: str
cid: str,
netuid: int,
):
"""
Adds a custom proposal to a specific subnet.
Expand All @@ -198,8 +198,5 @@ def add_custom_proposal(
resolved_key = classic_load_key(key)

ipfs = "ipfs://" + cid
proposal = {
"data": ipfs
}
with context.progress_status("Adding a proposal..."):
client.add_custom_proposal(resolved_key, proposal, netuid=netuid)
client.add_custom_subnet_proposal(resolved_key, ipfs, netuid=netuid)
52 changes: 44 additions & 8 deletions src/communex/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from copy import deepcopy
from dataclasses import dataclass
from typing import Any, TypeVar, Mapping
from substrateinterface import ( # type: ignore

from substrateinterface import ( #  type: ignore
ExtrinsicReceipt,
Keypair, # type: ignore
SubstrateInterface,
Expand Down Expand Up @@ -379,7 +379,7 @@ def split_chunks(chunk: Chunk, chunk_info: list[Chunk], chunk_info_idx: int):
mutaded_chunk_info.pop(chunk_info_idx)
for i in range(0, keys_amount, max_n_keys):
new_chunk = deepcopy(chunk)
splitted_keys = result_keys[i : i + max_n_keys]
splitted_keys = result_keys[i: i + max_n_keys]
splitted_query = deepcopy(query)
splitted_query[1][0] = splitted_keys
new_chunk.batch_requests = [splitted_query]
Expand Down Expand Up @@ -515,7 +515,7 @@ def concat_hash_len(key_hasher: str) -> int:

item_key_obj = substrate.decode_scale( # type: ignore
type_string=f"({', '.join(key_type_string)})",
scale_bytes="0x" + item[0][len(prefix) :],
scale_bytes="0x" + item[0][len(prefix):],
return_scale_obj=True,
block_hash=block_hash,
)
Expand Down Expand Up @@ -1376,15 +1376,51 @@ def add_subnet_proposal(
def add_custom_proposal(
self,
key: Keypair,
params: dict[Any, Any],
netuid: int = 0,
cid: str,
) -> ExtrinsicReceipt:

proposal = params
proposal["netuid"] = netuid
params = {
"data": cid
}

response = self.compose_call(fn="add_custom_proposal", params=params, key=key)
return response

def add_custom_subnet_proposal(
self,
key: Keypair,
cid: str,
netuid: int = 0,
) -> ExtrinsicReceipt:
"""
Submits a proposal for creating or modifying a custom subnet within the
network.
The proposal includes various parameters like the name, founder, share
allocations, and other subnet-specific settings.
Args:
key: The keypair used for signing the proposal transaction.
params: The parameters for the subnet proposal.
netuid: The network identifier.
Returns:
A receipt of the subnet proposal transaction.
"""

params = {
"data": cid,
"netuid": netuid,
}

response = self.compose_call(
fn="add_custom_subnet_proposal",
params=params,
key=key,
)

return response

def add_global_proposal(
self,
key: Keypair,
Expand Down

0 comments on commit f886e72

Please sign in to comment.