bitcoinrb-grpc 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 789a4d81089796944c4dc9b383516eb33068e21028531e371f3b79ec318ea7a3
4
- data.tar.gz: 91d513d7059a580d1f37a6467097992c0b4ae7ccff8864081e2fbe13edfa4ea6
3
+ metadata.gz: 2f7e6f764cbbfd51ed4f6a98ff9f0466bed57257420683babbc400ca0cac4c79
4
+ data.tar.gz: 2e34dfe009279d0b0e75aa38fa8de9541990280438671010c4aee78e8d117709
5
5
  SHA512:
6
- metadata.gz: 3e05de2b0249fe8eadbf253b25a90c20a1c0bc18524aacf9dde5aa5c81f8dee9f100328c1a6b5899f3f71c2b0e4766b273783d4bf7a163e01fc0af475f269896
7
- data.tar.gz: 7acbeb19cef64a31549ece381a031e556cb2b9ca37dca88e202a0e4a47afad7483ee2007dc3275ab7bd52d7cc9a516d59a350f560e6a01aa066ec8ac3a6e6e59
6
+ metadata.gz: 21ca38a506f519362795143e2a455a0107c11fca9d6ec7f1755f9ad346da6edd311716bc642af0ff0a1a44f685474edb560d3e58eec5dd2d343ee3a316a6fb0e
7
+ data.tar.gz: 9531c54501014015b9c2cacf59bd87bf19d796697791a3e930fa0ae13c86f43f4873f8e9c118aa953ef1bd36225554710661f21e202088c0b0d237bb2b61a701
data/config.yml ADDED
@@ -0,0 +1,4 @@
1
+ open_assets_explorer:
2
+ url: http://localhost:3000/tx/
3
+ #url: https://www.oaexplorer.com/tx/ # mainnet
4
+ #url: http://localhost:3000/tx/ # testnet
@@ -14,15 +14,17 @@ module Bitcoin
14
14
  end
15
15
 
16
16
  def self.oae_url
17
- case
18
- when Bitcoin.chain_params.mainnet?
19
- 'https://www.oaexplorer.com/tx/'
20
- when Bitcoin.chain_params.testnet?
21
- 'https://testnet.oaexplorer.com/tx/'
22
- when Bitcoin.chain_params.regtest?
23
- 'http://localhost:9292/tx/'
24
- end
17
+ @@config ||= load_config
18
+ @@config['url']
19
+ end
20
+
21
+ def self.load_config
22
+ file = 'config.yml'
23
+ yml = YAML.load_file(file)
24
+ config = yml['open_assets_explorer']
25
+ raise "config.yml should contain 'open_assets_explorer' section." unless config
26
+ config
25
27
  end
26
28
  end
27
29
  end
28
- end
30
+ end
@@ -22,10 +22,10 @@ module Bitcoin
22
22
  def watch_tx_confirmed(request, call)
23
23
  logger.info("watch_tx_confirmed: #{request}")
24
24
  utxo_handler << request
25
- channel = Concurrent::Channel.new(capacity: 100)
26
- Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventTxConfirmed])
27
- ResponseEnum.new(request, channel, WatchTxConfirmedResponseBuilder).each
25
+ response = []
26
+ Receiver.spawn(:receiver, request, response, publisher, [Bitcoin::Grpc::EventTxConfirmed])
28
27
  logger.info("watch_tx_confirmed: end")
28
+ ResponseEnum.new(request, response, WatchTxConfirmedResponseBuilder).each
29
29
  rescue => e
30
30
  logger.info("watch_tx_confirmed: #{e.message}")
31
31
  logger.info("watch_tx_confirmed: #{e.backtrace}")
@@ -34,10 +34,10 @@ module Bitcoin
34
34
  def watch_utxo(request, call)
35
35
  logger.info("watch_utxo: #{request}")
36
36
  utxo_handler << request
37
- channel = Concurrent::Channel.new(capacity: 100)
38
- Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventUtxoRegistered, Bitcoin::Grpc::EventUtxoSpent])
39
- ResponseEnum.new(request, channel, WatchUtxoResponseBuilder).each
37
+ response = []
38
+ Receiver.spawn(:receiver, request, response, publisher, [Bitcoin::Grpc::EventUtxoRegistered, Bitcoin::Grpc::EventUtxoSpent])
40
39
  logger.info("watch_utxo: end")
40
+ ResponseEnum.new(request, response, WatchUtxoResponseBuilder).each
41
41
  rescue => e
42
42
  logger.info("watch_utxo: #{e.message}")
43
43
  logger.info("watch_utxo: #{e.backtrace}")
@@ -46,10 +46,10 @@ module Bitcoin
46
46
  def watch_token(request, call)
47
47
  logger.info("watch_token: #{request}")
48
48
  utxo_handler << request
49
- channel = Concurrent::Channel.new(capacity: 100)
50
- Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventTokenIssued, Bitcoin::Grpc::EventTokenTransfered])
51
- ResponseEnum.new(request, channel, WatchTokenResponseBuilder).each
49
+ response = []
50
+ Receiver.spawn(:receiver, request, response, publisher, [Bitcoin::Grpc::EventTokenIssued, Bitcoin::Grpc::EventTokenTransfered])
52
51
  logger.info("watch_token: end")
52
+ ResponseEnum.new(request, response, WatchTokenResponseBuilder).each
53
53
  rescue => e
54
54
  logger.info("watch_token: #{e.message}")
55
55
  logger.info("watch_token: #{e.backtrace}")
@@ -92,39 +92,40 @@ module Bitcoin
92
92
  class Receiver < Concurrent::Actor::Context
93
93
  include Concurrent::Concern::Logging
94
94
 
95
- attr_reader :channel, :request
95
+ attr_reader :request, :response
96
96
 
97
- def initialize(channel, request, publisher, classes)
98
- @channel = channel
97
+ def initialize(request, response, publisher, classes)
99
98
  @request = request
99
+ @response = response
100
100
  classes.each {|c| publisher << [:subscribe, c] }
101
101
  end
102
102
  def on_message(message)
103
- log(::Logger::DEBUG, "Receiver#on_message:#{message}")
104
103
  if request.id == message.request_id
105
104
  log(::Logger::DEBUG, "Receiver#on_message:#{message}")
106
- channel << message
105
+ response << message
107
106
  end
108
107
  end
109
108
  end
110
109
 
111
110
  class ResponseEnum
112
- attr_reader :req, :channel, :wrapper_classs, :logger
111
+ attr_reader :req, :response, :wrapper_classs, :logger
113
112
 
114
- def initialize(req, channel, wrapper_classs)
113
+ def initialize(req, response, wrapper_classs)
115
114
  @req = req
116
- @channel = channel
115
+ @response = response
117
116
  @wrapper_classs = wrapper_classs
118
117
  @logger = Bitcoin::Logger.create(:debug)
119
118
  end
120
119
 
121
120
  def each
122
- logger.info("ResponseEnum#each")
123
121
  return enum_for(:each) unless block_given?
124
122
  loop do
125
- event = channel.take
126
- channel.close
127
- yield wrapper_classs.build(event.request_id, event)
123
+ event = response.first
124
+ if event
125
+ yield wrapper_classs.build(event.request_id, event)
126
+ else
127
+ sleep(1)
128
+ end
128
129
  end
129
130
  end
130
131
  end
@@ -1,5 +1,5 @@
1
1
  module Bitcoin
2
2
  module Grpc
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoinrb-grpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hajime Yamaguchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,6 +168,7 @@ files:
168
168
  - bin/console
169
169
  - bin/setup
170
170
  - bitcoinrb-grpc.gemspec
171
+ - config.yml
171
172
  - lib/bitcoin/grpc.rb
172
173
  - lib/bitcoin/grpc/grpc_pb.rb
173
174
  - lib/bitcoin/grpc/grpc_services_pb.rb