BitShares Forum
Main => Technical Support => Topic started by: clout on August 01, 2015, 02:00:34 am
-
Whats the format of sending and receiving messages with node.js. Why do I get this error:
3382681ms th_a api.cpp:39 database_api ] creating database api 140234194959320
3382687ms th_a websocket_api.cpp:115 on_message ] e.to_detail_string(): 11 eof_exception: End Of File
stringstream
{}
th_a sstream.cpp:109 peek
{"str":""}
th_a json.cpp:478 from_string
with the following code?:
var WebSocket = require('ws')
, ws = new WebSocket('ws://127.0.0.1:8090')
ws.on('open', function () {
var msg = {"id":1,
"method":"call",
"params":[0,"get_accounts",[["1.2.0"]]]
}
ws.send(msg)
})
ws.on('message', function(msg) {
console.log(msg)
})
-
Nvm I had to stringify the message. I'm dumb.
-
Nvm I had to stringify the message. I'm dumb.
:)
Take a look at these:
https://github.com/cryptonomex/graphene/wiki/websocket-rpc-howto
or a simple (plain javascript) example:
http://tmp.xeroc.org/.ws/index.html
//edit: It seems during my latest "changes" there were some lines of code dropped ... Need to rewrite the "connection.onOpen" again .. .. fixed it
-
That documentation is really confusing. I can obviously execute the example given there, but I don't know how to extend the process to subscribing to different database api's. I don't even really understand the format of params.
-
In order to subscribe, you need to:
1) login
2) get an instance id for "database"
3) before you can subscribe to any object change:
Maybe this helps for the "object id" stuff:
def object_id(self, name, instance=0) :
objects = {
"NULL" : "1.0.%d",
"BASE" : "1.1.%d",
"ACCOUNT" : "1.2.%d",
"FORCE_SETTLEMENT" : "1.3.%d",
"ASSET" : "1.4.%d",
"DELEGATE" : "1.5.%d",
"WITNESS" : "1.6.%d",
"LIMIT_ORDER" : "1.7.%d",
"CALL_ORDER" : "1.8.%d",
"CUSTOM" : "1.9.%d",
"PROPOSAL" : "1.10.%d",
"OPERATION_HISTORY" : "1.11.%d",
"WITHDRAW_PERMISSION" : "1.12.%d",
"VESTING_BALANCE" : "1.13.%d",
"WORKER" : "1.14.%d",
"BALANCE" : "1.15.%d",
"GLOBAL_PROPERTY" : "2.0.%d",
"DYNAMIC_GLOBAL_PROPERTY" : "2.1.%d",
"INDEX_META" : "2.2.%d",
"ASSET_DYNAMIC_DATA" : "2.3.%d",
"ASSET_BITASSET_DATA" : "2.4.%d",
"DELEGATE_FEEDS" : "2.5.%d",
"ACCOUNT_BALANCE" : "2.6.%d",
"ACCOUNT_STATISTICS" : "2.7.%d",
"ACCOUNT_DEBT" : "2.8.%d",
"TRANSACTION" : "2.9.%d",
"BLOCK_SUMMARY" : "2.10.%d",
"ACCOUNT_TRANSACTION_HISTORY" : "2.11.%d",
"WITNESS_SCHEDULE" : "2.12.%d",
}
return objects[name]%instance
IDs starting with "1." are blockchain state stuff .. and those with "2." indicated implementation/higher layer abstraction
-
Thanks @xeroc. Thats really helpful.