Class: Fabric::Envelope

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

Overview

Encapsulates an Envelop protobuf message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(envelope) ⇒ Envelope

Creates a new Envelope instance.

Parameters:

  • envelope (Common::Envelope)


16
17
18
# File 'lib/fabric/entities/envelope.rb', line 16

def initialize(envelope)
  @envelope = envelope
end

Instance Attribute Details

#envelopeCommon::Envelope (readonly)

Returns transaction envelope.

Returns:

  • (Common::Envelope)

    transaction envelope



9
10
11
# File 'lib/fabric/entities/envelope.rb', line 9

def envelope
  @envelope
end

Instance Method Details

#channel_headerCommon::ChannelHeader

Returns the deserialized transaction channel header

Envelope => Payload => Header => ChannelHeader

Returns:

  • (Common::ChannelHeader)

    envelop payload header channel header



96
97
98
# File 'lib/fabric/entities/envelope.rb', line 96

def channel_header
  @channel_header ||= Common::ChannelHeader.decode(header.channel_header)
end

#channel_nameString

Grabs the channel_name frmo the depths of the envelope.

Returns:

  • (String)

    channel name



105
106
107
# File 'lib/fabric/entities/envelope.rb', line 105

def channel_name
  channel_header.channel_id
end

#headerCommon::Header

Returns the envelope payload header.

Envelope => Payload => Header

Returns:

  • (Common::Header)

    Envelope Payload Header

Raises:



83
84
85
86
87
# File 'lib/fabric/entities/envelope.rb', line 83

def header
  raise Fabric::Error, 'Missing header' if payload.header.nil?

  @header ||= payload.header
end

#payloadCommon::Payload

Returns the deserialized payload.

Returns:

  • (Common::Payload)

    Envelope payload



72
73
74
# File 'lib/fabric/entities/envelope.rb', line 72

def payload
  @payload ||= Common::Payload.decode(envelope.payload)
end

#payload_bytesString

The protobuffer serialized form of the envelope payload.

Returns:

  • (String)

    serialized payload



34
35
36
# File 'lib/fabric/entities/envelope.rb', line 34

def payload_bytes
  envelope.payload
end

#payload_digestString

The digest of the payload.

Returns:

  • (String)

    payload digest



43
44
45
# File 'lib/fabric/entities/envelope.rb', line 43

def payload_digest
  Fabric.crypto_suite.digest(envelope.payload)
end

#resultPayload

Returns the results from the transaction result payload.

Returns:

  • (Payload)

    transaction result payload



63
64
65
# File 'lib/fabric/entities/envelope.rb', line 63

def result
  @result ||= parse_result_from_payload
end

#signature=(signature) ⇒ void

This method returns an undefined value.

Sets the envelope signature.

Parameters:

  • signature (String)


54
55
56
# File 'lib/fabric/entities/envelope.rb', line 54

def signature=(signature)
  envelope.signature = signature
end

#signed?Boolean

Checks if the envelope has been signed.

Returns:

  • (Boolean)

    true if the envelope has been signed; otherwise false.



25
26
27
# File 'lib/fabric/entities/envelope.rb', line 25

def signed?
  !envelope.signature.empty?
end

#transactionProtos::Transaction

Returns the deserialized transaction

Returns:

  • (Protos::Transaction)

    transaction



114
115
116
# File 'lib/fabric/entities/envelope.rb', line 114

def transaction
  @transaction ||= Protos::Transaction.decode(payload.data)
end