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 the withdrawn amount unit #7563

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions chain/types/fil.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"math/big"
"strings"

"github.com/filecoin-project/go-state-types/abi"

"github.com/filecoin-project/lotus/build"
)

Expand Down Expand Up @@ -122,6 +124,12 @@ func ParseFIL(s string) (FIL, error) {
return FIL{r.Num()}, nil
}

func ParseAttoFilToFIL(atto abi.TokenAmount) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't call it Parse, rather Format. Parse is usually reserved from going from string -> number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this function since we have a better thing already!

vfil := big.NewFloat(0)
vfil.Add(vfil, new(big.Float).SetInt(atto.Int))
return new(big.Float).Quo(vfil, big.NewFloat(float64(build.FilecoinPrecision))).String() + " FIL"
}

func MustParseFIL(s string) FIL {
n, err := ParseFIL(s)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,9 @@ var walletMarketWithdraw = &cli.Command{
return err
}

fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amt) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amt)
fmt.Printf("Note that this is less than the requested amount of %s \n", types.ParseAttoFilToFIL(amt))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ var actorWithdrawCmd = &cli.Command{
return err
}

fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amount) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amount)
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", types.ParseAttoFilToFIL(amount))
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/lotus-shed/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ var actorWithdrawCmd = &cli.Command{
return err
}

fmt.Printf("Successfully withdrew %s FIL\n", withdrawn)
fmt.Printf("Successfully withdrew %s \n", types.ParseAttoFilToFIL(withdrawn))
if withdrawn.LessThan(amount) {
fmt.Printf("Note that this is less than the requested amount of %s FIL\n", amount)
fmt.Printf("Note that this is less than the requested amount of %s \n", types.ParseAttoFilToFIL(amount))
}
}

Expand Down