Skip to content

Commit

Permalink
Print additional fields in the withdraw CLI command (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Jun 26, 2023
1 parent 3bb79ee commit 807ca08
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
23 changes: 14 additions & 9 deletions command/sidechain/withdraw/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package withdraw
import (
"bytes"
"fmt"
"math/big"

"github.com/0xPolygon/polygon-edge/command/helper"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
Expand All @@ -14,23 +15,27 @@ type withdrawParams struct {
jsonRPC string
}

type withdrawResult struct {
validatorAddress string
amount uint64
func (w *withdrawParams) validateFlags() error {
return sidechainHelper.ValidateSecretFlags(w.accountDir, w.accountConfig)
}

func (v *withdrawParams) validateFlags() error {
return sidechainHelper.ValidateSecretFlags(v.accountDir, v.accountConfig)
type withdrawResult struct {
validatorAddress string
amount *big.Int
exitEventID *big.Int
blockNumber uint64
}

func (ur withdrawResult) GetOutput() string {
func (r *withdrawResult) GetOutput() string {
var buffer bytes.Buffer

buffer.WriteString("\n[WITHDRAWAL]\n")

vals := make([]string, 0, 2)
vals = append(vals, fmt.Sprintf("Validator Address|%s", ur.validatorAddress))
vals = append(vals, fmt.Sprintf("Amount Withdrawn|%v", ur.amount))
vals := make([]string, 0, 4)
vals = append(vals, fmt.Sprintf("Validator Address|%s", r.validatorAddress))
vals = append(vals, fmt.Sprintf("Amount Withdrawn|%d", r.amount))
vals = append(vals, fmt.Sprintf("Exit Event ID|%d", r.exitEventID))
vals = append(vals, fmt.Sprintf("Inclusion Block Number|%d", r.blockNumber))

buffer.WriteString(helper.FormatKV(vals))
buffer.WriteString("\n")
Expand Down
19 changes: 13 additions & 6 deletions command/sidechain/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/bridge/common"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/polybftsecrets"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
Expand Down Expand Up @@ -91,10 +92,6 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("withdraw transaction failed on block: %d", receipt.BlockNumber)
}

result := &withdrawResult{
validatorAddress: validatorAccount.Ecdsa.Address().String(),
}

var (
withdrawalEvent contractsapi.WithdrawalEvent
foundLog bool
Expand All @@ -109,7 +106,6 @@ func runCommand(cmd *cobra.Command, _ []string) error {

if doesMatch {
foundLog = true
result.amount = withdrawalEvent.Amount.Uint64()

break
}
Expand All @@ -119,7 +115,18 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("could not find an appropriate log in receipt that withdraw happened on ValidatorSet")
}

outputter.WriteCommandResult(result)
exitEventID, err := common.ExtractExitEventID(receipt)
if err != nil {
return fmt.Errorf("withdrawal failed: %w", err)
}

outputter.WriteCommandResult(
&withdrawResult{
validatorAddress: validatorAccount.Ecdsa.Address().String(),
amount: withdrawalEvent.Amount,
exitEventID: exitEventID,
blockNumber: receipt.BlockNumber,
})

return nil
}

0 comments on commit 807ca08

Please sign in to comment.