All examples from this tutorial can be found as fully functional scripts on GitHub:
This tutorial shows how to interact with the Steem blockchain, Steem database and Steem Engine using Ruby. When accessing Steem Engine using Ruby their only one APIs available to chose: radiator.
In this particular chapter you learn how to read a single row from the Steem Engine database tables.
Basic knowledge of Ruby programming is needed. It is necessary to install at least Ruby 2.5 as well as the following ruby gems:
gem install bundler
gem install colorize
gem install contracts
gem install radiator
For reader with programming experience this tutorial is basic level.
Steem Engine allows users to add token and contacts to the steem block chain. Currently only three predefined contracts are know: "tokens", "market", and "steempegged". Each contract has one or more database table to store their data.
In order to read the content of a table it is necessary to know the name of database tables to query. The Steem-Print-Print-SSC-Contract.rb from the previous part of the tutorial prints all data of a Steem Engine contract — including the database tables used by the contract.
The table names are found in the aptly named attribute “tables”. Each table name is prefixed with their contract name. Presumably to make them unique throughout the system. Here a list of the currently known tables names:
Unique name | Contact | Table |
---|---|---|
market_buyBook | market | buyBook |
market_metrics | market | metrics |
market_sellBook | market | sellBook |
market_tradesHistory | market | tradesHistory |
steempegged_withdrawals | steempegged | withdrawals |
tokens_balances | tokens | balances |
tokens_contractsBalances | tokens | contractsBalances |
tokens_params | tokens | params |
tokens_pendingUnstakes | tokens | pendingUnstakes |
tokens_tokens | tokens | tokens |
As mentioned only radiator offers an API to access Steem Engine. For this radiator offerers a name space called Radiator::SSC
. To access the database tables their are two methods: Contracts.find_one
and Contracts.find
. The latter will be described in the next part of the tutorial.
Im this part of the tutorialContracts.find_one
is used to access the row of any table. The method has three mandatory parameters: contract
, table
and query
:
contract: The name of the contract. As mentione there are currently three known contracts: "tokens", "market", and "steempegged".
table: The name of the tables to query. See below.
query: A list of column names and values.
In order to just access the first row the query attribute is left empty and the result is just printed. There is no explicit error message, if the query fails no data is returned.
if ARGV.length == 0 then
puts "
Steem-Print-SSC-Table-Sample — Print first row of a steem engine table.
Usage:
Steem-Print-SSC-Table-Sample contract_name table_name
"
else
# read arguments from command line
_contract = ARGV[0]
_table = ARGV[1]
# the query attribute is mandantory, supply an empty query
# to receive the first row.
_row = Contracts.find_one(
contract: _contract,
table: _table,
query: {
}
)
if _row == nil then
puts "No data found, possible reasons:
⑴ The contract does not exist
⑵ The table does not exist
⑶ The table is empty
"
else
pp _row
end
end
Hint: Follow this link to Github for the complete script with comments and syntax highlighting : Steem-Print-SSC-Table-First.rb.
The output of the command for the table “tokens” of the contract “tokens” is:
The output of the command for the table “balances” of the contract “tokens” is:
From those output you can learn the names of the columns of the database and both tables will be used to update the Steem-Print-Balances.rb on GitHub script to print the Steem Engine Token in addition to Steem, Steem Dollar and VESTS.