Class: Universa::ContractState

Inherits:
Object
  • Object
show all
Defined in:
lib/universa/client.rb

Overview

The state of some contract reported by thee network. It is a convenience wrapper around Universa ItemState structure.

Instance Method Summary collapse

Constructor Details

#initialize(universa_contract_state) ⇒ ContractState

Returns a new instance of ContractState.



222
223
224
# File 'lib/universa/client.rb', line 222

def initialize(universa_contract_state)
  @source = universa_contract_state
end

Instance Method Details

#approved?Boolean

same as #is_approved

Returns:

  • (Boolean)


261
262
263
# File 'lib/universa/client.rb', line 261

def approved?
  is_approved
end

#errorsArray(Hash)

get errors reported by the network

Returns:

  • (Array(Hash))

    possibly empty array of error data



228
229
230
231
232
# File 'lib/universa/client.rb', line 228

def errors
  @_errors ||= @source.errors || []
rescue
  "failed to extract errors: #$!"
end

#errors?Boolean

Returns true if the state contain errors.

Returns:

  • (Boolean)

    true if the state contain errors



235
236
237
# File 'lib/universa/client.rb', line 235

def errors?
  !errors.empty?
end

#inspectObject



274
275
276
# File 'lib/universa/client.rb', line 274

def inspect
  to_s
end

#is_approvedObject

Returns true if the contract state was approved.

Returns:

  • true if the contract state was approved



251
252
253
254
255
256
257
258
# File 'lib/universa/client.rb', line 251

def is_approved
  case state
    when 'APPROVED', 'LOCKED'
      true
    else
      false
  end
end

#is_pendingObject

Check that state us PENDING. Pending state is neither approved nor rejected.

Returns:

  • true if this state is one of the PENDING states



246
247
248
# File 'lib/universa/client.rb', line 246

def is_pending
  state.start_with?('PENDING')
end

#pending?Boolean

same as #is_pending

Returns:

  • (Boolean)


266
267
268
# File 'lib/universa/client.rb', line 266

def pending?
  is_pending
end

#stateObject

Returns ItemState structure reported by the UMI.

Returns:

  • ItemState structure reported by the UMI



240
241
242
# File 'lib/universa/client.rb', line 240

def state
  @source.state
end

#to_sObject



270
271
272
# File 'lib/universa/client.rb', line 270

def to_s
  "<ContractState:#{state}>"
end