@@ -72,7 +72,7 @@ async def safe_stake_extrinsic(
72
72
hotkey_ss58_ : str ,
73
73
price_limit : Balance ,
74
74
status = None ,
75
- ) -> bool :
75
+ ) -> tuple [ bool , str ] :
76
76
err_out = partial (print_error , status = status )
77
77
failure_prelude = (
78
78
f":cross_mark: [red]Failed[/red] to stake { amount_ } on Netuid { netuid_ } "
@@ -104,25 +104,24 @@ async def safe_stake_extrinsic(
104
104
)
105
105
except SubstrateRequestException as e :
106
106
if "Custom error: 8" in str (e ):
107
- print_error (
108
- f"\n { failure_prelude } : Price exceeded tolerance limit. "
107
+ err_msg = (
108
+ f"{ failure_prelude } : Price exceeded tolerance limit. "
109
109
f"Transaction rejected because partial staking is disabled. "
110
110
f"Either increase price tolerance or enable partial staking." ,
111
- status = status ,
112
111
)
113
- return False
112
+ print_error ( " \n " + err_msg , status = status )
114
113
else :
115
- err_out (f"\n { failure_prelude } with error: { format_error_message (e )} " )
116
- return False
114
+ err_msg = f"{ failure_prelude } with error: { format_error_message (e )} "
115
+ err_out ("\n " + err_msg )
116
+ return False , err_msg
117
117
if not await response .is_success :
118
- err_out (
119
- f"\n { failure_prelude } with error: { format_error_message (await response .error_message )} "
120
- )
121
- return False
118
+ err_msg = f"{ failure_prelude } with error: { format_error_message (await response .error_message )} "
119
+ err_out ("\n " + err_msg )
120
+ return False , err_msg
122
121
else :
123
122
if json_output :
124
123
# the rest of this checking is not necessary if using json_output
125
- return True
124
+ return True , ""
126
125
block_hash = await subtensor .substrate .get_chain_head ()
127
126
new_balance , new_stake = await asyncio .gather (
128
127
subtensor .get_balance (wallet .coldkeypub .ss58_address , block_hash ),
@@ -160,11 +159,11 @@ async def safe_stake_extrinsic(
160
159
f":arrow_right: "
161
160
f"[{ COLOR_PALETTE ['STAKE' ]['STAKE_AMOUNT' ]} ]{ new_stake } \n "
162
161
)
163
- return True
162
+ return True , ""
164
163
165
164
async def stake_extrinsic (
166
165
netuid_i , amount_ , current , staking_address_ss58 , status = None
167
- ) -> bool :
166
+ ) -> tuple [ bool , str ] :
168
167
err_out = partial (print_error , status = status )
169
168
current_balance , next_nonce , call = await asyncio .gather (
170
169
subtensor .get_balance (wallet .coldkeypub .ss58_address ),
@@ -190,18 +189,18 @@ async def stake_extrinsic(
190
189
extrinsic , wait_for_inclusion = True , wait_for_finalization = False
191
190
)
192
191
except SubstrateRequestException as e :
193
- err_out (f"\n { failure_prelude } with error: { format_error_message (e )} " )
194
- return False
192
+ err_msg = f"{ failure_prelude } with error: { format_error_message (e )} "
193
+ err_out ("\n " + err_msg )
194
+ return False , err_msg
195
195
else :
196
196
if not await response .is_success :
197
- err_out (
198
- f"\n { failure_prelude } with error: { format_error_message (await response .error_message )} "
199
- )
200
- return False
197
+ err_msg = f"{ failure_prelude } with error: { format_error_message (await response .error_message )} "
198
+ err_out ("\n " + err_msg )
199
+ return False , err_msg
201
200
else :
202
201
if json_output :
203
202
# the rest of this is not necessary if using json_output
204
- return True
203
+ return True , ""
205
204
new_block_hash = await subtensor .substrate .get_chain_head ()
206
205
new_balance , new_stake = await asyncio .gather (
207
206
subtensor .get_balance (
@@ -230,7 +229,7 @@ async def stake_extrinsic(
230
229
f":arrow_right: "
231
230
f"[{ COLOR_PALETTE ['STAKE' ]['STAKE_AMOUNT' ]} ]{ new_stake } \n "
232
231
)
233
- return True
232
+ return True , ""
234
233
235
234
netuids = (
236
235
netuids if netuids is not None else await subtensor .get_all_subnet_netuids ()
@@ -417,13 +416,17 @@ async def stake_extrinsic(
417
416
for _ , staking_address in hotkeys_to_stake_to
418
417
}
419
418
successes = defaultdict (dict )
419
+ error_messages = defaultdict (dict )
420
420
with console .status (f"\n :satellite: Staking on netuid(s): { netuids } ..." ):
421
421
# We can gather them all at once but balance reporting will be in race-condition.
422
422
for (ni , staking_address ), coroutine in stake_coroutines .items ():
423
- success = await coroutine
423
+ success , er_msg = await coroutine
424
424
successes [ni ][staking_address ] = success
425
+ error_messages [ni ][staking_address ] = er_msg
425
426
if json_output :
426
- json_console .print (json .dumps ({"staking_success" : successes }))
427
+ json_console .print (
428
+ json .dumps ({"staking_success" : successes , "error_messages" : error_messages })
429
+ )
427
430
428
431
429
432
# Helper functions
0 commit comments