File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -128,3 +128,11 @@ type BlockRewards struct {
128
128
} `json:"uncles"`
129
129
UncleInclusionReward * BigInt `json:"uncleInclusionReward"`
130
130
}
131
+
132
+ // LatestPrice holds info from query for latest ether price
133
+ type LatestPrice struct {
134
+ ETHBTC float64 `json:"ethbtc,string"`
135
+ ETHBTCTimestamp Time `json:"ethbtc_timestamp"`
136
+ ETHUSD float64 `json:"ethusd,string"`
137
+ ETHUSDTimestamp Time `json:"ethusd_timestamp"`
138
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 LI Zhennan
3
+ *
4
+ * Use of this work is governed by a MIT License.
5
+ * You may find a license copy in project root.
6
+ */
7
+
8
+ package etherscan
9
+
10
+ // EtherTotalSupply gets total supply of ether
11
+ func (c * Client ) EtherTotalSupply () (totalSupply * BigInt , err error ) {
12
+ err = c .call ("stats" , "ethsupply" , nil , & totalSupply )
13
+ return
14
+ }
15
+
16
+ // EtherLatestPrice gets the latest ether price, in BTC and USD
17
+ func (c * Client ) EtherLatestPrice () (price LatestPrice , err error ) {
18
+ err = c .call ("stats" , "ethprice" , nil , & price )
19
+ return
20
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2018 LI Zhennan
3
+ *
4
+ * Use of this work is governed by a MIT License.
5
+ * You may find a license copy in project root.
6
+ */
7
+
8
+ package etherscan
9
+
10
+ import (
11
+ "math/big"
12
+ "testing"
13
+ )
14
+
15
+ func TestClient_EtherTotalSupply (t * testing.T ) {
16
+ totalSupply , err := api .EtherTotalSupply ()
17
+ noError (t , err , "api.EtherTotalSupply" )
18
+
19
+ if totalSupply .Int ().Cmp (big .NewInt (100 )) != 1 {
20
+ t .Errorf ("api.EtherTotalSupply not working, totalSupply is %s" , totalSupply .Int ().String ())
21
+ }
22
+ }
23
+
24
+ func TestClient_EtherLatestPrice (t * testing.T ) {
25
+ latest , err := api .EtherLatestPrice ()
26
+ noError (t , err , "api.EtherLatestPrice" )
27
+
28
+ if latest .ETHBTC == 0 {
29
+ t .Errorf ("ETHBTC got 0" )
30
+ }
31
+ if latest .ETHBTCTimestamp .Time ().IsZero () {
32
+ t .Errorf ("ETHBTCTimestamp is zero" )
33
+ }
34
+ if latest .ETHUSD == 0 {
35
+ t .Errorf ("ETHUSD got 0" )
36
+ }
37
+ if latest .ETHUSDTimestamp .Time ().IsZero () {
38
+ t .Errorf ("ETHUSDTimestamp is zero" )
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments