Method: Hive::Broadcast.witness_set_properties

Defined in:
lib/hive/broadcast.rb

.witness_set_properties(options, &block) ⇒ Object

Extensible replacement for #witness_update that supports additional properties added since HF20 and beyond.

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

Parameters:

  • options (Hash)

    options

Options Hash (options):

  • :wif (String)

    Active wif

  • :params (Hash)
    • :owner (String)

    • :props (String)

  • :pretend (Boolean)

    Just validate, do not broadcast.

See Also:


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(options, &block)
  required_fields = %i(owner props)
  params = options[:params]
  check_required_fields(params, *required_fields)
  
  props = params[:props]
  
  if !!( = props[:account_creation_fee] rescue nil)
    props[:account_creation_fee] = hexlify normalize_amount(options.merge amount: , serialize: true)
  end
  
  if !!(hbd_exchange_rate = props[:hbd_exchange_rate] rescue nil)
    props[:hbd_exchange_rate][:base] = normalize_amount(options.merge amount: hbd_exchange_rate[:base], serialize: true)
    props[:hbd_exchange_rate][:quote] = normalize_amount(options.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(options.merge(ops: ops), &block)
end