Merge pull request #5252 from filcloud/send-fund-check
add fund sufficient check in send
This commit is contained in:
commit
3ce296489b
21
cli/send.go
21
cli/send.go
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
@ -51,7 +52,7 @@ var sendCmd = &cli.Command{
|
|||||||
&cli.Uint64Flag{
|
&cli.Uint64Flag{
|
||||||
Name: "method",
|
Name: "method",
|
||||||
Usage: "specify method to invoke",
|
Usage: "specify method to invoke",
|
||||||
Value: 0,
|
Value: uint64(builtin.MethodSend),
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "params-json",
|
Name: "params-json",
|
||||||
@ -61,6 +62,10 @@ var sendCmd = &cli.Command{
|
|||||||
Name: "params-hex",
|
Name: "params-hex",
|
||||||
Usage: "specify invocation parameters in hex",
|
Usage: "specify invocation parameters in hex",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "force",
|
||||||
|
Usage: "must be specified for the action to take effect if maybe SysErrInsufficientFunds etc",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
if cctx.Args().Len() != 2 {
|
if cctx.Args().Len() != 2 {
|
||||||
@ -143,6 +148,20 @@ var sendCmd = &cli.Command{
|
|||||||
Params: params,
|
Params: params,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !cctx.Bool("force") {
|
||||||
|
// Funds insufficient check
|
||||||
|
fromBalance, err := api.WalletBalance(ctx, msg.From)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
totalCost := types.BigAdd(types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit))), msg.Value)
|
||||||
|
|
||||||
|
if fromBalance.LessThan(totalCost) {
|
||||||
|
fmt.Printf("WARNING: From balance %s less than total cost %s\n", types.FIL(fromBalance), types.FIL(totalCost))
|
||||||
|
return fmt.Errorf("--force must be specified for this action to have an effect; you have been warned")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if cctx.IsSet("nonce") {
|
if cctx.IsSet("nonce") {
|
||||||
msg.Nonce = cctx.Uint64("nonce")
|
msg.Nonce = cctx.Uint64("nonce")
|
||||||
sm, err := api.WalletSignMessage(ctx, fromAddr, msg)
|
sm, err := api.WalletSignMessage(ctx, fromAddr, msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user