From df973da74874711ac1dbde9808c3601a4befe01c Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 25 Dec 2020 16:25:46 +0800 Subject: [PATCH 1/6] add fund sufficient check in send --- cli/send.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/send.go b/cli/send.go index 55ea8b028..842862180 100644 --- a/cli/send.go +++ b/cli/send.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "golang.org/x/xerrors" "reflect" "github.com/urfave/cli/v2" @@ -15,6 +16,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "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/types" ) @@ -51,7 +53,7 @@ var sendCmd = &cli.Command{ &cli.Uint64Flag{ Name: "method", Usage: "specify method to invoke", - Value: 0, + Value: uint64(builtin.MethodSend), }, &cli.StringFlag{ Name: "params-json", @@ -61,6 +63,10 @@ var sendCmd = &cli.Command{ Name: "params-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 { if cctx.Args().Len() != 2 { @@ -143,6 +149,23 @@ var sendCmd = &cli.Command{ 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") { msg.Nonce = cctx.Uint64("nonce") sm, err := api.WalletSignMessage(ctx, fromAddr, msg) From 6b9daa4d1459d53aa2abc421be697d739651929b Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 25 Dec 2020 16:32:21 +0800 Subject: [PATCH 2/6] update return error --- cli/send.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/send.go b/cli/send.go index 842862180..965d2c9f9 100644 --- a/cli/send.go +++ b/cli/send.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "golang.org/x/xerrors" "reflect" "github.com/urfave/cli/v2" @@ -161,7 +160,7 @@ var sendCmd = &cli.Command{ 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; " + + return fmt.Errorf("--really-do-it must be specified for this action to have an effect; " + "you have been warned") } } From a7a6f24cebfbc91fb6b713861a4812829020f6a3 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 28 Dec 2020 11:08:19 +0800 Subject: [PATCH 3/6] add value for all method --- cli/send.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cli/send.go b/cli/send.go index 965d2c9f9..592989e52 100644 --- a/cli/send.go +++ b/cli/send.go @@ -153,10 +153,8 @@ var sendCmd = &cli.Command{ 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) - } + totalCost := types.BigAdd(types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit))), 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") { From dbe580de10e2636cb55362d1345c839b0ffb3ed3 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 6 Jan 2021 11:37:29 +0800 Subject: [PATCH 4/6] update realdoit to force --- cli/send.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/send.go b/cli/send.go index 592989e52..79f6e3699 100644 --- a/cli/send.go +++ b/cli/send.go @@ -63,7 +63,7 @@ var sendCmd = &cli.Command{ Usage: "specify invocation parameters in hex", }, &cli.BoolFlag{ - Name: "really-do-it", + Name: "force", Usage: "must be specified for the action to take effect if maybe SysErrInsufficientFunds etc", }, }, @@ -157,8 +157,8 @@ var sendCmd = &cli.Command{ 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 fmt.Errorf("--really-do-it must be specified for this action to have an effect; " + + if !cctx.Bool("force") { + return fmt.Errorf("--force must be specified for this action to have an effect; " + "you have been warned") } } From fef5d65c0f8b83a99041d8a324c9d54e00983989 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 7 Jan 2021 11:22:23 +0800 Subject: [PATCH 5/6] Update FIL format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ɓukasz Magiera --- cli/send.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/send.go b/cli/send.go index 79f6e3699..291a9398e 100644 --- a/cli/send.go +++ b/cli/send.go @@ -156,7 +156,7 @@ var sendCmd = &cli.Command{ totalCost := types.BigAdd(types.BigMul(msg.GasFeeCap, types.NewInt(uint64(msg.GasLimit))), msg.Value) if fromBalance.LessThan(totalCost) { - fmt.Printf("From balance %s attoFIL less than total cost %s attoFIL\n", fromBalance, totalCost) + fmt.Printf("From balance %s less than total cost %s\n", types.FIL(fromBalance), types.FIL(totalCost)) if !cctx.Bool("force") { return fmt.Errorf("--force must be specified for this action to have an effect; " + "you have been warned") From 9584c720268d1e4c6b0b0df7f946124168c87e52 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 7 Jan 2021 11:30:53 +0800 Subject: [PATCH 6/6] if force specified will not check insufficient fund --- cli/send.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cli/send.go b/cli/send.go index 291a9398e..d15dd5fb2 100644 --- a/cli/send.go +++ b/cli/send.go @@ -148,18 +148,17 @@ var sendCmd = &cli.Command{ Params: params, } - // 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 !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("From balance %s less than total cost %s\n", types.FIL(fromBalance), types.FIL(totalCost)) - if !cctx.Bool("force") { - return fmt.Errorf("--force must be specified for this action to have an effect; " + - "you have been warned") + 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") } }