Class: Scale::Types::MetadataModuleStorage

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

Instance Attribute Summary

Attributes included from Base

#value

Class Method Summary collapse

Methods included from Base

#==, included, #initialize, #to_human

Class Method Details

.decode(scale_bytes) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/metadata/metadata.rb', line 93

def self.decode(scale_bytes)
  name = String.decode(scale_bytes).value
  enum = {
    "type" => "enum",
    "value_list" => ["Optional", "Default"]
  }
  modifier = Scale::Types.get(enum).decode(scale_bytes).value
  result = {
    name: name,
    modifier: modifier
  }

  is_key_value = Bool.decode(scale_bytes).value
  result[:type] = if is_key_value
                    {
                      Map: {
                        key: String.decode(scale_bytes).value,
                        value: String.decode(scale_bytes).value,
                        linked: Bool.decode(scale_bytes).value
                      }
                    }
                  else
                    {
                      Plain: String.decode(scale_bytes).value
                    }
                  end

  result[:fallback] = Hex.decode(scale_bytes).value
  result[:documentation] = Scale::Types.get("Vec<String>").decode(scale_bytes).value.map(&:value)

  MetadataModuleStorage.new(result)
end