Class: Beowulf::Type::AuthorityUpdate

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/beowulf/type/authority_update.rb

Instance Method Summary collapse

Methods included from Utils

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

Constructor Details

#initialize(options = {}) ⇒ AuthorityUpdate

Returns a new instance of AuthorityUpdate.



8
9
10
11
12
13
# File 'lib/beowulf/type/authority_update.rb', line 8

def initialize(options = {})
  # puts 'AuthorityUpdate.initialize.options', options.to_json
  @weight_threshold = options[:weight_threshold] || 1
  @account_auths = options[:account_auths] || []
  @key_auths = options[:key_auths] || []
end

Instance Method Details

#to_bytesObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/beowulf/type/authority_update.rb', line 15

def to_bytes
  bytes = unhexlify("01")
  wt = @weight_threshold.to_i + 0
  bytes << [wt].pack("I")
  #uint8_t
  bytes << pakC(@account_auths.length)
  if @account_auths.length > 0
    @account_auths.each do ||
      bytes << pakStr([0])
      bytes << pakS([1])
    end
  end
  #uint8_t
  bytes << pakC(@key_auths.length)
  if @key_auths.length > 0
    @key_auths.each do |key|
      bytes << pakPubKey(key[0])
      bytes << pakS(key[1])
    end
  end
  bytes
end

#to_json(options = {}) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/beowulf/type/authority_update.rb', line 38

def to_json(options = {})
  JSON.dump ({
      :weight_threshold => @weight_threshold,
      :account_auths => @account_auths,
      :key_auths => @key_auths
  })
end