Skip to content

steem state Documentation

Nicholas edited this page Apr 18, 2019 · 10 revisions

steem-state Documentation

Documentation reference for the steem-state npm package (this does not include the steem-transact package).




steem-state

The steem-state package exports this function, which returns a state processor, which all below functions are from.

Arguments:

client: A dsteem client to use to interface with the Steem blockchain.

steem: A dsteem instance for utils around the blockchain API.

currentBlockNumber: The block to start processing transactions from.

blockComputeSpeed: How quickly to process previous blocks (amount of milliseconds between processing each block).

prefix: A string at the beginning of each operation id; used to show which DApp a transaction is for. An example would be SteemMonster's sm_ prefix.

mode: A string representing the block streaming mode: can be either latest or irreversible.




.on

The on function tells the processor a function to call when a certain custom_json operation id is read.

Arguments:

operationId: The operation id to use. Will be combined with the prefix to form the full operation id to look for.

callback: The function to call when an operation of operationId is found. The callback will be called with arguments (json, from, active) where json is the operation's json data, from is the operation's creator, and active is whether the operation was signed with an active key (true for signed with an active key).

Note for .on and all similar functions: the JSON object returned also has two extra properties: tx_id and block_num which tell the transaction id and block number respectively.




.onNoPrefix

The onNoPrefix function tells the processor a function to call when a certain custom_json operation id is read but does not automatically add on the prefix. Useful for interfacing with other steem-state applications or listening for resteems/follows.

Arguments:

operationId: The operation id to use. Will NOT be combined with the prefix to form the full operation id to look for.

callback: The function to call when an operation of operationId is found. The callback will be called with arguments (json, from, active) where json is the operation's json data, from is the operation's creator, and active is whether the operation was signed with an active key (true for signed with an active key).




.onOperation

The onOperation function tells the processor a function to call when a certain operation type is read. Useful for streaming STEEM transfers, posts, votes, etc.

Arguments:

type: The type of operation to stream. Could be (but not limited to) vote, comment.

callback: The function to call when an operation of type is found. The callback will be called with arguments (json) where json is the operation's json data.




.onBlock

The onBlock function tells the processor a function to call before a new block is processed.

Arguments:

callback: The fuction to call before a new block is processed. The callback will be called with an argument of the block's full json.




.start

The start function starts the processor and it starts reading from blocks starting from the block currentBlockNumber (argument to steem-state).




.stop

The stop function stops the processor cleanly then calls the callback. Always use this function to exit, not just process.exit().

Arguments:

callback: Called after a successful exit.

Example use:

processor.stop(function() {
  process.exit();
});

The above code would be used in the event that the user wished to close the program.


.isStreaming

Returns whether the client is up to date (streaming new blocks, not old ones). true return value = streaming new blocks.




.onStreamingStart

Subscribes to an event that is called when the processor is processing blocks at real-time. Useful to display info to the user to tell them that they are viewing new operations at real time.

Arguments:

callback: The function to call when the processor is processing blocks at real-time. callback will be called with no arguments.




.getCurrentBlockNumber

Returns the next block number processed by the processor.