Skip to content

Commit eb777d2

Browse files
authored
Merge pull request nanmu42#59 from nanmu42/develop
Use Github Action and clean up code
2 parents 45461ec + 8fe95ed commit eb777d2

File tree

6 files changed

+78
-37
lines changed

6 files changed

+78
-37
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: "42 6 * * 0"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: "1.x"
21+
22+
- name: Test
23+
env:
24+
ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }}
25+
run: go test -v -coverprofile=coverage.txt -covermode=count ./...
26+
27+
- name: Codecov
28+
uses: codecov/[email protected]
29+
30+
- name: golangci-lint
31+
uses: golangci/golangci-lint-action@v2

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
**English** | [中文](https://github.com/nanmu42/etherscan-api/blob/master/README_ZH.md)
2+
13
# etherscan-api
24

3-
[![Build Status](https://travis-ci.org/nanmu42/etherscan-api.svg?branch=master)](https://travis-ci.org/nanmu42/etherscan-api)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api)
5-
[![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api)
65
[![GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api?status.svg)](https://godoc.org/github.com/nanmu42/etherscan-api)
7-
[中文文档](https://github.com/nanmu42/etherscan-api/blob/master/README_ZH.md)
6+
[![CI status](https://github.com/nanmu42/etherscan-api/workflows/build/ci.svg)](https://github.com/nanmu42/etherscan-api/actions)
7+
[![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api)
8+
[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api)
89

9-
Go bindings to the Etherscan.io API(and its families like BscScan), with nearly Full implementation(accounts, transactions, tokens, contracts, blocks, stats), full network support(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba), and only depending on standard library. :wink:
10+
Golang client for the Etherscan.io API(and its families like BscScan), with nearly full implementation(accounts, transactions, tokens, contracts, blocks, stats), full network support(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba), and only depending on standard library. :wink:
1011

1112
# Usage
1213

13-
Create a API instance and off you go. :rocket:
14+
```bash
15+
go get github.com/nanmu42/etherscan-api
16+
```
17+
18+
Create an API instance and off you go. :rocket:
1419

1520
```go
1621
import (
@@ -70,6 +75,6 @@ I am not from Etherscan and I just find their service really useful, so I implem
7075

7176
# License
7277

73-
Use of this work is governed by a MIT License.
78+
Use of this work is governed by an MIT License.
7479

7580
You may find a license copy in project root.

README_ZH.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
[English](https://github.com/nanmu42/etherscan-api/blob/master/README.md) | **中文**
2+
13
# etherscan-api
24

3-
[![Build Status](https://travis-ci.org/nanmu42/etherscan-api.svg?branch=master)](https://travis-ci.org/nanmu42/etherscan-api)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api)
5-
[![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api)
65
[![GoDoc](https://godoc.org/github.com/nanmu42/etherscan-api?status.svg)](https://godoc.org/github.com/nanmu42/etherscan-api)
7-
[English Readme](https://github.com/nanmu42/etherscan-api/blob/master/README.md)
6+
[![CI status](https://github.com/nanmu42/etherscan-api/workflows/build/ci.svg)](https://github.com/nanmu42/etherscan-api/actions)
7+
[![codecov](https://codecov.io/gh/nanmu42/etherscan-api/branch/master/graph/badge.svg)](https://codecov.io/gh/nanmu42/etherscan-api)
8+
[![Go Report Card](https://goreportcard.com/badge/github.com/nanmu42/etherscan-api)](https://goreportcard.com/report/github.com/nanmu42/etherscan-api)
89

9-
Etherscan.io的Golang实现
10+
Etherscan API的Golang客户端
1011
支持几乎所有功能(accounts, transactions, tokens, contracts, blocks, stats),
1112
所有公共网络(Mainnet, Ropsten, Kovan, Rinkby, Goerli, Tobalaba)。
1213
本项目只依赖于官方库。 :wink:
1314

14-
# Usage
15+
# 使用方法
16+
17+
```bash
18+
go get github.com/nanmu42/etherscan-api
19+
```
1520

1621
填入网络选项和API Key即可开始使用。 :rocket:
1722

block.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
package etherscan
99

10-
import "strconv"
10+
import (
11+
"fmt"
12+
"strconv"
13+
)
1114

1215
// BlockReward gets block and uncle rewards by block number
1316
func (c *Client) BlockReward(blockNum int) (rewards BlockRewards, err error) {
@@ -19,21 +22,28 @@ func (c *Client) BlockReward(blockNum int) (rewards BlockRewards, err error) {
1922
return
2023
}
2124

22-
// BlockNumber gets closest block number by UNIX timestamp
25+
// BlockNumber gets the closest block number by UNIX timestamp
26+
//
27+
// valid closest option: before, after
2328
func (c *Client) BlockNumber(timestamp int64, closest string) (blockNumber int, err error) {
24-
var result string
29+
var blockNumberStr string
30+
2531
param := M{
26-
"timestamp": strconv.Itoa(int(timestamp)),
32+
"timestamp": strconv.FormatInt(timestamp, 10),
2733
"closest": closest,
2834
}
2935

30-
err = c.call("block", "getblocknobytime", param, &result)
36+
err = c.call("block", "getblocknobytime", param, &blockNumberStr)
37+
38+
if err != nil {
39+
return
40+
}
3141

42+
blockNumber, err = strconv.Atoi(blockNumberStr)
3243
if err != nil {
44+
err = fmt.Errorf("parsing block number %q: %w", blockNumberStr, err)
3345
return
3446
}
3547

36-
blockNum, err := strconv.ParseInt(result, 10, 64)
37-
blockNumber = int(blockNum)
3848
return
3949
}

block_e2e_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ func TestClient_BlockReward(t *testing.T) {
2626
}
2727

2828
func TestClient_BlockNumber(t *testing.T) {
29-
//Note: All values taken from docs.etherscan.io/api-endpoints/blocks
30-
const ans_before = 9251482
31-
const ans_after = 9251483
29+
// Note: All values taken from docs.etherscan.io/api-endpoints/blocks
30+
const ansBefore = 9251482
31+
const ansAfter = 9251483
3232

3333
blockNumber, err := api.BlockNumber(1578638524, "before")
3434
noError(t, err, "api.BlockNumber")
3535

36-
if blockNumber != ans_before {
37-
t.Errorf(`api.BlockNumber(1578638524, "before") not working, got %d, want %d`, blockNumber, ans_before)
36+
if blockNumber != ansBefore {
37+
t.Errorf(`api.BlockNumber(1578638524, "before") not working, got %d, want %d`, blockNumber, ansBefore)
3838
}
3939

4040
blockNumber, err = api.BlockNumber(1578638524, "after")
4141
noError(t, err, "api.BlockNumber")
4242

43-
if blockNumber != ans_after {
44-
t.Errorf(`api.BlockNumber(1578638524,"after") not working, got %d, want %d`, blockNumber, ans_after)
43+
if blockNumber != ansAfter {
44+
t.Errorf(`api.BlockNumber(1578638524,"after") not working, got %d, want %d`, blockNumber, ansAfter)
4545
}
4646
}

0 commit comments

Comments
 (0)