Class: Scale::Types::GenericAddress
- Inherits:
-
Object
- Object
- Scale::Types::GenericAddress
- Includes:
- Base
- Defined in:
- lib/scale/types.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.decode(scale_bytes) ⇒ Object
github.com/paritytech/substrate/wiki/External-Address-Format-(SS58) base58encode ( concat ( <address-type>, <address>, <checksum> ) ) ^^^^^^^^^ the <address> is 32 byte account id or 1, 2, 4, 8 byte account index scale_bytes: account length byte + <address>‘s bytes.
Instance Method Summary collapse
Methods included from Base
#==, included, #initialize, #to_human
Class Method Details
.decode(scale_bytes) ⇒ Object
github.com/paritytech/substrate/wiki/External-Address-Format-(SS58) base58encode ( concat ( <address-type>, <address>, <checksum> ) )
^^^^^^^^^
the <address> is 32 byte account id or 1, 2, 4, 8 byte account index scale_bytes: account length byte + <address>‘s bytes
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/scale/types.rb', line 294 def self.decode(scale_bytes) puts "BEGIN " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true account_length = scale_bytes.get_next_bytes(1).first if account_length == 0xff # 32 bytes address(Public key) account_id = scale_bytes.get_next_bytes(32).bytes_to_hex account_length = [account_length].bytes_to_hex puts " END " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true new({ account_id: account_id, account_length: account_length }) else account_index = if account_length == 0xfc # 2 bytes address(account index) scale_bytes.get_next_bytes(2).bytes_to_hex elsif account_length == 0xfd # 4 bytes address(account index) scale_bytes.get_next_bytes(4).bytes_to_hex elsif account_length == 0xfe # 8 bytes address(account index) scale_bytes.get_next_bytes(8).bytes_to_hex else [account_length].bytes_to_hex end # TODO: add account_idx account_length = [account_length].bytes_to_hex puts " END " + self::TYPE_NAME + ": #{scale_bytes}" if Scale::Types.debug == true new({ account_index: account_index, account_length: account_length }) end end |
Instance Method Details
#encode ⇒ Object
329 330 331 332 333 334 335 |
# File 'lib/scale/types.rb', line 329 def encode if self.value[:account_id] "#{self.value[:account_length][2..]}#{self.value[:account_id][2..]}" else "#{self.value[:account_length][2..]}#{self.value[:account_index][2..]}" end end |