This commit is contained in:
Jim McDonald
2020-11-17 15:53:42 +00:00
parent e042be75ce
commit 0b7a24df6e
14 changed files with 50 additions and 57 deletions

View File

@@ -17,7 +17,7 @@ import (
"github.com/spf13/viper"
)
// GetBaseDir() fetches the base directory for wallets.
// GetBaseDir fetches the base directory for wallets.
func GetBaseDir() string {
baseDir := viper.GetString("base-dir")
if baseDir == "" {

View File

@@ -74,6 +74,7 @@ type depositInfoCLI struct {
Amount uint64 `json:"amount"`
}
// DepositInfoFromJSON obtains deposit info from various possibly formx of JSON.
func DepositInfoFromJSON(input []byte) ([]*DepositInfo, error) {
if len(input) == 0 {
return nil, errors.New("no data supplied")

View File

@@ -26,8 +26,8 @@ import (
// Log is the ethdo global logger.
var Log zerolog.Logger
// initLogging initialises logging.
func initLogging() error {
// InitLogging initialises logging.
func InitLogging() error {
// Change the output file.
if viper.GetString("log-file") != "" {
f, err := os.OpenFile(viper.GetString("log-file"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)

View File

@@ -18,7 +18,7 @@ import (
"github.com/spf13/viper"
)
// GetStorePassphrases() fetches the store passphrase supplied by the user.
// GetStorePassphrase fetches the store passphrase supplied by the user.
func GetStorePassphrase() string {
storePassphrase := viper.GetString("store-passphrase")
if storePassphrase == "" {
@@ -28,7 +28,7 @@ func GetStorePassphrase() string {
return storePassphrase
}
// GetWalletPassphrases() fetches the wallet passphrase supplied by the user.
// GetWalletPassphrase fetches the wallet passphrase supplied by the user.
func GetWalletPassphrase() string {
walletPassphrase := viper.GetString("wallet-passphrase")
if walletPassphrase == "" {
@@ -38,12 +38,12 @@ func GetWalletPassphrase() string {
return walletPassphrase
}
// GetPassphrases() fetches the passphrases supplied by the user.
// GetPassphrases fetches the passphrases supplied by the user.
func GetPassphrases() []string {
return viper.GetStringSlice("passphrase")
}
// getPassphrase fetches the passphrase supplied by the user.
// GetPassphrase fetches the passphrase supplied by the user.
func GetPassphrase() (string, error) {
passphrases := GetPassphrases()
if len(passphrases) == 0 {

View File

@@ -60,36 +60,44 @@ func newScratchAccountFromPubKey(pubKey []byte) (*ScratchAccount, error) {
}, nil
}
// ID returns the account ID.
func (a *ScratchAccount) ID() uuid.UUID {
return a.id
}
// Name returns the account name.
func (a *ScratchAccount) Name() string {
return "scratch"
}
// PublicKey returns the account public key.
func (a *ScratchAccount) PublicKey() e2types.PublicKey {
return a.pubKey
}
// Path returns the account path.
func (a *ScratchAccount) Path() string {
return ""
}
// Lock locks the account.
func (a *ScratchAccount) Lock(ctx context.Context) error {
a.unlocked = false
return nil
}
// Unlock unlocks the account.
func (a *ScratchAccount) Unlock(ctx context.Context, passphrase []byte) error {
a.unlocked = true
return nil
}
// IsUnlocked returns true if the account is unlocked.
func (a *ScratchAccount) IsUnlocked(ctx context.Context) (bool, error) {
return a.unlocked, nil
}
// Sign signs data with the account's private key.
func (a *ScratchAccount) Sign(ctx context.Context, data []byte) (e2types.Signature, error) {
if !a.unlocked {
return nil, errors.New("locked")

View File

@@ -138,7 +138,7 @@ func TestScratchAccountFromPublicKey(t *testing.T) {
require.True(t, unlocked)
_, err = account.Sign(context.Background(), testutil.HexToBytes("0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"))
require.EqualError(t, err, "no private key")
account.Lock(context.Background())
require.NoError(t, account.Lock(context.Background()))
unlocked, err = account.IsUnlocked(context.Background())
require.NoError(t, err)
require.False(t, unlocked)