[Zcash] Expose zcash consensus info (#508)
This commit is contained in:
parent
fc25200ff8
commit
5534372e7c
25
api/types.go
25
api/types.go
@ -424,18 +424,19 @@ type BlockbookInfo struct {
|
|||||||
|
|
||||||
// BackendInfo is used to get information about blockchain
|
// BackendInfo is used to get information about blockchain
|
||||||
type BackendInfo struct {
|
type BackendInfo struct {
|
||||||
BackendError string `json:"error,omitempty"`
|
BackendError string `json:"error,omitempty"`
|
||||||
Chain string `json:"chain,omitempty"`
|
Chain string `json:"chain,omitempty"`
|
||||||
Blocks int `json:"blocks,omitempty"`
|
Blocks int `json:"blocks,omitempty"`
|
||||||
Headers int `json:"headers,omitempty"`
|
Headers int `json:"headers,omitempty"`
|
||||||
BestBlockHash string `json:"bestBlockHash,omitempty"`
|
BestBlockHash string `json:"bestBlockHash,omitempty"`
|
||||||
Difficulty string `json:"difficulty,omitempty"`
|
Difficulty string `json:"difficulty,omitempty"`
|
||||||
SizeOnDisk int64 `json:"sizeOnDisk,omitempty"`
|
SizeOnDisk int64 `json:"sizeOnDisk,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Subversion string `json:"subversion,omitempty"`
|
Subversion string `json:"subversion,omitempty"`
|
||||||
ProtocolVersion string `json:"protocolVersion,omitempty"`
|
ProtocolVersion string `json:"protocolVersion,omitempty"`
|
||||||
Timeoffset float64 `json:"timeOffset,omitempty"`
|
Timeoffset float64 `json:"timeOffset,omitempty"`
|
||||||
Warnings string `json:"warnings,omitempty"`
|
Warnings string `json:"warnings,omitempty"`
|
||||||
|
Consensus interface{} `json:"consensus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemInfo contains information about the running blockbook and backend instance
|
// SystemInfo contains information about the running blockbook and backend instance
|
||||||
|
|||||||
@ -1777,6 +1777,7 @@ func (w *Worker) GetSystemInfo(internal bool) (*SystemInfo, error) {
|
|||||||
Timeoffset: ci.Timeoffset,
|
Timeoffset: ci.Timeoffset,
|
||||||
Version: ci.Version,
|
Version: ci.Version,
|
||||||
Warnings: ci.Warnings,
|
Warnings: ci.Warnings,
|
||||||
|
Consensus: ci.Consensus,
|
||||||
}
|
}
|
||||||
glog.Info("GetSystemInfo finished in ", time.Since(start))
|
glog.Info("GetSystemInfo finished in ", time.Since(start))
|
||||||
return &SystemInfo{blockbookInfo, backendInfo}, nil
|
return &SystemInfo{blockbookInfo, backendInfo}, nil
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
"github.com/trezor/blockbook/bchain"
|
"github.com/trezor/blockbook/bchain"
|
||||||
"github.com/trezor/blockbook/bchain/coins/btc"
|
"github.com/trezor/blockbook/bchain/coins/btc"
|
||||||
|
"github.com/trezor/blockbook/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ZCashRPC is an interface to JSON-RPC bitcoind service
|
// ZCashRPC is an interface to JSON-RPC bitcoind service
|
||||||
@ -14,6 +15,23 @@ type ZCashRPC struct {
|
|||||||
*btc.BitcoinRPC
|
*btc.BitcoinRPC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResGetBlockChainInfo struct {
|
||||||
|
Error *bchain.RPCError `json:"error"`
|
||||||
|
Result struct {
|
||||||
|
Chain string `json:"chain"`
|
||||||
|
Blocks int `json:"blocks"`
|
||||||
|
Headers int `json:"headers"`
|
||||||
|
Bestblockhash string `json:"bestblockhash"`
|
||||||
|
Difficulty common.JSONNumber `json:"difficulty"`
|
||||||
|
Pruned bool `json:"pruned"`
|
||||||
|
SizeOnDisk int64 `json:"size_on_disk"`
|
||||||
|
Consensus struct {
|
||||||
|
Chaintip string `json:"chaintip"`
|
||||||
|
Nextblock string `json:"nextblock"`
|
||||||
|
} `json:"consensus"`
|
||||||
|
} `json:"result"`
|
||||||
|
}
|
||||||
|
|
||||||
// NewZCashRPC returns new ZCashRPC instance
|
// NewZCashRPC returns new ZCashRPC instance
|
||||||
func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
|
func NewZCashRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
|
||||||
b, err := btc.NewBitcoinRPC(config, pushHandler)
|
b, err := btc.NewBitcoinRPC(config, pushHandler)
|
||||||
@ -54,6 +72,41 @@ func (z *ZCashRPC) Initialize() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (z *ZCashRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
||||||
|
chainInfo := ResGetBlockChainInfo{}
|
||||||
|
err := z.Call(&btc.CmdGetBlockChainInfo{Method: "getblockchaininfo"}, &chainInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if chainInfo.Error != nil {
|
||||||
|
return nil, chainInfo.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
networkInfo := btc.ResGetNetworkInfo{}
|
||||||
|
err = z.Call(&btc.CmdGetNetworkInfo{Method: "getnetworkinfo"}, &networkInfo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if networkInfo.Error != nil {
|
||||||
|
return nil, networkInfo.Error
|
||||||
|
}
|
||||||
|
|
||||||
|
return &bchain.ChainInfo{
|
||||||
|
Bestblockhash: chainInfo.Result.Bestblockhash,
|
||||||
|
Blocks: chainInfo.Result.Blocks,
|
||||||
|
Chain: chainInfo.Result.Chain,
|
||||||
|
Difficulty: string(chainInfo.Result.Difficulty),
|
||||||
|
Headers: chainInfo.Result.Headers,
|
||||||
|
SizeOnDisk: chainInfo.Result.SizeOnDisk,
|
||||||
|
Version: string(networkInfo.Result.Version),
|
||||||
|
Subversion: string(networkInfo.Result.Subversion),
|
||||||
|
ProtocolVersion: string(networkInfo.Result.ProtocolVersion),
|
||||||
|
Timeoffset: networkInfo.Result.Timeoffset,
|
||||||
|
Consensus: chainInfo.Result.Consensus,
|
||||||
|
Warnings: networkInfo.Result.Warnings,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetBlock returns block with given hash.
|
// GetBlock returns block with given hash.
|
||||||
func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
func (z *ZCashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
@ -161,17 +161,18 @@ type MempoolEntry struct {
|
|||||||
|
|
||||||
// ChainInfo is used to get information about blockchain
|
// ChainInfo is used to get information about blockchain
|
||||||
type ChainInfo struct {
|
type ChainInfo struct {
|
||||||
Chain string `json:"chain"`
|
Chain string `json:"chain"`
|
||||||
Blocks int `json:"blocks"`
|
Blocks int `json:"blocks"`
|
||||||
Headers int `json:"headers"`
|
Headers int `json:"headers"`
|
||||||
Bestblockhash string `json:"bestblockhash"`
|
Bestblockhash string `json:"bestblockhash"`
|
||||||
Difficulty string `json:"difficulty"`
|
Difficulty string `json:"difficulty"`
|
||||||
SizeOnDisk int64 `json:"size_on_disk"`
|
SizeOnDisk int64 `json:"size_on_disk"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Subversion string `json:"subversion"`
|
Subversion string `json:"subversion"`
|
||||||
ProtocolVersion string `json:"protocolversion"`
|
ProtocolVersion string `json:"protocolversion"`
|
||||||
Timeoffset float64 `json:"timeoffset"`
|
Timeoffset float64 `json:"timeoffset"`
|
||||||
Warnings string `json:"warnings"`
|
Warnings string `json:"warnings"`
|
||||||
|
Consensus interface{} `json:"consensus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RPCError defines rpc error returned by backend
|
// RPCError defines rpc error returned by backend
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user