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