Skip to content

Instantly share code, notes, and snippets.

@inertia186
Last active April 9, 2024 04:28
Show Gist options
  • Save inertia186/db94986d168f7b35034b0d7ccba6f2b4 to your computer and use it in GitHub Desktop.
Save inertia186/db94986d168f7b35034b0d7ccba6f2b4 to your computer and use it in GitHub Desktop.
This script (stinkypete.rb) will conditionally claim rewards. See: https://hive.blog/radiator/@inertia/stinkypete-rb-reward-claim-script-for-steem
Stinky Pete ('stinkypete.rb') for HIVE. Please have a look at the README.md file.
stinkypete.log
  • Title: stinkypete.rb - Reward Claim script for HIVE
  • Tags: radiator ruby hive hivedev rewards
  • Notes:

New Features

  • Claim Rules
    • Added the ability to pick and choose which assets to claim.
      • E.g.: You can choose to claim only HBD.
    • Allow command-line overrides for asssets and minimum_mvests.
      • E.g.: $ ruby stinkypete.rb assets:hbd,hive minimum_mvests:0 will only claim hbd and hive for any amount available.
  • Switched code and examples to the Hive Blockchain

Overview

Stinky Pete allows you to claim rewards based on rules. You can manually run this script periodically or create a cron job.


Install

To use this Radiator script:

Linux
$ sudo apt-get install ruby-full git
$ gem install bundler
macOS
$ gem install bundler

I've tested it on various versions of ruby. The oldest one I got it to work was:

ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [aarch64-linux]

First, clone this gist and install the dependencies:

$ git clone https://gist.github.com/db94986d168f7b35034b0d7ccba6f2b4.git stinkypete
$ cd stinkypete
$ bundle install

Edit the file stinkypete.yml and provide the account you want to claim rewards for. You must use the posting-wif.


Upgrade

Typically, you can upgrade to the latest version by this command, from the original directory you cloned into:

$ git pull

Usually, this works fine as long as you haven't modified anything. If you get an error, try this:

$ git stash --all
$ git pull --rebase
$ git stash pop

If you're still having problems, I suggest starting a new clone.


Usage

To do the actual claim:

$ ruby stinkypete.rb

Stinky Pete will now check if the rules have been met and conditionally claim them.


Check here to see an updated version of this script:

https://gist.github.com/inertia186/db94986d168f7b35034b0d7ccba6f2b4


Troubleshooting

Problem: What does this error mean?
stinkypete.yml:1: syntax error, unexpected ':', expecting end-of-input
Solution: You ran ruby stinkypete.yml but you should run ruby stinkypete.rb.
Problem: Everything looks ok, but every time Stinky Pete tries to claim, I get this error:
`from_base58': Invalid version (RuntimeError)
Solution: You're trying to claim with an invalid key.

Make sure the .yml file account item has the correct name and posting_wif key.

Problem: The node I'm using is down.

Is there a list of nodes?

Solution: Yes:

https://developers.hive.io/quickstart/#quickstart-hive-full-nodes


![](http://i.imgur.com/ylQjmZO.png)

See my previous Ruby How To posts in: #radiator #ruby

Get in touch!

If you're using Stinky Pete, I'd love to hear from you. Drop me a line and tell me what you think! I'm @inertia on Hive.

License

I don't believe in intellectual "property". If you do, consider Stinky Pete as licensed under a Creative Commons CC0 License.

source 'https://rubygems.org'
gem 'radiator'
GEM
remote: https://rubygems.org/
specs:
awesome_print (1.9.2)
base58 (0.2.3)
bindata (2.5.0)
bitcoin-ruby (0.0.20)
eventmachine
ffi
scrypt
connection_pool (2.4.1)
eventmachine (1.2.7)
ffi (1.16.3)
ffi-compiler (1.3.2)
ffi (>= 1.15.5)
rake
hashie (5.0.0)
hive-ruby (1.0.5)
base58 (~> 0.2, >= 0.2.3)
bindata (~> 2.4, >= 2.4.4)
bitcoin-ruby (~> 0.0, = 0.0.20)
ffi (~> 1.9, >= 1.9.23)
hashie (>= 3.5)
json (~> 2.1, >= 2.1.0)
logging (~> 2.2, >= 2.2.0)
json (2.7.2)
little-plugger (1.1.4)
logging (2.3.1)
little-plugger (~> 1.1)
multi_json (~> 1.14)
multi_json (1.15.0)
net-http-persistent (4.0.2)
connection_pool (~> 2.2)
radiator (0.4.9)
awesome_print (~> 1.7, >= 1.7.0)
bitcoin-ruby (= 0.0.20)
ffi (~> 1.9, >= 1.9.18)
hashie (>= 3.5)
hive-ruby (~> 1.0, >= 1.0.3)
json (~> 2.0, >= 2.0.2)
logging (~> 2.2, >= 2.2.0)
net-http-persistent (>= 2.5.2)
steem-ruby (~> 0.9, >= 0.9.7)
rake (13.2.1)
scrypt (3.0.7)
ffi-compiler (>= 1.0, < 2.0)
steem-ruby (0.9.8)
base58 (~> 0.2, >= 0.2.3)
bindata (~> 2.4, >= 2.4.4)
bitcoin-ruby (~> 0.0, >= 0.0.18)
ffi (~> 1.9, >= 1.9.23)
hashie (~> 5.0, >= 4.1.0)
json (~> 2.1, >= 2.1.0)
logging (~> 2.2, >= 2.2.0)
PLATFORMS
aarch64-linux
DEPENDENCIES
radiator
BUNDLED WITH
2.4.22
require 'rubygems'
require 'bundler/setup'
require 'yaml'
Bundler.require
CONFIG_PATH = __FILE__.sub(/\.rb$/, '.yml')
config = YAML.load_file(CONFIG_PATH)
chain = config[:chain_options][:chain].to_sym
options = {
chain: chain,
url: config[:chain_options][:url],
logger: Logger.new(__FILE__.sub(/\.rb$/, '.log'))
}
account_name = config[:account][:name]
wif = config[:account][:posting_wif]
claim_rules = config[:claim_rules]
assets = claim_rules[:assets] || %w(hive hbd vests)
minimum_mvests = claim_rules[:minimum_mvests].to_f
ARGV.each do |arg|
if arg =~ /assets:.+/
assets = arg.split('assets:').last
sep = assets.gsub(/[a-zA-Z]+/, '')
assets = if sep.empty?
[assets]
else
assets.split(sep).map(&:downcase)
end
end
if arg =~ /minimum_mvests:.+/
minimum_mvests = arg.split('minimum_mvests:').last.to_f rescue 0.0
end
end
hive_chain = Radiator::Chain.new(options)
api = Radiator::Api.new(options)
response = api.get_accounts([account_name])
account = response.result.first
reward_hive_balance = account.reward_hive_balance.split(' ').first.to_f
reward_hbd_balance = account.reward_hbd_balance.split(' ').first.to_f
reward_vesting_balance = account.reward_vesting_balance.split(' ').first.to_f
if reward_hive_balance == 0.0 && reward_hbd_balance == 0.0 && reward_vesting_balance == 0.0
puts "Nothing to claim for #{account_name}."
exit
end
feed_history = api.get_feed_history.result
base_per_mvest = hive_chain.base_per_mvest
current_median_history = feed_history.current_median_history
base = current_median_history.base
base = base.split(' ').first.to_f
quote = current_median_history.quote
quote = quote.split(' ').first.to_f
base_per_debt = (base / quote) * base_per_mvest
base_per_debt = if chain == :hive
base_per_debt
else
gold_market = JSON[open("https://api.vaultoro.com/markets").read]
pol_usdt_btc = JSON[open("https://poloniex.com/public?command=returnOrderBook&currencyPair=USDT_BTC&depth=10").read]
pol_usdt_btc = pol_usdt_btc['asks'].first.first.to_f
btc_gld = gold_market['data']['LastPrice'].to_f
usdt_gld_per_milli = (btc_gld * pol_usdt_btc) / 1000
base_per_debt_as_usdt = base_per_debt * usdt_gld_per_milli
base_per_debt
end
reward_total_mvests_balance = 0.0
reward_total_mvests_balance += reward_hive_balance * base_per_mvest
reward_total_mvests_balance += reward_hbd_balance * base_per_debt
reward_total_mvests_balance += reward_vesting_balance
reward_total_mvests_balance = reward_total_mvests_balance / 1000000
reward_total_mvests_balance = reward_total_mvests_balance.round(6)
if reward_total_mvests_balance < minimum_mvests
puts "Not enough to claim (current total balance #{reward_total_mvests_balance} mvests, #{minimum_mvests} needed)"
exit
end
op = {
type: :claim_reward_balance,
account: account_name
}
if assets.include? 'hive'
op[:reward_hive] = account.reward_hive_balance
else
op[:reward_hive] = '0.000 HIVE'
end
if assets.include? 'hbd'
op[:reward_hbd] = account.reward_hbd_balance
else
op[:reward_hbd] = '0.000 HBD'
end
if assets.include? 'vests'
op[:reward_vests] = account.reward_vesting_balance
else
op[:reward_vests] = '0.000000 VESTS'
end
if op[:reward_hive] == '0.000 HIVE' && op[:reward_hbd] == '0.000 HBD' && op[:reward_vests] == '0.000000 VESTS'
puts "Nothing to claim for #{account_name}."
exit
else
claims = []
claims << op[:reward_hive] unless op[:reward_hive] == '0.000 HIVE'
claims << op[:reward_hbd] unless op[:reward_hbd] == '0.000 HBD'
claims << op[:reward_vests] unless op[:reward_vests] == '0.000 VESTS'
puts "Claiming: #{claims.join(' ')} (current total balance #{reward_total_mvests_balance} mvests)"
end
tx = Radiator::Transaction.new(options.merge(wif: wif))
tx.operations << op
puts tx.process(true)
:account:
:name: social
:posting_wif: 5JrvPrQeBBvCRdjv29iDvkwn3EQYZ9jqfAHzrCyUvfbEbRkrYFC
:claim_rules:
:assets:
- hive
- hbd
- vests
:minimum_mvests: 1.0
:chain_options:
:chain: hive
:url: https://api.hive.blog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment