Class: Fabric::Channel

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Channel

Returns a new instance of Channel.



6
7
8
9
10
11
12
13
# File 'lib/fabric/channel.rb', line 6

def initialize(opts = {})
  options = Fabric.options.merge opts

  @channel_id = options[:channel_id]
  @logger = FabricLogger.new options[:logger], options[:logger_filters]
  @identity = options[:identity]
  @crypto_suite = options[:crypto_suite]
end

Instance Attribute Details

#channel_idObject (readonly)

Returns the value of attribute channel_id.



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

def channel_id
  @channel_id
end

#crypto_suiteObject (readonly)

Returns the value of attribute crypto_suite.



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

def crypto_suite
  @crypto_suite
end

#identityObject (readonly)

Returns the value of attribute identity.



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

def identity
  @identity
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#orderersObject (readonly)

Returns the value of attribute orderers.



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

def orderers
  @orderers
end

#peersObject (readonly)

Returns the value of attribute peers.



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

def peers
  @peers
end

Instance Method Details

#create_transaction_infoObject



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

def create_transaction_info
  TransactionInfo.new crypto_suite, identity
end

#invoke(chaincode_response) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/fabric/channel.rb', line 43

def invoke(chaincode_response)
  transaction = Transaction.new crypto_suite,
                                identity,
                                proposal: chaincode_response.proposal,
                                responses: chaincode_response.proposal_responses

  send_transaction transaction

  chaincode_response
end

#query(request = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fabric/channel.rb', line 27

def query(request = {})
  request[:channel_id] = channel_id

  logging __method__, request

  proposal = Proposal.new crypto_suite, identity, request
  proposal_responses = peers.map { |peer| peer.send_process_proposal(proposal.signed_proposal) }

  chaincode_response = ChaincodeResponse.new proposal: proposal,
                                             proposal_responses: proposal_responses

  chaincode_response.validate!

  chaincode_response
end

#register_orderer(url, opts = {}) ⇒ Object



21
22
23
24
25
# File 'lib/fabric/channel.rb', line 21

def register_orderer(url, opts = {})
  @orderers ||= []

  @orderers << Orderer.new(url: url, opts: opts, logger: logger)
end

#register_peer(url, opts = {}) ⇒ Object



15
16
17
18
19
# File 'lib/fabric/channel.rb', line 15

def register_peer(url, opts = {})
  @peers ||= []

  @peers << Peer.new(url: url, opts: opts, logger: logger)
end