Make GetBlockInfo and GetChainInfo more coin independent
parent
d87d52b2fd
commit
7290f8bbcd
|
@ -127,6 +127,28 @@ func (b *BCashRPC) GetBlockRaw(hash string) ([]byte, error) {
|
|||
return hex.DecodeString(res.Result)
|
||||
}
|
||||
|
||||
// GetBlockInfo returns extended header (more info than in bchain.BlockHeader) with a list of txids
|
||||
func (b *BCashRPC) GetBlockInfo(hash string) (*bchain.BlockInfo, error) {
|
||||
glog.V(1).Info("rpc: getblock (verbosity=1) ", hash)
|
||||
|
||||
res := btc.ResGetBlockInfo{}
|
||||
req := cmdGetBlock{Method: "getblock"}
|
||||
req.Params.BlockHash = hash
|
||||
req.Params.Verbose = true
|
||||
err := b.Call(&req, &res)
|
||||
|
||||
if err != nil {
|
||||
return nil, errors.Annotatef(err, "hash %v", hash)
|
||||
}
|
||||
if res.Error != nil {
|
||||
if isErrBlockNotFound(res.Error) {
|
||||
return nil, bchain.ErrBlockNotFound
|
||||
}
|
||||
return nil, errors.Annotatef(res.Error, "hash %v", hash)
|
||||
}
|
||||
return &res.Result, nil
|
||||
}
|
||||
|
||||
// GetBlockFull returns block with given hash.
|
||||
func (b *BCashRPC) GetBlockFull(hash string) (*bchain.Block, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"math/big"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
|
@ -219,13 +218,13 @@ type CmdGetBlockChainInfo struct {
|
|||
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 float64 `json:"difficulty"`
|
||||
SizeOnDisk int64 `json:"size_on_disk"`
|
||||
Warnings string `json:"warnings"`
|
||||
Chain string `json:"chain"`
|
||||
Blocks int `json:"blocks"`
|
||||
Headers int `json:"headers"`
|
||||
Bestblockhash string `json:"bestblockhash"`
|
||||
Difficulty json.Number `json:"difficulty"`
|
||||
SizeOnDisk int64 `json:"size_on_disk"`
|
||||
Warnings string `json:"warnings"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
|
@ -238,11 +237,11 @@ type CmdGetNetworkInfo struct {
|
|||
type ResGetNetworkInfo struct {
|
||||
Error *bchain.RPCError `json:"error"`
|
||||
Result struct {
|
||||
Version int `json:"version"`
|
||||
Subversion string `json:"subversion"`
|
||||
ProtocolVersion int `json:"protocolversion"`
|
||||
Timeoffset float64 `json:"timeoffset"`
|
||||
Warnings string `json:"warnings"`
|
||||
Version json.Number `json:"version"`
|
||||
Subversion json.Number `json:"subversion"`
|
||||
ProtocolVersion json.Number `json:"protocolversion"`
|
||||
Timeoffset float64 `json:"timeoffset"`
|
||||
Warnings string `json:"warnings"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
|
@ -445,18 +444,14 @@ func (b *BitcoinRPC) GetChainInfo() (*bchain.ChainInfo, error) {
|
|||
Bestblockhash: resCi.Result.Bestblockhash,
|
||||
Blocks: resCi.Result.Blocks,
|
||||
Chain: resCi.Result.Chain,
|
||||
Difficulty: resCi.Result.Difficulty,
|
||||
Difficulty: string(resCi.Result.Difficulty),
|
||||
Headers: resCi.Result.Headers,
|
||||
SizeOnDisk: resCi.Result.SizeOnDisk,
|
||||
Subversion: resNi.Result.Subversion,
|
||||
Subversion: string(resNi.Result.Subversion),
|
||||
Timeoffset: resNi.Result.Timeoffset,
|
||||
}
|
||||
if resNi.Result.Version > 0 {
|
||||
rv.Version = strconv.Itoa(resNi.Result.Version)
|
||||
}
|
||||
if resNi.Result.ProtocolVersion > 0 {
|
||||
rv.ProtocolVersion = strconv.Itoa(resNi.Result.ProtocolVersion)
|
||||
}
|
||||
rv.Version = string(resNi.Result.Version)
|
||||
rv.ProtocolVersion = string(resNi.Result.ProtocolVersion)
|
||||
if len(resCi.Result.Warnings) > 0 {
|
||||
rv.Warnings = resCi.Result.Warnings + " "
|
||||
}
|
||||
|
|
|
@ -85,12 +85,12 @@ type BlockHeader struct {
|
|||
// BlockInfo contains extended block header data and a list of block txids
|
||||
type BlockInfo struct {
|
||||
BlockHeader
|
||||
Version int64 `json:"version"`
|
||||
MerkleRoot string `json:"merkleroot"`
|
||||
Nonce uint64 `json:"nonce"`
|
||||
Bits string `json:"bits"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
Txids []string `json:"tx,omitempty"`
|
||||
Version json.Number `json:"version"`
|
||||
MerkleRoot string `json:"merkleroot"`
|
||||
Nonce json.Number `json:"nonce"`
|
||||
Bits string `json:"bits"`
|
||||
Difficulty json.Number `json:"difficulty"`
|
||||
Txids []string `json:"tx,omitempty"`
|
||||
}
|
||||
|
||||
type MempoolEntry struct {
|
||||
|
@ -115,7 +115,7 @@ type ChainInfo struct {
|
|||
Blocks int `json:"blocks"`
|
||||
Headers int `json:"headers"`
|
||||
Bestblockhash string `json:"bestblockhash"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
Difficulty string `json:"difficulty"`
|
||||
SizeOnDisk int64 `json:"size_on_disk"`
|
||||
Version string `json:"version"`
|
||||
Subversion string `json:"subversion"`
|
||||
|
|
Loading…
Reference in New Issue