Class: Scale::Types::MetadataV0

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/metadata/metadata_v0.rb

Instance Attribute Summary collapse

Attributes included from Base

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#==, included, #to_human

Constructor Details

#initialize(value) ⇒ MetadataV0

Returns a new instance of MetadataV0.



7
8
9
10
11
# File 'lib/metadata/metadata_v0.rb', line 7

def initialize(value)
  @call_index = {}
  @event_index = {}
  super(value)
end

Instance Attribute Details

#call_indexObject

Returns the value of attribute call_index.



5
6
7
# File 'lib/metadata/metadata_v0.rb', line 5

def call_index
  @call_index
end

#event_indexObject

Returns the value of attribute event_index.



5
6
7
# File 'lib/metadata/metadata_v0.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/metadata/metadata_v0.rb', line 13

def self.decode(scale_bytes)
  value = {
    metadata: {
      version: 0,
      outerEvent: {
        name: Bytes.decode(scale_bytes).value,
        events: []
      },
      modules: [],
      outerDispatch: {
        name: "Call",
        calls: []
      }
    }
  }

  events_modules = Scale::Types.get("Vec<MetadataV0EventModule>").decode(scale_bytes).value.map(&:value)
  modules = Scale::Types.get("Vec<MetadataV0Module>").decode(scale_bytes).value.map(&:value)

  Bytes.decode(scale_bytes).value

  sections = Scale::Types.get("Vec<MetadataV0Section>").decode(scale_bytes).value.map(&:value)

  value[:metadata][:outerEvent][:events] = events_modules
  value[:metadata][:modules] = modules
  value[:metadata][:outerDispatch][:calls] = sections

  result = MetadataV0.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" % [call_module_index, index]
        # result.event_index[event[:lookup]] = [m, event]
      # end
      # event_module_index += 1
    # end
  # end

  result
end