class Fabric::Envelope
Encapsulates an Envelop protobuf message
Attributes
@return [Common::Envelope] transaction envelope
Public Class Methods
Creates a new Envelope
instance.
@param [Common::Envelope] envelope
# File lib/fabric/entities/envelope.rb, line 16 def initialize(envelope) @envelope = envelope end
Public Instance Methods
Returns the deserialized transaction channel header
Envelope
=> Payload => Header => ChannelHeader
@return [Common::ChannelHeader] envelop payload header channel header
# File lib/fabric/entities/envelope.rb, line 96 def channel_header @channel_header ||= Common::ChannelHeader.decode(header.channel_header) end
Grabs the channel_name
frmo the depths of the envelope.
@return [String] channel name
# File lib/fabric/entities/envelope.rb, line 105 def channel_name channel_header.channel_id end
Returns the deserialized payload.
@return [Common::Payload] Envelope
payload
# File lib/fabric/entities/envelope.rb, line 72 def payload @payload ||= Common::Payload.decode(envelope.payload) end
The protobuffer serialized form of the envelope payload.
@return [String] serialized payload
# File lib/fabric/entities/envelope.rb, line 34 def payload_bytes envelope.payload end
The digest of the payload.
@return [String] payload digest
# File lib/fabric/entities/envelope.rb, line 43 def payload_digest Fabric.crypto_suite.digest(envelope.payload) end
Returns the results from the transaction result payload.
@return [Payload] transaction result payload
# File lib/fabric/entities/envelope.rb, line 63 def result @result ||= parse_result_from_payload end
Sets the envelope signature.
@param [String] signature
@return [void]
# File lib/fabric/entities/envelope.rb, line 54 def signature=(signature) envelope.signature = signature end
Checks if the envelope has been signed.
@return [Boolean] true if the envelope has been signed; otherwise false.
# File lib/fabric/entities/envelope.rb, line 25 def signed? !envelope.signature.empty? end
Returns the deserialized transaction
@return [Protos::Transaction] transaction
# File lib/fabric/entities/envelope.rb, line 114 def transaction @transaction ||= Protos::Transaction.decode(payload.data) end
Private Instance Methods
Parse the transaction actions from the payload looking for the transaction result payload.
@return [String] result payload @raise [Fabric::Error] if the transaction result payload is not found
# File lib/fabric/entities/envelope.rb, line 126 def parse_result_from_payload errors = [] transaction.actions.each do |action| return parse_result_from_transaction_action(action) rescue Fabric::Error => e errors << e end raise Fabric::Error, "No proposal response found: #{errors.inspect}" end
Parse a single transaction action looking for the transaction result payload.
@param [Protos::TransactionAction] transaction_action
@return [Payload] transaction result payload @raise [Fabric::Error] if the endorsed_action is missing or the chaincode response is missing
# File lib/fabric/entities/envelope.rb, line 145 def parse_result_from_transaction_action(transaction_action) action_payload = Protos::ChaincodeActionPayload.decode(transaction_action.payload) endorsed_action = action_payload.action raise Fabric::Error, 'Missing endorsed action' if endorsed_action.nil? response_payload = Protos::ProposalResponsePayload.decode(endorsed_action.proposal_response_payload) chaincode_action = Protos::ChaincodeAction.decode(response_payload.extension) chaincode_response = chaincode_action.response raise Fabric::Error, 'Missing chaincode response' if chaincode_response.nil? chaincode_response.payload end