拨打 jsonrpc 连接到比特币
package main
import "rpc/jsonrpc"
import "fmt"
func main() {
rc, e := jsonrpc.Dial("tcp", "user:pass@localhost:8332")
if e != nil {fmt.Print(e);return;}
var blocks float64
rc.Call("getblockcount", "", &blocks)
if e != nil {fmt.Print(e); return;}
fmt.Print("%f blocks", blocks)
}
给我以下错误: 拨号 tcp user:pass@localhost:8332: 地址 user:pass@localhost:8332 中冒号太多
如何验证我的 rpc 连接?
package main
import "rpc/jsonrpc"
import "fmt"
func main() {
rc, e := jsonrpc.Dial("tcp", "user:pass@localhost:8332")
if e != nil {fmt.Print(e);return;}
var blocks float64
rc.Call("getblockcount", "", &blocks)
if e != nil {fmt.Print(e); return;}
fmt.Print("%f blocks", blocks)
}
Gives me the following error:dial tcp user:pass@localhost:8332: too many colons in address user:pass@localhost:8332
How do I authenticate my rpc connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Go rpc/jsonrpc 包(更一般地说,rpc 包)不支持身份验证。 jsonrpc.Dial 的有效字符串可以在底层 net 的第二个参数的文档中找到.拨号功能。
但我认为你还做出了一个很大的假设,即无论你尝试连接到什么系统(也许是比特币?)都支持 Go jsonrpc 协议,除非它是用 Go 编写的,否则几乎肯定不会。
The Go rpc/jsonrpc package (and more generally, the rpc package) does not support authentication. A valid string for the jsonrpc.Dial can be found in the documentation for the second argument of the underlying net.Dial function.
But I think you're also making a big assumption that whatever system you're trying to connect to (bitcoin maybe?) supports the Go jsonrpc protocol, which--unless it's written in Go--it almost assuredly does not.