Using Steem-API with Ruby Part 13 — Print Data from Steem Engine Database TablesteemCreated with Sketch.

in #utopian-io5 years ago (edited)

Steemit_Ruby_Engine.png

Repositories

SteemRubyTutorial

All examples from this tutorial can be found as fully functional scripts on GitHub:

radiator

Steem Engine

steem-engine_logo-horizontal-dark.png

What Will I Learn?

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.

img_train.png

In this particular chapter you learn how to read a single row from the Steem Engine database tables.

Requirements

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

Difficulty

For reader with programming experience this tutorial is basic level.

Tutorial Contents

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.

img_steem-engine_overview.png

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 nameContactTable
market_buyBookmarketbuyBook
market_metricsmarketmetrics
market_sellBookmarketsellBook
market_tradesHistorymarkettradesHistory
steempegged_withdrawalssteempeggedwithdrawals
tokens_balancestokensbalances
tokens_contractsBalancestokenscontractsBalances
tokens_paramstokensparams
tokens_pendingUnstakestokenspendingUnstakes
tokens_tokenstokenstokens

Implementation using radiator

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:

Screenshot at Jun 06 20-03-31.png

The output of the command for the table “balances” of the contract “tokens” is:

Screenshot at Jun 06 20-06-39.png

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.

Curriculum

First tutorial

Previous tutorial

Next tutorial

Proof of Work

Image Source

Beneficiary

Beneficiary.png

comment votes posts level payout commented voted

Sort:  

Thank you for your contribution @krischik.
After analyzing your tutorial we suggest the following points below:

  • Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

  • Your tutorial is very well structured and explained. Good job!

  • Thank you for following our suggestions in your previous tutorial.

Looking forward to your upcoming tutorials.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Your tutorial is quite short for a good tutorial. We recommend you aim for capturing at least 2-3 concepts.

I agree it's short but I disagree on capturing multiple concepts. I prefer one method / concept at a time.

If you are worried about me spoiling for upvotes then please make the upvote smaller in accordance to the size of the particular chapter.

Thank you for your review, @portugalcoin! Keep up the good work!

Hi @krischik!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Congratulations @krischik! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got more than 200 replies. Your next target is to reach 300 replies.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!

Hi, @krischik!

You just got a 4.79% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hey, @krischik!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.26
TRX 0.11
JST 0.033
BTC 64498.18
ETH 3079.08
USDT 1.00
SBD 3.86