Class: Fabric::Network

Inherits:
Object
  • Object
show all
Includes:
Accessors::Gateway
Defined in:
lib/fabric/network.rb

Overview

Network represents a blockchain network, or Fabric channel. The Network can be used to access deployed smart contracts, and to listen for events emitted when blocks are committed to the ledger.

JChan & THowe believe this should be called a Channel, however Hyperledger Fabric has decided upon the terminology network - https://github.com/hyperledger/fabric-gateway/issues/355#issuecomment-997888071

Instance Attribute Summary collapse

Attributes included from Accessors::Gateway

#client, #signer

Instance Method Summary collapse

Constructor Details

#initialize(gateway, name) ⇒ Network

Returns a new instance of Network.



17
18
19
20
# File 'lib/fabric/network.rb', line 17

def initialize(gateway, name)
  @gateway = gateway
  @name = name
end

Instance Attribute Details

#gatewayObject (readonly)

Returns the value of attribute gateway.



12
13
14
# File 'lib/fabric/network.rb', line 12

def gateway
  @gateway
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/fabric/network.rb', line 12

def name
  @name
end

Instance Method Details

#chaincode_events(contract, start_block: nil, call_options: {}) {|chaincode_event| ... } ⇒ Enumerator|GRPC::ActiveCall::Operation|nil

Get chaincode events emitted by transaction functions of a specific chaincode.

Parameters:

  • contract (Fabric::Contract)

    the chaincode to listen for events on

  • start_block (Integer) (defaults to: nil)

    Block number at which to start reading chaincode events.

  • call_options (Hash) (defaults to: {})

    gRPC call options (merged with default_call_options from initializer)

Yields:

  • (chaincode_event)

    loops through the chaincode events

Yield Parameters:

  • chaincode_event (Gateway::ChaincodeEventsResponse)

    the chaincode event

Returns:

  • (Enumerator|GRPC::ActiveCall::Operation|nil)

    Dependent on parameters passed; please see Fabric::Client#get_chaincode_events

See Also:



50
51
52
# File 'lib/fabric/network.rb', line 50

def chaincode_events(contract, start_block: nil, call_options: {}, &block)
  new_chaincode_events_request(contract, start_block: start_block).get_events(call_options, &block)
end

#new_chaincode_events_request(contract, start_block: nil) ⇒ Fabric::ChaincodeEventsRequest

TODO:

Test off-line signing flow.

Note:

I'm lying. I just copy and pasted the description from the node SDK. Offline signing should work, but it has not been explicitly tested.

Create a request to receive chaincode events emitted by transaction functions of a specific chaincode. Supports off-line signing flow.

Parameters:

  • contract (Fabric::Contract)

    the chaincode to listen for events on

  • start_block (Integer) (defaults to: nil)

    Block number at which to start reading chaincode events.

Returns:



66
67
68
# File 'lib/fabric/network.rb', line 66

def new_chaincode_events_request(contract, start_block: nil)
  ChaincodeEventsRequest.new(contract, start_block: start_block)
end

#new_contract(chaincode_name, contract_name = '') ⇒ Fabric::Contract

Creates a new contract instance

Parameters:

  • chaincode_name (string)

    name of the chaincode

  • contract_name (string) (defaults to: '')

    optional name of the contract

Returns:



30
31
32
# File 'lib/fabric/network.rb', line 30

def new_contract(chaincode_name, contract_name = '')
  Contract.new(self, chaincode_name, contract_name)
end