Class: Radiator::Type::Beneficiaries

Inherits:
Serializer show all
Defined in:
lib/radiator/type/beneficiaries.rb

Instance Method Summary collapse

Methods included from Utils

#debug, #error, #extract_signatures, #hexlify, #pakArr, #pakC, #pakHash, #pakI, #pakL!, #pakS, #pakStr, #pakc, #paks, #send_log, #unhexlify, #varint, #warning

Constructor Details

#initialize(value) ⇒ Beneficiaries

Returns a new instance of Beneficiaries.



5
6
7
# File 'lib/radiator/type/beneficiaries.rb', line 5

def initialize(value)
  super(:beneficiaries, value)
end

Instance Method Details

#to_bytesObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/radiator/type/beneficiaries.rb', line 9

def to_bytes
	#set sz 1,  op type 0, see
	#https://github.com/steemit/steem-js/blob/733332d09582e95c0ea868a6ac5b6ee8a1f115ee/src/auth/serializer/src/operations.js#L355
	varint(1) + varint(0) + varint(@value.size) + @value.map do |b|
	  case b
	  when ::Array then pakStr(b.first.to_s) + pakS(b.last)
	  else; pakStr(b.keys.first.to_s) + pakS(b.values.first)
    end
	end.join
end

#to_hObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/radiator/type/beneficiaries.rb', line 20

def to_h
  v = @value.map do |b|
    case b
    when ::Array then {account: b.first, weight: b.last}
    else; {account: b.keys.first, weight: b.values.first}
    end
  end
  
  {@key => v}
end

#to_sObject



31
32
33
# File 'lib/radiator/type/beneficiaries.rb', line 31

def to_s
  to_h.to_json
end