mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
Add JSONGetMethod to get method name from raw json reply.
This commit is contained in:
parent
96a68227bd
commit
a456d195d6
1 changed files with 16 additions and 6 deletions
22
jsonapi.go
22
jsonapi.go
|
@ -773,11 +773,9 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RpcCommand takes a message generated from one of the routines above
|
// JSONGetMethod takes a message and tries to find the bitcoin command that it
|
||||||
// along with the login/server info, sends it, and gets a reply, returning
|
// is in reply to so it can be processed further.
|
||||||
// a go struct with the result.
|
func JSONGetMethod(message []byte) (string, error) {
|
||||||
func RpcCommand(user string, password string, server string, message []byte) (Reply, error) {
|
|
||||||
var result Reply
|
|
||||||
// Need this so we can tell what kind of message we are sending
|
// Need this so we can tell what kind of message we are sending
|
||||||
// so we can unmarshal it properly.
|
// so we can unmarshal it properly.
|
||||||
var method string
|
var method string
|
||||||
|
@ -785,7 +783,7 @@ func RpcCommand(user string, password string, server string, message []byte) (Re
|
||||||
err := json.Unmarshal(message, &msg)
|
err := json.Unmarshal(message, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error, message does not appear to be valid json: %v", err)
|
err := fmt.Errorf("Error, message does not appear to be valid json: %v", err)
|
||||||
return result, err
|
return method, err
|
||||||
}
|
}
|
||||||
m := msg.(map[string]interface{})
|
m := msg.(map[string]interface{})
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
|
@ -795,6 +793,18 @@ func RpcCommand(user string, password string, server string, message []byte) (Re
|
||||||
}
|
}
|
||||||
if method == "" {
|
if method == "" {
|
||||||
err := fmt.Errorf("Error, no method specified.")
|
err := fmt.Errorf("Error, no method specified.")
|
||||||
|
return method, err
|
||||||
|
}
|
||||||
|
return method, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RpcCommand takes a message generated from one of the routines above
|
||||||
|
// along with the login/server info, sends it, and gets a reply, returning
|
||||||
|
// a go struct with the result.
|
||||||
|
func RpcCommand(user string, password string, server string, message []byte) (Reply, error) {
|
||||||
|
var result Reply
|
||||||
|
method, err := JSONGetMethod(message)
|
||||||
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
body, err := RpcRawCommand(user, password, server, message)
|
body, err := RpcRawCommand(user, password, server, message)
|
||||||
|
|
Loading…
Add table
Reference in a new issue