Class: Scale::Types::MetadataV3
- Inherits:
-
Object
- Object
- Scale::Types::MetadataV3
- Includes:
- Base
- Defined in:
- lib/metadata/metadata_v3.rb
Instance Attribute Summary collapse
-
#call_index ⇒ Object
Returns the value of attribute call_index.
-
#event_index ⇒ Object
Returns the value of attribute event_index.
Attributes included from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ MetadataV3
constructor
A new instance of MetadataV3.
Methods included from Base
Constructor Details
#initialize(value) ⇒ MetadataV3
Returns a new instance of MetadataV3.
7 8 9 10 11 |
# File 'lib/metadata/metadata_v3.rb', line 7 def initialize(value) @call_index = {} @event_index = {} super(value) end |
Instance Attribute Details
#call_index ⇒ Object
Returns the value of attribute call_index.
5 6 7 |
# File 'lib/metadata/metadata_v3.rb', line 5 def call_index @call_index end |
#event_index ⇒ Object
Returns the value of attribute event_index.
5 6 7 |
# File 'lib/metadata/metadata_v3.rb', line 5 def event_index @event_index end |
Class Method Details
.decode(scale_bytes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/metadata/metadata_v3.rb', line 13 def self.decode(scale_bytes) modules = Scale::Types.get("Vec<MetadataModule>").decode(scale_bytes).value value = { magicNumber: 1_635_018_093, metadata: { version: 3, modules: modules.map(&:value) } } result = MetadataV3.new(value) call_module_index = 0 event_module_index = 0 modules.map(&:value).each do |m| if m[:calls] m[:calls].each_with_index do |call, index| call[:lookup] = "%02x%02x" % [call_module_index, index] result.call_index[call[:lookup]] = [m, call] end call_module_index += 1 end if m[:events] m[:events].each_with_index do |event, index| event[:lookup] = "%02x%02x" % [event_module_index, index] result.event_index[event[:lookup]] = [m, event] end event_module_index += 1 end end result end |