Class: EthereumContractABI::ContractInterface::AbiTypes::Bytes

Inherits:
BaseType
  • Object
show all
Defined in:
lib/ethereum-contract-abi/contract/abi_types/bytes.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseType

#decode_value, #is_type_equal

Constructor Details

#initialize(num_bytes = nil) ⇒ Bytes

Returns a new instance of Bytes.



10
11
12
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 10

def initialize(num_bytes = nil)
  @num_bytes = num_bytes
end

Class Method Details

.from_string(string_type) ⇒ Object



34
35
36
37
38
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 34

def self.from_string(string_type)
  /(?<is_bytes>bytes)(?<bytes>\d+)?/ =~ string_type
  return nil unless is_bytes
  bytes ? self.new(bytes.to_i) : self.new
end

Instance Method Details

#bytesizeObject



18
19
20
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 18

def bytesize
  @num_bytes.nil? ? nil : (@num_bytes.to_f/32.0).ceil
end

#encode_value(bytes) ⇒ Object



30
31
32
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 30

def encode_value(bytes)
  BytesEncoder.encode(bytes, @num_bytes)
end

#is_dynamicObject



14
15
16
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 14

def is_dynamic
  @num_bytes.nil?
end

#to_sObject



22
23
24
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 22

def to_s
  "bytes#{@num_bytes}"
end

#valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ethereum-contract-abi/contract/abi_types/bytes.rb', line 26

def valid_value?(value)
  true
end