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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26b462c9b71e8dc9e2926e0c24b7b626cb40e13358fb36418d3ce121692aa579
4
- data.tar.gz: aff70180d2bdb947f0107cb3627fb7b95a4bde69068a8dc91acabb742dc78604
3
+ metadata.gz: a5f0568b7e6de9981790fc25887fb4b063d2a2b4b4013b3762f0ae5cb5255aaf
4
+ data.tar.gz: 88c6ba3db543a3c1bc0a138e7e40325a1cdfd680bd6bcb39c907ba7aa848f6b1
5
5
  SHA512:
6
- metadata.gz: fb8ad49f7dd5e04c6b4c125fdb19e7b61927c0f622770c85added66ccd4cbcbea36df5a7922de0a0f8fbb1c73b31ebae31ed160e500a8fd601a085c2f2444168
7
- data.tar.gz: 9cf3a1b4f2ce340052a31fcfc00f622326f885f833b0b158c5f4d2fc64a85557848c6573f47ce7690369d74d6ef8cc6521992ebe4f47b46bdfb2c8184d94d8ac
6
+ metadata.gz: a51e59cdc705fd1891221933f0ee146f685d64602fe75ef0ae71a125eb14023b927f5b86990225369b115bf3f96fc5d9d2aa851c52492dc4a7211a7f6f3cba88
7
+ data.tar.gz: 926eafcb4b4c5047099cffca1d4ca9d1d2ea2a761e352e8300b08ae7c01f7c7340940b613096562e77f1448e7599c87a5f84ea55dad5779eded99c374dfd7246
data/.editorconfig ADDED
@@ -0,0 +1,3 @@
1
+ indent_style = space
2
+ indent_size = 2
3
+ root = true
@@ -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,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: RSpec Tests
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7', '3.0']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake
36
+ env:
37
+ CODECOV_TOKEN: 4b75ccca-3149-4610-99fb-3a5aeff4ff00
@@ -0,0 +1,28 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ lint:
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 }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
20
+ restore-keys: |
21
+ ${{ runner.os }}-rubocop-
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 RuboCop
28
+ run: bundle exec rubocop --parallel
@@ -0,0 +1,10 @@
1
+ name: "TODO to Github Issues"
2
+ on: ["pull_request"]
3
+ jobs:
4
+ build:
5
+ runs-on: "ubuntu-latest"
6
+ steps:
7
+ - uses: "actions/checkout@master"
8
+ - name: "TODO to Issue"
9
+ uses: "alstr/todo-to-issue-action@v4.5"
10
+ id: "todo"
@@ -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/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - '*.gemspec'
7
+ - 'spec/**/*_spec.rb'
8
+ - spec/factories.rb
9
+
10
+ AllCops:
11
+ NewCops: enable
12
+ TargetRubyVersion: 2.6
13
+ Exclude:
14
+ - vendor/bundle/**/*
15
+ # exclude protoc generated code
16
+ - 'lib/gateway/*'
17
+ - 'lib/common/*'
18
+ - 'lib/gossip/*'
19
+ - 'lib/msp/*'
20
+ - 'lib/orderer/*'
21
+ - 'lib/peer/*'
22
+
23
+
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.7.5
@@ -0,0 +1,7 @@
1
+ {
2
+ "[ruby]": {
3
+ "editor.formatOnSave": true,
4
+ "editor.defaultFormatter": "misogi.ruby-rubocop"
5
+ },
6
+ "editor.formatOnSave": true
7
+ }
data/.yardopts ADDED
@@ -0,0 +1,8 @@
1
+ --exclude lib/gateway
2
+ --exclude lib/msp
3
+ --exclude lib/gossip
4
+ --exclude lib/orderer
5
+ --exclude lib/peer
6
+ --exclude lib/common
7
+ --markup-provider=redcarpet
8
+ --markup=markdown
data/CODE_OF_CONDUCT.md CHANGED
@@ -2,73 +2,132 @@
2
2
 
3
3
  ## Our Pledge
4
4
 
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
11
14
 
12
15
  ## Our Standards
13
16
 
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
16
19
 
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
22
27
 
23
- Examples of unacceptable behavior by participants include:
28
+ Examples of unacceptable behavior include:
24
29
 
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
28
33
  * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
31
36
  * Other conduct which could reasonably be considered inappropriate in a
32
37
  professional setting
33
38
 
34
- ## Our Responsibilities
39
+ ## Enforcement Responsibilities
35
40
 
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
39
45
 
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
45
50
 
46
51
  ## Scope
47
52
 
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
54
58
 
55
59
  ## Enforcement
56
60
 
57
61
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at jonathan.chan@ethicalidentity.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
62
+ reported to the community leaders responsible for enforcement at
63
+ oss@ethicalidentity.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
63
87
 
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
67
114
 
68
115
  ## Attribution
69
116
 
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [https://contributor-covenant.org/version/1/4][version]
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
72
133
 
73
- [homepage]: https://contributor-covenant.org
74
- [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in fabric-gateway.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
+ gem 'rake', '~> 12.3.3'
9
+ gem 'rspec', '~> 3.0'
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 TODO: Write your name
3
+ Copyright (c) 2021 The Ethical Identity Company
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Fabric::Gateway
2
2
 
3
- Hyperledger Fabric Gateway gRPC SDK generated directly from protos found at: https://github.com/hyperledger/fabric-protos.
3
+ [![Rspec Tests](https://github.com/EthicalIdentity/fabric-gateway-ruby/actions/workflows/rspec.yml/badge.svg)](https://github.com/EthicalIdentity/fabric-gateway-ruby/actions/workflows/rspec.yml?query=branch%3Amaster) [![codecov](https://codecov.io/gh/EthicalIdentity/fabric-gateway-ruby/branch/master/graph/badge.svg?token=AXHQEN0R2R)](https://codecov.io/gh/EthicalIdentity/fabric-gateway-ruby) [![Maintainability](https://api.codeclimate.com/v1/badges/84bab9bb5911d3564df6/maintainability)](https://codeclimate.com/github/EthicalIdentity/fabric-gateway-ruby/maintainability) [![Gem](https://img.shields.io/gem/v/fabric-gateway)](https://rubygems.org/gems/fabric-gateway) [![Downloads](https://img.shields.io/gem/dt/fabric-gateway)](https://rubygems.org/gems/fabric-gateway) [![GitHub license](https://img.shields.io/github/license/EthicalIdentity/fabric-gateway-ruby)](https://github.com/EthicalIdentity/fabric-gateway-ruby/blob/master/LICENSE.txt)
4
+
5
+
6
+
7
+ [Hyperledger Fabric Gateway SDK](https://hyperledger-fabric.readthedocs.io/en/latest/gateway.html) ported to idiomatic ruby.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,22 +22,100 @@ Or install it yourself as:
18
22
 
19
23
  $ gem install fabric-gateway
20
24
 
21
- ## Usage
25
+ ### ISSUES
22
26
 
23
- This is a pre-alpha library. None of the code has been tested or confirmed working yet.
27
+ Note, there is an issue with the grpc library for MacOS (https://github.com/grpc/grpc/issues/28271). It results in a segfault in ruby when trying to make a connection.
24
28
 
29
+ Workaround: Either run on linux or use a docker container as a workaround.
25
30
 
26
- non-working notes...
31
+ Will update to new version of grpc when fix is released.
27
32
 
28
- ```
29
- $ bin/console
33
+ ## Usage
30
34
 
31
- # how in the world do we grab a certificate and connect to the peer properly?
32
- stub=Gateway::Gateway::Stub.new('localhost:7051', :this_channel_is_insecure)
33
- stub.submit(Gateway::SubmitRequest.new(transaction_id: "123", channel_id: "2", prepared_transaction: Common::Envelope.new()))
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.
34
36
 
37
+ ```ruby
38
+ $ bin/console
39
+
40
+ # for running in application or script; not needed from bin/console
41
+ require 'fabric'
42
+
43
+ def load_certs
44
+ data_dir ='/your/certs/directory' # aka test-network/organizations
45
+ files = [
46
+ 'peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem',
47
+ 'peerOrganizations/org1.example.com/users/Admin\@org1.example.com/msp/keystore/9f7c67dd4dd6562d258593c0d5011a3bff9121e65e67ff7fd3212919ae400a88_sk',
48
+ 'peerOrganizations/org1.example.com/users/Admin\@org1.example.com/msp/signcerts/cert.pem'
49
+ ]
50
+ files.map { |f| File.open(File.join(data_dir, f)).read }
51
+ end
52
+
53
+ # needed if you are connecting via a different dns name or IP address
54
+ client_opts = {
55
+ channel_args: {
56
+ GRPC::Core::Channel::SSL_TARGET => 'peer0.org1.example.com'
57
+ }
58
+ }
59
+ # optional, if you want to set deadlines to the individual calls (in seconds)
60
+ default_call_options = {
61
+ endorse_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
62
+ evaluate_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
63
+ submit_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
64
+ commit_status_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(5) },
65
+ chaincode_events_options: { deadline: GRPC::Core::TimeConsts.from_relative_time(60) }
66
+ }
67
+ creds = GRPC::Core::ChannelCredentials.new(load_certs[0])
68
+ client=Fabric::Client.new('localhost:7051', creds, default_call_options: default_call_options, **client_opts)
69
+
70
+ identity = Fabric::Gateway::Identity.new(
71
+ {
72
+ msp_id: 'Org1MSP',
73
+ private_key: Fabric::Gateway.crypto_suite.key_from_pem(load_certs[1]),
74
+ pem_certificate: load_certs[2],
75
+ }
76
+ )
77
+
78
+ gateway = identity.new_gateway(client)
79
+ network = gateway.new_network('my_channel')
80
+ contract = network.new_contract('basic')
81
+
82
+ # Evaluate
83
+ puts contract.evaluate_transaction('GetAllAssets')
84
+
85
+ # Submit
86
+ puts contract.submit_transaction('CreateAsset', ['asset13', 'yellow', '5', 'Tom', '1300'])
87
+ puts contract.submit_transaction('UpdateAsset', %w[asset999 yellow 5 Tom 5555])
88
+
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
110
+
111
+ sleep 1
112
+ op.status
113
+ op.cancelled?
114
+ op.cancel
35
115
  ```
36
116
 
117
+ Please refer to the [full reference documentation](https://rubydoc.info/github/EthicalIdentity/fabric-gateway-ruby) for complete usage information.
118
+
37
119
  ## Development
38
120
 
39
121
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -46,6 +128,17 @@ To rebuild the proto code, run the regenerate script:
46
128
  $ bin/regenerate
47
129
  ```
48
130
 
131
+ Effort has been made to follow the design patterns and naming convention where possible from the official [Hyperledger Fabric Gateway SDK](https://github.com/hyperledger/fabric-gateway) while at the same time producing an idiomatic ruby gem. Our intention is to produce a gem that would be compatible with the documentation of the official SDK while natural to use for a seasoned ruby developer.
132
+
133
+ ## Development References & Resources
134
+
135
+ These are the libraries and knowledge necessary for developing this gem:
136
+
137
+ * gRPC - [gRPC Intro](https://grpc.io/docs/what-is-grpc/introduction/) / [gRPC on ruby](https://grpc.io/docs/languages/ruby/)
138
+ * Protocol Buffers (Protobuf) - [overview](https://developers.google.com/protocol-buffers/docs/proto3) / [ruby reference](https://developers.google.com/protocol-buffers/docs/reference/ruby-generated)
139
+ * [Hyperledger Fabric Protocol Specifications](https://openblockchain.readthedocs.io/en/latest/protocol-spec/)
140
+ * [Hyperledger Fabric Gateway Overview](https://hyperledger-fabric.readthedocs.io/en/latest/gateway.html) / [Fabric Gateway RFC](https://hyperledger.github.io/fabric-rfcs/text/0000-fabric-gateway.html)
141
+
49
142
  ## Contributing
50
143
 
51
144
  Bug reports and pull requests are welcome on GitHub at https://github.com/ethicalidentity/fabric-gateway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ethicalidentity/fabric-gateway/blob/master/CODE_OF_CONDUCT.md).
@@ -56,15 +149,33 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ethica
56
149
 
57
150
  - [x] Add license
58
151
  - [x] Add ChangeLog
59
- - [ ] Create Gem
60
- - [ ] Add usage instructions
61
- - [ ] Add testing?
152
+ - [x] Create Gem
153
+ - [x] Add testing & CI/CD
154
+ - [x] Add rubocop and linting
155
+ - [x] Add usage instructions
156
+ - [x] Setup auto-generation of API docs on rubydoc.info
157
+ - [x] Abstract connection and calls such that the protos aren't being interacted directly
158
+ - [x] Implement, Document & Test Evaluate
159
+ - [x] Implement, Document & Test Endorse
160
+ - [x] Implement, Document & Test Submit
161
+ - [x] Implement, Document & Test CommitStatus
162
+ - [x] Implement, Document & Test ChaincodeEvents
163
+ - [ ] Support Submit Async (currently blocks waiting for the transaction to be committed)
164
+ - [ ] Consider adding error handling, invalid transaction proposals will result in random GRPC::FailedPrecondition type errors
165
+ - [ ] Consider adding transaction_id information to Fabric::Errors that are raised; would help a lot for debugging.
166
+ - [ ] Consider adding integration tests against blockchain; might be a ton of stuff to setup
167
+ - [ ] Implement off-line signing - https://github.com/hyperledger/fabric-gateway/blob/1e4a926ddb98ec8ee969da3fc1500642ab389d01/node/src/contract.ts#L63
168
+ - [ ] Support for offline transaction signing (write scenario test for this) - https://github.com/hyperledger/fabric-gateway/blob/cf78fc11a439ced7dfd2f9b55886c55c73119b25/pkg/client/offlinesign_test.go
169
+
170
+
62
171
 
63
172
 
64
173
  ## License
65
174
 
66
175
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
67
176
 
177
+ Portions of the code are from https://github.com/kirshin/hyperledger-fabric-sdk.
178
+
68
179
  ## Code of Conduct
69
180
 
70
181
  Everyone interacting in the Fabric::Gateway project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ethicalidentity/fabric-gateway/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rake/notes/rake_task'
3
6
 
4
7
  RSpec::Core::RakeTask.new(:spec)
5
8
 
6
- task :default => :spec
9
+ task default: :spec