Class: Ciri::Types::Address
- Inherits:
-
Object
- Object
- Ciri::Types::Address
- Includes:
- Errors
- Defined in:
- lib/ciri/types/address.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(address) ⇒ Address
constructor
A new instance of Address.
- #to_hex ⇒ Object
- #to_s ⇒ Object (also: #to_str)
- #validate ⇒ Object
Constructor Details
#initialize(address) ⇒ Address
Returns a new instance of Address.
39 40 41 |
# File 'lib/ciri/types/address.rb', line 39 def initialize(address) @address = address.to_s end |
Class Method Details
.rlp_decode(data) ⇒ Object
30 31 32 33 34 |
# File 'lib/ciri/types/address.rb', line 30 def rlp_decode(data) address = self.new(RLP.decode(data)) address.validate address end |
.rlp_encode(address) ⇒ Object
26 27 28 |
# File 'lib/ciri/types/address.rb', line 26 def rlp_encode(address) RLP.encode(address.to_s) end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 |
# File 'lib/ciri/types/address.rb', line 43 def ==(other) self.class == other.class && to_s == other.to_s end |
#empty? ⇒ Boolean
57 58 59 |
# File 'lib/ciri/types/address.rb', line 57 def empty? @address.empty? end |
#to_hex ⇒ Object
53 54 55 |
# File 'lib/ciri/types/address.rb', line 53 def to_hex Utils.to_hex to_s end |
#to_s ⇒ Object Also known as: to_str
47 48 49 |
# File 'lib/ciri/types/address.rb', line 47 def to_s @address end |
#validate ⇒ Object
61 62 63 64 65 |
# File 'lib/ciri/types/address.rb', line 61 def validate # empty address is valid return if empty? raise InvalidError.new("address must be 20 size, got #{@address.size}") unless @address.size == 20 end |