Class: BinaryCodec::AccountId
- Inherits:
-
Hash160
- Object
- SerializedType
- ComparableSerializedType
- Hash
- Hash160
- BinaryCodec::AccountId
- Defined in:
- lib/binary-codec/types/account_id.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Class Method Summary collapse
-
.from(value) ⇒ AccountID
Defines how to construct an AccountID.
-
.from_base58(value) ⇒ AccountID
Defines how to build an AccountID from a base58 r-Address.
Instance Method Summary collapse
-
#initialize(bytes = nil) ⇒ AccountId
constructor
A new instance of AccountId.
-
#to_base58 ⇒ String
Defines how to encode AccountID into a base58 address.
-
#to_json ⇒ String
Overload of to_json.
Methods inherited from Hash
#compare_to, from_parser, #nibblet
Methods inherited from ComparableSerializedType
#compare_to, #eq, #gt, #gte, #lt, #lte
Methods inherited from SerializedType
from_bytes, from_hex, from_json, from_parser, get_type_by_name, #to_byte_sink, #to_bytes, #to_hex, #to_s
Constructor Details
#initialize(bytes = nil) ⇒ AccountId
Returns a new instance of AccountId.
14 15 16 |
# File 'lib/binary-codec/types/account_id.rb', line 14 def initialize(bytes = nil) super(bytes || Array.new(20, 0)) end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
10 11 12 |
# File 'lib/binary-codec/types/account_id.rb', line 10 def bytes @bytes end |
Class Method Details
.from(value) ⇒ AccountID
Defines how to construct an AccountID
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/binary-codec/types/account_id.rb', line 26 def self.from(value) if value.is_a?(AccountId) return value end if value.is_a?(String) return AccountId.new if value.empty? if valid_hex?(value) return AccountId.new(hex_to_bytes(value)) else return from_base58(value) end end raise 'Cannot construct AccountID from the value provided' end |
.from_base58(value) ⇒ AccountID
Defines how to build an AccountID from a base58 r-Address
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/binary-codec/types/account_id.rb', line 48 def self.from_base58(value) if @address_codec.valid_x_address?(value) classic = @address_codec.x_address_to_classic_address(value) if classic[:tag] != false raise 'Only allowed to have tag on Account or Destination' end value = classic[:classic_address] end AccountId.new(@address_codec.decode_account_id(value)) end |
Instance Method Details
#to_base58 ⇒ String
Defines how to encode AccountID into a base58 address
72 73 74 75 |
# File 'lib/binary-codec/types/account_id.rb', line 72 def to_base58 address_codec = AddressCodec::AddressCodec.new address_codec.encode_account_id(@bytes) end |
#to_json ⇒ String
Overload of to_json
65 66 67 |
# File 'lib/binary-codec/types/account_id.rb', line 65 def to_json to_base58 end |