@@ -30,7 +30,7 @@ import (
30
30
"github.com/ethereum/go-ethereum/crypto"
31
31
"github.com/ethereum/go-ethereum/internal/flags"
32
32
"github.com/ethereum/go-ethereum/log"
33
- "gopkg.in /urfave/cli.v1 "
33
+ "github.com /urfave/cli/v2 "
34
34
)
35
35
36
36
var (
@@ -39,49 +39,52 @@ var (
39
39
gitDate = ""
40
40
41
41
app * cli.App
42
+ )
42
43
44
+ var (
43
45
// Flags needed by abigen
44
- abiFlag = cli.StringFlag {
46
+ abiFlag = & cli.StringFlag {
45
47
Name : "abi" ,
46
48
Usage : "Path to the Ethereum contract ABI json to bind, - for STDIN" ,
47
49
}
48
- binFlag = cli.StringFlag {
50
+ binFlag = & cli.StringFlag {
49
51
Name : "bin" ,
50
52
Usage : "Path to the Ethereum contract bytecode (generate deploy method)" ,
51
53
}
52
- typeFlag = cli.StringFlag {
54
+ typeFlag = & cli.StringFlag {
53
55
Name : "type" ,
54
56
Usage : "Struct name for the binding (default = package name)" ,
55
57
}
56
- jsonFlag = cli.StringFlag {
58
+ jsonFlag = & cli.StringFlag {
57
59
Name : "combined-json" ,
58
60
Usage : "Path to the combined-json file generated by compiler, - for STDIN" ,
59
61
}
60
- excFlag = cli.StringFlag {
62
+ excFlag = & cli.StringFlag {
61
63
Name : "exc" ,
62
64
Usage : "Comma separated types to exclude from binding" ,
63
65
}
64
- pkgFlag = cli.StringFlag {
66
+ pkgFlag = & cli.StringFlag {
65
67
Name : "pkg" ,
66
68
Usage : "Package name to generate the binding into" ,
67
69
}
68
- outFlag = cli.StringFlag {
70
+ outFlag = & cli.StringFlag {
69
71
Name : "out" ,
70
72
Usage : "Output file for the generated binding (default = stdout)" ,
71
73
}
72
- langFlag = cli.StringFlag {
74
+ langFlag = & cli.StringFlag {
73
75
Name : "lang" ,
74
76
Usage : "Destination language for the bindings (go, java, objc)" ,
75
77
Value : "go" ,
76
78
}
77
- aliasFlag = cli.StringFlag {
79
+ aliasFlag = & cli.StringFlag {
78
80
Name : "alias" ,
79
81
Usage : "Comma separated aliases for function and event renaming, e.g. original1=alias1, original2=alias2" ,
80
82
}
81
83
)
82
84
83
85
func init () {
84
86
app = flags .NewApp (gitCommit , gitDate , "ethereum checkpoint helper tool" )
87
+ app .Name = "abigen"
85
88
app .Flags = []cli.Flag {
86
89
abiFlag ,
87
90
binFlag ,
@@ -93,17 +96,17 @@ func init() {
93
96
langFlag ,
94
97
aliasFlag ,
95
98
}
96
- app .Action = utils .MigrateFlags (abigen )
97
- cli .CommandHelpTemplate = flags .OriginCommandHelpTemplate
99
+ app .Action = abigen
98
100
}
99
101
100
102
func abigen (c * cli.Context ) error {
101
103
utils .CheckExclusive (c , abiFlag , jsonFlag ) // Only one source can be selected.
102
- if c .GlobalString (pkgFlag .Name ) == "" {
104
+
105
+ if c .String (pkgFlag .Name ) == "" {
103
106
utils .Fatalf ("No destination package specified (--pkg)" )
104
107
}
105
108
var lang bind.Lang
106
- switch c .GlobalString (langFlag .Name ) {
109
+ switch c .String (langFlag .Name ) {
107
110
case "go" :
108
111
lang = bind .LangGo
109
112
case "java" :
@@ -112,7 +115,7 @@ func abigen(c *cli.Context) error {
112
115
lang = bind .LangObjC
113
116
utils .Fatalf ("Objc binding generation is uncompleted" )
114
117
default :
115
- utils .Fatalf ("Unsupported destination language \" %s\" (--lang)" , c .GlobalString (langFlag .Name ))
118
+ utils .Fatalf ("Unsupported destination language \" %s\" (--lang)" , c .String (langFlag .Name ))
116
119
}
117
120
// If the entire solidity code was specified, build and bind based on that
118
121
var (
@@ -123,13 +126,13 @@ func abigen(c *cli.Context) error {
123
126
libs = make (map [string ]string )
124
127
aliases = make (map [string ]string )
125
128
)
126
- if c .GlobalString (abiFlag .Name ) != "" {
129
+ if c .String (abiFlag .Name ) != "" {
127
130
// Load up the ABI, optional bytecode and type name from the parameters
128
131
var (
129
132
abi []byte
130
133
err error
131
134
)
132
- input := c .GlobalString (abiFlag .Name )
135
+ input := c .String (abiFlag .Name )
133
136
if input == "-" {
134
137
abi , err = io .ReadAll (os .Stdin )
135
138
} else {
@@ -141,7 +144,7 @@ func abigen(c *cli.Context) error {
141
144
abis = append (abis , string (abi ))
142
145
143
146
var bin []byte
144
- if binFile := c .GlobalString (binFlag .Name ); binFile != "" {
147
+ if binFile := c .String (binFlag .Name ); binFile != "" {
145
148
if bin , err = os .ReadFile (binFile ); err != nil {
146
149
utils .Fatalf ("Failed to read input bytecode: %v" , err )
147
150
}
@@ -151,22 +154,22 @@ func abigen(c *cli.Context) error {
151
154
}
152
155
bins = append (bins , string (bin ))
153
156
154
- kind := c .GlobalString (typeFlag .Name )
157
+ kind := c .String (typeFlag .Name )
155
158
if kind == "" {
156
- kind = c .GlobalString (pkgFlag .Name )
159
+ kind = c .String (pkgFlag .Name )
157
160
}
158
161
types = append (types , kind )
159
162
} else {
160
163
// Generate the list of types to exclude from binding
161
164
exclude := make (map [string ]bool )
162
- for _ , kind := range strings .Split (c .GlobalString (excFlag .Name ), "," ) {
165
+ for _ , kind := range strings .Split (c .String (excFlag .Name ), "," ) {
163
166
exclude [strings .ToLower (kind )] = true
164
167
}
165
168
var contracts map [string ]* compiler.Contract
166
169
167
- if c .GlobalIsSet (jsonFlag .Name ) {
170
+ if c .IsSet (jsonFlag .Name ) {
168
171
var (
169
- input = c .GlobalString (jsonFlag .Name )
172
+ input = c .String (jsonFlag .Name )
170
173
jsonOutput []byte
171
174
err error
172
175
)
@@ -207,28 +210,28 @@ func abigen(c *cli.Context) error {
207
210
}
208
211
}
209
212
// Extract all aliases from the flags
210
- if c .GlobalIsSet (aliasFlag .Name ) {
213
+ if c .IsSet (aliasFlag .Name ) {
211
214
// We support multi-versions for aliasing
212
215
// e.g.
213
216
// foo=bar,foo2=bar2
214
217
// foo:bar,foo2:bar2
215
218
re := regexp .MustCompile (`(?:(\w+)[:=](\w+))` )
216
- submatches := re .FindAllStringSubmatch (c .GlobalString (aliasFlag .Name ), - 1 )
219
+ submatches := re .FindAllStringSubmatch (c .String (aliasFlag .Name ), - 1 )
217
220
for _ , match := range submatches {
218
221
aliases [match [1 ]] = match [2 ]
219
222
}
220
223
}
221
224
// Generate the contract binding
222
- code , err := bind .Bind (types , abis , bins , sigs , c .GlobalString (pkgFlag .Name ), lang , libs , aliases )
225
+ code , err := bind .Bind (types , abis , bins , sigs , c .String (pkgFlag .Name ), lang , libs , aliases )
223
226
if err != nil {
224
227
utils .Fatalf ("Failed to generate ABI binding: %v" , err )
225
228
}
226
229
// Either flush it out to a file or display on the standard output
227
- if ! c .GlobalIsSet (outFlag .Name ) {
230
+ if ! c .IsSet (outFlag .Name ) {
228
231
fmt .Printf ("%s\n " , code )
229
232
return nil
230
233
}
231
- if err := os .WriteFile (c .GlobalString (outFlag .Name ), []byte (code ), 0600 ); err != nil {
234
+ if err := os .WriteFile (c .String (outFlag .Name ), []byte (code ), 0600 ); err != nil {
232
235
utils .Fatalf ("Failed to write ABI binding: %v" , err )
233
236
}
234
237
return nil
0 commit comments