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

cmd/approve #2030

Merged
merged 3 commits into from
May 3, 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
18 changes: 13 additions & 5 deletions cmd/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ import (
"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/encoding"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"
)

func approveTokens(ctx *cli.Context) error {
amountArg := ctx.String(config.FlagAmount)
amount, _ := new(big.Int).SetString(amountArg, encoding.Base10)
if amount == nil {
fmt.Println("Please, introduce a valid amount in wei")
return nil
const bitSize uint = 256
useMaxAmountArg := ctx.Bool(config.FlagMaxAmount)
var amount *big.Int
if !useMaxAmountArg {
amountArg := ctx.String(config.FlagAmount)
amount, _ = new(big.Int).SetString(amountArg, encoding.Base10)
if amount == nil {
fmt.Println("Please, introduce a valid amount in wei")
return nil
}
} else {
amount = new(big.Int).Sub(new(big.Int).Lsh(common.Big1, bitSize), common.Big1)
}

addrKeyStorePath := ctx.String(config.FlagKeyStorePath)
Expand Down
8 changes: 7 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ func main() {
Name: config.FlagAmount,
Aliases: []string{"am"},
Usage: "Amount that is gonna be approved",
Required: true,
Required: false,
},
&cli.StringFlag{
Name: config.FlagMaxAmount,
Aliases: []string{"mam"},
Usage: "Maximum amount is gonna be approved",
Required: false,
},
&networkFlag,
&customNetworkFlag,
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
FlagPassword = "password"
// FlagMigrations is the flag for migrations.
FlagMigrations = "migrations"
// FlagMaxAmount is the flag to avoid to use the flag FlagAmount
FlagMaxAmount = "max-amount"
)

// Config represents the configuration of the entire Hermez Node
Expand Down