Class: Fabric::ChaincodeResponse
- Inherits:
-
Object
- Object
- Fabric::ChaincodeResponse
- Defined in:
- lib/fabric/chaincode_response.rb
Instance Attribute Summary collapse
-
#proposal ⇒ Object
readonly
Returns the value of attribute proposal.
-
#proposal_responses ⇒ Object
readonly
Returns the value of attribute proposal_responses.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
Instance Method Summary collapse
- #failure_response ⇒ Object
-
#initialize(attrs) ⇒ ChaincodeResponse
constructor
A new instance of ChaincodeResponse.
- #payload ⇒ Object
- #success? ⇒ Boolean
- #success_responses ⇒ Object
- #tx_id ⇒ Object
- #tx_timestamp ⇒ Object
- #tx_unix_timestamp ⇒ Object
- #validate! ⇒ Object
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
#proposal ⇒ Object (readonly)
Returns the value of attribute proposal.
3 4 5 |
# File 'lib/fabric/chaincode_response.rb', line 3 def proposal @proposal end |
#proposal_responses ⇒ Object (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 |
#responses ⇒ Object (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_response ⇒ Object
19 20 21 |
# File 'lib/fabric/chaincode_response.rb', line 19 def failure_response @failure_response ||= responses.find { |response| response.status == 500 } end |
#payload ⇒ Object
35 36 37 |
# File 'lib/fabric/chaincode_response.rb', line 35 def payload success_responses.first&.payload end |
#success? ⇒ Boolean
11 12 13 |
# File 'lib/fabric/chaincode_response.rb', line 11 def success? success_responses.any? end |
#success_responses ⇒ Object
15 16 17 |
# File 'lib/fabric/chaincode_response.rb', line 15 def success_responses @success_responses ||= responses.select { |response| response.status == 200 } end |
#tx_id ⇒ Object
23 24 25 |
# File 'lib/fabric/chaincode_response.rb', line 23 def tx_id proposal.tx_id end |
#tx_timestamp ⇒ Object
27 28 29 |
# File 'lib/fabric/chaincode_response.rb', line 27 def proposal. end |
#tx_unix_timestamp ⇒ Object
31 32 33 |
# File 'lib/fabric/chaincode_response.rb', line 31 def (.seconds * 1000 + .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. end |