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

feat(validator): remove the limit of validator subcommand amount flag #290

Merged
merged 1 commit into from
Apr 8, 2024
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
27 changes: 19 additions & 8 deletions kroma-validator/cmd/balance/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package balance

import (
"context"
"errors"
"fmt"
"math/big"

Expand All @@ -16,7 +17,7 @@ import (
)

func Deposit(ctx *cli.Context) error {
depositAmount := ctx.Uint64("amount")
amount := ctx.String("amount")

valpoolABI, err := bindings.ValidatorPoolMetaData.GetAbi()
if err != nil {
Expand All @@ -28,27 +29,32 @@ func Deposit(ctx *cli.Context) error {
return fmt.Errorf("failed to create deposit transaction data: %w", err)
}

if err = sendTransaction(ctx, txData, depositAmount); err != nil {
if err = sendTransaction(ctx, txData, amount); err != nil {
return err
}

return nil
}

func Withdraw(ctx *cli.Context) error {
withdrawAmount := ctx.Uint64("amount")
amount := ctx.String("amount")

withdrawAmount, success := new(big.Int).SetString(amount, 10)
if !success {
return errors.New("failed to parse withdraw amount")
}

valpoolABI, err := bindings.ValidatorPoolMetaData.GetAbi()
if err != nil {
return fmt.Errorf("failed to get ValidatorPool ABI: %w", err)
}

txData, err := valpoolABI.Pack("withdraw", new(big.Int).SetUint64(withdrawAmount))
txData, err := valpoolABI.Pack("withdraw", withdrawAmount)
if err != nil {
return fmt.Errorf("failed to create withdraw transaction data: %w", err)
}

if err = sendTransaction(ctx, txData, 0); err != nil {
if err = sendTransaction(ctx, txData, "0"); err != nil {
return err
}

Expand All @@ -66,14 +72,14 @@ func Unbond(ctx *cli.Context) error {
return fmt.Errorf("failed to create unbond transaction data: %w", err)
}

if err = sendTransaction(ctx, txData, 0); err != nil {
if err = sendTransaction(ctx, txData, "0"); err != nil {
return err
}

return nil
}

func sendTransaction(ctx *cli.Context, txData []byte, txValue uint64) error {
func sendTransaction(ctx *cli.Context, txData []byte, txValue string) error {
txMgrConfig := txmgr.ReadCLIConfig(ctx)
txManager, err := txmgr.NewSimpleTxManager("validator-balance", log.New(), &metrics.NoopTxMetrics{}, txMgrConfig)
if err != nil {
Expand All @@ -85,11 +91,16 @@ func sendTransaction(ctx *cli.Context, txData []byte, txValue uint64) error {
return fmt.Errorf("failed to parse ValidatorPool address: %w", err)
}

value, success := new(big.Int).SetString(txValue, 10)
if !success {
return errors.New("failed to parse tx value")
}

txCandidate := txmgr.TxCandidate{
TxData: txData,
To: &valpoolAddr,
GasLimit: 0,
Value: new(big.Int).SetUint64(txValue),
Value: value,
}

_, err = txManager.Send(context.Background(), txCandidate)
Expand Down
4 changes: 2 additions & 2 deletions kroma-validator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
Name: "deposit",
Usage: "Deposit ETH into ValidatorPool to be used as bond",
Flags: []cli.Flag{
&cli.Uint64Flag{
&cli.StringFlag{
Name: "amount",
Usage: "Amount to deposit into ValidatorPool (in wei)",
Required: true,
Expand All @@ -46,7 +46,7 @@ func main() {
Name: "withdraw",
Usage: "Withdraw ETH from ValidatorPool",
Flags: []cli.Flag{
&cli.Uint64Flag{
&cli.StringFlag{
Name: "amount",
Usage: "Amount to withdraw from ValidatorPool (in wei)",
Required: true,
Expand Down
Loading