Wallets record default address in keystore
This commit is contained in:
@@ -54,16 +54,11 @@ func (a *WalletAPI) WalletSignMessage(ctx context.Context, k address.Address, ms
|
||||
}
|
||||
|
||||
func (a *WalletAPI) WalletDefaultAddress(ctx context.Context) (address.Address, error) {
|
||||
addrs, err := a.Wallet.ListAddrs()
|
||||
if err != nil {
|
||||
return address.Undef, err
|
||||
}
|
||||
if len(addrs) == 0 {
|
||||
return address.Undef, xerrors.New("no addresses in wallet")
|
||||
}
|
||||
return a.Wallet.GetDefault()
|
||||
}
|
||||
|
||||
// TODO: store a default address in the config or 'wallet' portion of the repo
|
||||
return addrs[0], nil
|
||||
func (a *WalletAPI) WalletSetDefault(ctx context.Context, addr address.Address) error {
|
||||
return a.Wallet.SetDefault(addr)
|
||||
}
|
||||
|
||||
func (a *WalletAPI) WalletExport(ctx context.Context, addr address.Address) (*types.KeyInfo, error) {
|
||||
|
||||
@@ -2,11 +2,11 @@ package lp2p
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"github.com/filecoin-project/go-lotus/node/repo"
|
||||
"golang.org/x/xerrors"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
logging "github.com/ipfs/go-log"
|
||||
"github.com/libp2p/go-libp2p"
|
||||
connmgr "github.com/libp2p/go-libp2p-connmgr"
|
||||
@@ -31,7 +31,7 @@ func PrivKey(ks types.KeyStore) (crypto.PrivKey, error) {
|
||||
if err == nil {
|
||||
return crypto.UnmarshalPrivateKey(k.PrivateKey)
|
||||
}
|
||||
if !xerrors.Is(err, repo.ErrKeyNotFound) {
|
||||
if !xerrors.Is(err, types.ErrKeyInfoNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
pk, err := genLibp2pKey()
|
||||
|
||||
+2
-2
@@ -287,7 +287,7 @@ func (fsr *fsLockedRepo) Get(name string) (types.KeyInfo, error) {
|
||||
|
||||
fstat, err := os.Stat(keyPath)
|
||||
if os.IsNotExist(err) {
|
||||
return types.KeyInfo{}, xerrors.Errorf("opening key '%s': %w", name, ErrKeyNotFound)
|
||||
return types.KeyInfo{}, xerrors.Errorf("opening key '%s': %w", name, types.ErrKeyInfoNotFound)
|
||||
} else if err != nil {
|
||||
return types.KeyInfo{}, xerrors.Errorf("opening key '%s': %w", name, err)
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func (fsr *fsLockedRepo) Delete(name string) error {
|
||||
|
||||
_, err := os.Stat(keyPath)
|
||||
if os.IsNotExist(err) {
|
||||
return xerrors.Errorf("checking key before delete '%s': %w", name, ErrKeyNotFound)
|
||||
return xerrors.Errorf("checking key before delete '%s': %w", name, types.ErrKeyInfoNotFound)
|
||||
} else if err != nil {
|
||||
return xerrors.Errorf("checking key before delete '%s': %w", name, err)
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ var (
|
||||
ErrRepoAlreadyLocked = errors.New("repo is already locked")
|
||||
ErrClosedRepo = errors.New("repo is no longer open")
|
||||
|
||||
ErrKeyExists = errors.New("key already exists")
|
||||
ErrKeyNotFound = errors.New("key not found")
|
||||
ErrKeyExists = errors.New("key already exists")
|
||||
)
|
||||
|
||||
type Repo interface {
|
||||
|
||||
@@ -204,7 +204,7 @@ func (lmem *lockedMemRepo) Get(name string) (types.KeyInfo, error) {
|
||||
|
||||
key, ok := lmem.mem.keystore[name]
|
||||
if !ok {
|
||||
return types.KeyInfo{}, xerrors.Errorf("getting key '%s': %w", name, ErrKeyNotFound)
|
||||
return types.KeyInfo{}, xerrors.Errorf("getting key '%s': %w", name, types.ErrKeyInfoNotFound)
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
@@ -235,7 +235,7 @@ func (lmem *lockedMemRepo) Delete(name string) error {
|
||||
|
||||
_, isThere := lmem.mem.keystore[name]
|
||||
if !isThere {
|
||||
return xerrors.Errorf("deleting key '%s': %w", name, ErrKeyNotFound)
|
||||
return xerrors.Errorf("deleting key '%s': %w", name, types.ErrKeyInfoNotFound)
|
||||
}
|
||||
delete(lmem.mem.keystore, name)
|
||||
return nil
|
||||
|
||||
@@ -90,7 +90,7 @@ func basicTest(t *testing.T, repo Repo) {
|
||||
|
||||
k2prim, err := kstr.Get("k2")
|
||||
if assert.Error(t, err, "should not be able to get k2") {
|
||||
assert.True(t, xerrors.Is(err, ErrKeyNotFound), "returned error is ErrKeyNotFound")
|
||||
assert.True(t, xerrors.Is(err, types.ErrKeyInfoNotFound), "returned error is ErrKeyNotFound")
|
||||
}
|
||||
assert.Empty(t, k2prim, "there should be no output for k2")
|
||||
|
||||
@@ -110,6 +110,6 @@ func basicTest(t *testing.T, repo Repo) {
|
||||
|
||||
err = kstr.Delete("k2")
|
||||
if assert.Error(t, err) {
|
||||
assert.True(t, xerrors.Is(err, ErrKeyNotFound), "returned errror is ErrKeyNotFound")
|
||||
assert.True(t, xerrors.Is(err, types.ErrKeyInfoNotFound), "returned errror is ErrKeyNotFound")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user