class Fabric::Envelope

Encapsulates an Envelop protobuf message

Attributes

envelope[R]

@return [Common::Envelope] transaction envelope

Public Class Methods

new(envelope) click to toggle source

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

channel_header() click to toggle source

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
channel_name() click to toggle source

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
header() click to toggle source

Returns the envelope payload header.

Envelope => Payload => Header

@return [Common::Header] Envelope Payload Header

# File lib/fabric/entities/envelope.rb, line 83
def header
  raise Fabric::Error, 'Missing header' if payload.header.nil?

  @header ||= payload.header
end
payload() click to toggle source

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
payload_bytes() click to toggle source

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
payload_digest() click to toggle source

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
result() click to toggle source

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
signature=(signature) click to toggle source

Sets the envelope signature.

@param [String] signature

@return [void]

# File lib/fabric/entities/envelope.rb, line 54
def signature=(signature)
  envelope.signature = signature
end
signed?() click to toggle source

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
transaction() click to toggle source

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_result_from_payload() click to toggle source

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_result_from_transaction_action(transaction_action) click to toggle source

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