Class: IOTA::Models::Transfer

Inherits:
Base
  • Object
show all
Defined in:
lib/iota/models/transfer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Transfer

Returns a new instance of Transfer.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/iota/models/transfer.rb', line 6

def initialize(options)
  @utils = IOTA::Utils::Utils.new

  options = symbolize_keys(options)
  @address = options[:address] || nil
  if @address.nil?
    raise StandardError, "address not provided for transfer"
  end

  if @address.length == 90 && !@utils.isValidChecksum(@address)
    raise StandardError, "Invalid checksum: #{thisTransfer[:address]}"
  end

  @address = @utils.noChecksum(@address)

  @message = options[:message] || ''
  @obsoleteTag = options[:tag] || options[:obsoleteTag] || ''
  @value = options[:value]
  @hmacKey = options[:hmacKey] || nil

  if @hmacKey
    @message = ('9'*244) + @message
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



4
5
6
# File 'lib/iota/models/transfer.rb', line 4

def address
  @address
end

#hmacKeyObject

Returns the value of attribute hmacKey.



4
5
6
# File 'lib/iota/models/transfer.rb', line 4

def hmacKey
  @hmacKey
end

#messageObject

Returns the value of attribute message.



4
5
6
# File 'lib/iota/models/transfer.rb', line 4

def message
  @message
end

#obsoleteTagObject

Returns the value of attribute obsoleteTag.



4
5
6
# File 'lib/iota/models/transfer.rb', line 4

def obsoleteTag
  @obsoleteTag
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/iota/models/transfer.rb', line 4

def value
  @value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/iota/models/transfer.rb', line 31

def valid?
  keysToValidate = [
    { key: 'address', validator: :isAddress, args: nil },
    { key: 'value', validator: :isValue, args: nil },
    { key: 'message', validator: :isTrytes, args: nil },
    { key: 'obsoleteTag', validator: :isTrytes, args: '0,27' }
  ]

  validator = IOTA::Utils::ObjectValidator.new(keysToValidate)
  validator.valid?(self)
end