class Fabric::ChaincodeEventsRequest
Encapsulates a Chaincode Events Request protobuf message
Attributes
Public Class Methods
Creates a new ChaincodeEventsRequest
@param [Fabric::Contract] contract an instance of a contract @param [Integer] start_block
Block number at which to start reading chaincode events.
# File lib/fabric/entities/chaincode_events_requests.rb, line 21 def initialize(contract, start_block: nil) @contract = contract @start_block = start_block end
Public Instance Methods
Returns the chaincode events request
@return [Gateway::ChaincodeEventsRequest] chaincode events request - controls what events are returned
from a chaincode events request
# File lib/fabric/entities/chaincode_events_requests.rb, line 41 def chaincode_events_request @chaincode_events_request ||= new_chaincode_events_request end
Get chaincode events emitted by transaction functions of a specific chaincode.
@see Fabric::Client#chaincode_events
Fabric::Client#chaincode_events
- explanation of the different return types
and example usage.
@see www.rubydoc.info/gems/grpc/GRPC%2FClientStub:server_streamer Call options for options parameter
@param [Hash] options gRPC call options (merged with default_call_options from initializer) @yield [chaincode_event] loops through the chaincode events @yieldparam [Gateway::ChaincodeEventsResponse] chaincode_event the chaincode event
@return [Enumerator|GRPC::ActiveCall::Operation|nil] Dependent on parameters passed;
please see Fabric::Client#get_chaincode_events
# File lib/fabric/entities/chaincode_events_requests.rb, line 117 def get_events(options = {}, &block) sign client.chaincode_events(signed_request, options, &block) end
Get the serialized chaincode events request protobuffer message.
@return [String] protobuffer serialized chaincode events request
# File lib/fabric/entities/chaincode_events_requests.rb, line 50 def request_bytes signed_request.request end
Get the digest of the chaincode events request. This is used to generate a digital signature.
@return [String] chaincode events request digest
# File lib/fabric/entities/chaincode_events_requests.rb, line 59 def request_digest Fabric.crypto_suite.digest(request_bytes) end
Sign the chaincode events request; Noop if request already signed.
@return [void]
# File lib/fabric/entities/chaincode_events_requests.rb, line 88 def sign return if signed? self.signature = signer.sign(request_bytes) end
Returns the signed_request
signature
@return [String] Raw byte string signature
# File lib/fabric/entities/chaincode_events_requests.rb, line 79 def signature signed_request.signature end
Sets the signed request signature.
@param [String] signature
@return [void]
# File lib/fabric/entities/chaincode_events_requests.rb, line 70 def signature=(signature) signed_request.signature = signature end
Checks if the signed chaincode events has been signed.
@return [Boolean] true if the signed chaincode events has been signed; otherwise false.
# File lib/fabric/entities/chaincode_events_requests.rb, line 99 def signed? !signed_request.signature.empty? end
Returns the signed request
@return [Gateway::SignedChaincodeEventsRequest] generated signed request
# File lib/fabric/entities/chaincode_events_requests.rb, line 31 def signed_request @signed_request ||= ::Gateway::SignedChaincodeEventsRequest.new(request: chaincode_events_request.to_proto) end
Private Instance Methods
Generates a new chaincode events request
@return [Gateway::ChaincodeEventsRequest] chaincode events request - controls what events are returned
# File lib/fabric/entities/chaincode_events_requests.rb, line 130 def new_chaincode_events_request ::Gateway::ChaincodeEventsRequest.new( channel_id: network_name, chaincode_id: chaincode_name, identity: signer.to_proto, start_position: start_position ) end
Generates the start position for the chaincode events request; if no start_block
is specified, generates a seek next commit start position, otherwise generates a start_position
to the start_block
@return [Orderer::SeekPosition] start position for the chaincode events request
# File lib/fabric/entities/chaincode_events_requests.rb, line 154 def new_start_position specified = nil next_commit = nil if start_block specified = ::Orderer::SeekSpecified.new(number: start_block) else next_commit = ::Orderer::SeekNextCommit.new end Orderer::SeekPosition.new(specified: specified, next_commit: next_commit) end
Generates the start_position
for the chaincode events request or returns the cached start_position
@return [Orderer::SeekPosition] start position for the chaincode events request
# File lib/fabric/entities/chaincode_events_requests.rb, line 144 def start_position @start_position ||= new_start_position end