在3个以前,我刚接触bitshares系统时,特意学习了一下BTS的远程过程调用,所以就有了以下这篇文章。
之前的方式
在这篇文章中,我写到RPC调用间传递的json格式为:
{
"jsonrpc": "2.0",
"id": 1
"method": "get_accounts",
"params": [["1.2.0", "1.2.1"]],
}
例如:
curl --data '{"jsonrpc": "2.0", "method": "get_accounts", "params": [["1.2.0", "1.2.1"]], "id": 1}' http://127.0.0.1:8090/rpc
这也是bitshares文档中所说明的格式
http://docs.bitshares.org/api/rpc.html
但是今天我测试一个API get_account_history 时,却发现无法调用:
提示信息为一大堆API列表以及:
'message': 'Assert Exception: itr != _by_name.end(): no method with '"name 'get_account_history'"},
限于篇幅就不贴出全部信息啦,你可以自己用类似下列调用来重现一下出错信息。
curl --data '{"jsonrpc": "2.0", "method": "get_xxxx", "params": [], "id": 1}' https://ws.gdex.top
另一种方式
言归正传,我们主要目的不是研究怎样弄出出错信息的,而是要研究明白咋用这个API。既然上述文档页面没有找到,那么就去github上找找看,结果功夫不负有心,让我找到了如下链接:
https://github.com/bitshares/bitshares-core/wiki/API
以及类似这个例子:
curl --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "get_accounts", [["1.2.0"]]], "id": 1}' http://127.0.0.1:8090/rpc
有没有觉得很面熟,没错,STEEM的也和它长一样。但是STEEM支持直接写api名,比如database_api,而不用非得写数字。让我来试试bitshares是否一样?
curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["database_api", "get_account_by_name", ["oflyhigh"]], "id": 1}' https://ws.gdex.top
结果却提示我
'message': 'Assert Exception: itr != _by_name.end(): no method with '"name 'database_api'"},
原来在bitshares里它不叫database_api,小样,换个马甲我照样认识你!
curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["database", "get_account_by_name", ["oflyhigh"]], "id": 1}' https://ws.gdex.top
改了一下,一切正常。
上述调用也可以写成
curl -s --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "get_account_by_name", ["oflyhigh"]], "id": 1}' https://ws.gdex.top
但是没法用database的id 3
调用,看来我的理解还是有偏差的。不过我一项的原则就是好用就好,不深究了。
结论
我们可以以类似这样的方式调用API
curl --data '{"jsonrpc": "2.0", "method": "call", "params": ["database", "get_account_by_name", ["oflyhigh"]], "id": 1}' https://ws.gdex.top
支持以下类别:
- ['block', 1]
- ['crypto', 6]
- ['database', 3]
- ['debug', 8]
- ['history', 4]
- ['login', 0]
- ['network_broadcast', 2]
- ['network_node', 5]
别问后边的数字是干啥的,我也不懂,之所以放上,是想万一哪天就用到了呢?
咦,我不是再弄get_account_history
吗?咋跑题了呢,算了,跑就跑吧,至少我自己觉得这个挺有用的呢。
good job bro thanks for sharing...
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Sir, I read all your posts. And I'm also a programmer and ethical hacker.
But the problem is I do not understand your language. To read your post I have to use Google transilelet.
Please if you would like to post your english Then we would have benefited a lot.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
good post
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Cn
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
i like you steemit all friends, my account follow me
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Usually RPC is bestowed on protocols that specifically allow you to mention a "function name" and "parameters" and then wait for a response. As if calling a programming API but through a network protocol instead of directly jumping to library code in an executable. @oflyhigh
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
我就是来点赞我看不明白的神作。
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
bitshares有些api好像是只能通过websocket调用的。我这里发现get_full_accounts 只能用websocket调用
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
great.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit