Class: Dropzone::Profile

Inherits:
RecordBase show all
Includes:
StateAccumulator
Defined in:
lib/dropzone/profile.rb

Direct Known Subclasses

BuyerProfile, SellerProfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StateAccumulator

#blockchain, included, #messages

Methods inherited from RecordBase

#blockchain, #errors, #valid?

Constructor Details

#initialize(addr) ⇒ Profile

Returns a new instance of Profile.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/dropzone/profile.rb', line 7

def initialize(addr)
  @addr = addr

  messages.reverse.each_with_index do |seller, i|
    # There is a bit of extra logic if the seller profile was transferred
    # from elsewhere
    if i == 0 && seller.transfer_pkey
      # Load the profile from the prior address and pop it off the stack
      @prior_profile = self.class.new seller.sender_addr

      # It's possible the prior profile was invalid
      break unless @prior_profile.valid?

      # And it's possible the prior profile was deactivated or not
      # transferred to us:
      break unless @prior_profile.transfer_pkey == addr

      attrs_from @prior_profile
    else
      # This prevents a second inbound transfer from happening:
      next if seller.transfer_pkey == addr 

      # In case they transferred away :
      @transfer_pkey = seller.transfer_pkey

      attrs_from seller
    end

    break if @transfer_pkey
  end
end

Instance Attribute Details

#addrObject (readonly)

Returns the value of attribute addr.



5
6
7
# File 'lib/dropzone/profile.rb', line 5

def addr
  @addr
end

#prior_profileObject (readonly)

Returns the value of attribute prior_profile.



5
6
7
# File 'lib/dropzone/profile.rb', line 5

def prior_profile
  @prior_profile
end

#transfer_pkeyObject (readonly)

Returns the value of attribute transfer_pkey.



5
6
7
# File 'lib/dropzone/profile.rb', line 5

def transfer_pkey
  @transfer_pkey
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


40
# File 'lib/dropzone/profile.rb', line 40

def active?; @transfer_pkey.nil? end

#closed?Boolean

Returns:

  • (Boolean)


39
# File 'lib/dropzone/profile.rb', line 39

def closed?; (@transfer_pkey == 0); end

#found?Boolean

Returns:

  • (Boolean)


41
# File 'lib/dropzone/profile.rb', line 41

def found?; messages.length > 0; end