fabric-gateway 0.0.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +3 -0
  3. data/.github/workflows/codeql-analysis.yml +71 -0
  4. data/.github/workflows/rspec.yml +37 -0
  5. data/.github/workflows/rubocop.yml +28 -0
  6. data/.github/workflows/todo.yml +10 -0
  7. data/.github/workflows/yardoc.yml +28 -0
  8. data/.gitignore +1 -0
  9. data/.rubocop.yml +23 -0
  10. data/.ruby-version +1 -0
  11. data/.vscode/settings.json +7 -0
  12. data/.yardopts +8 -0
  13. data/CODE_OF_CONDUCT.md +105 -46
  14. data/Gemfile +5 -3
  15. data/LICENSE.txt +1 -1
  16. data/README.md +123 -12
  17. data/Rakefile +6 -3
  18. data/bin/console +4 -3
  19. data/bin/regenerate +1 -0
  20. data/bin/release +5 -0
  21. data/fabric-gateway.gemspec +31 -17
  22. data/lib/fabric/accessors/contract.rb +51 -0
  23. data/lib/fabric/accessors/gateway.rb +33 -0
  24. data/lib/fabric/accessors/network.rb +40 -0
  25. data/lib/fabric/client.rb +199 -0
  26. data/lib/fabric/constants.rb +8 -0
  27. data/lib/fabric/contract.rb +178 -0
  28. data/lib/fabric/ec_crypto_suite.rb +199 -0
  29. data/lib/fabric/entities/chaincode_events_requests.rb +166 -0
  30. data/lib/fabric/entities/envelope.rb +158 -0
  31. data/lib/fabric/entities/identity.rb +87 -0
  32. data/lib/fabric/entities/proposal.rb +189 -0
  33. data/lib/fabric/entities/proposed_transaction.rb +163 -0
  34. data/lib/fabric/entities/status.rb +32 -0
  35. data/lib/fabric/entities/transaction.rb +247 -0
  36. data/lib/fabric/gateway.rb +31 -6
  37. data/lib/fabric/network.rb +70 -0
  38. data/lib/fabric/version.rb +5 -0
  39. data/lib/fabric.rb +59 -0
  40. data/lib/msp/identities_pb.rb +25 -0
  41. metadata +162 -13
  42. data/Gemfile.lock +0 -42
  43. data/lib/fabric/gateway/version.rb +0 -5
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fabric
4
+ #
5
+ # Network represents a blockchain network, or Fabric channel. The Network can be used to access deployed smart
6
+ # contracts, and to listen for events emitted when blocks are committed to the ledger.
7
+ #
8
+ # JChan & THowe believe this should be called a Channel, however Hyperledger Fabric has decided upon the terminology
9
+ # network - https://github.com/hyperledger/fabric-gateway/issues/355#issuecomment-997888071
10
+ #
11
+ class Network
12
+ attr_reader :gateway, :name
13
+
14
+ # @!parse include Fabric::Accessors::Gateway
15
+ include Fabric::Accessors::Gateway
16
+
17
+ def initialize(gateway, name)
18
+ @gateway = gateway
19
+ @name = name
20
+ end
21
+
22
+ #
23
+ # Creates a new contract instance
24
+ #
25
+ # @param [string] chaincode_name name of the chaincode
26
+ # @param [string] contract_name optional name of the contract
27
+ #
28
+ # @return [Fabric::Contract] new contract instance
29
+ #
30
+ def new_contract(chaincode_name, contract_name = '')
31
+ Contract.new(self, chaincode_name, contract_name)
32
+ end
33
+
34
+ #
35
+ # Get chaincode events emitted by transaction functions of a specific chaincode.
36
+ #
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
+ #
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)
52
+ end
53
+
54
+ #
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.
61
+ #
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
65
+ #
66
+ def new_chaincode_events_request(contract, start_block: nil)
67
+ ChaincodeEventsRequest.new(contract, start_block: start_block)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fabric
4
+ VERSION = '0.4.0'
5
+ end
data/lib/fabric.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gateway/gateway_pb'
4
+ require 'gateway/gateway_services_pb'
5
+
6
+ require 'fabric/accessors/gateway'
7
+ require 'fabric/accessors/network'
8
+ require 'fabric/accessors/contract'
9
+
10
+ require 'fabric/entities/envelope'
11
+ require 'fabric/entities/identity'
12
+ require 'fabric/entities/proposal'
13
+ require 'fabric/entities/proposed_transaction'
14
+ require 'fabric/entities/status'
15
+ require 'fabric/entities/transaction'
16
+ require 'fabric/entities/chaincode_events_requests'
17
+
18
+ require 'fabric/constants'
19
+ require 'fabric/contract'
20
+ require 'fabric/client'
21
+ require 'fabric/ec_crypto_suite'
22
+ require 'fabric/gateway'
23
+ require 'fabric/network'
24
+ require 'fabric/version'
25
+
26
+ #
27
+ # Hyperledger Fabric Gateway SDK
28
+ #
29
+ module Fabric
30
+ class Error < StandardError; end
31
+ class InvalidArgument < Error; end
32
+ class NotYetImplemented < Error; end
33
+
34
+ #
35
+ # CommitError
36
+ #
37
+ # TODO: Add RSpec Tests for CommitError
38
+ # @todo TEST ME!
39
+ #
40
+ class CommitError < Error
41
+ attr_reader :code, :transaction_id
42
+
43
+ #
44
+ # Creates a transaction commit error from the status
45
+ #
46
+ # @param [Fabric::Status] status transaction status
47
+ #
48
+ def initialize(status)
49
+ super("Transaction #{status.transaction_id} failed to commit with status code #{status.code} - " +
50
+ Status::TRANSACTION_STATUSES.key(status.code).to_s)
51
+ @code = code
52
+ @transaction_id = status.transaction_id
53
+ end
54
+ end
55
+
56
+ def self.crypto_suite(opts = {})
57
+ @crypto_suite ||= Fabric::ECCryptoSuite.new opts
58
+ end
59
+ end
@@ -0,0 +1,25 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: msp/identities.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("msp/identities.proto", :syntax => :proto3) do
8
+ add_message "msp.SerializedIdentity" do
9
+ optional :mspid, :string, 1
10
+ optional :id_bytes, :bytes, 2
11
+ end
12
+ add_message "msp.SerializedIdemixIdentity" do
13
+ optional :nym_x, :bytes, 1
14
+ optional :nym_y, :bytes, 2
15
+ optional :ou, :bytes, 3
16
+ optional :role, :bytes, 4
17
+ optional :proof, :bytes, 5
18
+ end
19
+ end
20
+ end
21
+
22
+ module Msp
23
+ SerializedIdentity = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("msp.SerializedIdentity").msgclass
24
+ SerializedIdemixIdentity = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("msp.SerializedIdemixIdentity").msgclass
25
+ end
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.0.2
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: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -38,40 +38,192 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.42'
41
- description: 'Hyperledger Fabric Gateway gRPC SDK generated directly from protos found
42
- at: https://github.com/hyperledger/fabric-protos.'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_bot
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 6.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 6.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: grpc-tools
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.42'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.42'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake-notes
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.23.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.23.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.6.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.6.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.21.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.21.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: timecop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.9.4
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.9.4
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
43
168
  email:
44
169
  - jonathan.chan@ethicalidentity.com
45
170
  executables: []
46
171
  extensions: []
47
172
  extra_rdoc_files: []
48
173
  files:
174
+ - ".editorconfig"
175
+ - ".github/workflows/codeql-analysis.yml"
176
+ - ".github/workflows/rspec.yml"
177
+ - ".github/workflows/rubocop.yml"
178
+ - ".github/workflows/todo.yml"
179
+ - ".github/workflows/yardoc.yml"
49
180
  - ".gitignore"
50
181
  - ".gitmodules"
51
182
  - ".rspec"
183
+ - ".rubocop.yml"
184
+ - ".ruby-version"
52
185
  - ".travis.yml"
186
+ - ".vscode/settings.json"
187
+ - ".yardopts"
53
188
  - CHANGELOG.md
54
189
  - CODE_OF_CONDUCT.md
55
190
  - Gemfile
56
- - Gemfile.lock
57
191
  - LICENSE.txt
58
192
  - README.md
59
193
  - Rakefile
60
194
  - TAGS
61
195
  - bin/console
62
196
  - bin/regenerate
197
+ - bin/release
63
198
  - bin/setup
64
199
  - fabric-gateway.gemspec
65
200
  - lib/.DS_Store
66
201
  - lib/common/common_pb.rb
67
202
  - lib/common/policies_pb.rb
203
+ - lib/fabric.rb
68
204
  - lib/fabric/.DS_Store
205
+ - lib/fabric/accessors/contract.rb
206
+ - lib/fabric/accessors/gateway.rb
207
+ - lib/fabric/accessors/network.rb
208
+ - lib/fabric/client.rb
209
+ - lib/fabric/constants.rb
210
+ - lib/fabric/contract.rb
211
+ - lib/fabric/ec_crypto_suite.rb
212
+ - lib/fabric/entities/chaincode_events_requests.rb
213
+ - lib/fabric/entities/envelope.rb
214
+ - lib/fabric/entities/identity.rb
215
+ - lib/fabric/entities/proposal.rb
216
+ - lib/fabric/entities/proposed_transaction.rb
217
+ - lib/fabric/entities/status.rb
218
+ - lib/fabric/entities/transaction.rb
69
219
  - lib/fabric/gateway.rb
70
- - lib/fabric/gateway/version.rb
220
+ - lib/fabric/network.rb
221
+ - lib/fabric/version.rb
71
222
  - lib/gateway/gateway_pb.rb
72
223
  - lib/gateway/gateway_services_pb.rb
73
224
  - lib/gossip/message_pb.rb
74
225
  - lib/gossip/message_services_pb.rb
226
+ - lib/msp/identities_pb.rb
75
227
  - lib/msp/msp_principal_pb.rb
76
228
  - lib/orderer/ab_pb.rb
77
229
  - lib/orderer/ab_services_pb.rb
@@ -84,10 +236,7 @@ homepage: https://github.com/ethicalidentity/fabric-gateway-ruby
84
236
  licenses:
85
237
  - MIT
86
238
  metadata:
87
- allowed_push_host: https://rubygems.org
88
- homepage_uri: https://github.com/ethicalidentity/fabric-gateway-ruby
89
- source_code_uri: https://github.com/ethicalidentity/fabric-gateway-ruby
90
- changelog_uri: https://github.com/EthicalIdentity/fabric-gateway-ruby/blob/master/CHANGELOG.md
239
+ rubygems_mfa_required: 'true'
91
240
  post_install_message:
92
241
  rdoc_options: []
93
242
  require_paths:
@@ -96,15 +245,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
245
  requirements:
97
246
  - - ">="
98
247
  - !ruby/object:Gem::Version
99
- version: 2.3.0
248
+ version: 2.6.0
100
249
  required_rubygems_version: !ruby/object:Gem::Requirement
101
250
  requirements:
102
251
  - - ">="
103
252
  - !ruby/object:Gem::Version
104
253
  version: '0'
105
254
  requirements: []
106
- rubygems_version: 3.0.3
255
+ rubygems_version: 3.1.6
107
256
  signing_key:
108
257
  specification_version: 4
109
- summary: Hyperledger Fabric Gateway gRPC SDK
258
+ summary: Hyperledger Fabric Gateway SDK
110
259
  test_files: []
data/Gemfile.lock DELETED
@@ -1,42 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fabric-gateway (0.0.1)
5
- google-protobuf (>= 3.19.1)
6
- grpc (~> 1.42)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.4.4)
12
- google-protobuf (3.19.1)
13
- googleapis-common-protos-types (1.3.0)
14
- google-protobuf (~> 3.14)
15
- grpc (1.42.0)
16
- google-protobuf (~> 3.18)
17
- googleapis-common-protos-types (~> 1.0)
18
- rake (12.3.2)
19
- rspec (3.10.0)
20
- rspec-core (~> 3.10.0)
21
- rspec-expectations (~> 3.10.0)
22
- rspec-mocks (~> 3.10.0)
23
- rspec-core (3.10.1)
24
- rspec-support (~> 3.10.0)
25
- rspec-expectations (3.10.1)
26
- diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.10.0)
28
- rspec-mocks (3.10.2)
29
- diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.10.0)
31
- rspec-support (3.10.3)
32
-
33
- PLATFORMS
34
- ruby
35
-
36
- DEPENDENCIES
37
- fabric-gateway!
38
- rake (~> 12.0)
39
- rspec (~> 3.0)
40
-
41
- BUNDLED WITH
42
- 2.1.4
@@ -1,5 +0,0 @@
1
- module Fabric
2
- module Gateway
3
- VERSION = "0.0.2"
4
- end
5
- end