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.
45 46 47 |
# File 'lib/ciri/types/address.rb', line 45 def initialize(address) @address = address.to_s end |
Class Method Details
.rlp_decode(data) ⇒ Object
36 37 38 39 40 |
# File 'lib/ciri/types/address.rb', line 36 def rlp_decode(data) address = self.new(RLP.decode(data)) address.validate address end |
.rlp_encode(address) ⇒ Object
32 33 34 |
# File 'lib/ciri/types/address.rb', line 32 def rlp_encode(address) RLP.encode(address.to_s) end |
Instance Method Details
#==(other) ⇒ Object
49 50 51 |
# File 'lib/ciri/types/address.rb', line 49 def ==(other) self.class == other.class && to_s == other.to_s end |
#empty? ⇒ Boolean
63 64 65 |
# File 'lib/ciri/types/address.rb', line 63 def empty? @address.empty? end |
#to_hex ⇒ Object
59 60 61 |
# File 'lib/ciri/types/address.rb', line 59 def to_hex Utils.to_hex to_s end |
#to_s ⇒ Object Also known as: to_str
53 54 55 |
# File 'lib/ciri/types/address.rb', line 53 def to_s @address end |
#validate ⇒ Object
67 68 69 70 71 |
# File 'lib/ciri/types/address.rb', line 67 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 |