fix: return NotFoundErr from StateVerifiedClientStatus() if addr not found
This commit is contained in:
parent
2c7aa318c1
commit
8489fb258a
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"golang.org/x/xerrors"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
|
||||
@ -535,3 +536,5 @@ type Fault struct {
|
||||
Miner address.Address
|
||||
Epoch abi.ChainEpoch
|
||||
}
|
||||
|
||||
var NotFoundErr = xerrors.Errorf("Not found")
|
||||
|
@ -317,27 +317,25 @@ var clientDealCmd = &cli.Command{
|
||||
}
|
||||
|
||||
// Check if the address is a verified client
|
||||
dcap, err := api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK)
|
||||
if err != nil {
|
||||
_, err = api.StateVerifiedClientStatus(ctx, a, types.EmptyTSK)
|
||||
isVerified := true
|
||||
if err == lapi.NotFoundErr {
|
||||
isVerified = false
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
verifiedDeal := false
|
||||
if !dcap.IsZero() {
|
||||
verifiedDeal = true
|
||||
}
|
||||
|
||||
// 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
|
||||
// client, return an error
|
||||
verifiedDealParam := cctx.Bool("verified-deal")
|
||||
if verifiedDealParam && dcap.IsZero() {
|
||||
if verifiedDealParam && !isVerified {
|
||||
return xerrors.Errorf("address %s does not have verified client status", a)
|
||||
}
|
||||
|
||||
// Override the default
|
||||
verifiedDeal = verifiedDealParam
|
||||
isVerified = verifiedDealParam
|
||||
}
|
||||
|
||||
proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{
|
||||
@ -348,7 +346,7 @@ var clientDealCmd = &cli.Command{
|
||||
MinBlocksDuration: uint64(dur),
|
||||
DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")),
|
||||
FastRetrieval: cctx.Bool("fast-retrieval"),
|
||||
VerifiedDeal: verifiedDeal,
|
||||
VerifiedDeal: isVerified,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -812,7 +812,9 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
|
||||
return types.BigAdd(st.GetAvailableBalance(act.Balance), vested), nil
|
||||
}
|
||||
|
||||
// StateVerifiedClientStatus returns the data cap for the given address, or zero if the client is not registered
|
||||
// StateVerifiedClientStatus returns the data cap for the given address.
|
||||
// Returns ErrNotFound if there is not 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) {
|
||||
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
|
||||
if err != nil {
|
||||
@ -833,9 +835,8 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A
|
||||
|
||||
var dcap verifreg.DataCap
|
||||
if err := vh.Find(ctx, string(addr.Bytes()), &dcap); err != nil {
|
||||
// If there is no entry in the data cap table, just return zero
|
||||
if err == hamt.ErrNotFound {
|
||||
return verifreg.DataCap{}, nil
|
||||
return verifreg.DataCap{}, api.NotFoundErr
|
||||
}
|
||||
return verifreg.DataCap{}, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user