Class: Fabric::ChaincodeResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/fabric/chaincode_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ ChaincodeResponse

Returns a new instance of ChaincodeResponse.



5
6
7
8
9
# File 'lib/fabric/chaincode_response.rb', line 5

def initialize(attrs)
  @proposal = attrs[:proposal]
  @proposal_responses = attrs[:proposal_responses].compact
  @responses = proposal_responses.map(&:response)
end

Instance Attribute Details

#proposalObject (readonly)

Returns the value of attribute proposal.



3
4
5
# File 'lib/fabric/chaincode_response.rb', line 3

def proposal
  @proposal
end

#proposal_responsesObject (readonly)

Returns the value of attribute proposal_responses.



3
4
5
# File 'lib/fabric/chaincode_response.rb', line 3

def proposal_responses
  @proposal_responses
end

#responsesObject (readonly)

Returns the value of attribute responses.



3
4
5
# File 'lib/fabric/chaincode_response.rb', line 3

def responses
  @responses
end

Instance Method Details

#failure_responseObject



19
20
21
# File 'lib/fabric/chaincode_response.rb', line 19

def failure_response
  @failure_response ||= responses.find { |response| response.status == 500 }
end

#payloadObject



35
36
37
# File 'lib/fabric/chaincode_response.rb', line 35

def payload
  success_responses.first&.payload
end

#success?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/fabric/chaincode_response.rb', line 11

def success?
  success_responses.any?
end

#success_responsesObject



15
16
17
# File 'lib/fabric/chaincode_response.rb', line 15

def success_responses
  @success_responses ||= responses.select { |response| response.status == 200 }
end

#tx_idObject



23
24
25
# File 'lib/fabric/chaincode_response.rb', line 23

def tx_id
  proposal.tx_id
end

#tx_timestampObject



27
28
29
# File 'lib/fabric/chaincode_response.rb', line 27

def tx_timestamp
  proposal.tx_timestamp
end

#tx_unix_timestampObject



31
32
33
# File 'lib/fabric/chaincode_response.rb', line 31

def tx_unix_timestamp
  (tx_timestamp.seconds * 1000 + tx_timestamp.nanos / 10**6).to_i
end

#validate!Object



39
40
41
42
43
44
45
# File 'lib/fabric/chaincode_response.rb', line 39

def validate!
  return if success?

  raise NetworkOfflineError if proposal_responses.empty?

  raise ErrorFactory.create failure_response.message
end