Merge pull request #11140 from filecoin-project/fix/wallet-balance-cmd
fix: cli: Only display `warning` if behind sync
This commit is contained in:
commit
80928586d1
19
cli/sync.go
19
cli/sync.go
@ -273,11 +273,6 @@ func SyncWait(ctx context.Context, napi v0api.FullNode, watch bool) error {
|
||||
continue
|
||||
}
|
||||
|
||||
head, err := napi.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
working := -1
|
||||
for i, ss := range state.ActiveSyncs {
|
||||
switch ss.Stage {
|
||||
@ -332,7 +327,11 @@ func SyncWait(ctx context.Context, napi v0api.FullNode, watch bool) error {
|
||||
|
||||
_ = target // todo: maybe print? (creates a bunch of line wrapping issues with most tipsets)
|
||||
|
||||
if !watch && time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs) {
|
||||
isDone, err := IsSyncDone(ctx, napi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !watch && isDone {
|
||||
fmt.Println("\nDone!")
|
||||
return nil
|
||||
}
|
||||
@ -347,3 +346,11 @@ func SyncWait(ctx context.Context, napi v0api.FullNode, watch bool) error {
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
func IsSyncDone(ctx context.Context, napi v0api.FullNode) (bool, error) {
|
||||
head, err := napi.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs), nil
|
||||
}
|
||||
|
@ -206,7 +206,12 @@ var walletBalance = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
if balance.Equals(types.NewInt(0)) {
|
||||
inSync, err := IsSyncDone(ctx, api)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if balance.Equals(types.NewInt(0)) && !inSync {
|
||||
afmt.Printf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance))
|
||||
} else {
|
||||
afmt.Printf("%s\n", types.FIL(balance))
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/types/mock"
|
||||
)
|
||||
|
||||
func TestWalletNew(t *testing.T) {
|
||||
@ -133,6 +134,11 @@ func TestWalletBalance(t *testing.T) {
|
||||
|
||||
balance := big.NewInt(1234)
|
||||
|
||||
// add blocks to the chain
|
||||
first := mock.TipSet(mock.MkBlock(nil, 5, 4))
|
||||
head := mock.TipSet(mock.MkBlock(first, 15, 7))
|
||||
|
||||
mockApi.EXPECT().ChainHead(ctx).Return(head, nil)
|
||||
mockApi.EXPECT().WalletBalance(ctx, addr).Return(balance, nil)
|
||||
|
||||
//stm: @CLI_WALLET_BALANCE_001
|
||||
|
Loading…
Reference in New Issue
Block a user