forked from dcb9/janus
-
Notifications
You must be signed in to change notification settings - Fork 27
/
eth_hashrate.go
40 lines (32 loc) · 1 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/labstack/echo"
"github.com/qtumproject/janus/pkg/eth"
"github.com/qtumproject/janus/pkg/qtum"
)
//ProxyETHGetHashrate implements ETHProxy
type ProxyETHHashrate struct {
*qtum.Qtum
}
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) {
qtumresp, err := p.Qtum.GetHashrate(ctx)
if err != nil {
return nil, eth.NewCallbackError(err.Error())
}
// qtum res -> eth res
return p.ToResponse(qtumresp), nil
}
func (p *ProxyETHHashrate) ToResponse(qtumresp *qtum.GetHashrateResponse) *eth.HashrateResponse {
hexVal := hexutil.EncodeUint64(math.Float64bits(qtumresp.Difficulty))
ethresp := eth.HashrateResponse(hexVal)
return ðresp
}