Add delete functionality to the wallet
This commit is contained in:
parent
9e2603c1bf
commit
49b27da426
@ -101,6 +101,7 @@ type FullNode interface {
|
|||||||
WalletSetDefault(context.Context, address.Address) error
|
WalletSetDefault(context.Context, address.Address) error
|
||||||
WalletExport(context.Context, address.Address) (*types.KeyInfo, error)
|
WalletExport(context.Context, address.Address) (*types.KeyInfo, error)
|
||||||
WalletImport(context.Context, *types.KeyInfo) (address.Address, error)
|
WalletImport(context.Context, *types.KeyInfo) (address.Address, error)
|
||||||
|
WalletDelete(context.Context, address.Address) error
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
|
|
||||||
|
@ -104,6 +104,7 @@ type FullNodeStruct struct {
|
|||||||
WalletSetDefault func(context.Context, address.Address) error `perm:"admin"`
|
WalletSetDefault func(context.Context, address.Address) error `perm:"admin"`
|
||||||
WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"`
|
WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"`
|
||||||
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"`
|
||||||
|
WalletDelete func(context.Context, address.Address) error `perm:"write"`
|
||||||
|
|
||||||
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
ClientImport func(ctx context.Context, ref api.FileRef) (cid.Cid, error) `perm:"admin"`
|
||||||
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"`
|
||||||
@ -427,6 +428,10 @@ func (c *FullNodeStruct) WalletImport(ctx context.Context, ki *types.KeyInfo) (a
|
|||||||
return c.Internal.WalletImport(ctx, ki)
|
return c.Internal.WalletImport(ctx, ki)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *FullNodeStruct) WalletDelete(ctx context.Context, addr address.Address) error {
|
||||||
|
return c.Internal.WalletDelete(ctx, addr)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) {
|
||||||
return c.Internal.MpoolGetNonce(ctx, addr)
|
return c.Internal.MpoolGetNonce(ctx, addr)
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ import (
|
|||||||
var log = logging.Logger("wallet")
|
var log = logging.Logger("wallet")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
KNamePrefix = "wallet-"
|
KNamePrefix = "wallet-"
|
||||||
KDefault = "default"
|
KTrashPrefix = "trash-"
|
||||||
KTBLS = "bls"
|
KDefault = "default"
|
||||||
KTSecp256k1 = "secp256k1"
|
KTBLS = "bls"
|
||||||
|
KTSecp256k1 = "secp256k1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Wallet struct {
|
type Wallet struct {
|
||||||
@ -230,6 +231,23 @@ func (w *Wallet) HasKey(addr address.Address) (bool, error) {
|
|||||||
return k != nil, nil
|
return k != nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Wallet) DeleteKey(addr address.Address) error {
|
||||||
|
k, err := w.findKey(addr)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("failed to delete key %s : %w", addr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.keystore.Put(KTrashPrefix+k.Address.String(), k.KeyInfo); err != nil {
|
||||||
|
return xerrors.Errorf("failed to mark key %s as trashed: %w", addr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := w.keystore.Delete(KNamePrefix + k.Address.String()); err != nil {
|
||||||
|
return xerrors.Errorf("failed to delete key %s: %w", addr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type Key struct {
|
type Key struct {
|
||||||
types.KeyInfo
|
types.KeyInfo
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ var walletCmd = &cli.Command{
|
|||||||
walletSetDefault,
|
walletSetDefault,
|
||||||
walletSign,
|
walletSign,
|
||||||
walletVerify,
|
walletVerify,
|
||||||
|
walletDelete,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,3 +376,28 @@ var walletVerify = &cli.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var walletDelete = &cli.Command{
|
||||||
|
Name: "delete",
|
||||||
|
Usage: "Delete an account from the wallet",
|
||||||
|
ArgsUsage: "<address> ",
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
if !cctx.Args().Present() || cctx.NArg() != 1 {
|
||||||
|
return fmt.Errorf("must specify address to delete")
|
||||||
|
}
|
||||||
|
|
||||||
|
addr, err := address.NewFromString(cctx.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.WalletDelete(ctx, addr)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -76,3 +76,7 @@ func (a *WalletAPI) WalletExport(ctx context.Context, addr address.Address) (*ty
|
|||||||
func (a *WalletAPI) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) {
|
func (a *WalletAPI) WalletImport(ctx context.Context, ki *types.KeyInfo) (address.Address, error) {
|
||||||
return a.Wallet.Import(ki)
|
return a.Wallet.Import(ki)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *WalletAPI) WalletDelete(ctx context.Context, addr address.Address) error {
|
||||||
|
return a.Wallet.DeleteKey(addr)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user