Skip to content

Commit dffc7cc

Browse files
authored
Add ens command (#196)
* Add ens command * Clean command spaces * Update website * Update content
1 parent 68e8a69 commit dffc7cc

File tree

8 files changed

+145
-1
lines changed

8 files changed

+145
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# 0.1.2 (Unreleased)
33

4+
- Add `ens resolve` command to resolve an ENS name [[GH-196](https://github.com/umbracle/ethgo/issues/196)]
45
- Fix signing of typed transactions [[GH-197](https://github.com/umbracle/ethgo/issues/197)]
56
- Fix. Use `ethgo.BlockNumber` input to make `Call` in contract [[GH-194](https://github.com/umbracle/ethgo/issues/194)]
67
- Add `testcases` for contract signature and transaction signing [[GH-193](https://github.com/umbracle/ethgo/issues/193)]

cmd/commands/commands.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ func Commands() map[string]cli.CommandFactory {
2929
UI: ui,
3030
}, nil
3131
},
32+
"ens": func() (cli.Command, error) {
33+
return &EnsCommand{
34+
UI: ui,
35+
}, nil
36+
},
37+
"ens resolve": func() (cli.Command, error) {
38+
return &EnsResolveCommand{
39+
UI: ui,
40+
}, nil
41+
},
3242
"version": func() (cli.Command, error) {
3343
return &VersionCommand{
3444
UI: ui,

cmd/commands/ens.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package commands
2+
3+
import (
4+
"github.com/mitchellh/cli"
5+
)
6+
7+
// EnsCommand is the group command for ens
8+
type EnsCommand struct {
9+
UI cli.Ui
10+
}
11+
12+
// Help implements the cli.Command interface
13+
func (c *EnsCommand) Help() string {
14+
return `Usage: ethgo ens
15+
16+
Interact with ens`
17+
}
18+
19+
// Synopsis implements the cli.Command interface
20+
func (c *EnsCommand) Synopsis() string {
21+
return "Interact with ens"
22+
}
23+
24+
// Run implements the cli.Command interface
25+
func (c *EnsCommand) Run(args []string) int {
26+
return 0
27+
}

cmd/commands/ens_resolve.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package commands
2+
3+
import (
4+
"os"
5+
6+
"github.com/mitchellh/cli"
7+
flag "github.com/spf13/pflag"
8+
"github.com/umbracle/ethgo/ens"
9+
)
10+
11+
func defaultJsonRPCProvider() string {
12+
if provider := os.Getenv("JSONRPC_PROVIDER"); provider != "" {
13+
return provider
14+
}
15+
return "http://localhost:8545"
16+
}
17+
18+
// EnsResolveCommand is the command to resolve an ens name
19+
type EnsResolveCommand struct {
20+
UI cli.Ui
21+
22+
provider string
23+
}
24+
25+
// Help implements the cli.Command interface
26+
func (c *EnsResolveCommand) Help() string {
27+
return `Usage: ethgo ens resolve <name>
28+
29+
Resolve an ens name
30+
` + c.Flags().FlagUsages()
31+
}
32+
33+
// Synopsis implements the cli.Command interface
34+
func (c *EnsResolveCommand) Synopsis() string {
35+
return "Resolve an ens name"
36+
}
37+
38+
func (c *EnsResolveCommand) Flags() *flag.FlagSet {
39+
flags := flag.NewFlagSet("ens resolve", flag.PanicOnError)
40+
flags.StringVar(&c.provider, "provider", defaultJsonRPCProvider(), "")
41+
42+
return flags
43+
}
44+
45+
// Run implements the cli.Command interface
46+
func (c *EnsResolveCommand) Run(args []string) int {
47+
flags := c.Flags()
48+
if err := flags.Parse(args); err != nil {
49+
c.UI.Error(err.Error())
50+
return 1
51+
}
52+
53+
args = flags.Args()
54+
if len(args) != 1 {
55+
c.UI.Error("one argument <name> expected")
56+
return 1
57+
}
58+
59+
e, err := ens.NewENS(ens.WithAddress(c.provider))
60+
if err != nil {
61+
c.UI.Error(err.Error())
62+
return 1
63+
}
64+
65+
addr, err := e.Resolve(args[0])
66+
if err != nil {
67+
c.UI.Error(err.Error())
68+
return 1
69+
}
70+
71+
c.UI.Output(addr.String())
72+
return 0
73+
}

cmd/go.mod

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,32 @@ require (
1515
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
1616
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 // indirect
1717
github.com/bgentry/speakeasy v0.1.0 // indirect
18+
github.com/btcsuite/btcd v0.21.0-beta // indirect
19+
github.com/btcsuite/btcutil v1.0.2 // indirect
1820
github.com/fatih/color v1.7.0 // indirect
1921
github.com/google/gofuzz v1.2.0 // indirect
2022
github.com/google/uuid v1.1.2 // indirect
23+
github.com/gorilla/websocket v1.4.1 // indirect
2124
github.com/hashicorp/errwrap v1.0.0 // indirect
2225
github.com/hashicorp/go-multierror v1.0.0 // indirect
2326
github.com/huandu/xstrings v1.3.2 // indirect
2427
github.com/imdario/mergo v0.3.11 // indirect
28+
github.com/klauspost/compress v1.4.1 // indirect
29+
github.com/klauspost/cpuid v1.2.0 // indirect
2530
github.com/mattn/go-colorable v0.0.9 // indirect
2631
github.com/mattn/go-isatty v0.0.3 // indirect
2732
github.com/mitchellh/copystructure v1.0.0 // indirect
2833
github.com/mitchellh/mapstructure v1.1.2 // indirect
2934
github.com/mitchellh/reflectwalk v1.0.0 // indirect
3035
github.com/posener/complete v1.1.1 // indirect
36+
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
3137
github.com/umbracle/fastrlp v0.0.0-20211229195328-c1416904ae17 // indirect
38+
github.com/valyala/bytebufferpool v1.0.0 // indirect
39+
github.com/valyala/fasthttp v1.4.0 // indirect
3240
github.com/valyala/fastjson v1.4.1 // indirect
3341
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
3442
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
43+
golang.org/x/text v0.3.2 // indirect
3544
)
3645

3746
replace github.com/umbracle/ethgo => ../

cmd/go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ
1818
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
1919
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
2020
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
21+
github.com/btcsuite/btcd v0.21.0-beta h1:At9hIZdJW0s9E/fAz28nrz6AmcNlSVucCH796ZteX1M=
2122
github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94=
2223
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
2324
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
25+
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
2426
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
2527
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
2628
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
@@ -55,6 +57,7 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
5557
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
5658
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
5759
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
60+
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
5861
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
5962
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
6063
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
@@ -73,8 +76,10 @@ github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhB
7376
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
7477
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
7578
github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
79+
github.com/klauspost/compress v1.4.1 h1:8VMb5+0wMgdBykOV96DwNwKFQ+WTI4pzYURP99CcB9E=
7680
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
7781
github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
82+
github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE=
7883
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
7984
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
8085
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@@ -131,10 +136,13 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
131136
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
132137
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
133138
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
139+
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
134140
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
135141
github.com/umbracle/fastrlp v0.0.0-20211229195328-c1416904ae17 h1:ZZy8Rj2SqGcZn1hTcoLdwFBROzrf5KiuRwhp8G4nnfA=
136142
github.com/umbracle/fastrlp v0.0.0-20211229195328-c1416904ae17/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4=
143+
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
137144
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
145+
github.com/valyala/fasthttp v1.4.0 h1:PuaTGZIw3mjYhhhbVbCQp8aciRZN9YdoB7MGX9Ko76A=
138146
github.com/valyala/fasthttp v1.4.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
139147
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
140148
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
@@ -166,6 +174,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193
166174
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
167175
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
168176
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
177+
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
169178
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
170179
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
171180
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=

website/pages/cli/ens_resolve.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Ens resolve
3+
4+
The `ens resolve <name>` command resolves an ENS name to its Ethereum address.
5+
6+
## Usage
7+
8+
```shell
9+
$ ethgo ens resolve umbracle.eth [--provider https://mainnet.infura.io...]
10+
```
11+
12+
## Options
13+
14+
- `provider`: URL of the JSON-RPC endpoint to resolve queries (default=`http://localhost:8545`). It can also be set with the `JSONRPC_PROVIDER` environment variable.

website/pages/cli/meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"abigen": "Abigen",
3-
"version": "Version"
3+
"version": "Version",
4+
"ens_resolve": "Ens Resolve"
45
}

0 commit comments

Comments
 (0)