diff --git a/lib/hive/broadcast.rb b/lib/hive/broadcast.rb index 0adcfbfeecfe65bf176e79508c191553f552c233..d9a8af7ea1a8da7a8adb4a2047003278f0dc8f47 100644 --- a/lib/hive/broadcast.rb +++ b/lib/hive/broadcast.rb @@ -713,31 +713,29 @@ module Hive params = options[:params] check_required_fields(params, *required_fields) - if !!(account_creation_fee = params[:props][:account_creation_fee] rescue nil) - params[:props][:account_creation_fee] = normalize_amount(options.merge amount: account_creation_fee, serialize: true) + props = params[:props] + + if !!(account_creation_fee = props[:account_creation_fee] rescue nil) + props[:account_creation_fee] = hexlify normalize_amount(options.merge amount: account_creation_fee, serialize: true) end - if !!(sbd_exchange_rate = params[:props][:sbd_exchange_rate] rescue nil) - params[:props][:sbd_exchange_rate][:base] = normalize_amount(options.merge amount: sbd_exchange_rate[:base], serialize: true) - params[:props][:sbd_exchange_rate][:quote] = normalize_amount(options.merge amount: sbd_exchange_rate[:quote], serialize: true) - params[:props][:sbd_exchange_rate] = params[:props][:sbd_exchange_rate].to_json + if !!(sbd_exchange_rate = props[:sbd_exchange_rate] rescue nil) + props[:sbd_exchange_rate][:base] = normalize_amount(options.merge amount: sbd_exchange_rate[:base], serialize: true) + props[:sbd_exchange_rate][:quote] = normalize_amount(options.merge amount: sbd_exchange_rate[:quote], serialize: true) + props[:sbd_exchange_rate] = hexlify props[:sbd_exchange_rate].to_json end %i(key new_signing_key).each do |key| - if !!params[key] && params[key].size == 53 - params[key] = params[key][3..-1] + if !!props[key] && props[key].length == 53 + props[key] = hexlify props[key][3..-1] end end - %i(account_creation_fee sbd_exchange_rate url new_signing_key).each do |key| - next unless !!params[:props][key] - - val = params[:props][key].to_s - - params[:props][key] = hexlify val unless val =~ /^[0-9A-F]+$/i + if !!(val = props[:url]) + props[:url] = hexlify val unless val =~ /^[0-9A-F]+$/i end - params[:props] = params[:props].to_a + params[:props] = props.sort_by{|k,v| k} params[:extensions] ||= [] ops = [[:witness_set_properties, params]] diff --git a/lib/hive/marshal.rb b/lib/hive/marshal.rb index b130eb0a74fc9d9d411c62817cf6b254cab76e1a..7c32a619ebea091f5eb5ed2ec689dad2dbf40d5b 100644 --- a/lib/hive/marshal.rb +++ b/lib/hive/marshal.rb @@ -159,17 +159,16 @@ module Hive key = string.to_sym properties[key] = case key when :account_creation_fee then Hive::Type::Amount.new(string) - when :account_subsidy_budget then scan(3) - when :account_subsidy_decay, :maximum_block_size then uint32 - when :url then string + # when :account_subsidy_budget then int32 + # when :account_subsidy_decay, :maximum_block_size then uint32 when :sbd_exchange_rate JSON[string].tap do |rate| rate["base"] = Hive::Type::Amount.new(rate["base"]) rate["quote"] = Hive::Type::Amount.new(rate["quote"]) end - when :sbd_interest_rate then uint16 - when :key, :new_signing_key then @prefix + scan(50) - else; raise "Unknown witness property: #{key}" + # when :sbd_interest_rate then uint16 + when :url, :key, :new_signing_key then string + else; warn "Unsupported witness property: #{key}" end end @@ -180,6 +179,10 @@ module Hive unsigned_char == 0 and [] or raise "Found non-empty array." end + def uint64_array + varint.times{ uint64 } + end + def transaction(options = {}) trx = options[:trx] || Transaction.new diff --git a/lib/hive/mixins/serializable.rb b/lib/hive/mixins/serializable.rb index 035314e8c55d9656821649cb1b4fbe73ea1b9afc..31ba0eea6a13f3831438e8ab11378e8dc8e5328c 100644 --- a/lib/hive/mixins/serializable.rb +++ b/lib/hive/mixins/serializable.rb @@ -6,7 +6,7 @@ module Hive KNOWN_TYPES = NUMERIC_TYPES + %i(boolean string raw_bytes point_in_time public_key amount price authority optional_authority comment_options_extensions beneficiaries chain_properties required_auths - witness_properties empty_array lambda) + witness_properties uint64_array empty_array lambda) module ClassMethods def def_attr key_pair diff --git a/test/hive/broadcast_test.rb b/test/hive/broadcast_test.rb index 03c30d5b5123620f6c47e74a74f56f71a22dc6e6..08af1fa0671d2c17012b25c61d7900b3929e6330 100644 --- a/test/hive/broadcast_test.rb +++ b/test/hive/broadcast_test.rb @@ -46,6 +46,8 @@ module Hive [dgpo.current_supply.split(' ').last, dgpo.current_sbd_supply.split(' ').last, dgpo.total_vesting_shares.split(' ').last] end + @force_serialize = true + fail 'Are you nuts?' if OPS.include? :decline_voting_rights end @@ -292,7 +294,7 @@ module Hive {'bob': 1000} ] }, - force_serialize: true # FIXME + force_serialize: @force_serialize } vcr_cassette('broadcast_comment_with_options') do @@ -666,15 +668,15 @@ module Hive props: { account_creation_fee: "0.000 #{@core_symbol}", maximum_block_size: 131072, - sbd_interest_rate: 1000, - account_subsidy_budget: 50000, + # sbd_interest_rate: 1000, + # account_subsidy_budget: 50000, account_subsidy_decay: 330782, sbd_exchange_rate: {base: '1.000 HBD', quote: '1.000 HIVE'}, url: 'https://steemit.com', new_signing_key: 'STM8LoQjQqJHvotqBo7HjnqmUbFW9oJ2theyqonzUd9DdJ7YYHsvD' } }, - force_serialize: true # FIXME + force_serialize: @force_serialize } vcr_cassette('broadcast_witness_set_properties') do @@ -684,6 +686,43 @@ module Hive end end + def test_witness_set_properties_string_props + options = { + params: { + owner: @account_name, + props: { + account_creation_fee: "0.000 #{@core_symbol}", + sbd_exchange_rate: {base: '1.000 HBD', quote: '1.000 HIVE'}, + url: 'https://steemit.com', + new_signing_key: 'STM8LoQjQqJHvotqBo7HjnqmUbFW9oJ2theyqonzUd9DdJ7YYHsvD' + } + }, + force_serialize: @force_serialize + } + + vcr_cassette('broadcast_witness_set_properties_string_props') do + assert_raises MissingOtherAuthorityError do + Broadcast.witness_set_properties(@broadcast_options.merge(options)) + end + end + end + + def test_witness_set_properties_props_nil + options = { + params: { + owner: @account_name, + props: nil, + }, + force_serialize: @force_serialize + } + + vcr_cassette('broadcast_witness_set_properties_props_nil') do + assert_raises Hive::ArgumentError do + Broadcast.witness_set_properties(@broadcast_options.merge(options)) + end + end + end + def test_account_witness_vote options = { params: {