Radiator
Hive Ruby API Client
Install / Use
/learn @inertia186/RadiatorREADME
radiator
Hive/Steem Ruby API Client
Radiator is an API Client for interaction with the Hive/Steem network using Ruby.
Changes in v0.4.9
- Tweaks for Ruby 3 support
Changes in v0.4.8
- Eclipse Update
- Now wrapping
hive-rubyandsteem-ruby
Changes in v0.4.7
- Added
attr_readerforRadiator::Type::Amount#28 - Added restful fallback for
get_transactionduringrecover_transactions_on_error - Fix beneficiary serialization (thanks @eonwarped)
Changes in v0.4.6
- Added health check and persist option
Changes in v0.4.5
- Added support to query and stream a Steem Smart Contract backed side-chains like Steem Engine.
Changes in v0.4.0
- Gem updates
- AppBase Support
- Defaulting to
condenser_api.*inRadiator::Api(see below) - Handle/recover from new
AppBaseerrors.
- Defaulting to
Radiator::Streamnow detects if it's stalled and takes action if it has to wait too long for a new block.- Exponential back-off for stalls so that the node doesn't get slammed.
- Short delays (3 times block production) only result in a warning.
- Long delays (6 times block production) may try to switch to an alternate node.
- Fixed internal logging bug that would open too many files.
- This fix also mitigates issues like
SSL Verifyproblems (similar to #12)
- This fix also mitigates issues like
- Dropped GOLOS support.
Appbase is now supported.
If you were already using Radiator::Api then there is nothing to change. But if you made use of other API classes, like Radiator::FollowApi, then the method signatures have changed.
Pre-AppBase:
api = Radiator::FollowApi.new
api.get_followers('inertia', 0, 'blog', 10)
New Signature:
api = Radiator::FollowApi.new
api.get_followers(account: 'inertia', start: 0, type: 'blog', limit: 10)
-- or --
Switch to Condenser API:
The other strategy for using this version of Radiator is to just switch away from classes like Radiator::FollowApi over to Radiator::Api (also known as Radiator::CondenserApi) instead. Then you don't have to update individual method calls.
api = Radiator::Api.new
api.get_followers('inertia', 0, 'blog', 10)
Note about GOLOS
GOLOS is no longer supported in Radiator. If you want to continue to use GOLOS, you'll need to branch from v0.3.15 (pre-appbase) and add WebSockets support because GOLOS completely dropped JSON-RPC over HTTP clients support for some reason
Radiator has never and will never use WebSockets due to its server scalability requirements.
From a client perspective, WebSockets is great. I have nothing against WebSockets. So I might get around to it at some point, but GOLOS won't be part of Radiator anymore mainly because GOLOS has no plans to implement AppBase.
Changes in v0.3.0
- Gem updates
- Added failover subroutines (see Failover section, below).
- Added method closures support (aka passing a block to yield).
- You can now stream virtual operations (see Streaming section, below).
- Added more documentation.
- Added/expanded more api namespaces:
::BlockApi,::CondenserApi,::TagApi - Addressed an issue with logging on certain Windows configurations.
Fixes in v0.2.3
- Gem updates
- Added low-level support for persistence and retrying API requests.
- Now using exponential back-off for retries.
- Detecting presence of
transaction_ids(if enabled by the node). - Default for
Hashiewarnings now go to/dev/null, where they belong. - Added stray methods/operations.
Fixes in v0.2.2
- Gem updates
- Improved support for datatypes and handlers.
- UTF-8 handled more smoothly.
- Simplified operation construction.
- Improved keep-alive defaults.
- Better streaming reliability.
Also see: Documentation
Quick Start
Add the gem to your Gemfile:
gem 'radiator'
Then:
$ bundle install
If you don't have bundler, see the next section.
Prerequisites
minimum ruby version: 2.5
Linux
$ sudo apt-get install ruby-full git openssl libssl1.0.0 libssl-dev
$ gem install bundler
macOS
$ gem install bundler
Usage
require 'radiator'
api = Radiator::Api.new
api.get_dynamic_global_properties do |properties|
properties.virtual_supply
end
=> "271342874.337 STEEM"
... or ...
require 'radiator'
api = Radiator::Api.new
response = api.get_dynamic_global_properties
response.result.virtual_supply
=> "271342874.337 STEEM"
Follower API
api = Radiator::FollowApi.new
api.get_followers(account: 'inertia', start: 0, type: 'blog', limit: 100) do |followers|
followers.map(&:follower)
end
=> ["a11at",
"abarefootpoet",
"abit",
"alexgr",
"alexoz",
"andressilvera",
"applecrisp",
"arrowj",
"artificial",
"ash",
"ausbitbank",
"beachbum",
"ben99",
"benadapt",
.
.
.
"steemzine"]
Side Chain Support
Steem Smart Contract side-chains are supported by Radiator. The default side-chain is Hive/Steem Engine.
This will fetch the latest block from the side-chain ...
rpc = Radiator::SSC::Blockchain.new
rpc.latest_block_info
This will fetch block 1 ...
rpc.block_info(1)
Or a specific transaction ...
rpc.transaction_info('9d288aab2eb66064dc0d4492cb281512386e2293')
You can also do contract queries. This will look up the tokens contract:
rpc = Radiator::SSC::Contracts.new
rpc.contract('tokens')
This will look up a specific record in a contract result ...
rpc.find_one(
contract: "tokens",
table: "balances",
query: {
symbol: "STINGY",
account: "inertia"
}
)
Or get multiple results ...
rpc.find(
contract: "tokens",
table: "balances",
query: {
symbol: "STINGY"
}
)
Streaming
Here's an example of how to use a streaming instance to listen for votes:
require 'radiator'
stream = Radiator::Stream.new
stream.operations(:vote) do |op|
print "#{op.voter} voted for #{op.author}"
puts " (weight: #{op.weight / 100.0}%)"
end
The output would look like this and continue until interrupted.
richman voted for krnel (weight: 100.0%)
rainchen voted for rainchen (weight: 100.0%)
richman voted for exploretraveler (weight: 100.0%)
jlufer voted for michaelstobiersk (weight: 100.0%)
jlufer voted for michaelstobiersk (weight: 100.0%)
patelincho voted for borishaifa (weight: 100.0%)
richman voted for vetvso (weight: 100.0%)
jlufer voted for michaelstobiersk (weight: 100.0%)
richman voted for orcish (weight: 100.0%)
demotruk voted for skeptic (weight: -100.0%)
photorealistic voted for oecp85 (weight: 100.0%)
meesterboom voted for rubenalexander (weight: 100.0%)
thecurator voted for robyneggs (weight: 40.0%)
richman voted for originate (weight: 100.0%)
helikopterben voted for etcmike (weight: 100.0%)
.
.
.
You can also just stream all operations like this:
stream.operations do |op|
puts op.to_json
end
Example of the output:
{
"vote":{
"voter":"abudar",
"author":"rangkangandroid",
"permlink":"the-kalinga-tattoo-maker",
"weight":10000
}
}
{
"vote":{
"voter":"shenburen",
"author":"masteryoda",
"permlink":"daily-payouts-leaderboards-september-16",
"weight":10000
}
}
{
"vote":{
"voter":"stiletto",
"author":"fyrstikken",
"permlink":"everybody-hating-me",
"weight":2500
}
}
{
"comment":{
"parent_author":"mariandavp",
"parent_permlink":"re-onceuponatime-re-mariandavp-the-bridge-original-artwork-by-mariandavp-20160906t182016608z",
"author":"onceuponatime",
"permlink":"re-mariandavp-re-onceuponatime-re-mariandavp-the-bridge-original-artwork-by-mariandavp-20160917t054726763z",
"title":"",
"body":"https://www.steemimg.com/images/2016/09/17/oldcomputerpics551cb14c.jpg",
"json_metadata":"{\"tags\":[\"art\"],\"image\":[\"https://www.steemimg.com/images/2016/09/17/oldcomputerpics551cb14c.jpg\"]}"
}
}
{
"vote":{
"voter":"abudar",
"author":"rangkangandroid",
"permlink":"the-journey-north-through-the-eyes-of-kalinga-tradition",
"weight":10000
}
}
{
"limit_order_cancel":{
"owner":"fnait",
"orderid":2755220300
}
}
.
.
.
You can also stream virtual operations:
stream.operations(:producer_reward) do |op|
puts "#{op.producer} got a reward: #{op.vesting_shares}"
end
Example of the output:
anyx got a reward: 390.974648 VESTS
gtg got a reward: 390.974647 VESTS
someguy123 got a reward: 390.974646 VESTS
jesta got a reward: 390.974646 VESTS
blocktrades got a reward: 390.974645 VESTS
timcliff got a reward: 390.974644 VESTS
bhuz got a reward: 1961.046504 VESTS
.
.
.
Transactions are supported:
stream.transactions do |tx, trx_id|
puts "[#{trx_id}] #{tx.to_jso
