<center></center> ## Repositories ### SteemRubyTutorial All examples from this tutorial can be found as fully functional scripts on GitHub: * [SteemRubyTutorial](https://github.com/krischik/SteemRubyTutorial) * radiator sample code: [Steem-Print-Balances.rb](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb). ### radiator * Project Name: Radiator * Repository: [https://github.com/inertia186/radiator](https://github.com/inertia186/radiator) * Official Documentation: [https://www.rubydoc.info/gems/radiator](https://www.rubydoc.info/gems/radiator) * Official Tutorial: [https://developers.steem.io/tutorials-ruby/getting_started](https://developers.steem.io/tutorials-ruby/getting_started) ### Steem Engine <center></center> * Project Name: Steem Engine * Home Page: [https://steem-engine.com](https://steem-engine.com) * Repository: [https://github.com/harpagon210/steem-engine](https://github.com/harpagon210/steem-engine) * Official Documentation: [https://github.com/harpagon210/sscjs](https://github.com/harpagon210/sscjs) (JavaScript only) * Official Tutorial: N/A ## 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 the radiator APIs available. <center></center> In this particular chapter you learn how extend [Steem-Print-Balances.rb](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb) from the [Print Account Balances improved](Documents/Part-06.md) tutorial so it prints the steem engine token as well. ## 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: ```sh gem install bundler gem install colorize gem install contracts gem install radiator ``` The tutorial build on top of the following previous chapters: * [Print Steem Engine Token values](https://steemit.com/@krischik/using-steem-api-with-ruby-part-15) * [Print Account Balances improved](https://steemit.com/@krischik/using-steem-api-with-ruby-part-06) * [Print Steem Engine Token balances](https://steemit.com/@krischik/using-steem-api-with-ruby-part-16) ## Difficulty For reader with programming experience this tutorial is **basic level**. ## Tutorial Contents The stacked tokens are stored alongside the non stacked token inside the `balances` table. Of course not all token are staked so you should check if the `token` is `stakingEnabled`. ## Implementation using radiator ### [SCC::Balance](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/SCC/Balance.rb) Take the staked token into account when calculating steem value of the account's balance. ```ruby Contract None => Radiator::Type::Amount def to_steem _steem = if @symbol == "STEEMP" then @balance elsif token.staking_enabled then (@balance + @stake) * metric.last_price else @balance * metric.last_price end return Radiator::Type::Amount.to_amount( _steem, Radiator::Type::Amount::STEEM) end ``` Add the staked token to the formatted printout. ```ruby Contract None => String def to_ansi_s _na = "N/A" begin _steem = self.to_steem _sbd = self.to_sbd _staked = self.token.staking_enabled _retval = if _staked then ("%1$15.3f %2$s".white + " %3$15.3f %4$s".white + " %5$18.5f %7$-12s".blue + " %6$18.6f %7$-12s".blue) % [ _sbd.to_f, _sbd.asset, _steem.to_f, _steem.asset, @balance, @stake, @symbol] else ("%1$15.3f %2$s".white + " %3$15.3f %4$s".white + " %5$18.5f %7$-12s".blue + " %6$18s".white) % [ _sbd.to_f, _sbd.asset, _steem.to_f, _steem.asset, @balance, _na, @symbol] end rescue KeyError _retval = ( "%1$15s %2$s".white + " %3$15s %4$5s".white + " %5$18.5f %7$-12s".blue + " %6$18.6f %7$-12s".blue) % [ _na, _na, _na, _na, @balance, @stake, @symbol] end return _retval end ``` ### [SCC::Token](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/SCC/Token.rb) Add additional attributes describing staked token. ```ruby attr_reader :key, :value, :symbol, :issuer, :name, :metadata, :precision, :max_supply, :supply, :circulating_supply, :staking_enabled, :unstaking_cooldown, :delegation_enabled, :undelegation_cooldown, :loki Contract Any => nil def initialize(token) super(:symbol, token.symbol) @symbol = token.symbol @issuer = token.issuer @name = token.name @metadata = JSON.parse(token.metadata) @precision = token.precision @max_supply = token.maxSupply @supply = token.supply @circulating_supply = token.circulatingSupply @stakingEnabled = token.staking_enabled @total_staked = token.total_staked @unstakingCooldown = token.unstaking_cooldown @delegationEnabled = token.delegation_enabled @undelegationCooldown = token.undelegation_cooldown @loki = token["$loki"] return end # initialize ``` ### [Steem-Print-Balances.rb](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb) Update printout and add calculation of accounts steem engine token values. ```ruby _scc_balances = SCC::Balance.account account.name _scc_value = Radiator::Type::Amount.new("0.0 SBD") _scc_balances.each do |_scc_balance| token = _scc_balance.token puts(" %1$-22.22s = %2$s" % [token.name, _scc_balance.to_ansi_s]) # Add token value (in SDB to the account value. begin _sbd = _scc_balance.to_sbd _scc_value = _scc_value + _sbd _account_value = _account_value + _sbd rescue KeyError # do nothing. end end puts((" Account Value (engine) = " + "%1$15.3f %2$s".green) % [ _scc_value.to_f, _scc_value.asset]) puts((" Account Value = " + "%1$15.3f %2$s".green) % [ _account_value.to_f, _account_value.asset]) ``` **Hint:** Follow this link to Github for the complete script with comments and syntax highlighting : [Steem-Print-Balances.rb](https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb). ----- The output of the command changes from previous only printing the steem engine token have not been stacked: <center></center> to now printing the values of the staked Steem Engine Token as well: <center></center> # Curriculum ## First tutorial * [Using Steem-API with Ruby Part 1](https://steemit.com/@krischik/using-steem-api-with-ruby-part-1) ## Previous tutorial * [Using Steem-API with Ruby Part 17](https://steemit.com/@krischik/using-steem-api-with-ruby-part-17) ## Next tutorial * [Using Steem-API with Ruby Part 19](https://steemit.com/@krischik/using-steem-api-with-ruby-part-19) ## Proof of Work * GitHub: [SteemRubyTutorial Issue #20](https://github.com/krischik/SteemRubyTutorial/issues/20) ## Image Source * Ruby symbol: [Wikimedia](https://commons.wikimedia.org/wiki/File:Ruby_logo.svg), CC BY-SA 2.5. * Steemit logo [Wikimedia](https://commons.wikimedia.org/wiki/File:Steemit_New_Logo.png), CC BY-SA 4.0. * Steem Engine logo [Steem Engine](https://steem-engine.com) * Screenshots: @krischik, CC BY-NC-SA 4.0 <center></center>
author | krischik | ||||||
---|---|---|---|---|---|---|---|
permlink | using-steem-api-with-ruby-part-18 | ||||||
category | utopian-io | ||||||
json_metadata | {"app":"steempeak/1.17.0","format":"markdown","tags":["utopian-io","tutorials","ruby","steem-api","programming","palnet","neoxian","marlians","stem"],"users":["krischik","symbol","balance","stake","issuer","name","metadata","precision","max","supply","circulating","stakingEnabled","total","unstakingCooldown","delegationEnabled","undelegationCooldown","loki"],"links":["https://github.com/krischik/SteemRubyTutorial","https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb","https://github.com/inertia186/radiator","https://www.rubydoc.info/gems/radiator","https://developers.steem.io/tutorials-ruby/getting_started","https://steem-engine.com","https://github.com/harpagon210/steem-engine","https://github.com/harpagon210/sscjs","https://github.com/krischik/SteemRubyTutorial/blob/master/Scripts/Steem-Print-Balances.rb","https://Documents/Part-06.md"],"image":["https://files.steempeak.com/file/steempeak/krischik/ubbCGni5-image.png","https://cdn.steemitimages.com/DQmR1jWexK1B1gGwUgcVdGtwRkAZPZ5rUwBXBt6x55TMPjY/Steemit_Ruby_Engine.png","https://cdn.steemitimages.com/DQmcuU8q2NnZjUcj74ChEQDsUBdE4LNc8t9LpucE25TP7Sf/steem-engine_logo-horizontal-dark.png","https://cdn.steemitimages.com/DQmQjPngbfPaKwQ9VEjZcGQPWkFsSXPbvssuPGzuasmDjzA/img_train-dark.png","https://cdn.steemitimages.com/DQmWdg5GNopbmWUHBuEeaYuGmSc4bPYxR3XFymfMWoxLQ4F/Screenshot%20at%20Jul%2030%2015-23-14.png","https://files.steempeak.com/file/steempeak/krischik/JaSBtA1B-posts-50-60.png","https://files.steempeak.com/file/steempeak/krischik/3zh0hy1H-comments-58-70.png","https://files.steempeak.com/file/steempeak/krischik/VVR0lQ3T-votes-66-80.png","https://files.steempeak.com/file/steempeak/krischik/K8PLgaRh-level-90-90.png","https://files.steempeak.com/file/steempeak/krischik/EKjrC9xN-payout-66-80.png","https://files.steempeak.com/file/steempeak/krischik/bMY0fJGX-commented-58-70.png","https://files.steempeak.com/file/steempeak/krischik/P5yFKQ8S-voted-50-60.png"]} | ||||||
created | 2019-09-20 11:47:06 | ||||||
last_update | 2019-09-20 11:48:03 | ||||||
depth | 0 | ||||||
children | 2 | ||||||
last_payout | 2019-09-27 11:47:06 | ||||||
cashout_time | 1969-12-31 23:59:59 | ||||||
total_payout_value | 0.083 HBD | ||||||
curator_payout_value | 0.082 HBD | ||||||
pending_payout_value | 0.000 HBD | ||||||
promoted | 0.000 HBD | ||||||
body_length | 10,046 | ||||||
author_reputation | 15,247,708,436,415 | ||||||
root_title | "Using Steem-API with Ruby Part 18 — Print Stacked Steem Token" | ||||||
beneficiaries |
| ||||||
max_accepted_payout | 1,000,000.000 HBD | ||||||
percent_hbd | 0 | ||||||
post_id | 90,759,874 | ||||||
net_rshares | 769,249,219,609 | ||||||
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
arcange | 0 | 41,541,940,038 | 3% | ||
raphaelle | 0 | 1,174,890,783 | 3% | ||
anomaly | 0 | 55,415,789 | 1% | ||
techslut | 0 | 87,982,144,305 | 20% | ||
loshcat | 0 | 2,657,191,207 | 100% | ||
steem-plus | 0 | 157,976,708,660 | 8.68% | ||
steemtaker | 0 | 38,090,491,771 | 30% | ||
greenorange | 0 | 577,580,205 | 100% | ||
steemkitten | 0 | 4,541,720,594 | 77.57% | ||
portugalcoin | 0 | 18,565,343,473 | 20% | ||
didic | 0 | 9,641,757,661 | 20% | ||
reazuliqbal | 0 | 47,723,099,531 | 30% | ||
properfraction | 0 | 3,305,900,867 | 100% | ||
stmdev | 0 | 143,419,938 | 1% | ||
enforcer48 | 0 | 37,913,208,384 | 15% | ||
digital.mine | 0 | 153,161,550,915 | 20% | ||
socialbot | 0 | 81,786,302,872 | 15% | ||
axeminni | 0 | 55,920,355 | 3% | ||
jongreat | 0 | 0 | 100% | ||
abh12345.stem | 0 | 202,457,715 | 25% | ||
catnet | 0 | 80,206,812,126 | 77.56% | ||
ggvoter | 0 | 632,041,689 | 75% | ||
curation.stem | 0 | 771,349,306 | 75% | ||
stemd | 0 | 541,971,425 | 30% |
Hi, @krischik! You just got a **8.68%** 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](https://steemit.com/@steem-plus) to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.
author | steem-plus |
---|---|
permlink | using-steem-api-with-ruby-part-18---vote-steemplus |
category | utopian-io |
json_metadata | {} |
created | 2019-09-20 21:07:39 |
last_update | 2019-09-20 21:07:39 |
depth | 1 |
children | 0 |
last_payout | 2019-09-27 21:07:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 435 |
author_reputation | 247,952,188,232,400 |
root_title | "Using Steem-API with Ruby Part 18 — Print Stacked Steem Token" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 90,773,123 |
net_rshares | 0 |
/ᐠ.。.ᐟ\\
author | steemkitten |
---|---|
permlink | re-using-steem-api-with-ruby-part-18-20190921t000027z |
category | utopian-io |
json_metadata | "{"app": "beem/0.20.22"}" |
created | 2019-09-21 00:00:30 |
last_update | 2019-09-21 00:00:30 |
depth | 1 |
children | 0 |
last_payout | 2019-09-28 00:00:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 8 |
author_reputation | 2,121,135,936,104 |
root_title | "Using Steem-API with Ruby Part 18 — Print Stacked Steem Token" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 90,777,034 |
net_rshares | 0 |