Request
This is a message type, which gets a reply with a response type message.
Example:
const network = require('ocore/network.js');
const ws = network.getInboundDeviceWebSocket(device_address);
// function parameters: websocket, command, params, bReroutable, callback
var tag = network.sendRequest(ws, 'get_witnesses', null, false, getParentsAndLastBallAndWitnessListUnit);
function getParentsAndLastBallAndWitnessListUnit(ws, req, witnesses) {
var params = {
witnesses: witnesses
};
network.sendRequest(ws, 'light/get_parents_and_last_ball_and_witness_list_unit', params, false,
function(ws, req, response) {
console.log(response);
}
);
}
//you can have your own timeout logic and delete a pending request like this
setTimeout(function() {
var deleted = network.deletePendingRequest(ws, tag); // true if request was deleted
}, 30*1000);
Following is a list of request
type JSON messages that are sent over the network:
Get node list
This requests returns response with nodes that accept incoming connections.
{
type: 'request',
content: {
tag: tag,
command: 'get_peers'
}
}
Get a list of witnesses
This requests returns response with list of witnesses.
{
type: 'request',
content: {
tag: tag,
command: 'get_witnesses'
}
}
Get transaction data
This requests returns response with unit data. Example shows a unit, which created a new asset.
{
type: 'request',
content: {
tag: tag,
command: 'get_joint',
params: '0xXOuaP5e3z38TF5ooNtDhmwNkh1i21rBWDvrrxKt0U='
}
}
Send transaction data
This requests returns response whether composed unit was accepted or not. Unit object can be composed with ocore/composer.js
.
{
type: 'request',
content: {
tag: tag,
command: 'post_joint',
params: {Object}
}
}
Send heartbeat that you don't sleep
{
type: 'request',
content: {
tag: tag,
command: 'heartbeat'
}
}
Subscribe to transaction data
{
type: "request",
content: {
tag: tag,
command: "subscribe",
params: {
subscription_id: crypto.randomBytes(30).toString('base64'),
last_mci: 0,
library_version: "0.1"
}
}
}
Synchronous transaction data
{
type: 'request',
content: {
tag: tag,
command: 'catchup',
params: {
witnesses: witnesses,
last_stable_mci: last_stable_mci,
last_known_mci: last_known_mci
}
}
}
Get the hash tree
{
type: 'request',
content: {
tag: tag,
command: 'get_hash_tree',
params: {
from_ball: from_ball,
to_ball: to_bal
}
}
}
Get the main chain index
{
type: 'request',
content: {
tag: tag,
command: 'get_last_mci'
}
}
Send message to client that is connected to hub
{
type: 'request',
content: {
tag: tag,
command: 'hub/deliver',
params: {
to: device_address,
pubkey: pubkey,
signature: signature,
encrypted_package: encrypted_message
}
}
}
Get temporary public key
{
type: 'request',
content: {
tag: tag,
command: 'hub/get_temp_pubkey',
params: permanent_pubkey
}
}
Update temporary public key
{
type: 'request',
content: {
tag: tag,
command: 'hub/temp_pubkey',
params: {
temp_pubkey: temp_pubkey,
pubkey: permanent_pubkey,
signature: signature
}
}
}
Enable notifications
{
type: 'request',
content: {
tag: tag,
command: 'hub/enable_notification',
params: registrationId
}
}
Disable notifications
{
type: 'request',
content: {
tag: tag,
command: 'hub/disable_notification',
params: registrationId
}
}
Get list of chat bots
This requests returns response with chat bots of connected hub.
{
type: 'request',
content: {
tag: tag,
command: 'hub/get_bots'
}
}
Get asset metadata
This requests returns response with asset metadata (unit and registry). Example gets WCG Point asset metadata.
{
type: 'request',
content: {
tag: tag,
command: 'hub/get_asset_metadata',
params: 'IYzTSjJg4I3hvUaRXrihRm9+mSEShenPK8l8uKUOD3o='
}
}
Get transaction history
This requests returns response with transaction history of specified addresses.
{
type: 'request',
content: {
tag: tag,
command: 'light/get_history',
params: {
witnesses: witnesses,
requested_joints: joints,
addresses: addresses
}
}
}
Get chain link proofs
{
type: 'request',
content: {
tag: tag,
command: 'light/get_link_proofs',
params: units
}
}
Get the parent unit and the witness unit
{
type: 'request',
content: {
tag: tag,
command: 'light/get_parents_and_last_ball_and_witness_list_unit',
params: {
witnesses: witnesses
}
}
}
Get specific attestation unit
This requests returns response with attestation units for specified field and value.
{
type: 'request',
content: {
tag: tag,
command: 'light/get_attestation',
params: {
attestor_address: 'FZP4ZJBMS57LYL76S3J75OJYXGTFAIBL',
field: 'name',
value: 'tarmo888'
}
}
}
Get all attestation data about address
This requests returns response with all the attestation data about specific address.
{
type: 'request',
content: {
tag: tag,
command: 'light/get_attestations',
params: {
address: 'MNWLVYTQL5OF25DRRCR5DFNYXLSFY43K'
}
}
}
Pick divisible inputs for amount
This requests returns response with spendable inputs for specified asset, amount and addresses.
{
type: 'request',
content: {
tag: tag,
command: 'light/pick_divisible_coins_for_amount',
params: {
asset: '',
addresses: addresses,
last_ball_mci: last_ball_mci,
amount: amount,
spend_unconfirmed: 'own'
}
}
}
Get address definition
This requests returns response with address definition (smart-contracts have address smart-contract definition only after somebody has spent from it).
{
type: 'request',
content: {
tag: tag,
command: 'light/get_definition',
params: 'JEDZYC2HMGDBIDQKG3XSTXUSHMCBK725'
}
}
Get balances of addresses
This request returns a response with balances of one or more addresses.
{
type: 'request',
content: {
tag: tag,
command: 'light/get_balances',
params: [
'JEDZYC2HMGDBIDQKG3XSTXUSHMCBK725',
'UENJPVZ7HVHM6QGVGT6MWOJGGRTUTJXQ'
]
}
}
Get profile unit IDs of addresses
It is possible for users to post a profile information about themselves, this request returns a response with all the profile data units.
{
type: 'request',
content: {
tag: tag,
command: 'light/get_profile_units',
params: [
'MNWLVYTQL5OF25DRRCR5DFNYXLSFY43K'
]
}
}
Get the current state of votes for system vars
Get information about the current state of user votes for system variables such as op_list
, threshold_size
, base_tps_fee
, tps_interval
, and tps_fee_multiplier
. Since later votes by the same user concerning the same variable overwrite their previous votes, only the latest votes are shown. The response also includes the balances of the voting addresses. They determine the weight of the votes.
{
type: 'request',
content: {
tag: tag,
command: 'get_system_var_votes'
}
}
Custom Request
You can add your own communication protocol on top of the Obyte one. See event there.
{
type: 'request',
content: {
tag: tag,
command: 'custom',
params: params
}
}
Last updated
Was this helpful?