/
cmd_audit.go
111 lines (97 loc) · 2.95 KB
/
cmd_audit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"fmt"
"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 {
*rootConfig
PayoutsCSV string
ReceiptsCSV string
PayerType string
ReceiptsForce bool
}
func newAuditCommand(rootConfig *rootConfig) *cobra.Command {
config := &auditConfig{
rootConfig: rootConfig,
}
cmd := &cobra.Command{
Use: "audit CSVPATH",
Short: "Audits payouts",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
config.PayoutsCSV = args[0]
return checkCmd(doAudit(config))
},
}
cmd.Flags().StringVarP(
&config.ReceiptsCSV,
"receipts", "r",
"",
"File to receive payout receipts CSV",
)
cmd.Flags().BoolVarP(
&config.ReceiptsForce,
"force-receipts", "f",
false,
"Force receipts",
)
cmd.Flags().StringVarP(
&config.PayerType,
"type", "",
string(payer.Eth),
"Type of the payment (eth,sim)")
return cmd
}
func doAudit(config *auditConfig) error {
var sink auditSink
var bad bool
payerType, err := payer.PayerTypeFromString(config.PayerType)
if err != nil {
return err
}
chainID, err := strconv.Atoi(config.ChainID)
if err != nil {
return err
}
fmt.Printf("Auditing %q...\n", config.PayoutsCSV)
stats, err := payouts.Audit(config.Ctx, config.DataDir, config.PayoutsCSV, payerType, config.NodeAddress, chainID, sink, config.ReceiptsCSV, config.ReceiptsForce)
if err != nil {
return err
}
fmt.Println("Audit complete.")
fmt.Printf("Total.......................: %d\n", stats.Total)
fmt.Printf("Confirmed...................: %d\n", stats.Confirmed)
fmt.Printf("False Confirmed.............: %d\n", stats.FalseConfirmed)
fmt.Printf("Overpaid. ..................: %d\n", stats.Overpaid)
fmt.Printf("Unstarted...................: %d\n", stats.Unstarted)
fmt.Printf("Pending.....................: %d\n", stats.Pending)
fmt.Printf("Failed......................: %d\n", stats.Failed)
fmt.Printf("Dropped.....................: %d\n", stats.Dropped)
fmt.Printf("Unknown.....................: %d\n", stats.Unknown)
fmt.Printf("Mismatched..................: %d\n", stats.Mismatched)
if stats.DoublePays > 0 {
fmt.Println(aurora.Red(fmt.Sprintf("Double Pays.................: %d", stats.DoublePays)))
fmt.Println(aurora.Red(fmt.Sprintf("Double Pay Amount (raw STORJ value): %s", stats.DoublePayStorj)))
bad = true
}
if bad {
fmt.Println()
fmt.Println(aurora.Red("There were one or more problems with the payouts"))
}
return nil
}
type auditSink struct{}
func (auditSink) ReportStatus(format string, args ...interface{}) {
fmt.Println(aurora.White(fmt.Sprintf(format, args...)))
}
func (auditSink) ReportWarn(format string, args ...interface{}) {
fmt.Fprintln(os.Stderr, aurora.Yellow(fmt.Sprintf(format, args...)))
}
func (auditSink) ReportError(format string, args ...interface{}) {
fmt.Fprintln(os.Stderr, aurora.Red(fmt.Sprintf(format, args...)))
}