Skip to content

Commit

Permalink
Add String() to payer type (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
azdagron authored Jul 2, 2024
1 parent 3ce7e2d commit ddae89c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 9 deletions.
7 changes: 4 additions & 3 deletions cmd/crybapy/cmd_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"fmt"
"os"
"strconv"

"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
"os"
"storj.io/crypto-batch-payment/pkg/payer"
"storj.io/crypto-batch-payment/pkg/payouts"
"strconv"
)

type auditConfig struct {
Expand Down Expand Up @@ -47,7 +48,7 @@ func newAuditCommand(rootConfig *rootConfig) *cobra.Command {
cmd.Flags().StringVarP(
&config.PayerType,
"type", "",
string(payer.Eth),
payer.Eth.String(),
"Type of the payment (eth,sim)")
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crybapy/factory_payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func RegisterFlags(cmd *cobra.Command, config *PayerConfig) {
cmd.Flags().StringVarP(
&config.PayerType,
"type", "",
string(payer.Eth),
payer.Eth.String(),
"Type of the payment (eth,zksync2,zksync,zkwithdraw,sim,polygon)")
cmd.Flags().StringVarP(
&config.MaxFee,
Expand Down
2 changes: 1 addition & 1 deletion pkg/eth/payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewEthPayer(ctx context.Context,
}

func (e *EthPayer) String() string {
return string(payer.Eth)
return payer.Eth.String()
}

func (e *EthPayer) NextNonce(ctx context.Context) (uint64, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/payer/payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type Transaction struct {

// Payer is responsible for the final payment transfer
type Payer interface {
// Strings returns a string describing the payer type
String() string

// NextNonce queries chain for the next available nonce value.
NextNonce(ctx context.Context) (uint64, error)

Expand Down
4 changes: 4 additions & 0 deletions pkg/payer/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewSimPayer() (*SimPayer, error) {
}, nil
}

func (s *SimPayer) String() string {
return Sim.String()
}

func (s *SimPayer) NextNonce(ctx context.Context) (uint64, error) {
return uint64(0), nil
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/payer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
Polygon PayerType = "polygon"
)

func (pt PayerType) String() string {
return string(pt)
}

// PayerTypeFromString parses string to a PayerType const.
func PayerTypeFromString(t string) (PayerType, error) {
switch strings.ToLower(t) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/payouts/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func Audit(ctx context.Context, dir string, csvPath string, payerType payer.Paye
for _, dbPayout := range dbPayouts {
if txHash, ok := payoutGroupStatus[dbPayout.PayoutGroupID]; ok {
if txHash != "" {
receiptsCSV.Write([]string{dbPayout.Payee.String(), dbPayout.USD.String(), txHash, string(payerType)})
receiptsCSV.Write([]string{dbPayout.Payee.String(), dbPayout.USD.String(), txHash, payerType.String()})
}
continue
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func Audit(ctx context.Context, dir string, csvPath string, payerType payer.Paye
if confirmedCount > 0 {
txHash := confirmed[0].Hash
payoutGroupStatus[dbPayout.PayoutGroupID] = txHash
receiptsCSV.Write([]string{dbPayout.Payee.String(), dbPayout.USD.String(), txHash, string(payerType)})
receiptsCSV.Write([]string{dbPayout.Payee.String(), dbPayout.USD.String(), txHash, payerType.String()})
payoutsConfirmed += numPayouts
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func NewTestPayer() *TestPayer {
}
}

func (t *TestPayer) String() string {
return "test"
}

func (t *TestPayer) NextNonce(ctx context.Context) (uint64, error) {
ret := t.nextNonce
t.nextNonce++
Expand Down
2 changes: 1 addition & 1 deletion pkg/zksync/payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewPayer(
}

func (z Payer) String() string {
return string(payer.ZkSync)
return payer.ZkSync.String()
}

func (z Payer) NextNonce(ctx context.Context) (uint64, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/zksync2/payer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewPayer(
}

func (p *Payer) String() string {
return string(payer.ZkSync2)
return payer.ZkSync2.String()
}

func (p *Payer) NextNonce(ctx context.Context) (uint64, error) {
Expand Down

0 comments on commit ddae89c

Please sign in to comment.