Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
b813e4d4
Commit
b813e4d4
authored
Mar 26, 2016
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
accounts/abi/bind, cmd/abigen: dedup structs, exclude patterns
parent
798e4fb4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
template.go
accounts/abi/bind/template.go
+6
-6
main.go
cmd/abigen/main.go
+12
-0
No files found.
accounts/abi/bind/template.go
View file @
b813e4d4
...
...
@@ -148,8 +148,8 @@ package {{.Package}}
{{range .Calls}}
{{if .Structured}}
// {{
.Normalized.Name}}Result is the result of the {{.Normalized.Name}} invocation."
type {{.Normalized.Name}}Result struct {
// {{
$contract.Type}}{{.Normalized.Name}}Result is the result of the {{.Normalized.Name}} invocation.
type {{
$contract.Type}}{{
.Normalized.Name}}Result struct {
{{range .Normalized.Outputs}}{{.Name}} {{bindtype .Type}}
{{end}}
}
...
...
@@ -158,9 +158,9 @@ package {{.Package}}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}Caller) {{.Normalized.Name}}(opts *bind.CallOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{.Normalized.Name}}Result,{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}},{{end}}{{end}} error) {
func (_{{$contract.Type}} *{{$contract.Type}}Caller) {{.Normalized.Name}}(opts *bind.CallOpts {{range .Normalized.Inputs}}, {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{
$contract.Type}}{{
.Normalized.Name}}Result,{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}},{{end}}{{end}} error) {
var (
{{if .Structured}}ret = new({{.Normalized.Name}}Result){{else}}{{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type}})
{{if .Structured}}ret = new({{
$contract.Type}}{{
.Normalized.Name}}Result){{else}}{{range $i, $_ := .Normalized.Outputs}}ret{{$i}} = new({{bindtype .Type}})
{{end}}{{end}}
)
out := {{if .Structured}}ret{{else}}{{if eq (len .Normalized.Outputs) 1}}ret0{{else}}[]interface{}{
...
...
@@ -174,14 +174,14 @@ package {{.Package}}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{.Normalized.Name}}Result, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) {
func (_{{$contract.Type}} *{{$contract.Type}}Session) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{
$contract.Type}}{{
.Normalized.Name}}Result, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) {
return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
//
// Solidity: {{.Original.String}}
func (_{{$contract.Type}} *{{$contract.Type}}CallerSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{.Normalized.Name}}Result, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) {
func (_{{$contract.Type}} *{{$contract.Type}}CallerSession) {{.Normalized.Name}}({{range $i, $_ := .Normalized.Inputs}}{{if ne $i 0}},{{end}} {{.Name}} {{bindtype .Type}} {{end}}) ({{if .Structured}}{{
$contract.Type}}{{
.Normalized.Name}}Result, {{else}} {{range .Normalized.Outputs}}{{bindtype .Type}},{{end}} {{end}} error) {
return _{{$contract.Type}}.Contract.{{.Normalized.Name}}(&_{{$contract.Type}}.CallOpts {{range .Normalized.Inputs}}, {{.Name}}{{end}})
}
{{end}}
...
...
cmd/abigen/main.go
View file @
b813e4d4
...
...
@@ -22,6 +22,7 @@ import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common/compiler"
...
...
@@ -34,6 +35,7 @@ var (
solFlag
=
flag
.
String
(
"sol"
,
""
,
"Path to the Ethereum contract Solidity source to build and bind"
)
solcFlag
=
flag
.
String
(
"solc"
,
"solc"
,
"Solidity compiler to use if source builds are requested"
)
excFlag
=
flag
.
String
(
"exc"
,
""
,
"Comma separated types to exclude from binding"
)
pkgFlag
=
flag
.
String
(
"pkg"
,
""
,
"Go package name to generate the binding into"
)
outFlag
=
flag
.
String
(
"out"
,
""
,
"Output file for the generated binding (default = stdout)"
)
...
...
@@ -61,6 +63,12 @@ func main() {
types
[]
string
)
if
*
solFlag
!=
""
{
// Generate the list of types to exclude from binding
exclude
:=
make
(
map
[
string
]
bool
)
for
_
,
kind
:=
range
strings
.
Split
(
*
excFlag
,
","
)
{
exclude
[
strings
.
ToLower
(
kind
)]
=
true
}
// Build the Solidity source into bindable components
solc
,
err
:=
compiler
.
New
(
*
solcFlag
)
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to locate Solidity compiler: %v
\n
"
,
err
)
...
...
@@ -76,7 +84,11 @@ func main() {
fmt
.
Printf
(
"Failed to build Solidity contract: %v
\n
"
,
err
)
os
.
Exit
(
-
1
)
}
// Gather all non-excluded contract for binding
for
name
,
contract
:=
range
contracts
{
if
exclude
[
strings
.
ToLower
(
name
)]
{
continue
}
abi
,
_
:=
json
.
Marshal
(
contract
.
Info
.
AbiDefinition
)
// Flatten the compiler parse
abis
=
append
(
abis
,
string
(
abi
))
bins
=
append
(
bins
,
contract
.
Code
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment