add fund sufficient check in send
This commit is contained in:
parent
bb5a92e2f4
commit
df973da748
25
cli/send.go
25
cli/send.go
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -15,6 +16,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 +53,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 +63,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: "really-do-it",
|
||||||
|
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 +149,23 @@ var sendCmd = &cli.Command{
|
|||||||
Params: params,
|
Params: params,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funds insufficient check
|
||||||
|
fromBalance, err := api.WalletBalance(ctx, msg.From)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
totalCost := types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit)))
|
||||||
|
if msg.Method == builtin.MethodSend {
|
||||||
|
totalCost = types.BigAdd(totalCost, msg.Value)
|
||||||
|
}
|
||||||
|
if fromBalance.LessThan(totalCost) {
|
||||||
|
fmt.Printf("From balance %s attoFIL less than total cost %s attoFIL\n", fromBalance, totalCost)
|
||||||
|
if !cctx.Bool("really-do-it") {
|
||||||
|
return xerrors.Errorf("--really-do-it 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