Method: Hive::Broadcast.comment

Defined in:
lib/hive/broadcast.rb

.comment(options, &block) ⇒ Object

Creates a post/comment. This method simplifies content creation by combining ‘comment` and `comment_options` into one transaction.

options = {
  wif: wif,
  params: {
    author: 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(options)

options = {
  wif: wif,
  params: {
    author: 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(options)

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`:

options = {
  wif: wif,
  params: {
    author: 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(options)

Parameters:

  • options (Hash)

    options

Options Hash (options):

  • :wif (String)

    Posting wif

  • :params (Hash)
    • :author (String)

    • :title (String) Title of the content.

    • :body (String) Body of the content.

    • :metadata (Hash) Metadata of the content, becomes ‘json_metadata`.

    • :json_metadata (String) String version of ‘metadata` (use one or the other).

    • :permlink (String) (automatic) Permlink of the content, defaults to formatted title.

    • :parent_permlink (String) (automatic) Parent permlink of the content, defaults to first tag.

    • :parent_author (String) (optional) Parent author of the content (only used if reply).

    • :max_accepted_payout (String) (1000000.000 HBD) Maximum accepted payout, set to ‘0.000 HBD’ to deline payout

    • :percent_hbd (Numeric) (5000) Percent HIVE Dollars is used to set 50/50 or 100% HIVE Power

    • :allow_votes (Numeric) (true) Allow votes for this content.

    • :allow_curation_rewards (Numeric) (true) Allow curation rewards for this content.

    • :beneficiaries (Array<Hash>) Sets the beneficiaries of this content.

    • :author_vote_weight (Number) (optional) Cast a vote by the author in the same transaction.

    • :pretend (Boolean) Just validate, do not broadcast.

See Also:



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(options, &block)
  required_fields = %i(author body permlink parent_permlink)
  params = options[: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 = ['tags'] || []
  params[:parent_permlink] ||= tags.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(options.merge amount: params[:max_accepted_payout])
  else
    normalize_amount(options.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
  
  comment_options = {
    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]
    comment_options[:extensions] << [
      comment_options[:extensions].size,
      normalize_beneficiaries(options.merge(beneficiaries: params[:beneficiaries]))
    ]
  end
  
  ops << [:comment_options, comment_options]
  
  if !!params[:author_vote_weight]
    author_vote = {
      voter: params[:author],
      author: params[:author],
      permlink: params[:permlink],
      weight: params[:author_vote_weight]
    }
    
    ops << [:vote, author_vote]
  end
  
  process(options.merge(ops: ops), &block)
end