From 49eaf79b55feb8cdbc8a66bf2eed968232faa732 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Mon, 15 Nov 2021 17:50:01 +0800 Subject: [PATCH 1/9] add GetLogs --- logs.go | 14 ++++++++++++++ response.go | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 logs.go diff --git a/logs.go b/logs.go new file mode 100644 index 0000000..2aab41a --- /dev/null +++ b/logs.go @@ -0,0 +1,14 @@ +package etherscan + +// GetLogs gets a list of log for a single address +// startBlock and endBlock cann`t be nil +func (c *Client) GetLogs(address string, fromBlock string, toBlock string, topic0 string) (logs []Log, err error) { + param := M{ + "fromBlock": fromBlock, + "toBlock": toBlock, + "topic0": topic0, + } + compose(param, "address", address) + err = c.call("logs", "getLogs", param, logs) + return +} diff --git a/response.go b/response.go index b1338d3..c2c438f 100644 --- a/response.go +++ b/response.go @@ -136,3 +136,29 @@ type LatestPrice struct { ETHUSD float64 `json:"ethusd,string"` ETHUSDTimestamp Time `json:"ethusd_timestamp"` } + +type Log struct { + // Consensus fields: + // address of the contract that generated the event + Address string `json:"address" ` + // list of topics provided by the contract. + Topics []string `json:"topics"` + // supplied by the contract, usually ABI-encoded + Data []byte `json:"data"` + + // Derived fields. These fields are filled in by the node + // but not secured by consensus. + // block in which the transaction was included + BlockNumber string `json:"blockNumber"` + GasPrice string `json:"gasPrice"` + GasUsed string `json:"gasUsed"` + TimeStamp string `json:"timeStamp"` + // hash of the transaction + TxHash string `json:"transactionHash"` + // index of the transaction in the block + TxIndex string `json:"transactionIndex"` + // hash of the block in which the transaction was included + BlockHash string `json:"blockHash"` + // index of the log in the block + Index string `json:"logIndex"` +} From 08b169bf85b276c2c63e86498013ae15b5c093c1 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Mon, 15 Nov 2021 18:04:40 +0800 Subject: [PATCH 2/9] update module --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0a30134..7681230 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/nanmu42/etherscan-api +module github.com/yfwss/etherscan-api go 1.13 From 81761edf3cc04f949920c54ebaaf7d5075408721 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Tue, 16 Nov 2021 11:22:25 +0800 Subject: [PATCH 3/9] add v2 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7681230..1b189cb 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/yfwss/etherscan-api +module github.com/yfwss/etherscan-api /v2 go 1.13 From c34e93b26285f6005cac516eef0739ab42b7aff1 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Tue, 16 Nov 2021 13:34:31 +0800 Subject: [PATCH 4/9] add v2 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1b189cb..cd50169 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/yfwss/etherscan-api /v2 +module github.com/yfwss/etherscan-api/v2 go 1.13 From 8db4a31f99c0f1bf6a3e9b1ccf10457c75bb88e1 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Tue, 16 Nov 2021 17:49:21 +0800 Subject: [PATCH 5/9] fixbug --- response.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/response.go b/response.go index c2c438f..cb6130f 100644 --- a/response.go +++ b/response.go @@ -144,7 +144,7 @@ type Log struct { // list of topics provided by the contract. Topics []string `json:"topics"` // supplied by the contract, usually ABI-encoded - Data []byte `json:"data"` + Data string `json:"data"` // Derived fields. These fields are filled in by the node // but not secured by consensus. @@ -157,8 +157,6 @@ type Log struct { TxHash string `json:"transactionHash"` // index of the transaction in the block TxIndex string `json:"transactionIndex"` - // hash of the block in which the transaction was included - BlockHash string `json:"blockHash"` // index of the log in the block Index string `json:"logIndex"` } From 967672c8246b493b9ca225d8d22a2578353de18f Mon Sep 17 00:00:00 2001 From: wss <365089264@qq.com> Date: Tue, 16 Nov 2021 18:05:55 +0800 Subject: [PATCH 6/9] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 56acd1f..1cacd67 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -**English** | [中文](https://github.com/nanmu42/etherscan-api/blob/master/README_ZH.md) +**English** | [中文](https://github.com/yfwss/etherscan-api/blob/master/README_ZH.md) # etherscan-api @@ -12,14 +12,14 @@ Golang client for the Etherscan.io API(and its families like BscScan), with near # Usage ```bash -go get github.com/nanmu42/etherscan-api +go get github.com/yfwss/etherscan-api/v2 ``` Create an API instance and off you go. :rocket: ```go import ( - "github.com/nanmu42/etherscan-api" + "github.com/yfwss/etherscan-api/v2" "fmt" ) From 3c5c147e94585f158cfa1eb8ba88e5d702d08efd Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Wed, 17 Nov 2021 11:07:22 +0800 Subject: [PATCH 7/9] fixbug --- logs.go | 2 +- response.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/logs.go b/logs.go index 2aab41a..b674041 100644 --- a/logs.go +++ b/logs.go @@ -9,6 +9,6 @@ func (c *Client) GetLogs(address string, fromBlock string, toBlock string, topic "topic0": topic0, } compose(param, "address", address) - err = c.call("logs", "getLogs", param, logs) + err = c.call("logs", "getLogs", param, &logs) return } diff --git a/response.go b/response.go index cb6130f..c93782e 100644 --- a/response.go +++ b/response.go @@ -150,13 +150,13 @@ type Log struct { // but not secured by consensus. // block in which the transaction was included BlockNumber string `json:"blockNumber"` + TimeStamp string `json:"timeStamp"` GasPrice string `json:"gasPrice"` GasUsed string `json:"gasUsed"` - TimeStamp string `json:"timeStamp"` + // index of the log in the block + Index string `json:"logIndex"` // hash of the transaction TxHash string `json:"transactionHash"` // index of the transaction in the block TxIndex string `json:"transactionIndex"` - // index of the log in the block - Index string `json:"logIndex"` } From de739dca198a247fa55b85aa0f6d39cc56c84f17 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Thu, 18 Nov 2021 16:13:13 +0800 Subject: [PATCH 8/9] fixbug --- logs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logs.go b/logs.go index b674041..e9293fe 100644 --- a/logs.go +++ b/logs.go @@ -2,7 +2,7 @@ package etherscan // GetLogs gets a list of log for a single address // startBlock and endBlock cann`t be nil -func (c *Client) GetLogs(address string, fromBlock string, toBlock string, topic0 string) (logs []Log, err error) { +func (c *Client) GetLogs(address *string, fromBlock string, toBlock string, topic0 string) (logs []Log, err error) { param := M{ "fromBlock": fromBlock, "toBlock": toBlock, From 20ae28d6ce923d08f9e469e308c127c7c751bce6 Mon Sep 17 00:00:00 2001 From: wang shuai <365089264@qq.com> Date: Thu, 18 Nov 2021 18:48:02 +0800 Subject: [PATCH 9/9] fixbug No records found --- client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client.go b/client.go index e69679a..b1a7b08 100644 --- a/client.go +++ b/client.go @@ -172,6 +172,9 @@ func (c *Client) call(module, action string, param map[string]interface{}, outco err = wrapErr(err, "json unmarshal envelope") return } + if envelope.Status == 0 && envelope.Message == "No records found" { + return + } if envelope.Status != 1 { err = fmt.Errorf("etherscan server: %s", envelope.Message) return