Class: Radiator::Chain
- Inherits:
-
Object
- Object
- Radiator::Chain
- Defined in:
- lib/radiator/chain.rb
Overview
Examples …
To vote on a post/comment:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.vote!(10000, 'author', 'post-or-comment-permlink')
To post and vote in the same transaction:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.post!(title: 'title of my post', body: 'body of my post', tags: ['tag'], self_upvote: 10000)
To post and vote with declined payout:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
= {
title: 'title of my post',
body: 'body of my post',
tags: ['tag'],
self_upvote: 10000,
percent_steem_dollars: 0
}
steem.post!()
Constant Summary collapse
- VALID_OPTIONS =
%w( chain account_name wif ).map(&:to_sym)
Instance Method Summary collapse
-
#broadcast!(auto_reset = false) ⇒ Object
Broadcast queued operations.
-
#claim_reward_balance(options) ⇒ Object
Create a claim_reward_balance operation.
-
#claim_reward_balance!(permlink) ⇒ Object
Create a claim_reward_balance operation and broadcasts it right away.
-
#delete_comment(permlink) ⇒ Object
Create a delete_comment operation.
-
#delete_comment!(permlink) ⇒ Object
Create a delete_comment operation and broadcasts it right away.
-
#initialize(options = {}) ⇒ Chain
constructor
A new instance of Chain.
-
#post(options = {}) ⇒ Object
Creates a post operation.
-
#post!(options = {}) ⇒ Object
Create a vote operation and broadcasts it right away.
-
#reset ⇒ Object
Clears out queued operations.
-
#transfer(options = {}) ⇒ Object
Create a transfer operation.
-
#transfer!(options = {}) ⇒ Object
Create a transfer operation and broadcasts it right away.
-
#vote(weight, *args) ⇒ Object
Create a vote operation.
-
#vote!(weight, *args) ⇒ Object
Create a vote operation and broadcasts it right away.
Constructor Details
#initialize(options = {}) ⇒ Chain
Returns a new instance of Chain.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/radiator/chain.rb', line 34 def initialize( = {}) = .dup .each do |k, v| k = k.to_sym if VALID_OPTIONS.include?(k.to_sym) .delete(k) send("#{k}=", v) end end @account_name ||= ENV['ACCOUNT_NAME'] @wif ||= ENV['WIF'] raise ChainError, "Required option: chain" if @chain.nil? raise ChainError, "Required option: account_name, wif" if @account_name.nil? || @wif.nil? reset end |
Instance Method Details
#broadcast!(auto_reset = false) ⇒ Object
Broadcast queued operations.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/radiator/chain.rb', line 61 def broadcast!(auto_reset = false) begin transaction = Radiator::Transaction.new() transaction.operations = @operations response = transaction.process(true) rescue => e reset if auto_reset raise e end if !!response.result reset response else reset if auto_reset ErrorParser.new(response) end end |
#claim_reward_balance(options) ⇒ Object
Create a claim_reward_balance operation.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.claim_reward_balance(reward_sbd: '100.000 SBD')
steem.broadcast!
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/radiator/chain.rb', line 260 def claim_reward_balance() reward_steem = [:reward_steem] || '0.000 STEEM' reward_sbd = [:reward_sbd] || '0.000 SBD' reward_vests = [:reward_vests] || '0.000000 VESTS' @operations << { type: :claim_reward_balance, account: account_name, reward_steem: reward_steem, reward_sbd: reward_sbd, reward_vests: reward_vests } self end |
#claim_reward_balance!(permlink) ⇒ Object
Create a claim_reward_balance operation and broadcasts it right away.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.claim_reward_balance!(reward_sbd: '100.000 SBD')
284 |
# File 'lib/radiator/chain.rb', line 284 def claim_reward_balance!(permlink); claim_reward_balance(permlink).broadcast!(true); end |
#delete_comment(permlink) ⇒ Object
Create a delete_comment operation.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.delete_comment('permlink')
steem.broadcast!
228 229 230 231 232 233 234 235 236 |
# File 'lib/radiator/chain.rb', line 228 def delete_comment(permlink) @operations << { type: :delete_comment, author: account_name, permlink: permlink } self end |
#delete_comment!(permlink) ⇒ Object
Create a delete_comment operation and broadcasts it right away.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.delete_comment!('permlink')
246 |
# File 'lib/radiator/chain.rb', line 246 def delete_comment!(permlink); delete_comment(permlink).broadcast!(true); end |
#post(options = {}) ⇒ Object
Creates a post operation.
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
= {
title: 'This is my fancy post title.',
body: 'This is my fancy post body.',
tags: %w(thess are my fancy tags)
}
steem.post()
steem.broadcast!
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/radiator/chain.rb', line 151 def post( = {}) = [[:tags] || []].flatten title = [:title].to_s permlink = [:permlink] || title.downcase.gsub(/[^a-z0-9\-]+/, '-') parent_permlink = [:parent_permlink] || [0] raise ChainError, 'At least one tag is required or set the parent_permlink directy.' if parent_permlink.nil? body = [:body] = [:parent_author] || '' max_accepted_payout = [:max_accepted_payout] || default_max_acepted_payout percent_steem_dollars = [:percent_steem_dollars] allow_votes = [:allow_votes] || true allow_curation_rewards = [:allow_curation_rewards] || true self_vote = [:self_vote] .insert(0, parent_permlink) = .compact.uniq = { app: Radiator::AGENT_ID } [:tags] = if .any? @operations << { type: :comment, parent_permlink: parent_permlink, author: account_name, permlink: permlink, title: title, body: body, json_metadata: .to_json, parent_author: } if (!!max_accepted_payout && max_accepted_payout != default_max_acepted_payout ) || !!percent_steem_dollars || !allow_votes || !allow_curation_rewards @operations << { type: :comment_options, author: account_name, permlink: permlink, max_accepted_payout: max_accepted_payout, percent_steem_dollars: percent_steem_dollars, allow_votes: allow_votes, allow_curation_rewards: allow_curation_rewards, extensions: [] } end vote(self_vote, account_name, permlink) if !!self_vote self end |
#post!(options = {}) ⇒ Object
Create a vote operation and broadcasts it right away.
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
= {
title: 'This is my fancy post title.',
body: 'This is my fancy post body.',
tags: %w(thess are my fancy tags)
}
steem.post!()
217 |
# File 'lib/radiator/chain.rb', line 217 def post!( = {}); post().broadcast!(true); end |
#reset ⇒ Object
Clears out queued operations.
54 55 56 |
# File 'lib/radiator/chain.rb', line 54 def reset @operations = [] end |
#transfer(options = {}) ⇒ Object
Create a transfer operation.
steem = Steem.new(account_name: 'your account name', wif: 'your active wif')
steem.transfer(amount: '1.000 SBD', to: 'account name', memo: 'this is a memo')
steem.broadcast!
296 297 298 299 300 |
# File 'lib/radiator/chain.rb', line 296 def transfer( = {}) @operations << .merge(type: :transfer, from: account_name) self end |
#transfer!(options = {}) ⇒ Object
Create a transfer operation and broadcasts it right away.
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.transfer!(amount: '1.000 SBD', to: 'account name', memo: 'this is a memo')
308 |
# File 'lib/radiator/chain.rb', line 308 def transfer!( = {}); transfer().broadcast!(true); end |
#vote(weight, *args) ⇒ Object
Create a vote operation.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.vote(10000, 'author', 'permlink')
steem.broadcast!
… or …
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.vote(10000, '@author/permlink')
steem.broadcast!
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/radiator/chain.rb', line 96 def vote(weight, *args) , permlink = if args.size == 1 , permlink = parse_slug(args[0]) else , permlink = args end @operations << { type: :vote, voter: account_name, author: , permlink: permlink, weight: weight } self end |
#vote!(weight, *args) ⇒ Object
Create a vote operation and broadcasts it right away.
Examples:
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.vote!(10000, 'author', 'permlink')
… or …
steem = Steem.new(account_name: 'your account name', wif: 'your wif')
steem.vote!(10000, '@author/permlink')
127 |
# File 'lib/radiator/chain.rb', line 127 def vote!(weight, *args); vote(weight, *args).broadcast!(true); end |