Return pointers to structs

Update doc.go to use proper btcjson result type

Return pointers to structs

Update doc.go to use proper btcjson result type
This commit is contained in:
GeertJohan 2014-05-05 21:11:06 +02:00 committed by John C. Vernaleo
parent a5169bd880
commit 9965019da0
2 changed files with 15 additions and 15 deletions

2
doc.go
View file

@ -83,7 +83,7 @@ reply to the appropriate concrete type.
// Ensure there is a result and type assert it to a btcjson.InfoResult. // Ensure there is a result and type assert it to a btcjson.InfoResult.
if reply.Result != nil { if reply.Result != nil {
if info, ok := reply.Result.(btcjson.InfoResult); ok { if info, ok := reply.Result.(*btcjson.InfoResult); ok {
fmt.Println("balance =", info.Balance) fmt.Println("balance =", info.Balance)
} }
} }

View file

@ -355,13 +355,13 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
// We handle the error condition after the switch statement. // We handle the error condition after the switch statement.
switch cmd { switch cmd {
case "createmultisig": case "createmultisig":
var res CreateMultiSigResult var res *CreateMultiSigResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
} }
case "decodescript": case "decodescript":
var res DecodeScriptResult var res *DecodeScriptResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -384,7 +384,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
} }
} }
case "getinfo": case "getinfo":
var res InfoResult var res *InfoResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -394,7 +394,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
// string depending on the verbose flag. Choose the right form // string depending on the verbose flag. Choose the right form
// accordingly. // accordingly.
if bytes.IndexByte(objmap["result"], '{') > -1 { if bytes.IndexByte(objmap["result"], '{') > -1 {
var res BlockResult var res *BlockResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -407,7 +407,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
} }
} }
case "getnettotals": case "getnettotals":
var res GetNetTotalsResult var res *GetNetTotalsResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -429,10 +429,10 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
// hex-encoded string depending on the verbose flag. Choose the // hex-encoded string depending on the verbose flag. Choose the
// right form accordingly. // right form accordingly.
if bytes.IndexByte(objmap["result"], '{') > -1 { if bytes.IndexByte(objmap["result"], '{') > -1 {
var res TxRawResult var res *TxRawResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = &res result.Result = res
} }
} else { } else {
var res string var res string
@ -442,7 +442,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
} }
} }
case "decoderawtransaction": case "decoderawtransaction":
var res TxRawDecodeResult var res *TxRawDecodeResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -454,7 +454,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
result.Result = res result.Result = res
} }
case "getmininginfo": case "getmininginfo":
var res GetMiningInfoResult var res *GetMiningInfoResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -477,7 +477,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
} }
} }
case "gettransaction": case "gettransaction":
var res GetTransactionResult var res *GetTransactionResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -487,7 +487,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
// depending on whether or not data was provided. Choose the // depending on whether or not data was provided. Choose the
// right form accordingly. // right form accordingly.
if bytes.IndexByte(objmap["result"], '{') > -1 { if bytes.IndexByte(objmap["result"], '{') > -1 {
var res GetWorkResult var res *GetWorkResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -500,13 +500,13 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
} }
} }
case "validateaddress": case "validateaddress":
var res ValidateAddressResult var res *ValidateAddressResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
} }
case "signrawtransaction": case "signrawtransaction":
var res SignRawTransactionResult var res *SignRawTransactionResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
result.Result = res result.Result = res
@ -524,7 +524,7 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
result.Result = res result.Result = res
} }
case "listsinceblock": case "listsinceblock":
var res ListSinceBlockResult var res *ListSinceBlockResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)
if err == nil { if err == nil {
if res.Transactions == nil { if res.Transactions == nil {