cosmoverse 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +50 -0
  3. data/.tool-versions +1 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Gemfile +13 -0
  7. data/Gemfile.lock +62 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +54 -0
  10. data/Rakefile +16 -0
  11. data/buf.gen.yaml +35 -0
  12. data/buf.yaml +7 -0
  13. data/docker/gaia/Dockerfile +13 -0
  14. data/docker/gaia/wait_for_next_block +10 -0
  15. data/docker-compose.yml +21 -0
  16. data/lib/cosmoverse/cosmos/bank.rb +33 -0
  17. data/lib/cosmoverse/cosmos/client/base.rb +27 -0
  18. data/lib/cosmoverse/cosmos/client/grpc.rb +28 -0
  19. data/lib/cosmoverse/cosmos/client/http.rb +36 -0
  20. data/lib/cosmoverse/cosmos/client.rb +19 -0
  21. data/lib/cosmoverse/cosmos/collectable.rb +50 -0
  22. data/lib/cosmoverse/cosmos/config.rb +26 -0
  23. data/lib/cosmoverse/cosmos/ibc/denom_trace.rb +58 -0
  24. data/lib/cosmoverse/cosmos/tx.rb +85 -0
  25. data/lib/cosmoverse/cosmos.rb +13 -0
  26. data/lib/cosmoverse/proto/amino/amino_pb.rb +20 -0
  27. data/lib/cosmoverse/proto/cosmos/bank/v1beta1/bank_pb.rb +71 -0
  28. data/lib/cosmoverse/proto/cosmos/bank/v1beta1/query_pb.rb +138 -0
  29. data/lib/cosmoverse/proto/cosmos/bank/v1beta1/query_services_pb.rb +89 -0
  30. data/lib/cosmoverse/proto/cosmos/base/abci/v1beta1/abci_pb.rb +108 -0
  31. data/lib/cosmoverse/proto/cosmos/base/query/v1beta1/pagination_pb.rb +39 -0
  32. data/lib/cosmoverse/proto/cosmos/base/v1beta1/coin_pb.rb +46 -0
  33. data/lib/cosmoverse/proto/cosmos/crypto/multisig/v1beta1/multisig_pb.rb +37 -0
  34. data/lib/cosmoverse/proto/cosmos/msg/v1/msg_pb.rb +26 -0
  35. data/lib/cosmoverse/proto/cosmos/query/v1/query_pb.rb +26 -0
  36. data/lib/cosmoverse/proto/cosmos/tx/signing/v1beta1/signing_pb.rb +65 -0
  37. data/lib/cosmoverse/proto/cosmos/tx/v1beta1/service_pb.rb +132 -0
  38. data/lib/cosmoverse/proto/cosmos/tx/v1beta1/service_services_pb.rb +61 -0
  39. data/lib/cosmoverse/proto/cosmos/tx/v1beta1/tx_pb.rb +114 -0
  40. data/lib/cosmoverse/proto/cosmos_proto/cosmos_pb.rb +37 -0
  41. data/lib/cosmoverse/proto/gogoproto/gogo_pb.rb +20 -0
  42. data/lib/cosmoverse/proto/ibc/applications/transfer/v1/query_pb.rb +70 -0
  43. data/lib/cosmoverse/proto/ibc/applications/transfer/v1/query_services_pb.rb +43 -0
  44. data/lib/cosmoverse/proto/ibc/applications/transfer/v1/transfer_pb.rb +34 -0
  45. data/lib/cosmoverse/proto/tendermint/abci/types_pb.rb +370 -0
  46. data/lib/cosmoverse/proto/tendermint/abci/types_services_pb.rb +49 -0
  47. data/lib/cosmoverse/proto/tendermint/crypto/keys_pb.rb +31 -0
  48. data/lib/cosmoverse/proto/tendermint/crypto/proof_pb.rb +52 -0
  49. data/lib/cosmoverse/proto/tendermint/types/block_pb.rb +33 -0
  50. data/lib/cosmoverse/proto/tendermint/types/evidence_pb.rb +54 -0
  51. data/lib/cosmoverse/proto/tendermint/types/params_pb.rb +56 -0
  52. data/lib/cosmoverse/proto/tendermint/types/types_pb.rb +137 -0
  53. data/lib/cosmoverse/proto/tendermint/types/validator_pb.rb +43 -0
  54. data/lib/cosmoverse/proto/tendermint/version/types_pb.rb +34 -0
  55. data/lib/cosmoverse/version.rb +5 -0
  56. data/lib/cosmoverse.rb +13 -0
  57. data/sig/cosmoverse.rbs +4 -0
  58. metadata +118 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c46b63dc4d1b909c43b32972106b85bc91fb7356fcc5a613934b453d39c8fa7
4
+ data.tar.gz: 9b8a7a7858db8dbe436e4b6478fbfb808a1755113a72d316a02721f5e06cc280
5
+ SHA512:
6
+ metadata.gz: 9457064c33424e43850a84448730c3e3006b21f3d146ddf2833fde14c24218af0316027b4bb8958c18698aee59821375f3297ea063cb57681f92c7e39799cc49
7
+ data.tar.gz: 91e42a051eba0904f25e2a225bd3f95c62446db75b1e3aad9fc21eda5e3e9d7411b7ab4975f717527b61e8cf0141e37cbd5d14d5283af876f55fa0cf5242be3c
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.1
7
+ NewCops: enable
8
+
9
+ Style/HashSyntax:
10
+ Exclude:
11
+ - lib/cosmoverse/proto/**/*
12
+
13
+ Style/StringLiterals:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+ Exclude:
17
+ - lib/cosmoverse/proto/**/*
18
+
19
+ Style/StringLiteralsInInterpolation:
20
+ Enabled: true
21
+ EnforcedStyle: double_quotes
22
+
23
+ Layout/LineLength:
24
+ Max: 120
25
+ Exclude:
26
+ - lib/cosmoverse/proto/**/*
27
+
28
+ Metrics/BlockLength:
29
+ Exclude:
30
+ - lib/cosmoverse/proto/**/*
31
+ - lib/cosmoverse/cosmos/gogoproto/**/*
32
+
33
+ Lint/EmptyBlock:
34
+ Exclude:
35
+ - lib/cosmoverse/proto/**/*
36
+
37
+ Metrics/MethodLength:
38
+ Exclude:
39
+ - test/**/*
40
+
41
+ Metrics/AbcSize:
42
+ Exclude:
43
+ - test/**/*
44
+
45
+ Style/Documentation:
46
+ Enabled: false
47
+
48
+ Naming/VariableNumber:
49
+ Exclude:
50
+ - lib/cosmoverse/proto/**/*
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.1.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.1.alpha] - 2023-04-16
4
+
5
+ - Release of alpha test version.
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at post.armin@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in cosmoverse.gemspec
6
+ gemspec
7
+
8
+ gem "byebug"
9
+ gem "minitest"
10
+ gem "rake"
11
+ gem "rubocop"
12
+ gem "rubocop-minitest"
13
+ gem "rubocop-rake"
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cosmoverse (0.1.0)
5
+ grpc
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ byebug (11.1.3)
12
+ google-protobuf (3.21.1-x86_64-darwin)
13
+ google-protobuf (3.21.1-x86_64-linux)
14
+ googleapis-common-protos-types (1.3.1)
15
+ google-protobuf (~> 3.14)
16
+ grpc (1.46.3-x86_64-darwin)
17
+ google-protobuf (~> 3.19)
18
+ googleapis-common-protos-types (~> 1.0)
19
+ grpc (1.46.3-x86_64-linux)
20
+ google-protobuf (~> 3.19)
21
+ googleapis-common-protos-types (~> 1.0)
22
+ minitest (5.16.0)
23
+ parallel (1.22.1)
24
+ parser (3.1.2.0)
25
+ ast (~> 2.4.1)
26
+ rainbow (3.1.1)
27
+ rake (13.0.6)
28
+ regexp_parser (2.5.0)
29
+ rexml (3.2.5)
30
+ rubocop (1.30.1)
31
+ parallel (~> 1.10)
32
+ parser (>= 3.1.0.0)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ regexp_parser (>= 1.8, < 3.0)
35
+ rexml (>= 3.2.5, < 4.0)
36
+ rubocop-ast (>= 1.18.0, < 2.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 3.0)
39
+ rubocop-ast (1.18.0)
40
+ parser (>= 3.1.1.0)
41
+ rubocop-minitest (0.20.1)
42
+ rubocop (>= 0.90, < 2.0)
43
+ rubocop-rake (0.6.0)
44
+ rubocop (~> 1.0)
45
+ ruby-progressbar (1.11.0)
46
+ unicode-display_width (2.1.0)
47
+
48
+ PLATFORMS
49
+ x86_64-darwin-21
50
+ x86_64-linux
51
+
52
+ DEPENDENCIES
53
+ byebug
54
+ cosmoverse!
55
+ minitest
56
+ rake
57
+ rubocop
58
+ rubocop-minitest
59
+ rubocop-rake
60
+
61
+ BUNDLED WITH
62
+ 2.3.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Armin Kirchner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Cosmoverse
2
+
3
+ The Cosmoverse GEM tries to make it easy to request data directly from the Cosmos blockchains. Cosmovers attempt to wrap complex blockchain data types in an easy-to-understand structure.
4
+
5
+ This project is in a very early stage and will most likely change dramatically.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add cosmoverse
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install cosmoverse
16
+
17
+ ## Usage
18
+
19
+ ### Example: Getting all balanced for an account.
20
+
21
+ ```
22
+ # Query default tendermint endpoint (https://rpc.cosmos.network)
23
+ Cosmoverse::Cosmos.all_balances 'cosmos111111111111111111111111111111111111111'
24
+
25
+ # Query local tendermint JSON::RPC host
26
+ Cosmoverse::Cosmos.all_balances 'cosmos111111111111111111111111111111111111111', tendermint_rpc_host: 'http://localhost:26657'
27
+
28
+ # Query local gRPC host
29
+ Cosmoverse::Cosmos.all_balances 'cosmos111111111111111111111111111111111111111', tendermint_rpc_host: 'localhost:9090'
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `docker-compose up -d` and `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ### Generate from cosmos protos
39
+
40
+ ```
41
+ bin/generate_protos
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cosmoverse. 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/[USERNAME]/cosmoverse/blob/master/CODE_OF_CONDUCT.md).
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the Cosmoverse project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cosmoverse/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/buf.gen.yaml ADDED
@@ -0,0 +1,35 @@
1
+ version: v1
2
+ managed:
3
+ enabled: true
4
+ override:
5
+ RUBY_PACKAGE:
6
+ amino/amino.proto: Cosmoverse::Proto::Amino
7
+ cosmos/bank/v1beta1/bank.proto: Cosmoverse::Proto::Cosmos::Bank::V1beta1::Bank
8
+ cosmos/bank/v1beta1/query.proto: Cosmoverse::Proto::Cosmos::Bank::V1beta1::Query
9
+ cosmos/base/query/v1beta1/pagination.proto: Cosmoverse::Proto::Cosmos::Base::Query::V1beta1::Pagination
10
+ cosmos/base/v1beta1/coin.proto: Cosmoverse::Proto::Cosmos::Base::V1beta1::Coin
11
+ cosmos/msg/v1/msg.proto: Cosmoverse::Proto::Cosmos::Msg::V1::Msg
12
+ cosmos/query/v1/query.proto: Cosmoverse::Proto::Cosmos::Query::V1::Query
13
+ cosmos/tx/v1beta1/service.proto: Cosmoverse::Proto::Cosmos::Tx::V1beta1::Service
14
+ cosmos/tx/v1beta1/tx.proto: Cosmoverse::Proto::Cosmos::Tx::V1beta1::Tx
15
+ cosmos/tx/signing/v1beta1/signing.proto: Cosmoverse::Proto::Cosmos::Tx::Signing::V1beta1::Signing
16
+ cosmos/base/abci/v1beta1/abci.proto: Cosmoverse::Proto::Cosmos::Base::Abci::V1beta1::Abci
17
+ cosmos/crypto/multisig/v1beta1/multisig.proto: Cosmoverse::Proto::Cosmos::Crypto::Multisig::V1beta1::Multisig
18
+ tendermint/abci/types.proto: Cosmoverse::Proto::Tendermint::Abci::Types
19
+ tendermint/crypto/proof.proto: Cosmoverse::Proto::Tendermint::Crypto::Proof
20
+ tendermint/crypto/keys.proto: Cosmoverse::Proto::Tendermint::Crypto::Keys
21
+ tendermint/types/types.proto: Cosmoverse::Proto::Tendermint::Types::Types
22
+ tendermint/types/params.proto: Cosmoverse::Proto::Tendermint::Types::Params
23
+ tendermint/types/validator.proto: Cosmoverse::Proto::Tendermint::Types::Validator
24
+ tendermint/types/block.proto: Cosmoverse::Proto::Tendermint::Types::Block
25
+ tendermint/types/evidence.proto: Cosmoverse::Proto::Tendermint::Types::Evidence
26
+ tendermint/version/types.proto: Cosmoverse::Proto::Tendermint::Version::Types
27
+ gogoproto/gogo.proto: Cosmoverse::Proto::Gogoproto
28
+ cosmos_proto/cosmos.proto: Cosmoverse::Proto::CosmosProto
29
+ ibc/applications/transfer/v1/query.proto: Cosmoverse::Proto::Ibc::Applications::Transfer::V1
30
+ ibc/applications/transfer/v1/transfer.proto: Cosmoverse::Proto::Ibc::Applications::Transfer::V1
31
+ plugins:
32
+ - remote: buf.build/protocolbuffers/plugins/ruby
33
+ out: lib/cosmoverse/proto
34
+ - remote: buf.build/grpc/plugins/ruby
35
+ out: lib/cosmoverse/proto
data/buf.yaml ADDED
@@ -0,0 +1,7 @@
1
+ version: v1
2
+ lint:
3
+ use:
4
+ - DEFAULT
5
+ breaking:
6
+ use:
7
+ - FILE
@@ -0,0 +1,13 @@
1
+ FROM golang:1.18-alpine3.16
2
+
3
+ WORKDIR /usr/src/app
4
+
5
+ RUN apk add git make gcc musl-dev linux-headers jq
6
+ RUN git clone -b v7.0.2 https://github.com/cosmos/gaia \
7
+ && cd gaia \
8
+ && make install \
9
+ && cd .. \
10
+ && rm -Rf gaia
11
+
12
+ COPY ./wait_for_next_block /bin/
13
+ RUN chmod +x /bin/wait_for_next_block
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ CURRENT_HEIGHT="$( gaiad query block | jq '.block.header.height' )"
6
+
7
+ while [ "$CURRENT_HEIGHT" == "$( gaiad query block | jq '.block.header.height' )" ]; do
8
+ echo '... waiting for next block'
9
+ sleep 1
10
+ done
@@ -0,0 +1,21 @@
1
+ version: '3'
2
+ services:
3
+ gaia:
4
+ build:
5
+ context: docker/gaia/.
6
+ ports:
7
+ - "26656:26656"
8
+ - "26657:26657"
9
+ - "1317:1317"
10
+ - "9090:9090"
11
+ - "9091:9091"
12
+ command:
13
+ - sh
14
+ - -c
15
+ - |
16
+ gaiad init tester --chain-id testhub
17
+ echo 'luggage rotate orient usage program cloud armed warrior rich erase acquire remember' | gaiad keys add tester --recover --keyring-backend test
18
+ gaiad add-genesis-account cosmos14eadktsf4zzah6har7h7a46tunnj7rq7lmppy5 10000000000stake,1000000000000uatom
19
+ gaiad gentx tester 10000000000stake --chain-id testhub --keyring-backend test
20
+ gaiad collect-gentxs
21
+ gaiad start --rpc.laddr tcp://0.0.0.0:26657
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cosmoverse/proto/cosmos/bank/v1beta1/query_services_pb"
4
+
5
+ module Cosmoverse
6
+ module Cosmos
7
+ module Bank
8
+ RequestParamter = Struct.new("RequestParamter", :request, :request_method) do
9
+ def service_class
10
+ Cosmoverse::Proto::Cosmos::Bank::V1beta1::Query::Query::Service
11
+ end
12
+ end
13
+
14
+ def self.all_balances(address)
15
+ request = Cosmoverse::Proto::Cosmos::Bank::V1beta1::Query::QueryAllBalancesRequest.new(address:)
16
+ request_param = RequestParamter.new(request, :all_balances)
17
+ Cosmoverse::Cosmos::Client.call(request_param)
18
+ end
19
+
20
+ def self.total_supply
21
+ request = Cosmoverse::Proto::Cosmos::Bank::V1beta1::Query::QueryTotalSupplyRequest.new
22
+ request_param = RequestParamter.new(request, :total_supply)
23
+ Cosmoverse::Cosmos::Client.call(request_param)
24
+ end
25
+
26
+ def self.denoms_metadata
27
+ request = Cosmoverse::Proto::Cosmos::Bank::V1beta1::Query::QueryDenomsMetadataRequest.new
28
+ request_param = RequestParamter.new(request, :denoms_metadata)
29
+ Cosmoverse::Cosmos::Client.call(request_param)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cosmoverse
4
+ module Cosmos
5
+ module Client
6
+ class Base
7
+ def self.call(request_param)
8
+ new(request_param).call
9
+ end
10
+
11
+ def initialize(request_param)
12
+ @request = request_param.request
13
+ @service_class = request_param.service_class
14
+ @request_method = request_param.request_method
15
+ end
16
+
17
+ private
18
+
19
+ def response_class
20
+ Object.const_get(request.class.name.sub(/Request\z/, "Response"))
21
+ end
22
+
23
+ attr_reader :request, :service_class, :request_method
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cosmoverse
4
+ module Cosmos
5
+ module Client
6
+ class Grpc < Base
7
+ def call
8
+ stub.public_send(request_method, request)
9
+ end
10
+
11
+ private
12
+
13
+ def stub
14
+ stub_class.new(
15
+ "#{Cosmoverse::Cosmos.config.grpc_host}:#{Cosmoverse::Cosmos.config.grpc_port}",
16
+ :this_channel_is_insecure
17
+ )
18
+ end
19
+
20
+ def stub_class
21
+ *names, _ = service_class.name.split("::")
22
+
23
+ Object.const_get("#{names.join("::")}::Stub")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cosmoverse
4
+ module Cosmos
5
+ module Client
6
+ class Http < Base
7
+ def call
8
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: ssl?) { |http| http.request(http_request) }
9
+ rpc_response = JSON.parse(response.body)
10
+ value = Base64.decode64(rpc_response.fetch("result").fetch("response").fetch("value"))
11
+ response_class.decode(value)
12
+ end
13
+
14
+ private
15
+
16
+ def ssl? = uri.scheme == "https"
17
+
18
+ def uri = URI(Cosmoverse::Cosmos.config.tendermint_host)
19
+
20
+ def path = "/#{service_class.service_name}/#{capitalized_request_method}"
21
+
22
+ def capitalized_request_method = request_method.to_s.split("_").map(&:capitalize).join
23
+
24
+ def http_request
25
+ Net::HTTP::Post.new(uri, "Content-Type" => "application/json").tap do |post|
26
+ post.body = json_rpc_params.to_json
27
+ end
28
+ end
29
+
30
+ def json_rpc_params = { id: -1, jsonrpc: "2.0", method: "abci_query", params: }
31
+
32
+ def params = { path:, data: request.to_proto.unpack1("H*") }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cosmoverse/cosmos/client/base"
4
+ require "cosmoverse/cosmos/client/grpc"
5
+ require "cosmoverse/cosmos/client/http"
6
+
7
+ module Cosmoverse
8
+ module Cosmos
9
+ module Client
10
+ class << self
11
+ def call(request_param)
12
+ client_class_name = Cosmoverse::Cosmos.config.mode.to_s.capitalize
13
+
14
+ Object.const_get("Cosmoverse::Cosmos::Client::#{client_class_name}").call(request_param)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cosmoverse
4
+ module Cosmos
5
+ module Collectable
6
+ module Loadable
7
+ def get(request_parameter, limit: 0, offset: 0)
8
+ request_parameter.request.pagination =
9
+ Cosmoverse::Proto::Cosmos::Base::Query::V1beta1::Pagination::PageRequest.new(limit:, offset:)
10
+ response = Cosmoverse::Cosmos::Client.call(request_parameter)
11
+ new(request_parameter:, response:)
12
+ end
13
+ end
14
+
15
+ include Enumerable
16
+
17
+ def initialize(request_parameter:, response:)
18
+ @request_parameter = request_parameter
19
+ @response = response
20
+ end
21
+
22
+ def each(&)
23
+ if block_given?
24
+ records.each(&)
25
+ else
26
+ to_enum(:each)
27
+ end
28
+ end
29
+
30
+ def limit = request_parameter.request.pagination.limit
31
+ def offset = request_parameter.request.pagination.offset
32
+ def total = response.pagination.total
33
+ def next_offset = offset + records.count
34
+ def next_page? = next_offset < total
35
+
36
+ def next_page
37
+ return unless next_page?
38
+
39
+ self.class.get(request_parameter, limit:, offset: next_offset)
40
+ end
41
+
42
+ def records
43
+ raise NotImplementedError, "#records has to be implemented"
44
+ end
45
+
46
+ attr_reader :request_parameter, :response
47
+ private :request_parameter, :response, :records
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cosmoverse
4
+ module Cosmos
5
+ class << self
6
+ def configure
7
+ yield config
8
+ end
9
+
10
+ def config
11
+ @config ||= Config.new
12
+ end
13
+ end
14
+
15
+ class Config
16
+ attr_accessor :mode, :tendermint_host, :grpc_host, :grpc_port
17
+
18
+ def initialize
19
+ @mode = :grpc
20
+ @tendermint_host = "http://localhost:26657"
21
+ @grpc_host = "127.0.0.1"
22
+ @grpc_port = "9090"
23
+ end
24
+ end
25
+ end
26
+ end