Class: Hive::Broadcast
- Inherits:
-
Object
- Object
- Hive::Broadcast
- Defined in:
- lib/hive/broadcast.rb
Overview
These class methods make it simple to do things like broacast a Broadcast.vote or Broadcast.comment operation. They accept all of the fields expected by the blockchain plus the following additional options:
* wif
* url (optional)
* database_api (optional)
* block_api (optional)
* network_broadcast_api (optional)
* pretend (optional)
These options are not sent in the broadcast. The ‘wif` authorities can be posting, active, and owner.
Setting ‘url` will allow you to specify a different node instead of taking the default: (ChainConfig::NETWORKS_HIVE_DEFAULT_NODE).
Setting ‘database_api`, `block_api`, and `network_broadcast_api` is optional, doing so will allow you to override the default node and/or the RPC Client.
When passing the ‘pretend` field, if it is set to True, nothing is broadcasted, but the `wif` is checked for the proper authority.
For details on what to pass to these methods, check out the Steem Developer Portal Broadcast Operations page.
Constant Summary collapse
- DEFAULT_MAX_ACCEPTED_PAYOUT =
Type::Amount.new(amount: '1000000000', precision: 3, nai: '@@000000013')
Constants included from Retriable
Retriable::MAX_BACKOFF, Retriable::MAX_RETRY_COUNT, Retriable::MAX_RETRY_ELAPSE, Retriable::RETRYABLE_EXCEPTIONS
Class Method Summary collapse
-
.account_create(options, &block) ⇒ Object
Create an account.
- .account_create_with_delegation(options, &block) ⇒ Object
-
.account_update(options, &block) ⇒ Object
Update an account.
- .account_update2(options, &block) ⇒ Object
- .account_witness_proxy(options, &block) ⇒ Object
-
.account_witness_vote(options, &block) ⇒ Object
All accounts with a VFS (Vesting Fund Shares) can vote for or against any witness.
- .cancel_transfer_from_savings(options, &block) ⇒ Object
-
.change_recovery_account(options, &block) ⇒ Object
Each account lists another account as their recovery account.
- .claim_account(options, &block) ⇒ Object
- .claim_reward_balance(options, &block) ⇒ Object
-
.comment(options, &block) ⇒ Object
Creates a post/comment.
-
.convert(options, &block) ⇒ Object
This operation instructs the blockchain to start a conversion between HIVE and HBD, the funds are deposited after 3.5 days.
-
.create_claimed_account(options, &block) ⇒ Object
Create a claimed account.
- .create_proposal(options, &block) ⇒ Object
-
.custom(options, &block) ⇒ Object
Provides a generic way to add higher level protocols on top of witness consensus.
-
.custom_binary(options, &block) ⇒ Object
The semmantics for this operation are the same as the Broadcast.custom_json operation, but with a binary payload.
-
.custom_json(options, &block) ⇒ Object
Serves the same purpose as Broadcast.custom but also supports required posting authorities.
-
.decline_voting_rights(options, &block) ⇒ Object
An account can chose to decline their voting rights after a 30 day delay.
-
.delegate_vesting_shares(options, &block) ⇒ Object
Delegate vesting shares from one account to the other.
-
.delete_comment(options, &block) ⇒ Object
Deletes a post/comment.
-
.escrow_approve(options, &block) ⇒ Object
The agent and to accounts must approve an escrow transaction for it to be valid on the blockchain.
-
.escrow_dispute(options, &block) ⇒ Object
If either the sender or receiver of an escrow payment has an issue, they can raise it for dispute.
-
.escrow_release(options, &block) ⇒ Object
This operation can be used by anyone associated with the escrow transfer to release funds if they have permission.
-
.escrow_transfer(options, &block) ⇒ Object
The purpose of this operation is to enable someone to send money contingently to another individual.
-
.feed_publish(options, &block) ⇒ Object
Feeds can only be published by the top N witnesses which are included in every round and are used to define the exchange rate between hive and the dollar.
-
.limit_order_cancel(options, &block) ⇒ Object
Cancels an order and returns the balance to owner.
-
.limit_order_create(options, &block) ⇒ Object
This operation creates a limit order and matches it against existing open orders.
- .process(options, &block) ⇒ Object
- .recover_account(options, &block) ⇒ Object
- .remove_proposal(options, &block) ⇒ Object
-
.request_account_recovery(options, &block) ⇒ Object
All account recovery requests come from a listed recovery account.
-
.set_withdraw_vesting_route(options, &block) ⇒ Object
Allows an account to setup a vesting withdraw but with the additional request for the funds to be transferred directly to another account’s balance rather than the withdrawing account.
-
.transfer(options, &block) ⇒ Object
Transfers asset from one account to another.
- .transfer_from_savings(options, &block) ⇒ Object
-
.transfer_to_savings(options, &block) ⇒ Object
For time locked savings accounts.
-
.transfer_to_vesting(options, &block) ⇒ Object
This operation converts HIVE into VFS (Vesting Fund Shares) at the current exchange rate.
- .update_proposal_votes(options, &block) ⇒ Object
-
.vote(options, &block) ⇒ Object
This operation is used to cast a vote on a post/comment.
-
.withdraw_vesting(options, &block) ⇒ Object
At any given point in time an account can be withdrawing from their vesting shares.
-
.witness_set_properties(options, &block) ⇒ Object
Extensible replacement for #witness_update that supports additional properties added since HF20 and beyond.
-
.witness_update(options, &block) ⇒ Object
Users who wish to become a witness must pay a fee acceptable to the current witnesses to apply for the position and allow voting to begin.
Methods included from Retriable
Methods included from Utils
Class Method Details
.account_create(options, &block) ⇒ Object
Create an account.
= {
wif: wif,
params: {
fee: '1.000 HIVE',
creator: creator_account_name,
new_account_name: new_account_name,
owner: {
weight_threshold: 1,
account_auths: [],
key_auths: [[owner_public_key, 1]],
},
active: {
weight_threshold: 1,
account_auths: [],
key_auths: [[active_public_key, 1]],
},
posting: {
weight_threshold: 1,
account_auths: [],
key_auths: [[posting_public_key, 1]],
},
memo_key: memo_public_key,
json_metadata: '{}'
}
}
Hive::Broadcast.account_create()
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/hive/broadcast.rb', line 496 def self.account_create(, &block) required_fields = %i(fee creator new_account_name owner active posting memo_key json_metadata) params = [:params] if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params.delete(:metadata) || {} ||= (JSON[params[:json_metadata]] || nil) || {} params[:json_metadata] = .to_json check_required_fields(params, *required_fields) params[:fee] = normalize_amount(.merge amount: params[:fee]) ops = [[:account_create, params]] process(.merge(ops: ops), &block) end |
.account_create_with_delegation(options, &block) ⇒ Object
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
# File 'lib/hive/broadcast.rb', line 1200 def self.account_create_with_delegation(, &block) required_fields = %i(fee delegation creator new_account_name owner active posting memo_key) params = [:params] if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params.delete(:metadata) || {} ||= (JSON[params[:json_metadata]] || nil) || {} params[:json_metadata] = .to_json check_required_fields(params, *required_fields) params[:fee] = normalize_amount(.merge amount: params[:fee]) params[:delegation] = normalize_amount(.merge amount: params[:delegation]) params[:extensions] ||= [] ops = [[:account_create_with_delegation, params]] process(.merge(ops: ops), &block) end |
.account_update(options, &block) ⇒ Object
Update an account.
= {
wif: wif,
params: {
account: new_account_name,
owner: {
weight_threshold: 1,
account_auths: [],
key_auths: [[owner_public_key, 1]],
},
active: {
weight_threshold: 1,
account_auths: [],
key_auths: [[active_public_key, 1]],
},
posting: {
weight_threshold: 1,
account_auths: [],
key_auths: [[posting_public_key, 1]],
},
memo_key: memo_public_key,
json_metadata: '{}'
}
}
Hive::Broadcast.account_update()
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/hive/broadcast.rb', line 618 def self.account_update(, &block) required_fields = %i(account) params = [:params] if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params.delete(:metadata) || {} ||= (JSON[params[:json_metadata]] || nil) || {} params[:json_metadata] = .to_json check_required_fields(params, *required_fields) ops = [[:account_update, params]] process(.merge(ops: ops), &block) end |
.account_update2(options, &block) ⇒ Object
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/hive/broadcast.rb', line 1277 def self.account_update2(, &block) required_fields = %i(account) params = [:params] check_required_fields(params, *required_fields) if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params.delete(:metadata) || {} ||= (JSON[params[:json_metadata]] || nil) || {} params[:json_metadata] = .to_json ops = [[:account_update2, params]] process(.merge(ops: ops), &block) end |
.account_witness_proxy(options, &block) ⇒ Object
778 779 780 781 782 783 784 785 786 |
# File 'lib/hive/broadcast.rb', line 778 def self.account_witness_proxy(, &block) required_fields = %i(account proxy) params = [:params] check_required_fields(params, *required_fields) ops = [[:account_witness_proxy, params]] process(.merge(ops: ops), &block) end |
.account_witness_vote(options, &block) ⇒ Object
All accounts with a VFS (Vesting Fund Shares) can vote for or against any witness.
761 762 763 764 765 766 767 768 769 |
# File 'lib/hive/broadcast.rb', line 761 def self.account_witness_vote(, &block) required_fields = %i(account witness approve) params = [:params] check_required_fields(params, *required_fields) ops = [[:account_witness_vote, params]] process(.merge(ops: ops), &block) end |
.cancel_transfer_from_savings(options, &block) ⇒ Object
1130 1131 1132 1133 1134 1135 1136 1137 1138 |
# File 'lib/hive/broadcast.rb', line 1130 def self.cancel_transfer_from_savings(, &block) required_fields = %i(from request_id) params = [:params] check_required_fields(params, *required_fields) ops = [[:cancel_transfer_from_savings, params]] process(.merge(ops: ops), &block) end |
.change_recovery_account(options, &block) ⇒ Object
Each account lists another account as their recovery account.
938 939 940 941 942 943 944 945 946 947 948 |
# File 'lib/hive/broadcast.rb', line 938 def self.change_recovery_account(, &block) required_fields = %i(account_to_recover) params = [:params] check_required_fields(params, *required_fields) params[:new_recovery_account] ||= '' params[:extensions] ||= [] ops = [[:change_recovery_account, params]] process(.merge(ops: ops), &block) end |
.claim_account(options, &block) ⇒ Object
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/hive/broadcast.rb', line 1231 def self.claim_account(, &block) required_fields = %i(creator fee) params = [:params] check_required_fields(params, *required_fields) params[:fee] = normalize_amount(.merge amount: params[:fee]) params[:extensions] ||= [] ops = [[:claim_account, params]] process(.merge(ops: ops), &block) end |
.claim_reward_balance(options, &block) ⇒ Object
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/hive/broadcast.rb', line 1254 def self.claim_reward_balance(, &block) required_fields = %i(account) params = [:params] check_required_fields(params, *required_fields) params[:reward_hive] = normalize_amount(.merge amount: params[:reward_hive]) params[:reward_hbd] = normalize_amount(.merge amount: params[:reward_hbd]) params[:reward_vests] = normalize_amount(.merge amount: params[:reward_vests]) ops = [[:claim_reward_balance, params]] process(.merge(ops: ops), &block) end |
.comment(options, &block) ⇒ Object
Creates a post/comment. This method simplifies content creation by combining ‘comment` and `comment_options` into one transaction.
= {
wif: wif,
params: {
author: ,
title: 'This is my fancy post title.',
body: 'This is my fancy post body.',
metadata: {
tags: %w(these are my fancy tags)
}
}
}
Hive::Broadcast.comment()
= {
wif: wif,
params: {
author: ,
title: 'This is my fancy post title.',
body: 'This is my fancy post body.',
metadata: {
tags: %w(these are my fancy tags)
},
beneficiaries: [
{account: "david", weight: 500},
{account: "erin", weight: 500},
{account: "faythe", weight: 1000},
{account: "frank", weight: 500}
]
}
}
Hive::Broadcast.comment()
In addition to the above denormalized ‘comment_options` fields, the author can also vote for the content in the same transaction by setting `author_vote_weight`:
= {
wif: wif,
params: {
author: ,
title: 'This is my fancy post title.',
body: 'This is my fancy post body.',
metadata: {
tags: %w(these are my fancy tags)
},
author_vote_weight: 10000
}
}
Hive::Broadcast.comment()
147 148 149 150 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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/hive/broadcast.rb', line 147 def self.comment(, &block) required_fields = %i(author body permlink parent_permlink) params = [:params] if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params[:metadata] || {} ||= (JSON[params[:json_metadata]] || nil) || {} ['app'] ||= Hive::AGENT_ID = ['tags'] || [] params[:parent_permlink] ||= .first if !!params[:title] params[:permlink] ||= params[:title].downcase.gsub(/[^a-z0-9\-]+/, '-') end check_required_fields(params, *required_fields) ops = [[:comment, { parent_author: params[:parent_author] || '', parent_permlink: params[:parent_permlink], author: params[:author], permlink: params[:permlink], title: params[:title] || '', body: params[:body], json_metadata: .to_json }]] max_accepted_payout = if params.keys.include? :max_accepted_payout normalize_amount(.merge amount: params[:max_accepted_payout]) else normalize_amount(.merge amount: DEFAULT_MAX_ACCEPTED_PAYOUT) end allow_votes = if params.keys.include? :allow_votes !!params[:allow_votes] else true end allow_curation_rewards = if params.keys.include? :allow_curation_rewards !!params[:allow_curation_rewards] else true end = { author: params[:author], permlink: params[:permlink], max_accepted_payout: max_accepted_payout, percent_hbd: params[:percent_hbd] || 10000, # allow_replies: allow_replies, allow_votes: allow_votes, allow_curation_rewards: allow_curation_rewards, extensions: [] } if !!params[:beneficiaries] [:extensions] << [ [:extensions].size, normalize_beneficiaries(.merge(beneficiaries: params[:beneficiaries])) ] end ops << [:comment_options, ] if !!params[:author_vote_weight] = { voter: params[:author], author: params[:author], permlink: params[:permlink], weight: params[:author_vote_weight] } ops << [:vote, ] end process(.merge(ops: ops), &block) end |
.convert(options, &block) ⇒ Object
This operation instructs the blockchain to start a conversion between HIVE and HBD, the funds are deposited after 3.5 days.
441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/hive/broadcast.rb', line 441 def self.convert(, &block) required_fields = %i(owner requestid amount) params = [:params] check_required_fields(params, *required_fields) params[:amount] = normalize_amount(.merge amount: params[:amount]) ops = [[:convert, params]] process(.merge(ops: ops), &block) end |
.create_claimed_account(options, &block) ⇒ Object
Create a claimed account.
= {
wif: wif,
params: {
creator: creator_account_name,
new_account_name: new_account_name,
owner: {
weight_threshold: 1,
account_auths: [],
key_auths: [[owner_public_key, 1]],
},
active: {
weight_threshold: 1,
account_auths: [],
key_auths: [[active_public_key, 1]],
},
posting: {
weight_threshold: 1,
account_auths: [],
key_auths: [[posting_public_key, 1]],
},
memo_key: memo_public_key,
json_metadata: '{}'
}
}
Hive::Broadcast.create_claimed_account()
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/hive/broadcast.rb', line 559 def self.create_claimed_account(, &block) required_fields = %i(creator new_account_name owner active posting memo_key json_metadata) params = [:params] if !!params[:metadata] && !!params[:json_metadata] raise Hive::ArgumentError, 'Assign either metadata or json_metadata, not both.' end = params.delete(:metadata) || {} ||= (JSON[params[:json_metadata]] || nil) || {} params[:json_metadata] = .to_json check_required_fields(params, *required_fields) params[:extensions] ||= [] ops = [[:create_claimed_account, params]] process(.merge(ops: ops), &block) end |
.create_proposal(options, &block) ⇒ Object
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
# File 'lib/hive/broadcast.rb', line 1308 def self.create_proposal(, &block) required_fields = %i(creator start_date end_date daily_pay subject permlink) params = [:params] check_required_fields(params, *required_fields) params[:start_date] = Time.parse(params[:start_date].to_s) params[:start_date] = params[:start_date].strftime('%Y-%m-%dT%H:%M:%S') params[:end_date] = Time.parse(params[:end_date].to_s) params[:end_date] = params[:end_date].strftime('%Y-%m-%dT%H:%M:%S') params[:daily_pay] = normalize_amount(.merge amount: params[:daily_pay]) ops = [[:create_proposal, params]] process(.merge(ops: ops), &block) end |
.custom(options, &block) ⇒ Object
Provides a generic way to add higher level protocols on top of witness consensus.
799 800 801 802 803 804 805 806 807 |
# File 'lib/hive/broadcast.rb', line 799 def self.custom(, &block) required_fields = %i(required_auths id data) params = [:params] check_required_fields(params, *required_fields) ops = [[:custom, params]] process(.merge(ops: ops), &block) end |
.custom_binary(options, &block) ⇒ Object
The semmantics for this operation are the same as the custom_json operation, but with a binary payload.
819 820 821 822 823 824 825 826 827 |
# File 'lib/hive/broadcast.rb', line 819 def self.custom_binary(, &block) required_fields = %i(id data) params = [:params] check_required_fields(params, *required_fields) ops = [[:custom_binary, params]] process(.merge(ops: ops), &block) end |
.custom_json(options, &block) ⇒ Object
Serves the same purpose as custom but also supports required posting authorities.
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/hive/broadcast.rb', line 842 def self.custom_json(, &block) required_fields = %i(id) params = [:params] if !!params[:data] && !!params[:json] raise Hive::ArgumentError, 'Assign either data or json, not both.' end data = params.delete(:data) || {} data ||= (JSON[params[:json]] || nil) || {} params[:json] = data.to_json check_required_fields(params, *required_fields) params[:required_auths] ||= [] params[:required_posting_auths] ||= [] ops = [[:custom_json, params]] process(.merge(ops: ops), &block) end |
.decline_voting_rights(options, &block) ⇒ Object
An account can chose to decline their voting rights after a 30 day delay. This includes voting on content and witnesses. **The voting rights cannot be acquired again once they have been declined.** This is only to formalize a smart contract between certain accounts and the community that currently only exists as a social contract.
1153 1154 1155 1156 1157 1158 1159 1160 1161 |
# File 'lib/hive/broadcast.rb', line 1153 def self.decline_voting_rights(, &block) required_fields = %i(account decline) params = [:params] check_required_fields(params, *required_fields) ops = [[:decline_voting_rights, params]] process(.merge(ops: ops), &block) end |
.delegate_vesting_shares(options, &block) ⇒ Object
Delegate vesting shares from one account to the other.
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 |
# File 'lib/hive/broadcast.rb', line 1173 def self.delegate_vesting_shares(, &block) required_fields = %i(delegator delegatee vesting_shares) params = [:params] check_required_fields(params, *required_fields) params[:vesting_shares] = normalize_amount(.merge amount: params[:vesting_shares]) ops = [[:delegate_vesting_shares, params]] process(.merge(ops: ops), &block) end |
.delete_comment(options, &block) ⇒ Object
242 243 244 245 246 247 248 249 250 |
# File 'lib/hive/broadcast.rb', line 242 def self.delete_comment(, &block) required_fields = %i(author permlink) params = [:params] check_required_fields(params, *required_fields) ops = [[:delete_comment, params]] process(.merge(ops: ops), &block) end |
.escrow_approve(options, &block) ⇒ Object
The agent and to accounts must approve an escrow transaction for it to be valid on the blockchain.
1066 1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/hive/broadcast.rb', line 1066 def self.escrow_approve(, &block) required_fields = %i(from to agent who escrow_id approve) params = [:params] check_required_fields(params, *required_fields) ops = [[:escrow_approve, params]] process(.merge(ops: ops), &block) end |
.escrow_dispute(options, &block) ⇒ Object
If either the sender or receiver of an escrow payment has an issue, they can raise it for dispute.
1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'lib/hive/broadcast.rb', line 1013 def self.escrow_dispute(, &block) required_fields = %i(from to agent who escrow_id) params = [:params] check_required_fields(params, *required_fields) ops = [[:escrow_dispute, params]] process(.merge(ops: ops), &block) end |
.escrow_release(options, &block) ⇒ Object
This operation can be used by anyone associated with the escrow transfer to release funds if they have permission.
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 |
# File 'lib/hive/broadcast.rb', line 1039 def self.escrow_release(, &block) required_fields = %i(from to agent who receiver escrow_id) params = [:params] check_required_fields(params, *required_fields) params[:hbd_amount] = normalize_amount(.merge amount: params[:hbd_amount]) params[:hive_amount] = normalize_amount(.merge amount: params[:hive_amount]) ops = [[:escrow_release, params]] process(.merge(ops: ops), &block) end |
.escrow_transfer(options, &block) ⇒ Object
The purpose of this operation is to enable someone to send money contingently to another individual.
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
# File 'lib/hive/broadcast.rb', line 969 def self.escrow_transfer(, &block) required_fields = %i(from to agent escrow_id fee ratification_deadline) params = [:params] if !!params[:meta] && !!params[:json_meta] raise Hive::ArgumentError, 'Assign either meta or json_meta, not both.' end = params.delete(:meta) || {} ||= (JSON[params[:json_meta]] || nil) || {} params[:json_meta] = .to_json check_required_fields(params, *required_fields) params[:hbd_amount] = normalize_amount(.merge amount: params[:hbd_amount]) params[:hive_amount] = normalize_amount(.merge amount: params[:hive_amount]) params[:fee] = normalize_amount(.merge amount: params[:fee]) params[:ratification_deadline] = Time.parse(params[:ratification_deadline].to_s) params[:ratification_deadline] = params[:ratification_deadline].strftime('%Y-%m-%dT%H:%M:%S') if !!params[:escrow_expiration] params[:escrow_expiration] = Time.parse(params[:escrow_expiration].to_s) params[:escrow_expiration] = params[:escrow_expiration].strftime('%Y-%m-%dT%H:%M:%S') end ops = [[:escrow_transfer, params]] process(.merge(ops: ops), &block) end |
.feed_publish(options, &block) ⇒ Object
Feeds can only be published by the top N witnesses which are included in every round and are used to define the exchange rate between hive and the dollar.
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/hive/broadcast.rb', line 414 def self.feed_publish(, &block) required_fields = %i(publisher exchange_rate) params = [:params] check_required_fields(params, *required_fields) exchange_rate = params[:exchange_rate] rescue nil || {} base = exchange_rate[:base] quote = exchange_rate[:quote] params[:exchange_rate][:base] = normalize_amount(.merge amount: base) params[:exchange_rate][:quote] = normalize_amount(.merge amount: quote) ops = [[:feed_publish, params]] process(.merge(ops: ops), &block) end |
.limit_order_cancel(options, &block) ⇒ Object
Cancels an order and returns the balance to owner.
393 394 395 396 397 398 399 400 401 |
# File 'lib/hive/broadcast.rb', line 393 def self.limit_order_cancel(, &block) required_fields = %i(owner orderid) params = [:params] check_required_fields(params, *required_fields) ops = [[:limit_order_cancel, params]] process(.merge(ops: ops), &block) end |
.limit_order_create(options, &block) ⇒ Object
This operation creates a limit order and matches it against existing open orders.
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/hive/broadcast.rb', line 365 def self.limit_order_create(, &block) required_fields = %i(owner orderid amount_to_sell min_to_receive fill_or_kill) params = [:params] check_required_fields(params, *required_fields) params[:amount_to_sell] = normalize_amount(.merge amount: params[:amount_to_sell]) params[:min_to_receive] = normalize_amount(.merge amount: params[:min_to_receive]) if !!params[:expiration] params[:expiration] = Time.parse(params[:expiration].to_s) params[:expiration] = params[:expiration].strftime('%Y-%m-%dT%H:%M:%S') end ops = [[:limit_order_create, params]] process(.merge(ops: ops), &block) end |
.process(options, &block) ⇒ Object
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 |
# File 'lib/hive/broadcast.rb', line 1365 def self.process(, &block) ops = [:ops] tx = TransactionBuilder.new() response = nil loop do; begin tx.operations = ops trx = tx.transaction response = if !![:pretend] if !![:app_base] database_api().(trx: trx) else database_api().(trx) end else if !![:app_base] network_broadcast_api().broadcast_transaction(trx: trx) else network_broadcast_api().broadcast_transaction_synchronous(trx) end end break rescue => e if can_retry? e tx.expiration = nil redo end raise e end; end if !!block block.call response.result else return response.result end end |
.recover_account(options, &block) ⇒ Object
917 918 919 920 921 922 923 924 925 926 |
# File 'lib/hive/broadcast.rb', line 917 def self.recover_account(, &block) required_fields = %i(account_to_recover new_owner_authority recent_owner_authority) params = [:params] check_required_fields(params, *required_fields) params[:extensions] ||= [] ops = [[:recover_account, params]] process(.merge(ops: ops), &block) end |
.remove_proposal(options, &block) ⇒ Object
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 |
# File 'lib/hive/broadcast.rb', line 1351 def self.remove_proposal(, &block) required_fields = %i(proposal_owner proposal_ids) params = [:params] check_required_fields(params, *required_fields) ops = [[:remove_proposal, params]] process(.merge(ops: ops), &block) end |
.request_account_recovery(options, &block) ⇒ Object
All account recovery requests come from a listed recovery account.
897 898 899 900 901 902 903 904 905 906 |
# File 'lib/hive/broadcast.rb', line 897 def self.request_account_recovery(, &block) required_fields = %i(recovery_account account_to_recover new_owner_authority) params = [:params] check_required_fields(params, *required_fields) params[:extensions] ||= [] ops = [[:request_account_recovery, params]] process(.merge(ops: ops), &block) end |
.set_withdraw_vesting_route(options, &block) ⇒ Object
Allows an account to setup a vesting withdraw but with the additional request for the funds to be transferred directly to another account’s balance rather than the withdrawing account.
876 877 878 879 880 881 882 883 884 |
# File 'lib/hive/broadcast.rb', line 876 def self.set_withdraw_vesting_route(, &block) required_fields = %i(from_account to_account percent auto_vest) params = [:params] check_required_fields(params, *required_fields) ops = [[:set_withdraw_vesting_route, params]] process(.merge(ops: ops), &block) end |
.transfer(options, &block) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/hive/broadcast.rb', line 277 def self.transfer(, &block) required_fields = %i(from to amount memo) params = [:params] check_required_fields(params, *required_fields) params[:amount] = normalize_amount(.merge amount: params[:amount]) ops = [[:transfer, params]] process(.merge(ops: ops), &block) end |
.transfer_from_savings(options, &block) ⇒ Object
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 |
# File 'lib/hive/broadcast.rb', line 1110 def self.transfer_from_savings(, &block) required_fields = %i(from request_id to amount) params = [:params] check_required_fields(params, *required_fields) params[:memo] ||= '' params[:amount] = normalize_amount(.merge amount: params[:amount]) ops = [[:transfer_from_savings, params]] process(.merge(ops: ops), &block) end |
.transfer_to_savings(options, &block) ⇒ Object
For time locked savings accounts.
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 |
# File 'lib/hive/broadcast.rb', line 1087 def self.transfer_to_savings(, &block) required_fields = %i(from to amount) params = [:params] check_required_fields(params, *required_fields) params[:memo] ||= '' params[:amount] = normalize_amount(.merge amount: params[:amount]) ops = [[:transfer_to_savings, params]] process(.merge(ops: ops), &block) end |
.transfer_to_vesting(options, &block) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/hive/broadcast.rb', line 313 def self.transfer_to_vesting(, &block) required_fields = %i(from to amount) params = [:params] check_required_fields(params, *required_fields) params[:amount] = normalize_amount(.merge amount: params[:amount]) ops = [[:transfer_to_vesting, params]] process(.merge(ops: ops), &block) end |
.update_proposal_votes(options, &block) ⇒ Object
1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 |
# File 'lib/hive/broadcast.rb', line 1333 def self.update_proposal_votes(, &block) required_fields = %i(voter proposal_ids approve) params = [:params] check_required_fields(params, *required_fields) ops = [[:update_proposal_votes, params]] process(.merge(ops: ops), &block) end |
.vote(options, &block) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/hive/broadcast.rb', line 63 def self.vote(, &block) required_fields = %i(voter author permlink weight) params = [:params] check_required_fields(params, *required_fields) ops = [[:vote, params]] process(.merge(ops: ops), &block) end |
.withdraw_vesting(options, &block) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/hive/broadcast.rb', line 339 def self.withdraw_vesting(, &block) required_fields = %i(account vesting_shares) params = [:params] check_required_fields(params, *required_fields) params[:vesting_shares] = normalize_amount(.merge amount: params[:vesting_shares]) ops = [[:withdraw_vesting, params]] process(.merge(ops: ops), &block) end |
.witness_set_properties(options, &block) ⇒ Object
Extensible replacement for #witness_update that supports additional properties added since HF20 and beyond.
= {
wif: wif,
params: {
owner: witness_account_name,
props: {
account_creation_fee: '0.000 HIVE',
maximum_block_size: 131072,
hbd_interest_rate: 1000,
account_subsidy_budget: 50000,
account_subsidy_decay: 330782,
hbd_exchange_rate: '1.000 HIVE',
url: "https://hive.blog",
new_signing_key: 'STM8LoQjQqJHvotqBo7HjnqmUbFW9oJ2theyqonzUd9DdJ7YYHsvD'
}
}
}
Hive::Broadcast.witness_set_properties()
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 |
# File 'lib/hive/broadcast.rb', line 711 def self.witness_set_properties(, &block) required_fields = %i(owner props) params = [:params] check_required_fields(params, *required_fields) props = params[:props] if !!(account_creation_fee = props[:account_creation_fee] rescue nil) props[:account_creation_fee] = hexlify normalize_amount(.merge amount: account_creation_fee, serialize: true) end if !!(hbd_exchange_rate = props[:hbd_exchange_rate] rescue nil) props[:hbd_exchange_rate][:base] = normalize_amount(.merge amount: hbd_exchange_rate[:base], serialize: true) props[:hbd_exchange_rate][:quote] = normalize_amount(.merge amount: hbd_exchange_rate[:quote], serialize: true) props[:hbd_exchange_rate] = hexlify props[:hbd_exchange_rate].to_json end %i(key new_signing_key).each do |key| begin if !!props[key] && props[key].length == 53 props[key] = hexlify props[key][3..-1] end rescue => e raise Hive::ArgumentError, "Unable to parse #{key}: #{e}" end end if !!(val = props[:url]) props[:url] = hexlify val unless val =~ /^[0-9A-F]+$/i end params[:props] = props.sort_by{|k,v| k} params[:extensions] ||= [] ops = [[:witness_set_properties, params]] process(.merge(ops: ops), &block) end |
.witness_update(options, &block) ⇒ Object
Users who wish to become a witness must pay a fee acceptable to the current witnesses to apply for the position and allow voting to begin.
= {
wif: wif,
params: {
owner: witness_account_name,
url: '',
block_signing_key: 'STM8ZSyzjPm48GmUuMSRufkVYkwYbZzbxeMysAVp7KFQwbTf98TcG',
props: {
account_creation_fee: '0.000 HIVE',
maximum_block_size: 131072,
hbd_interest_rate:1000
},
fee: '0.000 HIVE',
}
}
Hive::Broadcast.witness_update()
667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'lib/hive/broadcast.rb', line 667 def self.witness_update(, &block) required_fields = %i(owner block_signing_key props fee) params = [:params] check_required_fields(params, *required_fields) account_creation_fee = params[:props][:account_creation_fee] rescue nil params[:props][:account_creation_fee] = normalize_amount(.merge amount: account_creation_fee) params[:fee] = normalize_amount(.merge amount: params[:fee]) ops = [[:witness_update, params]] process(.merge(ops: ops), &block) end |