bitcoinrb-grpc 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c892a34f49745c28f301ca246f810b408047612c795e55544b52bc0e3ad6959
4
+ data.tar.gz: fa59b4f233f20002011dbf51ddee37d785098fda34b217624986376be80c7a0c
5
+ SHA512:
6
+ metadata.gz: 1490e11ae29593cbf7de6818f32ab0e8b26104e9e552313d89e885161d84dbfa8d8749feccc859af8f6ff121b2a55b6fdd25d2a7215e7eded4dba743fee50537
7
+ data.tar.gz: ee3cddb22076018d1f48f204a7b5c63001a235b99e2171084a7c39e36332f381c1ed02987ea39ba63b17830172189edbf51683ae14d67d929e31e65a97aded06
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
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.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
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
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
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
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
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.
39
+
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.
45
+
46
+ ## Scope
47
+
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.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at gen.yamaguchi0@gmail.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.
63
+
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.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bitcoinrb-grpc.gemspec
6
+ gemspec
@@ -0,0 +1,66 @@
1
+ # Bitcoinrb::Grpc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bitcoin/grpc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bitcoinrb-grpc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bitcoinrb-grpc
22
+
23
+ ## Usage
24
+
25
+ ### Server
26
+
27
+ ```
28
+ ./bin/bitcoinrbd start --network=regtest
29
+ ```
30
+
31
+ ### Client
32
+
33
+
34
+ ```ruby
35
+
36
+ stub = Bitcoin::Grpc::Blockchain::Stub.new("localhost:8080",:this_channel_is_insecure)
37
+
38
+ # Watch utxo
39
+ res = stub.watch_utxo(Bitcoin::Grpc::WatchUtxoRequest.new)
40
+ res.each {|r| puts r}
41
+
42
+ # Watch tx
43
+ tx_hash = "0f35034353babea07fd27edee27575a6f88b3786af00e195b4811e512c798171"
44
+ tx_payload = "0200000001427f57d9fb12521da329adbda27af5c03e03810ad476066a7e653a011fdbced7000000004847304402205ad2d520e37ce7a278029042bbad7c25d26addec6978a1db4e233dcb6603891f022013601c5211b836a77b02c630e17fa211e9ab1cc39b1cc003721c41b7a967a84201feffffff0200e1f5050000000016001445fcf49e1a60e8ea9ef774a0bc0839aaecf15fdd242d5a030000000016001425a2bbd8b5e1d90d061b5adbb3db283c39ebc8ab5a130000"
45
+ res = stub.watch_tx_confirmed(Bitcoin::Grpc::WatchTxConfirmedRequest.new(tx_hash:tx_hash, tx_payload: tx_payload, confirmations: 3))
46
+ res.each {|r| puts r}
47
+
48
+ # Watch token (Open Assets)
49
+ res = stub.watch_token(Bitcoin::Grpc::WatchTokenRequest.new(asset_type: ))
50
+ res.each {|r| puts r}
51
+
52
+ ```
53
+
54
+ ## Development
55
+
56
+ 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.
57
+
58
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bitcoinrb-grpc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the Bitcoinrb::Grpc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bitcoinrb-grpc/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'bitcoin'
5
+
6
+
7
+ require 'thor'
8
+ require 'daemon_spawn'
9
+
10
+ class BitcoinDaemon < DaemonSpawn::Base
11
+ def start(args)
12
+ puts "Bitcoinrb daemon start : #{Time.now} #{args}"
13
+ conf = Bitcoin::Node::Configuration.new(network: args.first[:network])
14
+
15
+ require 'bitcoin/grpc'
16
+ require 'extensions/bitcoin/rpc/request_handler'
17
+ require 'extensions/bitcoin/wallet/base'
18
+ require 'extensions/bitcoin/tx'
19
+
20
+ node = Bitcoin::Node::SPV.new(conf)
21
+ Thread.new { Bitcoin::Grpc::Server.run(node) }
22
+ node.run
23
+ end
24
+
25
+ def stop(args)
26
+ puts "Bitcoinrb daemon stop : #{Time.now} #{args}"
27
+ end
28
+ end
29
+
30
+ class Bitcoinrbd < Thor
31
+
32
+ class_option :network, aliases: '-n', default: :mainnet
33
+
34
+ desc 'start', 'start bitcoinrb daemon.'
35
+ def start
36
+ network = options['network'] ? options['network'].to_sym : :mainnet
37
+ Bitcoin.chain_params = network
38
+ FileUtils.mkdir_p(Bitcoin.base_dir)
39
+ execute_daemon(['start', network: network])
40
+ end
41
+
42
+ desc 'stop', 'stop bitcoinrb daemon.'
43
+ def stop
44
+ network = options['network'] ? options['network'].to_sym : :mainnet
45
+ Bitcoin.chain_params = network
46
+ execute_daemon(['stop', network: network])
47
+ end
48
+
49
+ private
50
+
51
+ def execute_daemon(cmd_args)
52
+ BitcoinDaemon.spawn!({working_dir: Bitcoin.base_dir,
53
+ log_file: "#{Bitcoin.base_dir}/log/debug.log",
54
+ pid_file: "#{Bitcoin.base_dir}/bitcoinrbd-grpc.pid",
55
+ sync_log: true,
56
+ singleton: true}, cmd_args)
57
+ end
58
+ end
59
+
60
+ Bitcoinrbd.start(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'bitcoin'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "bitcoin/grpc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitcoinrb-grpc"
8
+ spec.version = Bitcoin::Grpc::VERSION
9
+ spec.authors = ["Hajime Yamaguchi"]
10
+ spec.email = ["gen.yamaguchi0@gmail.com"]
11
+
12
+ spec.summary = ''
13
+ spec.description = ''
14
+ spec.homepage = ''
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency 'grpc'
27
+ spec.add_development_dependency 'grpc-tools'
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+
31
+ spec.add_runtime_dependency 'bitcoinrb'
32
+ spec.add_runtime_dependency 'concurrent-ruby'
33
+ spec.add_runtime_dependency 'concurrent-ruby-edge'
34
+ spec.add_runtime_dependency 'httpclient'
35
+ spec.add_runtime_dependency 'leveldb-ruby'
36
+ end
@@ -0,0 +1,35 @@
1
+ require 'bitcoin'
2
+ require 'bitcoin/grpc/version'
3
+
4
+ require 'concurrent'
5
+ require 'concurrent-edge'
6
+ require 'leveldb'
7
+
8
+ require 'extensions/bitcoin/rpc/request_handler'
9
+ require 'extensions/bitcoin/wallet/base'
10
+ require 'extensions/bitcoin/tx'
11
+
12
+ module Bitcoin
13
+
14
+
15
+ module Grpc
16
+ class Error < StandardError; end
17
+
18
+ require 'bitcoin/grpc/grpc_pb'
19
+ require 'bitcoin/grpc/grpc_services_pb'
20
+
21
+ autoload :OapService, 'bitcoin/grpc/oap_service'
22
+ autoload :Server, 'bitcoin/grpc/server'
23
+ end
24
+
25
+ module Wallet
26
+ autoload :AssetFeature, 'bitcoin/wallet/asset_feature'
27
+ autoload :AssetHandler, 'bitcoin/wallet/asset_handler'
28
+ autoload :Publisher, 'bitcoin/wallet/publisher'
29
+ autoload :Signer, 'bitcoin/wallet/signer'
30
+ autoload :UtxoDB, 'bitcoin/wallet/utxo_db'
31
+ autoload :UtxoHandler, 'bitcoin/wallet/utxo_handler'
32
+ end
33
+ end
34
+
35
+ Concurrent.use_simple_logger Logger::DEBUG
@@ -0,0 +1,99 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: bitcoin/grpc/grpc.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "bitcoin.grpc.WatchTxConfirmedRequest" do
8
+ optional :tx_hash, :string, 1
9
+ optional :confirmations, :uint32, 2
10
+ end
11
+ add_message "bitcoin.grpc.WatchTxConfirmedResponse" do
12
+ oneof :event do
13
+ optional :confirmed, :message, 1, "bitcoin.grpc.EventTxConfirmed"
14
+ end
15
+ end
16
+ add_message "bitcoin.grpc.WatchUtxoRequest" do
17
+ end
18
+ add_message "bitcoin.grpc.WatchUtxoResponse" do
19
+ oneof :event do
20
+ optional :registered, :message, 1, "bitcoin.grpc.EventUtxoRegistered"
21
+ optional :spent, :message, 2, "bitcoin.grpc.EventUtxoSpent"
22
+ end
23
+ end
24
+ add_message "bitcoin.grpc.WatchTokenRequest" do
25
+ optional :asset_type, :bytes, 1
26
+ end
27
+ add_message "bitcoin.grpc.WatchTokenResponse" do
28
+ oneof :event do
29
+ optional :issued, :message, 1, "bitcoin.grpc.EventTokenIssued"
30
+ optional :transfered, :message, 2, "bitcoin.grpc.EventTokenTransfered"
31
+ optional :burned, :message, 3, "bitcoin.grpc.EventTokenBurned"
32
+ end
33
+ end
34
+ add_message "bitcoin.grpc.WatchAssetIdAssignedRequest" do
35
+ optional :tx_hash, :string, 1
36
+ optional :tx_payload, :string, 2
37
+ end
38
+ add_message "bitcoin.grpc.EventTxConfirmed" do
39
+ optional :tx_hash, :string, 1
40
+ optional :tx_payload, :string, 2
41
+ optional :block_height, :uint32, 3
42
+ optional :tx_index, :uint32, 4
43
+ optional :confirmations, :uint32, 5
44
+ end
45
+ add_message "bitcoin.grpc.EventUtxoRegistered" do
46
+ optional :tx_hash, :string, 1
47
+ optional :tx_payload, :string, 2
48
+ optional :utxo, :message, 3, "bitcoin.grpc.Utxo"
49
+ end
50
+ add_message "bitcoin.grpc.EventUtxoSpent" do
51
+ optional :tx_hash, :string, 1
52
+ optional :tx_payload, :string, 2
53
+ optional :utxo, :message, 3, "bitcoin.grpc.Utxo"
54
+ end
55
+ add_message "bitcoin.grpc.EventTokenIssued" do
56
+ optional :asset, :message, 1, "bitcoin.grpc.AssetOutput"
57
+ end
58
+ add_message "bitcoin.grpc.EventTokenTransfered" do
59
+ optional :asset, :message, 2, "bitcoin.grpc.AssetOutput"
60
+ end
61
+ add_message "bitcoin.grpc.EventTokenBurned" do
62
+ optional :asset, :message, 3, "bitcoin.grpc.AssetOutput"
63
+ end
64
+ add_message "bitcoin.grpc.Utxo" do
65
+ optional :tx_hash, :string, 1
66
+ optional :index, :uint32, 2
67
+ optional :block_height, :uint32, 3
68
+ optional :value, :uint64, 4
69
+ optional :script_pubkey, :string, 5
70
+ end
71
+ add_message "bitcoin.grpc.AssetOutput" do
72
+ optional :asset_type, :bytes, 1
73
+ optional :asset_id, :string, 2
74
+ optional :asset_quantity, :uint64, 3
75
+ optional :tx_hash, :string, 4
76
+ optional :index, :uint32, 5
77
+ optional :block_height, :uint32, 6
78
+ end
79
+ end
80
+
81
+ module Bitcoin
82
+ module Grpc
83
+ WatchTxConfirmedRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchTxConfirmedRequest").msgclass
84
+ WatchTxConfirmedResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchTxConfirmedResponse").msgclass
85
+ WatchUtxoRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchUtxoRequest").msgclass
86
+ WatchUtxoResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchUtxoResponse").msgclass
87
+ WatchTokenRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchTokenRequest").msgclass
88
+ WatchTokenResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchTokenResponse").msgclass
89
+ WatchAssetIdAssignedRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.WatchAssetIdAssignedRequest").msgclass
90
+ EventTxConfirmed = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventTxConfirmed").msgclass
91
+ EventUtxoRegistered = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventUtxoRegistered").msgclass
92
+ EventUtxoSpent = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventUtxoSpent").msgclass
93
+ EventTokenIssued = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventTokenIssued").msgclass
94
+ EventTokenTransfered = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventTokenTransfered").msgclass
95
+ EventTokenBurned = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventTokenBurned").msgclass
96
+ Utxo = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.Utxo").msgclass
97
+ AssetOutput = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.AssetOutput").msgclass
98
+ end
99
+ end