forked from qtumproject/janus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eth_hashrate.go
40 lines (32 loc) · 1.01 KB
/
eth_hashrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package transformer
import (
"context"
"math"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/kaonone/eth-rpc-gate/pkg/eth"
"github.com/kaonone/eth-rpc-gate/pkg/kaon"
"github.com/labstack/echo"
)
// ProxyETHGetHashrate implements ETHProxy
type ProxyETHHashrate struct {
*kaon.Kaon
}
func (p *ProxyETHHashrate) Method() string {
return "eth_hashrate"
}
func (p *ProxyETHHashrate) Request(_ *eth.JSONRPCRequest, c echo.Context) (interface{}, *eth.JSONRPCError) {
return p.request(c.Request().Context())
}
func (p *ProxyETHHashrate) request(ctx context.Context) (*eth.HashrateResponse, *eth.JSONRPCError) {
kaonresp, err := p.Kaon.GetHashrate(ctx)
if err != nil {
return nil, eth.NewCallbackError(err.Error())
}
// kaon res -> eth res
return p.ToResponse(kaonresp), nil
}
func (p *ProxyETHHashrate) ToResponse(kaonresp *kaon.GetHashrateResponse) *eth.HashrateResponse {
hexVal := hexutil.EncodeUint64(math.Float64bits(kaonresp.Difficulty))
ethresp := eth.HashrateResponse(hexVal)
return ðresp
}