remove Blockchaininfo json type assertions, no functional change
This commit is contained in:
parent
38d71a8f1d
commit
c8ee805933
|
@ -50,10 +50,27 @@ var Sleep func(d time.Duration)
|
||||||
// Log as a global variable simplifies logging
|
// Log as a global variable simplifies logging
|
||||||
var Log *logrus.Entry
|
var Log *logrus.Entry
|
||||||
|
|
||||||
|
type (
|
||||||
|
Upgradeinfo struct {
|
||||||
|
// there are other fields that aren't needed here, omit them
|
||||||
|
ActivationHeight int
|
||||||
|
}
|
||||||
|
ConsensusInfo struct {
|
||||||
|
Nextblock string
|
||||||
|
Chaintip string
|
||||||
|
}
|
||||||
|
Blockchaininfo struct {
|
||||||
|
Chain string
|
||||||
|
Upgrades map[string]Upgradeinfo
|
||||||
|
Headers int
|
||||||
|
Consensus ConsensusInfo
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// GetSaplingInfo returns the result of the getblockchaininfo RPC to zcashd
|
// GetSaplingInfo returns the result of the getblockchaininfo RPC to zcashd
|
||||||
func GetSaplingInfo() (int, int, string, string) {
|
func GetSaplingInfo() (int, int, string, string) {
|
||||||
// This request must succeed or we can't go on; give zcashd time to start up
|
// This request must succeed or we can't go on; give zcashd time to start up
|
||||||
var f interface{}
|
var blockchaininfo Blockchaininfo
|
||||||
retryCount := 0
|
retryCount := 0
|
||||||
for {
|
for {
|
||||||
result, rpcErr := RawRequest("getblockchaininfo", []json.RawMessage{})
|
result, rpcErr := RawRequest("getblockchaininfo", []json.RawMessage{})
|
||||||
|
@ -61,7 +78,7 @@ func GetSaplingInfo() (int, int, string, string) {
|
||||||
if retryCount > 0 {
|
if retryCount > 0 {
|
||||||
Log.Warn("getblockchaininfo RPC successful")
|
Log.Warn("getblockchaininfo RPC successful")
|
||||||
}
|
}
|
||||||
err := json.Unmarshal(result, &f)
|
err := json.Unmarshal(result, &blockchaininfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Log.Fatalf("error parsing JSON getblockchaininfo response: %v", err)
|
Log.Fatalf("error parsing JSON getblockchaininfo response: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -80,23 +97,14 @@ func GetSaplingInfo() (int, int, string, string) {
|
||||||
Sleep(time.Duration(10+retryCount*5) * time.Second) // backoff
|
Sleep(time.Duration(10+retryCount*5) * time.Second) // backoff
|
||||||
}
|
}
|
||||||
|
|
||||||
chainName := f.(map[string]interface{})["chain"].(string)
|
|
||||||
|
|
||||||
upgradeJSON := f.(map[string]interface{})["upgrades"]
|
|
||||||
|
|
||||||
// If the sapling consensus branch doesn't exist, it must be regtest
|
// If the sapling consensus branch doesn't exist, it must be regtest
|
||||||
saplingHeight := float64(0)
|
var saplingHeight int
|
||||||
if saplingJSON, ok := upgradeJSON.(map[string]interface{})["76b809bb"]; ok { // Sapling ID
|
if saplingJSON, ok := blockchaininfo.Upgrades["76b809bb"]; ok { // Sapling ID
|
||||||
saplingHeight = saplingJSON.(map[string]interface{})["activationheight"].(float64)
|
saplingHeight = saplingJSON.ActivationHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
blockHeight := f.(map[string]interface{})["headers"].(float64)
|
return saplingHeight, blockchaininfo.Headers, blockchaininfo.Chain,
|
||||||
|
blockchaininfo.Consensus.Nextblock
|
||||||
consensus := f.(map[string]interface{})["consensus"]
|
|
||||||
|
|
||||||
branchID := consensus.(map[string]interface{})["nextblock"].(string)
|
|
||||||
|
|
||||||
return int(saplingHeight), int(blockHeight), chainName, branchID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
|
func getBlockFromRPC(height int) (*walletrpc.CompactBlock, error) {
|
||||||
|
|
|
@ -163,26 +163,13 @@ func DarksideSendTransaction(txHex []byte) ([]byte, error) {
|
||||||
func darksideRawRequest(method string, params []json.RawMessage) (json.RawMessage, error) {
|
func darksideRawRequest(method string, params []json.RawMessage) (json.RawMessage, error) {
|
||||||
switch method {
|
switch method {
|
||||||
case "getblockchaininfo":
|
case "getblockchaininfo":
|
||||||
type upgradeinfo struct {
|
blockchaininfo := Blockchaininfo{
|
||||||
// there are other fields that aren't needed here, omit them
|
|
||||||
ActivationHeight int `json:"activationheight"`
|
|
||||||
}
|
|
||||||
type consensus struct {
|
|
||||||
Nextblock string `json:"nextblock"`
|
|
||||||
Chaintip string `json:"chaintip"`
|
|
||||||
}
|
|
||||||
blockchaininfo := struct {
|
|
||||||
Chain string `json:"chain"`
|
|
||||||
Upgrades map[string]upgradeinfo `json:"upgrades"`
|
|
||||||
Headers int `json:"headers"`
|
|
||||||
Consensus consensus `json:"consensus"`
|
|
||||||
}{
|
|
||||||
Chain: state.chainName,
|
Chain: state.chainName,
|
||||||
Upgrades: map[string]upgradeinfo{
|
Upgrades: map[string]Upgradeinfo{
|
||||||
"76b809bb": {ActivationHeight: state.saplingActivation},
|
"76b809bb": {ActivationHeight: state.saplingActivation},
|
||||||
},
|
},
|
||||||
Headers: state.startHeight + len(state.blocks) - 1,
|
Headers: state.startHeight + len(state.blocks) - 1,
|
||||||
Consensus: consensus{state.branchID, state.branchID},
|
Consensus: ConsensusInfo{state.branchID, state.branchID},
|
||||||
}
|
}
|
||||||
return json.Marshal(blockchaininfo)
|
return json.Marshal(blockchaininfo)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue