11import re
2- from typing import Optional , Union
2+ from typing import Optional
33
44import typer
55from rich .progress import track
99from torusdk .balance import to_rems
1010from torusdk .cli ._common import (
1111 CustomCtx ,
12+ extract_cid ,
13+ input_to_rems ,
1214 make_custom_context ,
15+ merge_models ,
1316 render_pydantic_table ,
1417)
1518from torusdk .client import TorusClient
1619from torusdk .key import local_key_adresses
17- from torusdk .misc import local_keys_to_stakedbalance , get_global_params
18- from torusdk .types .types import OptionalNetworkParams
20+ from torusdk .misc import (
21+ get_emission_params ,
22+ get_global_params ,
23+ local_keys_to_stakedbalance ,
24+ )
1925from torusdk .types .proposal import (
20- Proposal ,
26+ Emission ,
2127 GlobalCustom ,
2228 GlobalParams ,
23- Emission ,
29+ OptionalEmission ,
30+ Proposal ,
31+ TransferDaoTreasury ,
2432)
33+ from torusdk .types .types import OptionalNetworkParams
2534from torusdk .util import convert_cid_on_proposal
26- from torusdk .cli ._common import merge_models
2735
2836proposal_app = typer .Typer (no_args_is_help = True )
2937
@@ -135,33 +143,31 @@ def list_proposals(ctx: Context, query_cid: bool = typer.Option(True)):
135143 emission_p = [
136144 * filter (lambda x : isinstance (x .data , Emission ), parsed_proposals )
137145 ]
138-
146+ transfer_p = [
147+ * filter (
148+ lambda x : isinstance (x .data , TransferDaoTreasury ), parsed_proposals
149+ )
150+ ]
139151 render_pydantic_table (
140152 custom_p , context .console , "Custom Proposals" , ["data" ]
141153 )
142154 render_pydantic_table (
143155 global_params_p , context .console , "Global Params Proposals"
144156 )
145157 render_pydantic_table (emission_p , context .console , "Emission Proposals" )
158+ render_pydantic_table (transfer_p , context .console , "Transfer Proposals" )
146159
147160
148161@proposal_app .command ()
149162def transfer_dao_funds (
150163 ctx : Context ,
151164 signer_key : str ,
152165 amount : float ,
153- cid_hash : str ,
154166 dest : str ,
167+ cid : str = typer .Argument (..., callback = extract_cid ),
155168):
156169 context = make_custom_context (ctx )
157170
158- if not re .match (IPFS_REGEX , cid_hash ):
159- context .error (f"CID provided is invalid: { cid_hash } " )
160- raise typer .Exit (code = 1 )
161-
162- ipfs_prefix = "ipfs://"
163- cid = ipfs_prefix + cid_hash
164-
165171 nano_amount = to_rems (amount )
166172 keypair = context .load_key (signer_key , None )
167173 dest = context .resolve_ss58 (dest )
@@ -174,16 +180,20 @@ def transfer_dao_funds(
174180def propose_globally (
175181 ctx : Context ,
176182 key : str ,
177- cid : str ,
183+ cid_hash : str = typer . Argument (..., callback = extract_cid ) ,
178184 max_name_length : Optional [int ] = None ,
179185 min_name_length : Optional [int ] = None ,
180186 max_allowed_agents : Optional [int ] = None ,
181187 max_allowed_weights : Optional [int ] = None ,
182188 min_weight_stake : Optional [int ] = None ,
183189 min_weight_control_fee : Optional [int ] = None ,
184- min_staking_fee : Optional [int ] = None ,
190+ min_staking_fee : Optional [float ] = typer .Argument (
191+ ..., callback = input_to_rems
192+ ),
185193 dividends_participation_weight : Optional [int ] = None ,
186- proposal_cost : Optional [int ] = None ,
194+ proposal_cost : Optional [float ] = typer .Argument (
195+ ..., callback = input_to_rems
196+ ),
187197):
188198 local_variables = locals ()
189199 proposal_args = OptionalNetworkParams .model_validate (local_variables )
@@ -194,18 +204,23 @@ def propose_globally(
194204 proposal = merge_models (global_params , proposal_args )
195205
196206 kp = context .load_key (key )
197- cid_hash = re .match (IPFS_REGEX , cid )
198- if not cid_hash :
199- context .error (f"CID provided is invalid: { cid } " )
200- raise typer .Exit (code = 1 )
201- client .add_global_proposal (kp , proposal , cid )
207+ client .add_global_proposal (kp , proposal , cid_hash )
202208
203209
204210@proposal_app .command ()
205211def propose_emission (
206212 ctx : Context ,
207213 key : str ,
208- recycling_percentage : Optional [int ],
209- treasury_percentage : Optional [int ],
214+ cid : str = typer .Argument (..., callback = extract_cid ),
215+ recycling_percentage : Optional [int ] = typer .Option (None ),
216+ treasury_percentage : Optional [int ] = typer .Option (None ),
210217):
211- pass
218+ local_variables = locals ()
219+ proposal_args = OptionalEmission .model_validate (local_variables )
220+
221+ context = make_custom_context (ctx )
222+ client = context .com_client ()
223+ emission_params = get_emission_params (client )
224+ proposal = merge_models (emission_params , proposal_args )
225+ kp = context .load_key (key )
226+ client .add_emission_proposal (kp , proposal , cid )
0 commit comments