Class: Beowulf::Type::Authority
- Inherits:
-
Object
- Object
- Beowulf::Type::Authority
- Includes:
- Utils
- Defined in:
- lib/beowulf/type/authority.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Authority
constructor
A new instance of Authority.
- #to_bytes ⇒ Object
- #to_json(options = {}) ⇒ Object
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 = {}) ⇒ Authority
Returns a new instance of Authority.
8 9 10 11 12 13 |
# File 'lib/beowulf/type/authority.rb', line 8 def initialize( = {}) # puts 'Authority.initialize.options', options.to_json @weight_threshold = [:weight_threshold] || 1 @account_auths = [:account_auths] || [] @key_auths = [:key_auths] || [] end |
Instance Method Details
#to_bytes ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/beowulf/type/authority.rb', line 15 def to_bytes 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 |account| bytes << pakStr(account[0]) bytes << pakS(account[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
37 38 39 40 41 42 43 |
# File 'lib/beowulf/type/authority.rb', line 37 def to_json( = {}) JSON.dump ({ :weight_threshold => @weight_threshold, :account_auths => @account_auths, :key_auths => @key_auths }) end |