fabric-gateway 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +71 -0
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/todo.yml +10 -0
- data/.github/workflows/yardoc.yml +28 -0
- data/.yardopts +6 -0
- data/README.md +28 -4
- data/Rakefile +0 -1
- data/fabric-gateway.gemspec +3 -2
- data/lib/fabric/client.rb +61 -8
- data/lib/fabric/contract.rb +24 -0
- data/lib/fabric/entities/chaincode_events_requests.rb +166 -0
- data/lib/fabric/entities/envelope.rb +7 -2
- data/lib/fabric/network.rb +26 -12
- data/lib/fabric/version.rb +1 -1
- data/lib/fabric.rb +2 -0
- metadata +22 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f0568b7e6de9981790fc25887fb4b063d2a2b4b4013b3762f0ae5cb5255aaf
|
4
|
+
data.tar.gz: 88c6ba3db543a3c1bc0a138e7e40325a1cdfd680bd6bcb39c907ba7aa848f6b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a51e59cdc705fd1891221933f0ee146f685d64602fe75ef0ae71a125eb14023b927f5b86990225369b115bf3f96fc5d9d2aa851c52492dc4a7211a7f6f3cba88
|
7
|
+
data.tar.gz: 926eafcb4b4c5047099cffca1d4ca9d1d2ea2a761e352e8300b08ae7c01f7c7340940b613096562e77f1448e7599c87a5f84ea55dad5779eded99c374dfd7246
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ master ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ master ]
|
20
|
+
schedule:
|
21
|
+
- cron: '25 10 * * 6'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v1
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v1
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v1
|
71
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: Yardoc Documentation Coverage
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- name: Set up Ruby 2.7
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.7
|
15
|
+
- name: Cache gems
|
16
|
+
uses: actions/cache@v1
|
17
|
+
with:
|
18
|
+
path: vendor/bundle
|
19
|
+
key: ${{ runner.os }}-yardoc-${{ hashFiles('**/Gemfile.lock') }}
|
20
|
+
restore-keys: |
|
21
|
+
${{ runner.os }}-yardoc-
|
22
|
+
- name: Install gems
|
23
|
+
run: |
|
24
|
+
bundle config path vendor/bundle
|
25
|
+
bundle config set without 'default doc job cable storage ujs test db'
|
26
|
+
bundle install --jobs 4 --retry 3
|
27
|
+
- name: Run yard stats
|
28
|
+
run: bundle exec yard stats --list-undoc --no-cache --fail-on-warning
|
data/.yardopts
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
Hyperledger Fabric Gateway
|
7
|
+
[Hyperledger Fabric Gateway SDK](https://hyperledger-fabric.readthedocs.io/en/latest/gateway.html) ported to idiomatic ruby.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -32,7 +32,7 @@ Will update to new version of grpc when fix is released.
|
|
32
32
|
|
33
33
|
## Usage
|
34
34
|
|
35
|
-
This is
|
35
|
+
This is a beta stage library with all the main hyperledger gateway calls implemented. Although this library has good unit test coverage, it is fairly new and has not yet been run in production environments. The library will be updated to 1.0.0 when the library has proven to be stable.
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
$ bin/console
|
@@ -86,8 +86,32 @@ puts contract.evaluate_transaction('GetAllAssets')
|
|
86
86
|
puts contract.submit_transaction('CreateAsset', ['asset13', 'yellow', '5', 'Tom', '1300'])
|
87
87
|
puts contract.submit_transaction('UpdateAsset', %w[asset999 yellow 5 Tom 5555])
|
88
88
|
|
89
|
-
# Chaincode Events -
|
89
|
+
# Chaincode Events - simple (blocking until deadline is reached or connection closed)
|
90
|
+
contract.chaincode_events do |event|
|
91
|
+
puts event
|
92
|
+
end
|
93
|
+
|
94
|
+
# Chaincode Events - advanced
|
95
|
+
# chaincode events are blocking and run indefinitely, so this is probably the more typical use case to give
|
96
|
+
# more control over the connection
|
97
|
+
|
98
|
+
last_processed_block = nil # store this in something persistent
|
99
|
+
|
100
|
+
op = contract.chaincode_events(start_block: last_processed_block, call_options: { return_op: true }) do |event|
|
101
|
+
last_processed_block = event.block_number # update the last_processed_block so we can resume from this point
|
102
|
+
puts event
|
103
|
+
end
|
104
|
+
|
105
|
+
t = Thread.new do
|
106
|
+
call = op.execute
|
107
|
+
rescue GRPC::Cancelled => e
|
108
|
+
puts 'We cancelled the operation outside of this thread.'
|
109
|
+
end
|
90
110
|
|
111
|
+
sleep 1
|
112
|
+
op.status
|
113
|
+
op.cancelled?
|
114
|
+
op.cancel
|
91
115
|
```
|
92
116
|
|
93
117
|
Please refer to the [full reference documentation](https://rubydoc.info/github/EthicalIdentity/fabric-gateway-ruby) for complete usage information.
|
@@ -135,7 +159,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ethica
|
|
135
159
|
- [x] Implement, Document & Test Endorse
|
136
160
|
- [x] Implement, Document & Test Submit
|
137
161
|
- [x] Implement, Document & Test CommitStatus
|
138
|
-
- [
|
162
|
+
- [x] Implement, Document & Test ChaincodeEvents
|
139
163
|
- [ ] Support Submit Async (currently blocks waiting for the transaction to be committed)
|
140
164
|
- [ ] Consider adding error handling, invalid transaction proposals will result in random GRPC::FailedPrecondition type errors
|
141
165
|
- [ ] Consider adding transaction_id information to Fabric::Errors that are raised; would help a lot for debugging.
|
data/Rakefile
CHANGED
data/fabric-gateway.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Jonathan Chan']
|
9
9
|
spec.email = ['jonathan.chan@ethicalidentity.com']
|
10
10
|
|
11
|
-
spec.summary = 'Hyperledger Fabric Gateway
|
12
|
-
spec.description = 'Hyperledger Fabric Gateway
|
11
|
+
spec.summary = 'Hyperledger Fabric Gateway SDK'
|
12
|
+
spec.description = 'Ruby port of the Hyperledger Fabric Gateway SDK'
|
13
13
|
spec.homepage = 'https://github.com/ethicalidentity/fabric-gateway-ruby'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
@@ -38,6 +38,7 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.add_development_dependency('rubocop-rspec', '~> 2.6.0')
|
39
39
|
spec.add_development_dependency('simplecov', '~> 0.21.2')
|
40
40
|
spec.add_development_dependency('timecop', '~> 0.9.4')
|
41
|
+
spec.add_development_dependency('yard', '~> 0.9.27')
|
41
42
|
spec.metadata = {
|
42
43
|
'rubygems_mfa_required' => 'true'
|
43
44
|
}
|
data/lib/fabric/client.rb
CHANGED
@@ -53,8 +53,9 @@ module Fabric
|
|
53
53
|
#
|
54
54
|
# Submits an evaluate_request to the gateway to be evaluted.
|
55
55
|
#
|
56
|
+
# @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:request_response Call options for options parameter
|
56
57
|
# @param [Gateway::EvaluateRequest] evaluate_request
|
57
|
-
# @param [Hash] options gRPC call options (merged with
|
58
|
+
# @param [Hash] options gRPC call options (merged with default_call_options from initializer)
|
58
59
|
#
|
59
60
|
# @return [Gateway::EvaluateResponse] evaluate_response
|
60
61
|
#
|
@@ -92,6 +93,7 @@ module Fabric
|
|
92
93
|
# @param [Gateway::CommitStatusRequest] commit_status_request
|
93
94
|
# @param [Hash] options gRPC call options (merged with default options) @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:request_response
|
94
95
|
#
|
96
|
+
# Returns an enum or if you pass a block, use the block.
|
95
97
|
# @return [Gateway::CommitStatusResponse] commit_status_response
|
96
98
|
#
|
97
99
|
def commit_status(commit_status_request, options = {})
|
@@ -101,13 +103,64 @@ module Fabric
|
|
101
103
|
#
|
102
104
|
# Subscribe to chaincode events
|
103
105
|
#
|
104
|
-
# @
|
105
|
-
#
|
106
|
-
#
|
107
|
-
#
|
108
|
-
# @
|
109
|
-
#
|
110
|
-
#
|
106
|
+
# @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:server_streamer GRPC::ClientStub#server_streamer
|
107
|
+
# - gRPC Underlying Call Reference
|
108
|
+
#
|
109
|
+
#
|
110
|
+
# @overload chaincode_events(chaincode_events_request)
|
111
|
+
# @example Utilizing Blocking Enumerator
|
112
|
+
# call = client.chaincode_events(chaincode_events_request)
|
113
|
+
# call.each do |event|
|
114
|
+
# pp event
|
115
|
+
# end
|
116
|
+
# @param [Gateway::ChaincodeEventsRequest] chaincode_events_request
|
117
|
+
# @param [Hash] options gRPC call options (merged with default options)
|
118
|
+
# @return [Enumerator] enumerator with Gateway::ChaincodeEventsResponse objects
|
119
|
+
# @overload chaincode_events(chaincode_events_request)
|
120
|
+
# @example Utilizing a blocking block
|
121
|
+
# client.chaincode_events(chaincode_events_request) do |event|
|
122
|
+
# pp event
|
123
|
+
# end
|
124
|
+
# @param [Gateway::ChaincodeEventsRequest] chaincode_events_request
|
125
|
+
# @param [Hash] options gRPC call options (merged with default options)
|
126
|
+
# @yield [event] Blocking call that yields Gateway::ChaincodeEventsResponse objects when received from the server
|
127
|
+
# @yieldparam event [Gateway::ChaincodeEventsResponse] chaincode event
|
128
|
+
# @return [nil]
|
129
|
+
# @overload chaincode_events(chaincode_events_request, {return_op: true})
|
130
|
+
# @example Utilizing an operation control object and a enumerator
|
131
|
+
# op = client.chaincode_events(chaincode_events_request, {return_op: true})
|
132
|
+
#
|
133
|
+
# t = Thread.new do
|
134
|
+
# call = op.execute
|
135
|
+
# call.each do |event|
|
136
|
+
# pp event
|
137
|
+
# end
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# op.status
|
141
|
+
# op.cancelled?
|
142
|
+
# op.cancel
|
143
|
+
# @param [Gateway::ChaincodeEventsRequest] chaincode_events_request
|
144
|
+
# @param [Hash] options gRPC call options (merged with default options)
|
145
|
+
# @return [GRPC::ActiveCall::Operation]
|
146
|
+
# @overload chaincode_events(chaincode_events_request, {return_op: true})
|
147
|
+
# @example Utilizing an operation control object and a block
|
148
|
+
# op = client.chaincode_events(chaincode_events_request, {return_op: true}) do |event|
|
149
|
+
# pp event
|
150
|
+
# end
|
151
|
+
#
|
152
|
+
# t = Thread.new do
|
153
|
+
# call = op.execute
|
154
|
+
# end
|
155
|
+
#
|
156
|
+
# op.status
|
157
|
+
# op.cancelled?
|
158
|
+
# op.cancel
|
159
|
+
# @param [Gateway::ChaincodeEventsRequest] chaincode_events_request
|
160
|
+
# @param [Hash] options gRPC call options (merged with default options)
|
161
|
+
# @yield [event] Blocking call that yields Gateway::ChaincodeEventsResponse objects when received from the server
|
162
|
+
# @yieldparam event [Gateway::ChaincodeEventsResponse] chaincode event
|
163
|
+
# @return [GRPC::ActiveCall::Operation]
|
111
164
|
#
|
112
165
|
def chaincode_events(chaincode_events_request, options = {}, &block)
|
113
166
|
@grpc_client.chaincode_events(chaincode_events_request,
|
data/lib/fabric/contract.rb
CHANGED
@@ -117,6 +117,30 @@ module Fabric
|
|
117
117
|
raise NotYetImplemented
|
118
118
|
end
|
119
119
|
|
120
|
+
#
|
121
|
+
# Get chaincode events emitted by transaction functions of the chaincode.
|
122
|
+
#
|
123
|
+
# @see Fabric::Client#chaincode_events Fabric::Client#chaincode_events - explanation of the different return types
|
124
|
+
# and example usage.
|
125
|
+
# @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:server_streamer Call options for options parameter
|
126
|
+
#
|
127
|
+
# @param [Integer] start_block Block number at which to start reading chaincode events.
|
128
|
+
# @param [Hash] call_options gRPC call options (merged with default_call_options from initializer)
|
129
|
+
# @yield [chaincode_event] loops through the chaincode events
|
130
|
+
# @yieldparam [Gateway::ChaincodeEventsResponse] chaincode_event the chaincode event
|
131
|
+
#
|
132
|
+
# @return [Enumerator|GRPC::ActiveCall::Operation|nil] Dependent on parameters passed;
|
133
|
+
# please see Fabric::Client#get_chaincode_events
|
134
|
+
#
|
135
|
+
def chaincode_events(start_block: nil, call_options: {}, &block)
|
136
|
+
network.chaincode_events(
|
137
|
+
self,
|
138
|
+
start_block: start_block,
|
139
|
+
call_options: call_options,
|
140
|
+
&block
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
120
144
|
#
|
121
145
|
# Creates a transaction proposal that can be evaluated or endorsed. Supports off-line signing flow.
|
122
146
|
#
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fabric
|
4
|
+
#
|
5
|
+
# Encapsulates a Chaincode Events Request protobuf message
|
6
|
+
#
|
7
|
+
class ChaincodeEventsRequest
|
8
|
+
attr_reader :contract,
|
9
|
+
:start_block
|
10
|
+
|
11
|
+
# @!parse include Fabric::Accessors::Network
|
12
|
+
# @!parse include Fabric::Accessors::Gateway
|
13
|
+
include Fabric::Accessors::Contract
|
14
|
+
|
15
|
+
#
|
16
|
+
# Creates a new ChaincodeEventsRequest
|
17
|
+
#
|
18
|
+
# @param [Fabric::Contract] contract an instance of a contract
|
19
|
+
# @param [Integer] start_block Block number at which to start reading chaincode events.
|
20
|
+
#
|
21
|
+
def initialize(contract, start_block: nil)
|
22
|
+
@contract = contract
|
23
|
+
@start_block = start_block
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Returns the signed request
|
28
|
+
#
|
29
|
+
# @return [Gateway::SignedChaincodeEventsRequest] generated signed request
|
30
|
+
#
|
31
|
+
def signed_request
|
32
|
+
@signed_request ||= ::Gateway::SignedChaincodeEventsRequest.new(request: chaincode_events_request.to_proto)
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Returns the chaincode events request
|
37
|
+
#
|
38
|
+
# @return [Gateway::ChaincodeEventsRequest] chaincode events request - controls what events are returned
|
39
|
+
# from a chaincode events request
|
40
|
+
#
|
41
|
+
def chaincode_events_request
|
42
|
+
@chaincode_events_request ||= new_chaincode_events_request
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Get the serialized chaincode events request protobuffer message.
|
47
|
+
#
|
48
|
+
# @return [String] protobuffer serialized chaincode events request
|
49
|
+
#
|
50
|
+
def request_bytes
|
51
|
+
signed_request.request
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Get the digest of the chaincode events request. This is used to generate a digital signature.
|
56
|
+
#
|
57
|
+
# @return [String] chaincode events request digest
|
58
|
+
#
|
59
|
+
def request_digest
|
60
|
+
Fabric.crypto_suite.digest(request_bytes)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Sets the signed request signature.
|
65
|
+
#
|
66
|
+
# @param [String] signature
|
67
|
+
#
|
68
|
+
# @return [void]
|
69
|
+
#
|
70
|
+
def signature=(signature)
|
71
|
+
signed_request.signature = signature
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Returns the signed_request signature
|
76
|
+
#
|
77
|
+
# @return [String] Raw byte string signature
|
78
|
+
#
|
79
|
+
def signature
|
80
|
+
signed_request.signature
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Sign the chaincode events request; Noop if request already signed.
|
85
|
+
#
|
86
|
+
# @return [void]
|
87
|
+
#
|
88
|
+
def sign
|
89
|
+
return if signed?
|
90
|
+
|
91
|
+
self.signature = signer.sign(request_bytes)
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Checks if the signed chaincode events has been signed.
|
96
|
+
#
|
97
|
+
# @return [Boolean] true if the signed chaincode events has been signed; otherwise false.
|
98
|
+
#
|
99
|
+
def signed?
|
100
|
+
!signed_request.signature.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Get chaincode events emitted by transaction functions of a specific chaincode.
|
105
|
+
#
|
106
|
+
# @see Fabric::Client#chaincode_events Fabric::Client#chaincode_events - explanation of the different return types
|
107
|
+
# and example usage.
|
108
|
+
# @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:server_streamer Call options for options parameter
|
109
|
+
#
|
110
|
+
# @param [Hash] options gRPC call options (merged with default_call_options from initializer)
|
111
|
+
# @yield [chaincode_event] loops through the chaincode events
|
112
|
+
# @yieldparam [Gateway::ChaincodeEventsResponse] chaincode_event the chaincode event
|
113
|
+
#
|
114
|
+
# @return [Enumerator|GRPC::ActiveCall::Operation|nil] Dependent on parameters passed;
|
115
|
+
# please see Fabric::Client#get_chaincode_events
|
116
|
+
#
|
117
|
+
def get_events(options = {}, &block)
|
118
|
+
sign
|
119
|
+
|
120
|
+
client.chaincode_events(signed_request, options, &block)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
#
|
126
|
+
# Generates a new chaincode events request
|
127
|
+
#
|
128
|
+
# @return [Gateway::ChaincodeEventsRequest] chaincode events request - controls what events are returned
|
129
|
+
#
|
130
|
+
def new_chaincode_events_request
|
131
|
+
::Gateway::ChaincodeEventsRequest.new(
|
132
|
+
channel_id: network_name,
|
133
|
+
chaincode_id: chaincode_name,
|
134
|
+
identity: signer.to_proto,
|
135
|
+
start_position: start_position
|
136
|
+
)
|
137
|
+
end
|
138
|
+
|
139
|
+
#
|
140
|
+
# Generates the start_position for the chaincode events request or returns the cached start_position
|
141
|
+
#
|
142
|
+
# @return [Orderer::SeekPosition] start position for the chaincode events request
|
143
|
+
#
|
144
|
+
def start_position
|
145
|
+
@start_position ||= new_start_position
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# Generates the start position for the chaincode events request; if no start_block is specified,
|
150
|
+
# generates a seek next commit start position, otherwise generates a start_position to the start_block
|
151
|
+
#
|
152
|
+
# @return [Orderer::SeekPosition] start position for the chaincode events request
|
153
|
+
#
|
154
|
+
def new_start_position
|
155
|
+
specified = nil
|
156
|
+
next_commit = nil
|
157
|
+
|
158
|
+
if start_block
|
159
|
+
specified = ::Orderer::SeekSpecified.new(number: start_block)
|
160
|
+
else
|
161
|
+
next_commit = ::Orderer::SeekNextCommit.new
|
162
|
+
end
|
163
|
+
Orderer::SeekPosition.new(specified: specified, next_commit: next_commit)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
@@ -49,12 +49,17 @@ module Fabric
|
|
49
49
|
#
|
50
50
|
# @param [String] signature
|
51
51
|
#
|
52
|
-
# @return [
|
52
|
+
# @return [void]
|
53
53
|
#
|
54
54
|
def signature=(signature)
|
55
55
|
envelope.signature = signature
|
56
56
|
end
|
57
57
|
|
58
|
+
#
|
59
|
+
# Returns the results from the transaction result payload.
|
60
|
+
#
|
61
|
+
# @return [Payload] transaction result payload
|
62
|
+
#
|
58
63
|
def result
|
59
64
|
@result ||= parse_result_from_payload
|
60
65
|
end
|
@@ -113,7 +118,7 @@ module Fabric
|
|
113
118
|
private
|
114
119
|
|
115
120
|
#
|
116
|
-
# Parse the transaction
|
121
|
+
# Parse the transaction actions from the payload looking for the transaction result payload.
|
117
122
|
#
|
118
123
|
# @return [String] result payload
|
119
124
|
# @raise [Fabric::Error] if the transaction result payload is not found
|
data/lib/fabric/network.rb
CHANGED
@@ -32,25 +32,39 @@ module Fabric
|
|
32
32
|
end
|
33
33
|
|
34
34
|
#
|
35
|
-
#
|
36
|
-
# @see https://github.com/hyperledger/fabric-gateway/blob/08118cf0a792898925d0b2710b0a9e7c5ec23228/node/src/network.ts
|
37
|
-
# @see https://github.com/hyperledger/fabric-gateway/blob/main/pkg/client/network.go
|
35
|
+
# Get chaincode events emitted by transaction functions of a specific chaincode.
|
38
36
|
#
|
39
|
-
# @return
|
37
|
+
# @see Fabric::Client#chaincode_events Fabric::Client#chaincode_events - explanation of the different return types
|
38
|
+
# and example usage.
|
39
|
+
# @see https://www.rubydoc.info/gems/grpc/GRPC%2FClientStub:server_streamer Call options for options parameter
|
40
40
|
#
|
41
|
-
|
42
|
-
|
41
|
+
# @param [Fabric::Contract] contract the chaincode to listen for events on
|
42
|
+
# @param [Integer] start_block Block number at which to start reading chaincode events.
|
43
|
+
# @param [Hash] call_options gRPC call options (merged with default_call_options from initializer)
|
44
|
+
# @yield [chaincode_event] loops through the chaincode events
|
45
|
+
# @yieldparam chaincode_event [Gateway::ChaincodeEventsResponse] the chaincode event
|
46
|
+
#
|
47
|
+
# @return [Enumerator|GRPC::ActiveCall::Operation|nil] Dependent on parameters passed;
|
48
|
+
# please see Fabric::Client#get_chaincode_events
|
49
|
+
#
|
50
|
+
def chaincode_events(contract, start_block: nil, call_options: {}, &block)
|
51
|
+
new_chaincode_events_request(contract, start_block: start_block).get_events(call_options, &block)
|
43
52
|
end
|
44
53
|
|
45
54
|
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
55
|
+
# Create a request to receive chaincode events emitted by transaction functions of a specific chaincode. Supports
|
56
|
+
# off-line signing flow.
|
57
|
+
#
|
58
|
+
# @note I'm lying. I just copy and pasted the description from the node SDK. Offline signing should work, but it has
|
59
|
+
# not been explicitly tested.
|
60
|
+
# @todo Test off-line signing flow.
|
49
61
|
#
|
50
|
-
# @
|
62
|
+
# @param [Fabric::Contract] contract the chaincode to listen for events on
|
63
|
+
# @param [Integer] start_block Block number at which to start reading chaincode events.
|
64
|
+
# @return [Fabric::ChaincodeEventsRequest] Encapsulated ChaincodeEventsRequest
|
51
65
|
#
|
52
|
-
def new_chaincode_events_request
|
53
|
-
|
66
|
+
def new_chaincode_events_request(contract, start_block: nil)
|
67
|
+
ChaincodeEventsRequest.new(contract, start_block: start_block)
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
data/lib/fabric/version.rb
CHANGED
data/lib/fabric.rb
CHANGED
@@ -13,6 +13,7 @@ require 'fabric/entities/proposal'
|
|
13
13
|
require 'fabric/entities/proposed_transaction'
|
14
14
|
require 'fabric/entities/status'
|
15
15
|
require 'fabric/entities/transaction'
|
16
|
+
require 'fabric/entities/chaincode_events_requests'
|
16
17
|
|
17
18
|
require 'fabric/constants'
|
18
19
|
require 'fabric/contract'
|
@@ -33,6 +34,7 @@ module Fabric
|
|
33
34
|
#
|
34
35
|
# CommitError
|
35
36
|
#
|
37
|
+
# TODO: Add RSpec Tests for CommitError
|
36
38
|
# @todo TEST ME!
|
37
39
|
#
|
38
40
|
class CommitError < Error
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabric-gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-protobuf
|
@@ -150,8 +150,21 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 0.9.4
|
153
|
-
|
154
|
-
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: yard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.9.27
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.9.27
|
167
|
+
description: Ruby port of the Hyperledger Fabric Gateway SDK
|
155
168
|
email:
|
156
169
|
- jonathan.chan@ethicalidentity.com
|
157
170
|
executables: []
|
@@ -159,8 +172,11 @@ extensions: []
|
|
159
172
|
extra_rdoc_files: []
|
160
173
|
files:
|
161
174
|
- ".editorconfig"
|
175
|
+
- ".github/workflows/codeql-analysis.yml"
|
162
176
|
- ".github/workflows/rspec.yml"
|
163
177
|
- ".github/workflows/rubocop.yml"
|
178
|
+
- ".github/workflows/todo.yml"
|
179
|
+
- ".github/workflows/yardoc.yml"
|
164
180
|
- ".gitignore"
|
165
181
|
- ".gitmodules"
|
166
182
|
- ".rspec"
|
@@ -193,6 +209,7 @@ files:
|
|
193
209
|
- lib/fabric/constants.rb
|
194
210
|
- lib/fabric/contract.rb
|
195
211
|
- lib/fabric/ec_crypto_suite.rb
|
212
|
+
- lib/fabric/entities/chaincode_events_requests.rb
|
196
213
|
- lib/fabric/entities/envelope.rb
|
197
214
|
- lib/fabric/entities/identity.rb
|
198
215
|
- lib/fabric/entities/proposal.rb
|
@@ -238,5 +255,5 @@ requirements: []
|
|
238
255
|
rubygems_version: 3.1.6
|
239
256
|
signing_key:
|
240
257
|
specification_version: 4
|
241
|
-
summary: Hyperledger Fabric Gateway
|
258
|
+
summary: Hyperledger Fabric Gateway SDK
|
242
259
|
test_files: []
|