66 "errors"
77 "fmt"
88 "os"
9- "os/exec"
109 "strings"
1110 "time"
1211)
@@ -33,15 +32,15 @@ func (s *svc) EnsureKey(ctx context.Context, name string) (KeyInfo, error) {
3332 }
3433
3534 // Check if key already exists
36- show := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir )
35+ show := commandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir )
3736 out , err := show .Output ()
3837 if err == nil {
3938 // Key exists - fetch details
4039 return s .getKeyInfo (ctx , name , strings .TrimSpace (string (out )), "" )
4140 }
4241
4342 // Key doesn't exist - create it and capture output
44- add := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "add" , name , "--keyring-backend" , s .opts .Keyring , "--algo" , "eth_secp256k1" , "--home" , s .opts .HomeDir )
43+ add := commandContext (ctx , s .opts .BinPath , "keys" , "add" , name , "--keyring-backend" , s .opts .Keyring , "--algo" , "eth_secp256k1" , "--home" , s .opts .HomeDir )
4544
4645 // Capture output to parse mnemonic
4746 output , err := add .CombinedOutput ()
@@ -53,7 +52,7 @@ func (s *svc) EnsureKey(ctx context.Context, name string) (KeyInfo, error) {
5352 mnemonic := extractMnemonic (string (output ))
5453
5554 // Get the address
56- out2 , err := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir ).Output ()
55+ out2 , err := commandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir ).Output ()
5756 if err != nil {
5857 return KeyInfo {}, fmt .Errorf ("keys show: %w" , err )
5958 }
@@ -65,7 +64,7 @@ func (s *svc) EnsureKey(ctx context.Context, name string) (KeyInfo, error) {
6564// getKeyInfo fetches full key details
6665func (s * svc ) getKeyInfo (ctx context.Context , name , addr , mnemonic string ) (KeyInfo , error ) {
6766 // Get key details in JSON format
68- cmd := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir , "--output" , "json" )
67+ cmd := commandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir , "--output" , "json" )
6968 out , err := cmd .Output ()
7069 if err != nil {
7170 return KeyInfo {Address : addr , Name : name , Mnemonic : mnemonic }, nil
@@ -176,13 +175,13 @@ func (s *svc) ImportKey(ctx context.Context, name string, mnemonic string) (KeyI
176175 }
177176
178177 // Check if key already exists
179- show := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir )
178+ show := commandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir )
180179 if out , err := show .Output (); err == nil {
181180 return KeyInfo {}, fmt .Errorf ("key '%s' already exists with address %s" , name , strings .TrimSpace (string (out )))
182181 }
183182
184183 // Import key using --recover flag with mnemonic piped via stdin
185- add := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "add" , name ,
184+ add := commandContext (ctx , s .opts .BinPath , "keys" , "add" , name ,
186185 "--recover" ,
187186 "--keyring-backend" , s .opts .Keyring ,
188187 "--algo" , "eth_secp256k1" ,
@@ -206,7 +205,7 @@ func (s *svc) ImportKey(ctx context.Context, name string, mnemonic string) (KeyI
206205 }
207206
208207 // Get the address of the imported key
209- out2 , err := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir ).Output ()
208+ out2 , err := commandContext (ctx , s .opts .BinPath , "keys" , "show" , name , "-a" , "--keyring-backend" , s .opts .Keyring , "--home" , s .opts .HomeDir ).Output ()
210209 if err != nil {
211210 return KeyInfo {}, fmt .Errorf ("failed to get imported key address: %w" , err )
212211 }
@@ -226,7 +225,7 @@ func (s *svc) findExistingKeyByMnemonic(ctx context.Context, name, mnemonic stri
226225 }
227226 defer os .RemoveAll (tmpDir )
228227
229- dryRun := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "add" , "temp" ,
228+ dryRun := commandContext (ctx , s .opts .BinPath , "keys" , "add" , "temp" ,
230229 "--recover" , "--dry-run" ,
231230 "--keyring-backend" , "test" ,
232231 "--algo" , "eth_secp256k1" ,
@@ -247,7 +246,7 @@ func (s *svc) findExistingKeyByMnemonic(ctx context.Context, name, mnemonic stri
247246 }
248247
249248 // List all keys and find the one with matching address
250- listCmd := exec . CommandContext (ctx , s .opts .BinPath , "keys" , "list" ,
249+ listCmd := commandContext (ctx , s .opts .BinPath , "keys" , "list" ,
251250 "--keyring-backend" , s .opts .Keyring ,
252251 "--home" , s .opts .HomeDir ,
253252 "--output" , "json" )
@@ -280,7 +279,7 @@ func (s *svc) GetEVMAddress(ctx context.Context, addr string) (string, error) {
280279 if s .opts .BinPath == "" {
281280 s .opts .BinPath = "pchaind"
282281 }
283- cmd := exec . CommandContext (ctx , s .opts .BinPath , "debug" , "addr" , addr )
282+ cmd := commandContext (ctx , s .opts .BinPath , "debug" , "addr" , addr )
284283 out , err := cmd .Output ()
285284 if err != nil {
286285 return "" , fmt .Errorf ("debug addr: %w" , err )
@@ -304,7 +303,7 @@ func (s *svc) IsValidator(ctx context.Context, addr string) (bool, error) {
304303 s .opts .BinPath = "pchaind"
305304 }
306305 // Compare local consensus pubkey with remote validators
307- showVal := exec . CommandContext (ctx , s .opts .BinPath , "tendermint" , "show-validator" , "--home" , s .opts .HomeDir )
306+ showVal := commandContext (ctx , s .opts .BinPath , "tendermint" , "show-validator" , "--home" , s .opts .HomeDir )
308307 b , err := showVal .Output ()
309308 if err != nil {
310309 return false , fmt .Errorf ("show-validator: %w" , err )
@@ -320,7 +319,7 @@ func (s *svc) IsValidator(ctx context.Context, addr string) (bool, error) {
320319 }
321320 // Query validators from remote
322321 remote := fmt .Sprintf ("https://%s" , s .opts .GenesisDomain )
323- q := exec . CommandContext (ctx , s .opts .BinPath , "query" , "staking" , "validators" , "--node" , remote , "-o" , "json" )
322+ q := commandContext (ctx , s .opts .BinPath , "query" , "staking" , "validators" , "--node" , remote , "-o" , "json" )
324323 vb , err := q .Output ()
325324 if err != nil {
326325 return false , fmt .Errorf ("query validators: %w" , err )
@@ -354,7 +353,7 @@ func (s *svc) IsAddressValidator(ctx context.Context, cosmosAddr string) (bool,
354353
355354 // Query validators from remote
356355 remote := fmt .Sprintf ("https://%s" , s .opts .GenesisDomain )
357- q := exec . CommandContext (ctx , s .opts .BinPath , "query" , "staking" , "validators" , "--node" , remote , "-o" , "json" )
356+ q := commandContext (ctx , s .opts .BinPath , "query" , "staking" , "validators" , "--node" , remote , "-o" , "json" )
358357 vb , err := q .Output ()
359358 if err != nil {
360359 return false , fmt .Errorf ("query validators: %w" , err )
@@ -401,7 +400,7 @@ func (s *svc) Balance(ctx context.Context, addr string) (string, error) {
401400 }
402401 // Always query remote genesis node for canonical state during validator registration
403402 remote := fmt .Sprintf ("https://%s" , s .opts .GenesisDomain )
404- q := exec . CommandContext (ctx , s .opts .BinPath , "query" , "bank" , "balances" , addr , "--node" , remote , "-o" , "json" )
403+ q := commandContext (ctx , s .opts .BinPath , "query" , "bank" , "balances" , addr , "--node" , remote , "-o" , "json" )
405404 out , err := q .Output ()
406405 if err != nil {
407406 return "0" , fmt .Errorf ("query balance: %w" , err )
@@ -427,7 +426,7 @@ func (s *svc) Register(ctx context.Context, args RegisterArgs) (string, error) {
427426 // Prepare validator JSON - use a separate timeout for this command
428427 showCtx , showCancel := context .WithTimeout (context .Background (), 30 * time .Second )
429428 defer showCancel ()
430- pubJSON , err := exec . CommandContext (showCtx , s .opts .BinPath , "tendermint" , "show-validator" , "--home" , s .opts .HomeDir ).Output ()
429+ pubJSON , err := commandContext (showCtx , s .opts .BinPath , "tendermint" , "show-validator" , "--home" , s .opts .HomeDir ).Output ()
431430 if err != nil {
432431 return "" , fmt .Errorf ("show-validator: %w" , err )
433432 }
@@ -460,7 +459,7 @@ func (s *svc) Register(ctx context.Context, args RegisterArgs) (string, error) {
460459 remote := fmt .Sprintf ("https://%s" , s .opts .GenesisDomain )
461460 ctxTimeout , cancel := context .WithTimeout (ctx , 60 * time .Second )
462461 defer cancel ()
463- cmd := exec . CommandContext (ctxTimeout , s .opts .BinPath , "tx" , "staking" , "create-validator" , tmp .Name (),
462+ cmd := commandContext (ctxTimeout , s .opts .BinPath , "tx" , "staking" , "create-validator" , tmp .Name (),
464463 "--from" , args .KeyName ,
465464 "--chain-id" , s .opts .ChainID ,
466465 "--keyring-backend" , s .opts .Keyring ,
@@ -541,7 +540,7 @@ func (s *svc) Unjail(ctx context.Context, keyName string) (string, error) {
541540 ctxTimeout , cancel := context .WithTimeout (ctx , 60 * time .Second )
542541 defer cancel ()
543542
544- cmd := exec . CommandContext (ctxTimeout , s .opts .BinPath , "tx" , "slashing" , "unjail" ,
543+ cmd := commandContext (ctxTimeout , s .opts .BinPath , "tx" , "slashing" , "unjail" ,
545544 "--from" , keyName ,
546545 "--chain-id" , s .opts .ChainID ,
547546 "--keyring-backend" , s .opts .Keyring ,
@@ -608,7 +607,7 @@ func (s *svc) WithdrawRewards(ctx context.Context, validatorAddr string, keyName
608607 ctxTimeout , cancel := context .WithTimeout (ctx , 60 * time .Second )
609608 defer cancel ()
610609
611- cmd := exec . CommandContext (ctxTimeout , s .opts .BinPath , args ... )
610+ cmd := commandContext (ctxTimeout , s .opts .BinPath , args ... )
612611 out , err := cmd .CombinedOutput ()
613612 if err != nil {
614613 // Extract and enhance error message
@@ -672,7 +671,7 @@ func (s *svc) Delegate(ctx context.Context, args DelegateArgs) (string, error) {
672671 ctxTimeout , cancel := context .WithTimeout (ctx , 60 * time .Second )
673672 defer cancel ()
674673
675- cmd := exec . CommandContext (ctxTimeout , s .opts .BinPath , "tx" , "staking" , "delegate" ,
674+ cmd := commandContext (ctxTimeout , s .opts .BinPath , "tx" , "staking" , "delegate" ,
676675 args .ValidatorAddress ,
677676 fmt .Sprintf ("%s%s" , args .Amount , s .opts .Denom ),
678677 "--from" , args .KeyName ,
0 commit comments