Convert errors in RPC server to new btcjson consts.
This commit is contained in:
parent
231efa35f5
commit
9442d96929
1 changed files with 12 additions and 41 deletions
53
rpcserver.go
53
rpcserver.go
|
@ -602,7 +602,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd, walletNotification
|
||||||
err = msgtx.Deserialize(bytes.NewBuffer(serializedTx))
|
err = msgtx.Deserialize(bytes.NewBuffer(serializedTx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := btcjson.Error{
|
err := btcjson.Error{
|
||||||
Code: -22,
|
Code: btcjson.ErrDeserialization.Code,
|
||||||
Message: "Unable to deserialize raw tx",
|
Message: "Unable to deserialize raw tx",
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -612,7 +612,7 @@ func handleSendRawTransaction(s *rpcServer, cmd btcjson.Cmd, walletNotification
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("RPCS: Failed to process transaction: %v", err)
|
log.Errorf("RPCS: Failed to process transaction: %v", err)
|
||||||
err = btcjson.Error{
|
err = btcjson.Error{
|
||||||
Code: -22,
|
Code: btcjson.ErrDeserialization.Code,
|
||||||
Message: "Failed to process transaction",
|
Message: "Failed to process transaction",
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -666,13 +666,9 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
|
|
||||||
handler, ok := handlers[cmd.Method()]
|
handler, ok := handlers[cmd.Method()]
|
||||||
if !ok {
|
if !ok {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32601,
|
|
||||||
Message: "Method not found",
|
|
||||||
}
|
|
||||||
reply = btcjson.Reply{
|
reply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrMethodNotFound,
|
||||||
Id: &id,
|
Id: &id,
|
||||||
}
|
}
|
||||||
return reply, ErrMethodNotImplemented
|
return reply, ErrMethodNotImplemented
|
||||||
|
@ -691,7 +687,7 @@ func jsonRead(body []byte, s *rpcServer, walletNotification chan []byte) (reply
|
||||||
// error to begin with, make a new one to send,
|
// error to begin with, make a new one to send,
|
||||||
// but this really should not happen.
|
// but this really should not happen.
|
||||||
rawJSONError := btcjson.Error{
|
rawJSONError := btcjson.Error{
|
||||||
Code: -32603,
|
Code: btcjson.ErrInternal.Code,
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
}
|
}
|
||||||
reply = btcjson.Reply{
|
reply = btcjson.Reply{
|
||||||
|
@ -713,14 +709,9 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
var message btcjson.Message
|
var message btcjson.Message
|
||||||
err := json.Unmarshal(body, &message)
|
err := json.Unmarshal(body, &message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32700,
|
|
||||||
Message: "Parse error",
|
|
||||||
}
|
|
||||||
|
|
||||||
reply := btcjson.Reply{
|
reply := btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrParse,
|
||||||
Id: nil,
|
Id: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -835,26 +826,18 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
case "notifynewtxs":
|
case "notifynewtxs":
|
||||||
params, ok := message.Params.([]interface{})
|
params, ok := message.Params.([]interface{})
|
||||||
if !ok || len(params) != 1 {
|
if !ok || len(params) != 1 {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32602,
|
|
||||||
Message: "Invalid parameters",
|
|
||||||
}
|
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrInvalidParams,
|
||||||
Id: &message.Id,
|
Id: &message.Id,
|
||||||
}
|
}
|
||||||
return ErrBadParamsField
|
return ErrBadParamsField
|
||||||
}
|
}
|
||||||
addr, ok := params[0].(string)
|
addr, ok := params[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32602,
|
|
||||||
Message: "Invalid parameters",
|
|
||||||
}
|
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrInvalidParams,
|
||||||
Id: &message.Id,
|
Id: &message.Id,
|
||||||
}
|
}
|
||||||
return ErrBadParamsField
|
return ErrBadParamsField
|
||||||
|
@ -862,7 +845,7 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
addrhash, _, err := btcutil.DecodeAddress(addr)
|
addrhash, _, err := btcutil.DecodeAddress(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonError := btcjson.Error{
|
jsonError := btcjson.Error{
|
||||||
Code: -32602,
|
Code: btcjson.ErrInvalidParams.Code,
|
||||||
Message: "Cannot decode address",
|
Message: "Cannot decode address",
|
||||||
}
|
}
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
|
@ -885,13 +868,9 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
case "notifyspent":
|
case "notifyspent":
|
||||||
params, ok := message.Params.([]interface{})
|
params, ok := message.Params.([]interface{})
|
||||||
if !ok || len(params) != 2 {
|
if !ok || len(params) != 2 {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32602,
|
|
||||||
Message: "Invalid parameters",
|
|
||||||
}
|
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrInvalidParams,
|
||||||
Id: &message.Id,
|
Id: &message.Id,
|
||||||
}
|
}
|
||||||
return ErrBadParamsField
|
return ErrBadParamsField
|
||||||
|
@ -899,13 +878,9 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
hashBE, ok1 := params[0].(string)
|
hashBE, ok1 := params[0].(string)
|
||||||
index, ok2 := params[1].(float64)
|
index, ok2 := params[1].(float64)
|
||||||
if !ok1 || !ok2 {
|
if !ok1 || !ok2 {
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32602,
|
|
||||||
Message: "Invalid parameters",
|
|
||||||
}
|
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrInvalidParams,
|
||||||
Id: &message.Id,
|
Id: &message.Id,
|
||||||
}
|
}
|
||||||
return ErrBadParamsField
|
return ErrBadParamsField
|
||||||
|
@ -913,7 +888,7 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
hash, err := btcwire.NewShaHashFromStr(hashBE)
|
hash, err := btcwire.NewShaHashFromStr(hashBE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jsonError := btcjson.Error{
|
jsonError := btcjson.Error{
|
||||||
Code: -32602,
|
Code: btcjson.ErrInvalidParams.Code,
|
||||||
Message: "Hash string cannot be parsed.",
|
Message: "Hash string cannot be parsed.",
|
||||||
}
|
}
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
|
@ -933,13 +908,9 @@ func jsonWSRead(walletNotification chan []byte, replychan chan *btcjson.Reply, b
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
jsonError := btcjson.Error{
|
|
||||||
Code: -32601,
|
|
||||||
Message: "Method not found",
|
|
||||||
}
|
|
||||||
rawReply = btcjson.Reply{
|
rawReply = btcjson.Reply{
|
||||||
Result: nil,
|
Result: nil,
|
||||||
Error: &jsonError,
|
Error: &btcjson.ErrMethodNotFound,
|
||||||
Id: &message.Id,
|
Id: &message.Id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue