Skip to content

Instantly share code, notes, and snippets.

@inertia186
Last active March 25, 2018 22:29
Embed
What would you like to do?
This script (stinkypete.rb) will conditionally claim rewards. See: https://steemit.com/radiator/@inertia/stinkypete-rb-reward-claim-script-for-steem
Stinky Pete ('stinkypete.rb') for STEEM. Please have a look at the README.md file.
stinkypete.log
  • Title: stinkypete.rb - Reward Claim script for STEEM
  • Tags: radiator ruby steem steemdev 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 SBD.
    • Allow command-line overrides for asssets and minimum_mvests.
      • E.g.: $ ruby stinkypete.rb assets:sbd,steem minimum_mvests:0 will only claim sbd and steem for any amount available.

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 openssl libssl1.0.0 libssl-dev
$ 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.0.0p645 (2015-04-13 revision 50299) [x86_64-darwin14.4.0]

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, special thanks to @ripplerm.

https://ripplerm.github.io/steem-servers/


![](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 STEEM and SteemSpeak.

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:
bitcoin-ruby (0.0.10)
ffi (1.9.17)
hashie (3.5.5)
json (1.8.6)
little-plugger (1.1.4)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
multi_json (1.12.1)
net-http-persistent (2.9.4)
radiator (0.2.1)
bitcoin-ruby (= 0.0.10)
ffi (= 1.9.17)
hashie (~> 3.5, >= 3.5.5)
json (~> 1.8, >= 1.8.6)
logging (~> 2.2, >= 2.2.0)
net-http-persistent (~> 2.9, >= 2.9.4)
PLATFORMS
ruby
DEPENDENCIES
radiator
BUNDLED WITH
1.14.6
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(steem sbd 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
api = Radiator::Api.new(options)
response = api.get_accounts([account_name])
account = response.result.first
reward_steem_balance = account.reward_steem_balance.split(' ').first.to_f
reward_sbd_balance = account.reward_sbd_balance.split(' ').first.to_f
reward_vesting_balance = account.reward_vesting_balance.split(' ').first.to_f
if reward_steem_balance == 0.0 && reward_sbd_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 = api.steem_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 == :steem
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_steem_balance * base_per_mvest
reward_total_mvests_balance += reward_sbd_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? 'steem'
op[:reward_steem] = account.reward_steem_balance
else
op[:reward_steem] = '0.000 STEEM'
end
if assets.include? 'sbd'
op[:reward_sbd] = account.reward_sbd_balance
else
op[:reward_sbd] = '0.000 SBD'
end
if assets.include? 'vests'
op[:reward_vests] = account.reward_vesting_balance
else
op[:reward_vests] = '0.000000 VESTS'
end
if op[:reward_steem] == '0.000 STEEM' && op[:reward_sbd] == '0.000 SBD' && op[:reward_vests] == '0.000000 VESTS'
puts "Nothing to claim for #{account_name}."
exit
else
claims = []
claims << op[:reward_steem] unless op[:reward_steem] == '0.000 STEEM'
claims << op[:reward_sbd] unless op[:reward_sbd] == '0.000 SBD'
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:
- steem
- sbd
- vests
:minimum_mvests: 1.0
:chain_options:
:chain: steem
:url: https://steemd.steemit.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment