Class: Fabric::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
# File 'lib/fabric/client.rb', line 5

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

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

Instance Attribute Details

#event_hubsObject (readonly)

Returns the value of attribute event_hubs.



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

def event_hubs
  @event_hubs
end

#identityObject (readonly)

Returns the value of attribute identity.



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

def identity
  @identity
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#orderersObject (readonly)

Returns the value of attribute orderers.



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

def orderers
  @orderers
end

#peersObject (readonly)

Returns the value of attribute peers.



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

def peers
  @peers
end

Instance Method Details

#invoke(request = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fabric/client.rb', line 50

def invoke(request = {})
  logging __method__, request

  proposal = Proposal.new identity, request

  responses = send_query(proposal) { |response| parse_peer_response response }

  transaction = Transaction.new identity, proposal: proposal, responses: responses

  send_transaction(transaction) { |response| parse_orderer_response response }

  responses.map { |response| parse_chaincode_response response.response }

  transaction
end

#query(request = {}) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/fabric/client.rb', line 42

def query(request = {})
  logging __method__, request

  proposal = Proposal.new identity, request

  send_query(proposal) { |response| parse_chaincode_response response.response }
end

#register_event_hub(options, extra_options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/fabric/client.rb', line 32

def register_event_hub(options, extra_options = {})
  @event_hubs ||= []

  options = { host: options } if options.is_a?(String)
  extra_options.merge!(options)
  extra_options.merge!(logger: logger)

  @event_hubs << EventHub.new(extra_options[:host], extra_options[:creds], extra_options)
end

#register_orderer(options, extra_options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/fabric/client.rb', line 22

def register_orderer(options, extra_options = {})
  @orderers ||= []

  options = { host: options } if options.is_a?(String)
  extra_options.merge!(options)
  extra_options.merge!(logger: logger)

  @orderers << Orderer.new(extra_options[:host], extra_options[:creds], extra_options)
end

#register_peer(options, extra_options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/fabric/client.rb', line 12

def register_peer(options, extra_options = {})
  @peers ||= []

  options = { host: options } if options.is_a?(String)
  extra_options.merge!(options)
  extra_options.merge!(logger: logger)

  @peers << Peer.new(extra_options[:host], extra_options[:creds], extra_options)
end