status-go/cmd/wnode-status/test_accounts.go
Ivan Daniluk 4536e99275 Improve statusd CLI usage (#441)
This PR refactors CLI API, removes obsolete commands and splits status code into smaller pieces:

* get rid of subcommands API (no ./status <command>)
* get rid of custom cli app package
* use stdlib flag package for handling command line flags
* move cross-compilation / mobile related code to lib/ package
* move wnode command into separate binary (cmd/node-status, name is subject to discuss)
* remove faucet command as obsolete
* update/add docs/READMES/wikis for new command line flags

It makes statusd code much simpler and smaller, separates concerns (lib, wnode and statusd are different things).
2017-11-03 18:07:13 -04:00

70 lines
1.7 KiB
Go

package main
import (
"fmt"
"path/filepath"
"github.com/status-im/status-go/geth/account"
"github.com/status-im/status-go/geth/common"
)
// LoadTestAccounts loads public key files for test accounts
func LoadTestAccounts(dataDir string) error {
files := []string{"test-account1.pk", "test-account2.pk"}
dir := filepath.Join(dataDir, "keystore")
for _, filename := range files {
if err := common.ImportTestAccount(dir, filename); err != nil {
return err
}
}
return nil
}
// InjectTestAccounts injects test accounts into running node
func InjectTestAccounts(node common.NodeManager) error {
testConfig, err := common.LoadTestConfig()
if err != nil {
return err
}
if err = injectAccountIntoWhisper(node, testConfig.Account1.Address,
testConfig.Account1.Password); err != nil {
return err
}
if err = injectAccountIntoWhisper(node, testConfig.Account2.Address,
testConfig.Account2.Password); err != nil {
return err
}
return nil
}
// injectAccountIntoWhisper adds key pair into Whisper. Similar to Select/Login,
// but allows multiple accounts to be injected.
func injectAccountIntoWhisper(node common.NodeManager, address, password string) error {
keyStore, err := node.AccountKeyStore()
if err != nil {
return err
}
acct, err := common.ParseAccountString(address)
if err != nil {
return account.ErrAddressToAccountMappingFailure
}
_, accountKey, err := keyStore.AccountDecryptedKey(acct, password)
if err != nil {
return fmt.Errorf("%s: %v", account.ErrAccountToKeyMappingFailure.Error(), err)
}
whisperService, err := node.WhisperService()
if err != nil {
return err
}
if _, err = whisperService.AddKeyPair(accountKey.PrivateKey); err != nil {
return err
}
return nil
}