Call first eth rpc method
This commit is contained in:
parent
a61ea71d08
commit
4b121dd60f
@ -3,23 +3,25 @@ package eth
|
|||||||
import (
|
import (
|
||||||
"blockbook/bchain"
|
"blockbook/bchain"
|
||||||
"blockbook/common"
|
"blockbook/common"
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EthRPC is an interface to JSON-RPC eth service.
|
// EthRPC is an interface to JSON-RPC eth service.
|
||||||
type EthRPC struct {
|
type EthRPC struct {
|
||||||
client *ethclient.Client
|
client *ethclient.Client
|
||||||
rpcURL string
|
ctx context.Context
|
||||||
user string
|
ctxCancel context.CancelFunc
|
||||||
password string
|
rpcURL string
|
||||||
Parser *EthParser
|
Parser *EthParser
|
||||||
Testnet bool
|
Testnet bool
|
||||||
Network string
|
Network string
|
||||||
Mempool *bchain.Mempool
|
Mempool *bchain.Mempool
|
||||||
ParseBlocks bool
|
metrics *common.Metrics
|
||||||
metrics *common.Metrics
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEthRPC returns new EthRPC instance.
|
// NewEthRPC returns new EthRPC instance.
|
||||||
@ -28,18 +30,24 @@ func NewEthRPC(url string, user string, password string, timeout time.Duration,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
s := &EthRPC{
|
s := &EthRPC{
|
||||||
client: c,
|
client: c,
|
||||||
rpcURL: url,
|
ctx: ctx,
|
||||||
user: user,
|
ctxCancel: cancel,
|
||||||
password: password,
|
rpcURL: url,
|
||||||
ParseBlocks: parse,
|
metrics: metrics,
|
||||||
metrics: metrics,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// always create parser
|
// always create parser
|
||||||
s.Parser = &EthParser{}
|
s.Parser = &EthParser{}
|
||||||
|
|
||||||
|
h, err := c.HeaderByNumber(s.ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
glog.Info("best block ", h.Number)
|
||||||
|
|
||||||
// // parameters for getInfo request
|
// // parameters for getInfo request
|
||||||
// if s.Parser.Params.Net == wire.MainNet {
|
// if s.Parser.Params.Net == wire.MainNet {
|
||||||
// s.Testnet = false
|
// s.Testnet = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user