Class: Lisk::Delegate

Inherits:
Object
  • Object
show all
Defined in:
lib/lisk/delegate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, delegate_name) ⇒ Delegate

Returns a new instance of Delegate.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lisk/delegate.rb', line 13

def initialize api, delegate_name
  @api = api
  @delegate_name = delegate_name
  delegate = @api.delegates_get_by_name delegate_name
  if delegate.nil?
    @registered = false
  else
    @registered = true
    @address = delegate["address"]
    @public_key = delegate["publicKey"]
  end
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



7
8
9
# File 'lib/lisk/delegate.rb', line 7

def address
  @address
end

#apiObject

Returns the value of attribute api.



5
6
7
# File 'lib/lisk/delegate.rb', line 5

def api
  @api
end

#delegate_nameObject

Returns the value of attribute delegate_name.



6
7
8
# File 'lib/lisk/delegate.rb', line 6

def delegate_name
  @delegate_name
end

#public_keyObject

Returns the value of attribute public_key.



8
9
10
# File 'lib/lisk/delegate.rb', line 8

def public_key
  @public_key
end

#registeredObject

Returns the value of attribute registered.



11
12
13
# File 'lib/lisk/delegate.rb', line 11

def registered
  @registered
end

#secretObject

Returns the value of attribute secret.



9
10
11
# File 'lib/lisk/delegate.rb', line 9

def secret
  @secret
end

#secret_secondaryObject

Returns the value of attribute secret_secondary.



10
11
12
# File 'lib/lisk/delegate.rb', line 10

def secret_secondary
  @secret_secondary
end

Instance Method Details

#is_registered?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/lisk/delegate.rb', line 26

def is_registered?
  return registered
end

#registerObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lisk/delegate.rb', line 35

def register
  if not self.is_registered?
    delegate = {}
    delegate[:username] = @delegate_name
    if not @secret_secondary.nil?
      delegate[:secondSecret] = @secret_secondary
    end
    if not @secret.nil?
      delegate[:secret] = @secret
      registration = api.delegates_put delegate
      return registration
    else
      return false
    end
  else
    return false
  end
end

#set_secrets(secret, second_secret = nil) ⇒ Object



30
31
32
33
# File 'lib/lisk/delegate.rb', line 30

def set_secrets secret, second_secret = nil
  @secret = secret
  @secret_secondary = second_secret
end