fix: use nil return from StateVerifiedClientStatus for not-found

This commit is contained in:
Dirk McCormick 2020-07-07 09:59:14 -04:00
parent 40113933b4
commit c86e864d55
4 changed files with 20 additions and 23 deletions

View File

@ -241,7 +241,7 @@ type FullNode interface {
StateGetReceipt(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error)
StateMinerSectorCount(context.Context, address.Address, types.TipSetKey) (MinerSectors, error)
StateCompute(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*ComputeStateOutput, error)
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error)
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*verifreg.DataCap, error)
// MethodGroup: Msig
// The Msig methods are used to interact with multisig wallets on the

View File

@ -317,14 +317,13 @@ var clientDealCmd = &cli.Command{
}
// Check if the address is a verified client
_, err = api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK)
isVerified := true
if err == lapi.NotFoundErr {
isVerified = false
} else if err != nil {
dcap, err := api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK)
if err != nil {
return err
}
isVerified := dcap != nil
// If the user has explicitly set the --verified-deal flag
if cctx.IsSet("verified-deal") {
// If --verified-deal is true, but the address is not a verified

View File

@ -3,12 +3,10 @@ package main
import (
"bytes"
"fmt"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/build"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
@ -303,13 +301,13 @@ var verifRegCheckClientCmd = &cli.Command{
dcap, err := api.StateVerifiedClientStatus(ctx, caddr, types.EmptyTSK)
if err != nil {
if err == lapi.NotFoundErr {
return xerrors.Errorf("client %s is not a verified client", err)
}
return err
}
if dcap == nil {
return xerrors.Errorf("client %s is not a verified client", err)
}
fmt.Println(dcap)
fmt.Println(*dcap)
return nil
},

View File

@ -813,33 +813,33 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
}
// StateVerifiedClientStatus returns the data cap for the given address.
// Returns ErrNotFound if there is not entry in the data cap table for the
// Returns nil if there is no entry in the data cap table for the
// address.
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) {
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*verifreg.DataCap, error) {
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
if err != nil {
return verifreg.DataCap{}, err
return nil, err
}
cst := cbor.NewCborStore(a.StateManager.ChainStore().Blockstore())
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return verifreg.DataCap{}, err
return nil, err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return verifreg.DataCap{}, err
return nil, err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(addr.Bytes()), &dcap); err != nil {
if err == hamt.ErrNotFound {
return verifreg.DataCap{}, api.NotFoundErr
return nil, nil
}
return verifreg.DataCap{}, err
return nil, err
}
return dcap, nil
return &dcap, nil
}