Merge pull request #419 from filecoin-project/fix/change-default

handle changing default address
This commit is contained in:
Whyrusleeping 2019-10-18 21:01:00 +09:00 committed by GitHub
commit b877d41c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 8 deletions

View File

@ -4,7 +4,10 @@ import (
"fmt" "fmt"
) )
var ErrKeyInfoNotFound = fmt.Errorf("key info not found") var (
ErrKeyInfoNotFound = fmt.Errorf("key info not found")
ErrKeyExists = fmt.Errorf("key already exists")
)
// KeyInfo is used for storing keys in KeyStore // KeyInfo is used for storing keys in KeyStore
type KeyInfo struct { type KeyInfo struct {

View File

@ -3,7 +3,6 @@ package vm
import ( import (
"context" "context"
"fmt" "fmt"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"math/big" "math/big"
"github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/build"
@ -13,6 +12,7 @@ import (
"github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/bufbstore" "github.com/filecoin-project/lotus/lib/bufbstore"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
"go.opencensus.io/trace" "go.opencensus.io/trace"
@ -20,6 +20,7 @@ import (
bserv "github.com/ipfs/go-blockservice" bserv "github.com/ipfs/go-blockservice"
cid "github.com/ipfs/go-cid" cid "github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld" hamt "github.com/ipfs/go-hamt-ipld"
blockstore "github.com/ipfs/go-ipfs-blockstore"
ipld "github.com/ipfs/go-ipld-format" ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
dag "github.com/ipfs/go-merkledag" dag "github.com/ipfs/go-merkledag"
@ -460,7 +461,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
return nil, xerrors.Errorf("fatal error: %w", actorErr) return nil, xerrors.Errorf("fatal error: %w", actorErr)
} }
if actorErr != nil { if actorErr != nil {
log.Warnf("[%d] Send actor error: %+v", vm.blockHeight, actorErr) log.Warnf("[from=%s,n=%d,h=%d] Send actor error: %+v", msg.From, msg.Nonce, vm.blockHeight, actorErr)
} }
var errcode uint8 var errcode uint8

View File

@ -8,6 +8,7 @@ import (
"github.com/filecoin-project/go-bls-sigs" "github.com/filecoin-project/go-bls-sigs"
logging "github.com/ipfs/go-log"
"github.com/minio/blake2b-simd" "github.com/minio/blake2b-simd"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -16,6 +17,8 @@ import (
"github.com/filecoin-project/lotus/lib/crypto" "github.com/filecoin-project/lotus/lib/crypto"
) )
var log = logging.Logger("wallet")
const ( const (
KNamePrefix = "wallet-" KNamePrefix = "wallet-"
KDefault = "default" KDefault = "default"
@ -170,6 +173,12 @@ func (w *Wallet) SetDefault(a address.Address) error {
return err return err
} }
if err := w.keystore.Delete(KDefault); err != nil {
if !xerrors.Is(err, types.ErrKeyInfoNotFound) {
log.Warnf("failed to unregister current default key: %s", err)
}
}
if err := w.keystore.Put(KDefault, ki); err != nil { if err := w.keystore.Put(KDefault, ki); err != nil {
return err return err
} }

View File

@ -327,7 +327,7 @@ func (fsr *fsLockedRepo) Put(name string, info types.KeyInfo) error {
_, err := os.Stat(keyPath) _, err := os.Stat(keyPath)
if err == nil { if err == nil {
return xerrors.Errorf("checking key before put '%s': %w", name, ErrKeyExists) return xerrors.Errorf("checking key before put '%s': %w", name, types.ErrKeyExists)
} else if !os.IsNotExist(err) { } else if !os.IsNotExist(err) {
return xerrors.Errorf("checking key before put '%s': %w", name, err) return xerrors.Errorf("checking key before put '%s': %w", name, err)
} }

View File

@ -15,8 +15,6 @@ var (
ErrNoAPIToken = errors.New("API token not set") ErrNoAPIToken = errors.New("API token not set")
ErrRepoAlreadyLocked = errors.New("repo is already locked") ErrRepoAlreadyLocked = errors.New("repo is already locked")
ErrClosedRepo = errors.New("repo is no longer open") ErrClosedRepo = errors.New("repo is no longer open")
ErrKeyExists = errors.New("key already exists")
) )
type Repo interface { type Repo interface {

View File

@ -219,7 +219,7 @@ func (lmem *lockedMemRepo) Put(name string, key types.KeyInfo) error {
_, isThere := lmem.mem.keystore[name] _, isThere := lmem.mem.keystore[name]
if isThere { if isThere {
return xerrors.Errorf("putting key '%s': %w", name, ErrKeyExists) return xerrors.Errorf("putting key '%s': %w", name, types.ErrKeyExists)
} }
lmem.mem.keystore[name] = key lmem.mem.keystore[name] = key

View File

@ -81,7 +81,7 @@ func basicTest(t *testing.T, repo Repo) {
err = kstr.Put("k1", k1) err = kstr.Put("k1", k1)
if assert.Error(t, err, "putting key under the same name should error") { if assert.Error(t, err, "putting key under the same name should error") {
assert.True(t, xerrors.Is(err, ErrKeyExists), "returned error is ErrKeyExists") assert.True(t, xerrors.Is(err, types.ErrKeyExists), "returned error is ErrKeyExists")
} }
k1prim, err := kstr.Get("k1") k1prim, err := kstr.Get("k1")