Skip to content

Commit c3d0400

Browse files
committed
feat: multiple scanners (matic, bsc)
1 parent 731ebb1 commit c3d0400

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ func New(network Network, APIKey string) *Client {
4343
return NewCustomized(Customization{
4444
Timeout: 30 * time.Second,
4545
Key: APIKey,
46-
BaseURL: fmt.Sprintf(`https://%s.etherscan.io/api?`, network.SubDomain()),
46+
BaseURL: network.Domain(),
4747
})
4848
}
4949

5050
// Customization is used in NewCustomized()
5151
type Customization struct {
5252
// Timeout for API call
5353
Timeout time.Duration
54-
// API key applied from Etherscan
54+
// API key applied from scanner
5555
Key string
5656
// Base URL like `https://api.etherscan.io/api?`
5757
BaseURL string

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestClient_craftURL(t *testing.T) {
15-
c := New(Ropsten, "abc123")
15+
c := New(EthRopsten, "abc123")
1616

1717
const expected = `https://api-ropsten.etherscan.io/api?action=craftURL&apikey=abc123&four=d&four=e&four=f&module=testing&one=1&three=1&three=2&three=3&two=2`
1818
output := c.craftURL("testing", "craftURL", M{

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This work is a nearly Full implementation
44
// (accounts, transactions, tokens, contracts, blocks, stats),
5-
// with full network support(Mainnet, Ropsten, Kovan, Rinkby, Tobalaba),
5+
// with full network support(EthMainnet, EthRopsten, EthKovan, EthRinkby, EthTobalaba),
66
// and only depending on standard library.
77
//
88
// Example can be found at https://github.com/nanmu42/etherscan-api

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module github.com/nanmu42/etherscan-api
1+
module github.com/uded/etherscan-api
22

3-
go 1.13
3+
go 1.18
44

5-
require github.com/google/go-cmp v0.5.7 // indirect
5+
require github.com/google/go-cmp v0.5.7

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
22
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
3+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
34
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

network.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,35 @@
88
package etherscan
99

1010
const (
11-
//// Ethereum public networks
11+
// // Ethereum public networks
1212

13-
// Mainnet Ethereum mainnet for production
14-
Mainnet Network = "api"
15-
// Ropsten Testnet(POW)
16-
Ropsten Network = "api-ropsten"
17-
// Kovan Testnet(POA)
18-
Kovan Network = "api-kovan"
19-
// Rinkby Testnet(CLIQUE)
20-
Rinkby Network = "api-rinkeby"
21-
// Goerli Testnet(CLIQUE)
22-
Goerli Network = "api-goerli"
23-
// Tobalaba Testnet
24-
Tobalaba Network = "api-tobalaba"
13+
// EthMainnet Ethereum mainnet for production
14+
EthMainnet Network = "https://api.etherscan.io/api?"
15+
// EthRopsten Testnet(POW)
16+
EthRopsten Network = "https://api-ropsten.etherscan.io/api?"
17+
// EthKovan Testnet(POA)
18+
EthKovan Network = "https://api-kovan.etherscan.io/api?"
19+
// EthRinkby Testnet(CLIQUE)
20+
EthRinkby Network = "https://api-rinkeby.etherscan.io/api?"
21+
// EthGoerli Testnet(CLIQUE)
22+
EthGoerli Network = "https://api-goerli.etherscan.io/api?"
23+
// EthTobalaba Testnet
24+
EthTobalaba Network = "https://api-tobalaba.etherscan.io/api?"
25+
// MaticMainnet Matic mainnet for production
26+
MaticMainnet Network = "https://api.polygonscan.com/api?"
27+
// MaticTestnet Matic testnet for development
28+
MaticTestnet Network = "https://api-testnet.polygonscan.com/api?"
29+
// BscMainnet Bsc mainnet for production
30+
BscMainnet Network = "https://api.bscscan.com/api?"
31+
// BscTestnet Bsc testnet for development
32+
BscTestnet Network = "https://api-testnet.bscscan.com/api?"
2533
)
2634

2735
// Network is ethereum network type (mainnet, ropsten, etc)
2836
type Network string
2937

3038
// SubDomain returns the subdomain of etherscan API
3139
// via n provided.
32-
func (n Network) SubDomain() (sub string) {
40+
func (n Network) Domain() (sub string) {
3341
return string(n)
3442
}

setup_e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
}
3333
bucket = NewBucket(500 * time.Millisecond)
3434

35-
api = New(Mainnet, apiKey)
35+
api = New(EthMainnet, apiKey)
3636
api.Verbose = true
3737
api.BeforeRequest = func(module string, action string, param map[string]interface{}) error {
3838
bucket.Take()

0 commit comments

Comments
 (0)