diff --git a/api/api.go b/api/api.go index 8e9bd6b29..5ca4a156b 100644 --- a/api/api.go +++ b/api/api.go @@ -107,6 +107,7 @@ type FullNode interface { // wallet WalletNew(context.Context, string) (address.Address, error) + WalletHas(context.Context, address.Address) (bool, error) WalletList(context.Context) ([]address.Address, error) WalletBalance(context.Context, address.Address) (types.BigInt, error) WalletSign(context.Context, address.Address, []byte) (*types.Signature, error) diff --git a/api/struct.go b/api/struct.go index 332a36db9..2073f144f 100644 --- a/api/struct.go +++ b/api/struct.go @@ -56,6 +56,7 @@ type FullNodeStruct struct { MinerCreateBlock func(context.Context, address.Address, *types.TipSet, []types.Ticket, types.ElectionProof, []*types.SignedMessage) (*chain.BlockMsg, error) `perm:"write"` WalletNew func(context.Context, string) (address.Address, error) `perm:"write"` + WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"` WalletList func(context.Context) ([]address.Address, error) `perm:"write"` WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"` WalletSign func(context.Context, address.Address, []byte) (*types.Signature, error) `perm:"sign"` @@ -173,6 +174,10 @@ func (c *FullNodeStruct) WalletNew(ctx context.Context, typ string) (address.Add return c.Internal.WalletNew(ctx, typ) } +func (c *FullNodeStruct) WalletHas(ctx context.Context, addr address.Address) (bool, error) { + return c.Internal.WalletHas(ctx, addr) +} + func (c *FullNodeStruct) WalletList(ctx context.Context) ([]address.Address, error) { return c.Internal.WalletList(ctx) } diff --git a/node/impl/full.go b/node/impl/full.go index 3fb40eb84..aae954b0c 100644 --- a/node/impl/full.go +++ b/node/impl/full.go @@ -244,6 +244,10 @@ func (a *FullNodeAPI) WalletNew(ctx context.Context, typ string) (address.Addres return a.Wallet.GenerateKey(typ) } +func (a *FullNodeAPI) WalletHas(ctx context.Context, addr address.Address) (bool, error) { + return a.Wallet.HasKey(addr) +} + func (a *FullNodeAPI) WalletList(ctx context.Context) ([]address.Address, error) { return a.Wallet.ListAddrs() } diff --git a/storage/miner.go b/storage/miner.go index a303bef11..4c74cd7f8 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -49,7 +49,7 @@ type storageMinerApi interface { WalletBalance(context.Context, address.Address) (types.BigInt, error) WalletSign(context.Context, address.Address, []byte) (*types.Signature, error) - WalletList(context.Context) ([]address.Address, error) + WalletHas(context.Context, address.Address) (bool, error) } func NewMiner(api storageMinerApi, addr address.Address, h host.Host, ds datastore.Batching, sb *sectorbuilder.SectorBuilder) (*Miner, error) { @@ -173,17 +173,10 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error { m.worker = worker - addrs, err := m.api.WalletList(ctx) + has, err := m.api.WalletHas(ctx, worker) if err != nil { return errors.Wrap(err, "failed to check wallet for worker key") } - var has bool - for _, a := range addrs { - if a == worker { - has = true - break - } - } if !has { return errors.New("key for worker not found in local wallet")