1

I am trying to use curl via SSH to utilize the deriveaddresses bitcoin-cli rpc command.

let descriptor = "wpkh(xpub6Dy2ikUu5mXbDdhw2vAP1C4eiQM8rTz1NiWQt2BzGi83iHC2gEgTSD54JveyuHF9VLAqNkCGnee1jdBL7nA3JNorbqjSSS8DEV6Hn3PuNBt/*)#mn5jvyc3"

    let command = "curl --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"deriveaddresses\", \"params\": [\"\(descriptor)\" 99] }' -H 'content-type: text/plain;' http://user:[email protected]:8332/"

    var error: NSError?

    let queue = DispatchQueue(label: "com.app.getInitialNodeConnection")
    queue.async {

        if let responseString = self.ssh.session?.channel.execute(command, error: &error) {

            guard let responseData = responseString.data(using: .utf8) else { return }

            do {

                let json = try JSONSerialization.jsonObject(with: responseData, options: [.allowFragments]) as Any

                print("json = \(json)")

            } catch {


            }

        }

    }`

I get the following error:

json = { error = { code = "-32700"; message = "Parse error"; }; id = "<null>"; result = "<null>"; }

Is it not working because I need to escape special characters in the descriptor?

1 Answer 1

1

I figured it out, just need a comma after the descriptor param.

let descriptor = "\"wpkh(xpub6Dy2ikUu5mXbDdhw2vAP1C4eiQM8rTz1NiWQt2BzGi83iHC2gEgTSD54JveyuHF9VLAqNkCGnee1jdBL7nA3JNorbqjSSS8DEV6Hn3PuNBt/*)#mn5jvyc3\""

    let command = "curl --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"deriveaddresses\", \"params\":[\(descriptor), 99] }' -H 'content-type: text/plain;' http://user:[email protected]:8332/"

    var error: NSError?

    let queue = DispatchQueue(label: "com.FullyNoded.getInitialNodeConnection")
    queue.async {

        if let responseString = self.ssh.session?.channel.execute(command, error: &error) {

            guard let responseData = responseString.data(using: .utf8) else { return }

            do {

                let json = try JSONSerialization.jsonObject(with: responseData, options: [.allowFragments]) as Any

                print("json = \(json)")

            } catch {


            }

        }

    }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.