-
Notifications
You must be signed in to change notification settings - Fork 2
HTTP及Websocket调用
Gabrielle Zhou edited this page Oct 11, 2018
·
14 revisions
CYBEX中任意节点包含两种API接⼝,所有API数据均使用JSON-RPC2.0形式。可以选择使用HTTP或Websocket⽅式进⾏访问。两种方式的params参数结构均为:
[API-identifier, Method-to-Call, Call-Parameters]
HTTP⽅式仅允许只读的查询数据库,如:
$ curl --data '{"jsonrpc": "2.0", "method": "call", "params": [0, "get_accounts", [["1.2.0"]]], "id": 1}' http://127.0.0.1:8090/rpc
返回结果
{
"id": 1,
"result": [{
"id": "1.2.0",
"annotations": [],
"membership_expiration_date": "1969-12-31T23:59:59",
"registrar": "1.2.0",
"referrer": "1.2.0",
"lifetime_referrer": "1.2.0",
"network_fee_percentage": 2000,
"lifetime_referrer_fee_percentage": 8000,
"referrer_rewards_percentage": 0,
"name": "committee-account",
"owner": {
"weight_threshold": 1,
"account_autos": [],
"key_auths": [],
"address_auths": []
},
"active": {
"weight_threshold": 6,
"account_auths": [
["1.2.5", 1],
["1.2.6", 1],
["1.2.7", 1],
["1.2.8", 1],
["1.2.9", 1],
["1.2.10", 1],
["1.2.11", 1],
["1.2.12", 1],
["1.2.13", 1],
["1.2.14", 1]
],
"key_auths": [],
"address_auths": []
},
"options": {
"memo_key": "GPH1111111111111111111111111111111114T1Anm",
"voting_account": "1.2.0",
"num_witness": 0,
"num_committee": 0,
"votes": [],
"extensions": []
},
"statistics": "2.7.0",
"whitelisting_accounts": [],
"blacklisting_accounts": []
}]
}
Websocket⽅式需要登录(链上执行⼴播需要会话信息)并可执行查询和修改操作。wscat调用示例:
$ npm install -g wscat
$ wscat -c ws://127.0.0.1:8090
> {"id":1, "method":"call", "params":[0,"get_accounts",[["1.2.0"]]]}
返回结果
{
"id": 1,
"result": [{
"id": "1.2.0",
"annotations": [],
"membership_expiration_date": "1969-12-31T23:59:59",
"registrar": "1.2.0",
"referrer": "1.2.0",
"lifetime_referrer": "1.2.0",
"network_fee_percentage": 2000,
"lifetime_referrer_fee_percentage": 8000,
"referrer_rewards_percentage": 0,
"name": "committee-account",
"owner": {
"weight_threshold": 1,
"account_autos": [],
"key_auths": [],
"address_auths": []
},
"active": {
"weight_threshold": 6,
"account_auths": [
["1.2.5", 1],
["1.2.6", 1],
["1.2.7", 1],
["1.2.8", 1],
["1.2.9", 1],
["1.2.10", 1],
["1.2.11", 1],
["1.2.12", 1],
["1.2.13", 1],
["1.2.14", 1]
],
"key_auths": [],
"address_auths": []
},
"options": {
"memo_key": "GPH1111111111111111111111111111111114T1Anm",
"voting_account": "1.2.0",
"num_witness": 0,
"num_committee": 0,
"votes": [],
"extensions": []
},
"statistics": "2.7.0",
"whitelisting_accounts": [],
"blacklisting_accounts": []
}]
}