Skip to content

Commit 7604065

Browse files
author
lizekun
committed
add geth proxy
1 parent 5adb18a commit 7604065

File tree

3 files changed

+65
-9
lines changed

3 files changed

+65
-9
lines changed

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (c *Client) call(module, action string, param map[string]interface{}, outco
6868
err = fmt.Errorf("[ouch! panic recovered] please report this with what you did and what you expected, panic detail: %v", r)
6969
}
7070
}()
71-
71+
fmt.Println(c.craftURL(module, action, param))
7272
req, err := http.NewRequest(http.MethodGet, c.craftURL(module, action, param), http.NoBody)
7373
if err != nil {
7474
err = wrapErr(err, "http.NewRequest")
@@ -129,8 +129,8 @@ func (c *Client) call(module, action string, param map[string]interface{}, outco
129129
err = wrapErr(err, "json unmarshal envelope")
130130
return
131131
}
132-
if envelope.Status != 1 {
133-
err = fmt.Errorf("etherscan server: %s", envelope.Message)
132+
if envelope.Error.Code != 0 {
133+
err = fmt.Errorf("etherscan server: %s", envelope.Error.Message)
134134
return
135135
}
136136

geth.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package etherscan
2+
3+
import (
4+
"strconv"
5+
)
6+
7+
func (c *Client) GetBlockByNumber(blockNum int64) (block Block, err error) {
8+
param := M{
9+
"boolean": "true",
10+
"tag": strconv.FormatInt(blockNum, 16),
11+
}
12+
13+
err = c.call("proxy", "eth_getBlockByNumber", param, &block)
14+
return
15+
}

response.go

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,57 @@
77

88
package etherscan
99

10-
import "encoding/json"
10+
import (
11+
"encoding/json"
12+
)
1113

1214
// Envelope is the carrier of nearly every response
1315
type Envelope struct {
14-
// 1 for good, 0 for error
15-
Status int `json:"status,string"`
16-
// OK for good, other words when Status equals 0
17-
Message string `json:"message"`
18-
// where response lies
1916
Result json.RawMessage `json:"result"`
17+
Error struct {
18+
Code int `json:"code"`
19+
Message string `json:"message"`
20+
}
21+
}
22+
23+
type Transaction struct {
24+
BlockHash string `json:"blockHash"`
25+
BlockNumber string `json:"blockNumber"`
26+
From string `json:"from"`
27+
Gas string `json:"gas"`
28+
GasPrice string `json:"gasPrice"`
29+
Hash string `json:"hash"`
30+
Input string `json:"input"`
31+
Nonce string `json:"nonce"`
32+
To string `json:"to"`
33+
TransactionIndex string `json:"transactionIndex"`
34+
Value string `json:"value"`
35+
V string `json:"v"`
36+
R string `json:"r"`
37+
S string `json:"s"`
38+
}
39+
40+
type Block struct {
41+
Difficulty string `json:"difficulty"`
42+
ExtraData string `json:"extraData"`
43+
GasLimit string `json:"gasLimit"`
44+
GasUsed string `json:"gasUsed"`
45+
Hash string `json:"hash"`
46+
LogsBloom string `json:"logsBloom"`
47+
Miner string `json:"miner"`
48+
MixHash string `json:"mixHash"`
49+
Nonce string `json:"nonce"`
50+
Number string `json:"number"`
51+
ParentHash string `json:"parentHash"`
52+
ReceiptsRoot string `json:"receiptsRoot"`
53+
Sha3Uncles string `json:"sha3Uncles"`
54+
Size string `json:"size"`
55+
StateRoot string `json:"stateRoot"`
56+
Timestamp string `json:"timestamp"`
57+
TotalDifficulty string `json:"totalDifficulty"`
58+
Transactions []Transaction `json:"transactions"`
59+
TransactionsRoot string `json:"transactionsRoot"`
60+
Uncles []interface{} `json:"uncles"`
2061
}
2162

2263
// AccountBalance account and its balance in pair

0 commit comments

Comments
 (0)