Replace common error with defined value.
This commit is contained in:
parent
6aea36c550
commit
766d571317
2 changed files with 14 additions and 16 deletions
26
jsonapi.go
26
jsonapi.go
|
@ -6,9 +6,14 @@ package btcjson
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrIncorrectArgTypes describes an error where the wrong argument types
|
||||||
|
// are present.
|
||||||
|
var ErrIncorrectArgTypes = errors.New("incorrect arguement types")
|
||||||
|
|
||||||
// Message contains a message to be sent to the bitcoin client.
|
// Message contains a message to be sent to the bitcoin client.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
Jsonrpc string `json:"jsonrpc"`
|
Jsonrpc string `json:"jsonrpc"`
|
||||||
|
@ -500,8 +505,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
add, ok3 := args[(i*4)+2].(string)
|
add, ok3 := args[(i*4)+2].(string)
|
||||||
amt, ok4 := args[(i*4)+3].(float64)
|
amt, ok4 := args[(i*4)+3].(float64)
|
||||||
if !ok1 || !ok2 || !ok3 || !ok4 {
|
if !ok1 || !ok2 || !ok3 || !ok4 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
vList[i].Txid = txid
|
vList[i].Txid = txid
|
||||||
vList[i].Vout = vout
|
vList[i].Vout = vout
|
||||||
|
@ -518,8 +522,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
var comment string
|
var comment string
|
||||||
_, ok1 := args[0].(string)
|
_, ok1 := args[0].(string)
|
||||||
if !ok1 {
|
if !ok1 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
addresses := make(map[string]float64)
|
addresses := make(map[string]float64)
|
||||||
for i := 1; i < len(args); i += 2 {
|
for i := 1; i < len(args); i += 2 {
|
||||||
|
@ -528,8 +531,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
if len(args) > i+1 {
|
if len(args) > i+1 {
|
||||||
amt, ok2 := args[i+1].(float64)
|
amt, ok2 := args[i+1].(float64)
|
||||||
if !ok2 {
|
if !ok2 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
// Put a single pair into addresses
|
// Put a single pair into addresses
|
||||||
addresses[add] = amt
|
addresses[add] = amt
|
||||||
|
@ -556,8 +558,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
}
|
}
|
||||||
_, ok1 := args[0].(bool)
|
_, ok1 := args[0].(bool)
|
||||||
if !ok1 {
|
if !ok1 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
finalMessage, err = jsonWithArgs(message, id, args)
|
finalMessage, err = jsonWithArgs(message, id, args)
|
||||||
// one required string (hex) and optional sets of one string, one int,
|
// one required string (hex) and optional sets of one string, one int,
|
||||||
|
@ -569,8 +570,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
}
|
}
|
||||||
_, ok1 := args[0].(string)
|
_, ok1 := args[0].(string)
|
||||||
if !ok1 {
|
if !ok1 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
type txlist struct {
|
type txlist struct {
|
||||||
Txid string `json:"txid"`
|
Txid string `json:"txid"`
|
||||||
|
@ -584,8 +584,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
vout, ok3 := args[2].(uint32)
|
vout, ok3 := args[2].(uint32)
|
||||||
spkey, ok4 := args[3].(string)
|
spkey, ok4 := args[3].(string)
|
||||||
if !ok1 || !ok2 || !ok3 || !ok4 {
|
if !ok1 || !ok2 || !ok3 || !ok4 {
|
||||||
err = fmt.Errorf("incorrect arguement types")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
txList[0].Txid = txid
|
txList[0].Txid = txid
|
||||||
txList[0].Vout = vout
|
txList[0].Vout = vout
|
||||||
|
@ -600,8 +599,7 @@ func CreateMessageWithId(message string, id interface{}, args ...interface{}) ([
|
||||||
spkey, ok3 := args[(i*4)+3].(string)
|
spkey, ok3 := args[(i*4)+3].(string)
|
||||||
pkey, ok4 := args[(i*4)+4].(string)
|
pkey, ok4 := args[(i*4)+4].(string)
|
||||||
if !ok1 || !ok2 || !ok3 || !ok4 {
|
if !ok1 || !ok2 || !ok3 || !ok4 {
|
||||||
err = fmt.Errorf("Incorrect arguement types.")
|
return finalMessage, ErrIncorrectArgTypes
|
||||||
return finalMessage, err
|
|
||||||
}
|
}
|
||||||
txList[i].Txid = txid
|
txList[i].Txid = txid
|
||||||
txList[i].Vout = vout
|
txList[i].Vout = vout
|
||||||
|
|
|
@ -202,7 +202,7 @@ github.com/conformal/btcjson/jsoncmd.go GetNetTotalsCmd.Method 100.00% (1/1
|
||||||
github.com/conformal/btcjson/jsoncmd.go ListReceivedByAccountCmd.Id 100.00% (1/1)
|
github.com/conformal/btcjson/jsoncmd.go ListReceivedByAccountCmd.Id 100.00% (1/1)
|
||||||
github.com/conformal/btcjson/jsoncmd.go ListLockUnspentCmd.Method 100.00% (1/1)
|
github.com/conformal/btcjson/jsoncmd.go ListLockUnspentCmd.Method 100.00% (1/1)
|
||||||
github.com/conformal/btcjson/jsoncmd.go GetNetworkHashPSCmd.Id 100.00% (1/1)
|
github.com/conformal/btcjson/jsoncmd.go GetNetworkHashPSCmd.Id 100.00% (1/1)
|
||||||
github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 96.18% (327/340)
|
github.com/conformal/btcjson/jsonapi.go CreateMessageWithId 96.11% (321/334)
|
||||||
github.com/conformal/btcjson/jsoncmd.go SendFromCmd.MarshalJSON 92.86% (13/14)
|
github.com/conformal/btcjson/jsoncmd.go SendFromCmd.MarshalJSON 92.86% (13/14)
|
||||||
github.com/conformal/btcjson/jsoncmd.go SendManyCmd.MarshalJSON 92.86% (13/14)
|
github.com/conformal/btcjson/jsoncmd.go SendManyCmd.MarshalJSON 92.86% (13/14)
|
||||||
github.com/conformal/btcjson/jsoncmd.go MoveCmd.MarshalJSON 91.67% (11/12)
|
github.com/conformal/btcjson/jsoncmd.go MoveCmd.MarshalJSON 91.67% (11/12)
|
||||||
|
@ -410,5 +410,5 @@ github.com/conformal/btcjson/jsoncmd.go RegisterCustomCmd 0.00% (0/1)
|
||||||
github.com/conformal/btcjson/jsonapi.go TlsRpcRawCommand 0.00% (0/1)
|
github.com/conformal/btcjson/jsonapi.go TlsRpcRawCommand 0.00% (0/1)
|
||||||
github.com/conformal/btcjson/jsonresults.go Vin.IsCoinBase 0.00% (0/1)
|
github.com/conformal/btcjson/jsonresults.go Vin.IsCoinBase 0.00% (0/1)
|
||||||
github.com/conformal/btcjson/jsonapi.go RpcRawCommand 0.00% (0/1)
|
github.com/conformal/btcjson/jsonapi.go RpcRawCommand 0.00% (0/1)
|
||||||
github.com/conformal/btcjson --------------------------------------- 77.82% (2365/3039)
|
github.com/conformal/btcjson --------------------------------------- 77.78% (2359/3033)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue