Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/wallet balance cmd #6107

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion cmd/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"strings"
"time"

"github.com/howeyc/gopass"

Expand Down Expand Up @@ -261,10 +262,35 @@ var balanceCmd = &cmds.Command{
return err
}

return printOneString(re, (types.FIL)(balance).String())
isDone, err := isSyncDone(req.Context, env)
if err != nil {
return err
}

var balanceStr string
if balance.Equals(big.NewInt(0)) && !isDone {
balanceStr = fmt.Sprintf("%s (warning: may display 0 if chain sync in progress)", types.FIL(balance))
} else {
balanceStr = (types.FIL)(balance).String()
}

return printOneString(re, balanceStr)
},
}

func isSyncDone(ctx context.Context, env cmds.Environment) (bool, error) {
head, err := getEnv(env).ChainAPI.ChainHead(ctx)
if err != nil {
return false, err
}
params, err := getEnv(env).ChainAPI.StateGetNetworkParams(ctx)
if err != nil {
return false, err
}

return time.Now().Unix()-int64(head.MinTimestamp()) < int64(params.BlockDelaySecs), nil
}

// WalletSerializeResult is the type wallet export and import return and expect.
type WalletSerializeResult struct {
KeyInfo []*key.KeyInfo
Expand Down
4 changes: 2 additions & 2 deletions cmd/address_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestWalletBalance(t *testing.T) {

t.Log("[success] not found, zero")
balance := cmdClient.RunSuccess(ctx, "wallet", "balance", addr.String()).ReadStdout()
assert.Equal(t, "0 FIL\n", balance)
assert.Equal(t, "0 FIL (warning: may display 0 if chain sync in progress)\n", balance)

t.Log("[success] balance 1394000000000000000000000000")
balance = cmdClient.RunSuccess(ctx, "wallet", "balance", builtin.RewardActorAddr.String()).ReadStdout()
Expand All @@ -69,7 +69,7 @@ func TestWalletBalance(t *testing.T) {
var addrNew cmd.AddressResult
cmdClient.RunSuccessFirstLine(ctx, "wallet", "new")
balance = cmdClient.RunSuccess(ctx, "wallet", "balance", addrNew.Address.String()).ReadStdout()
assert.Equal(t, "0 FIL\n", balance)
assert.Equal(t, "0 FIL (warning: may display 0 if chain sync in progress)\n", balance)
}

func TestWalletLoadFromFile(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ func (ei *EventIndex) migrateToVersion2(ctx context.Context, chainStore *chain.S
currTS := chainStore.GetHead()

for int64(currTS.Height()) >= minHeight.Int64 {
if currTS.Height() == 0 {
break
}

if currTS.Height()%1000 == 0 {
log.Infof("Migrating height %d (remaining %d)", currTS.Height(), int64(currTS.Height())-minHeight.Int64)
}
Expand Down