bitcoinrb-grpc 0.1.5 → 0.1.6

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: e14a674b10187c411a04fffc871add50169f06db7670812c7e8ea81df0208e16
4
- data.tar.gz: 7259ab262c29de7acc1ec01798731635c63247c3faeb69eeee24fe0d37ded098
3
+ metadata.gz: 5fd690cfb65d57221b690f52d81c51f720a587edb44da2974376c9662776cfaf
4
+ data.tar.gz: 7445feccbfac03004e8ed1a6185c127d3ded063562dffdff5864991b7a69201e
5
5
  SHA512:
6
- metadata.gz: 26b335c3419c163165071696690e167d995fc53bac47c52da777180bddb48e80bff831d39f9bdc75988aff1c0faaae51f78692252ce51ee31737cb63581de665
7
- data.tar.gz: c01904de80b687ccb4460e362b83edd10cfcf939dcaf716e6c9b34f6a3756b82ae23ebb177e005404d37edd78bcdbbb95d626ce4bdc48b851770dc9e50ee09fc
6
+ metadata.gz: 4c43a439477b4002c0c6bd6d2dea4f572a7a2556bb205ff4db066fcd77b95617354e87c538c6a5234094f57b596d5c73f5eb50ac69188a85b39813b2aaa850d9
7
+ data.tar.gz: 50220524bc52b4a4e8d22ef5a253678100850f31a778ad924882e47f38a5379462b7d03c8be1e0750ae3ecaf209956aaf14b4c214d17c4134967e33acfe6ca02
@@ -90,7 +90,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
90
90
  end
91
91
  add_message "bitcoin.grpc.WatchTokenRequest" do
92
92
  optional :id, :uint32, 1
93
- optional :asset_type, :bytes, 2
93
+ optional :asset_type, :uint32, 2
94
+ optional :asset_id, :string, 3
94
95
  end
95
96
  add_message "bitcoin.grpc.WatchTokenResponse" do
96
97
  optional :id, :uint32, 1
@@ -158,7 +159,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
158
159
  optional :script_pubkey, :string, 5
159
160
  end
160
161
  add_message "bitcoin.grpc.AssetOutput" do
161
- optional :asset_type, :bytes, 1
162
+ optional :asset_type, :uint32, 1
162
163
  optional :asset_id, :string, 2
163
164
  optional :asset_quantity, :uint64, 3
164
165
  optional :tx_hash, :string, 4
@@ -71,7 +71,7 @@ module Bitcoin
71
71
 
72
72
  def watch_token(request, call)
73
73
  logger.info("watch_token: #{request}")
74
- utxo_handler << request
74
+ asset_handler << request
75
75
  response = []
76
76
  Receiver.spawn(:receiver, request, response, publisher, [Bitcoin::Grpc::EventTokenIssued, Bitcoin::Grpc::EventTokenTransfered])
77
77
  logger.info("watch_token: end")
@@ -1,5 +1,5 @@
1
1
  module Bitcoin
2
2
  module Grpc
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -15,7 +15,7 @@ module Bitcoin
15
15
  logger.info("UtxoDB#save_token:#{[asset_type, asset_id, asset_quantity, utxo.inspect]}")
16
16
  level_db.batch do
17
17
  asset_output = Bitcoin::Grpc::AssetOutput.new(
18
- asset_type: [asset_type].pack('C'),
18
+ asset_type: asset_type,
19
19
  asset_id: asset_id,
20
20
  asset_quantity: asset_quantity,
21
21
  tx_hash: utxo.tx_hash,
@@ -28,6 +28,7 @@ module Bitcoin
28
28
  # out_point
29
29
  key = KEY_PREFIX[:asset_out_point] + out_point.to_payload.bth
30
30
  return if level_db.contains?(key)
31
+
31
32
  level_db.put(key, payload)
32
33
 
33
34
  # script_pubkey
@@ -54,11 +55,11 @@ module Bitcoin
54
55
  level_db.delete(key)
55
56
 
56
57
  if utxo.script_pubkey
57
- key = KEY_PREFIX[:asset_script_pubkey] + asset_output.asset_type.bth + utxo.script_pubkey + out_point.to_payload.bth
58
+ key = KEY_PREFIX[:asset_script_pubkey] + [asset_output.asset_type].pack('C').bth + utxo.script_pubkey + out_point.to_payload.bth
58
59
  level_db.delete(key)
59
60
  end
60
61
 
61
- key = KEY_PREFIX[:asset_height] + asset_output.asset_type.bth + [utxo.block_height].pack('N').bth + out_point.to_payload.bth
62
+ key = KEY_PREFIX[:asset_height] + [asset_output.asset_type].pack('C').bth + [utxo.block_height].pack('N').bth + out_point.to_payload.bth
62
63
  level_db.delete(key)
63
64
  return asset_output
64
65
  end
@@ -3,7 +3,7 @@
3
3
  module Bitcoin
4
4
  module Wallet
5
5
  class AssetHandler < Concurrent::Actor::RestartingContext
6
- attr_reader :utxo_db, :publisher
6
+ attr_reader :utxo_db, :publisher, :watchings
7
7
 
8
8
  def initialize(spv, publisher)
9
9
  publisher << [:subscribe, Bitcoin::Grpc::EventUtxoSpent]
@@ -11,10 +11,13 @@ module Bitcoin
11
11
  @publisher = publisher
12
12
  @utxo_db = spv.wallet.utxo_db
13
13
  @logger = Bitcoin::Logger.create(:debug)
14
+ @watchings = []
14
15
  end
15
16
 
16
17
  def on_message(message)
17
18
  case message
19
+ when Bitcoin::Grpc::WatchTokenRequest
20
+ watchings << message
18
21
  when Bitcoin::Grpc::EventUtxoSpent
19
22
  tx = Bitcoin::Tx.parse_from_payload(message.tx_payload.htb)
20
23
  log(::Logger::DEBUG, "tx=#{tx}, open_assets?=#{tx.open_assets?}")
@@ -26,10 +29,12 @@ module Bitcoin
26
29
  when tx.open_assets?
27
30
  outputs = Bitcoin::Grpc::OapService.outputs_with_open_asset_id(message.tx_hash)
28
31
  begin
32
+ puts outputs
29
33
  if outputs
30
34
  outputs.each do |output|
31
35
  asset_id = output['asset_id']
32
36
  next unless asset_id
37
+
33
38
  asset_id_as_hex = Bitcoin::Base58.decode(asset_id)
34
39
  asset_quantity = output['asset_quantity']
35
40
  oa_output_type = output['oa_output_type']
@@ -37,13 +42,20 @@ module Bitcoin
37
42
  out_point = Bitcoin::OutPoint.new(tx.tx_hash, output['n'])
38
43
  utxo = utxo_db.get_utxo(out_point)
39
44
  next unless utxo
45
+
40
46
  asset_output = utxo_db.save_token(AssetFeature::AssetType::OPEN_ASSETS, asset_id_as_hex, asset_quantity, utxo)
41
47
  next unless asset_output
42
- if oa_output_type == 'issuance'
43
- publisher << Bitcoin::Grpc::EventTokenIssued.new(request_id: 0, asset: asset_output)
44
- else
45
- publisher << Bitcoin::Grpc::EventTokenTransfered.new(request_id: 0, asset: asset_output)
48
+
49
+ item_to_delete = []
50
+ watchings.select { |item| item.asset_id == asset_id }.each do |item|
51
+ if oa_output_type == 'issuance'
52
+ publisher << Bitcoin::Grpc::EventTokenIssued.new(request_id: item.id, asset: asset_output)
53
+ else
54
+ publisher << Bitcoin::Grpc::EventTokenTransfered.new(request_id: item.id, asset: asset_output)
55
+ end
56
+ item_to_delete << item
46
57
  end
58
+ item_to_delete.each { |item| watchings.delete(item) }
47
59
  end
48
60
  else
49
61
  raise 'can not get asset_id'
@@ -120,7 +120,8 @@ message WatchUtxoSpentResponse {
120
120
 
121
121
  message WatchTokenRequest {
122
122
  uint32 id = 1;
123
- bytes asset_type = 2;
123
+ uint32 asset_type = 2;
124
+ string asset_id = 3;
124
125
  }
125
126
 
126
127
  message WatchTokenResponse {
@@ -201,7 +202,7 @@ message Utxo {
201
202
  }
202
203
 
203
204
  message AssetOutput {
204
- bytes asset_type = 1;
205
+ uint32 asset_type = 1;
205
206
  string asset_id = 2;
206
207
  uint64 asset_quantity = 3;
207
208
  string tx_hash = 4;
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.5
4
+ version: 0.1.6
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-07-02 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler