bitcoinrb-grpc 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424e2253993bc766b1f087578da27e42998111280126bc699605150708740a7c
4
- data.tar.gz: c3248a38a651e57f57b1ae8043b6f112fd7af75fe5ad6a0ce9d03ae837d9673a
3
+ metadata.gz: 3fcac84338b9a2eb74ee9d72b276a1ff6ea8cebd2c35052d3a857a650b53e877
4
+ data.tar.gz: 9d614d0891e3544fefa96c93f213eebabced6496d41914b451d466a9268d3f50
5
5
  SHA512:
6
- metadata.gz: 2415425f2098278894c025a5451b3d342755ef30cd918ae612f934ad148cc9d622be5d630c532039ab1d9c65414ce44f3ed71159c9120114185f5caf7ce0ebff
7
- data.tar.gz: b1ca87670b8bf33b589b895a9cd563cc11dae8d65f18dbbec1900ec50c95f88b25f6146113929667dc47f88ba20485c510559598e80a1b15a97c0a92af30d8d0
6
+ metadata.gz: bf53e08ca4e325a6c5160bd10be916f687938e0d6b6b836fd3af92cd5891ebf40ea528718fafc738aa8f467fe2f4eb4ffe38ddfe85f38bcb680af27a2c27b745
7
+ data.tar.gz: 53f829615c9edd13f41b7efca47ac4c6b16407a408eb5b6b841204fd11c09c00ca049b2ef19659517051af7fd5ce0ba66d02121cd6042a4f997f4d8c80314a46
@@ -5,6 +5,8 @@ module Bitcoin
5
5
  autoload :ListUnspent, 'bitcoin/grpc/api/list_unspent'
6
6
  autoload :ListColoredUnspent, 'bitcoin/grpc/api/list_colored_unspent'
7
7
  autoload :ListUncoloredUnspent, 'bitcoin/grpc/api/list_uncolored_unspent'
8
+ autoload :GetBalance, 'bitcoin/grpc/api/get_balance'
9
+ autoload :GetTokenBalance, 'bitcoin/grpc/api/get_token_balance'
8
10
  end
9
11
  end
10
12
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bitcoin
4
+ module Grpc
5
+ module Api
6
+ class GetBalance
7
+ attr_reader :spv
8
+
9
+ def initialize(spv)
10
+ @spv = spv
11
+ end
12
+
13
+ def execute(request)
14
+ height = spv.chain.latest_block.height
15
+ balance = spv.wallet.get_balance(request.account_name)
16
+ Bitcoin::Grpc::GetBalanceResponse.new(balance: balance)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bitcoin
4
+ module Grpc
5
+ module Api
6
+ class GetTokenBalance
7
+ attr_reader :spv
8
+
9
+ def initialize(spv)
10
+ @spv = spv
11
+ end
12
+
13
+ def execute(request)
14
+ height = spv.chain.latest_block.height
15
+ assets = spv.wallet.list_unspent_assets_in_account(
16
+ request.asset_type,
17
+ request.asset_id,
18
+ account_name: request.account_name,
19
+ current_block_height: height,
20
+ min: 0,
21
+ max: 9999999
22
+ )
23
+ balance = assets.sum(&:value)
24
+ token_balance = assets.sum(&:asset_quantity)
25
+
26
+ Bitcoin::Grpc::GetTokenBalanceResponse.new(balance: balance, token_balance: token_balance)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -143,6 +143,21 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
143
143
  add_message "bitcoin.grpc.ListUncoloredUnspentResponse" do
144
144
  repeated :utxos, :message, 1, "bitcoin.grpc.Utxo"
145
145
  end
146
+ add_message "bitcoin.grpc.GetBalanceRequest" do
147
+ optional :account_name, :string, 1
148
+ end
149
+ add_message "bitcoin.grpc.GetBalanceResponse" do
150
+ optional :balance, :uint64, 1
151
+ end
152
+ add_message "bitcoin.grpc.GetTokenBalanceRequest" do
153
+ optional :account_name, :string, 1
154
+ optional :asset_type, :uint32, 4
155
+ optional :asset_id, :string, 5
156
+ end
157
+ add_message "bitcoin.grpc.GetTokenBalanceResponse" do
158
+ optional :token_balance, :uint64, 1
159
+ optional :balance, :uint64, 2
160
+ end
146
161
  add_message "bitcoin.grpc.EventTxConfirmed" do
147
162
  optional :request_id, :uint32, 1
148
163
  optional :tx_hash, :string, 2
@@ -233,6 +248,10 @@ module Bitcoin
233
248
  ListColoredUnspentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.ListColoredUnspentResponse").msgclass
234
249
  ListUncoloredUnspentRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.ListUncoloredUnspentRequest").msgclass
235
250
  ListUncoloredUnspentResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.ListUncoloredUnspentResponse").msgclass
251
+ GetBalanceRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.GetBalanceRequest").msgclass
252
+ GetBalanceResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.GetBalanceResponse").msgclass
253
+ GetTokenBalanceRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.GetTokenBalanceRequest").msgclass
254
+ GetTokenBalanceResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.GetTokenBalanceResponse").msgclass
236
255
  EventTxConfirmed = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventTxConfirmed").msgclass
237
256
  EventUtxoRegistered = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventUtxoRegistered").msgclass
238
257
  EventUtxoSpent = Google::Protobuf::DescriptorPool.generated_pool.lookup("bitcoin.grpc.EventUtxoSpent").msgclass
@@ -24,6 +24,8 @@ module Bitcoin
24
24
  rpc :ListUnspent, ListUnspentRequest, ListUnspentResponse
25
25
  rpc :ListColoredUnspent, ListColoredUnspentRequest, ListColoredUnspentResponse
26
26
  rpc :ListUncoloredUnspent, ListUncoloredUnspentRequest, ListUncoloredUnspentResponse
27
+ rpc :GetBalance, GetBalanceRequest, GetBalanceResponse
28
+ rpc :GetTokenBalance, GetTokenBalanceRequest, GetTokenBalanceResponse
27
29
  end
28
30
 
29
31
  Stub = Service.rpc_stub_class
@@ -120,6 +120,14 @@ module Bitcoin
120
120
  logger.error("list_uncolored_unspent: #{e.message}")
121
121
  logger.error("list_uncolored_unspent: #{e.backtrace}")
122
122
  end
123
+
124
+ def get_balance(request, _call)
125
+ logger.info("get_balance: #{request}")
126
+ Bitcoin::Grpc::Api::GetBalance.new(spv).execute(request)
127
+ rescue => e
128
+ logger.error("get_balance: #{e.message}")
129
+ logger.error("get_balance: #{e.backtrace}")
130
+ end
123
131
  end
124
132
 
125
133
  class EventsReceiver < Concurrent::Actor::Context
@@ -1,5 +1,5 @@
1
1
  module Bitcoin
2
2
  module Grpc
3
- VERSION = "0.1.8"
3
+ VERSION = "0.1.9"
4
4
  end
5
5
  end
@@ -13,6 +13,8 @@ service Blockchain {
13
13
  rpc ListUnspent(ListUnspentRequest) returns (ListUnspentResponse);
14
14
  rpc ListColoredUnspent(ListColoredUnspentRequest) returns (ListColoredUnspentResponse);
15
15
  rpc ListUncoloredUnspent(ListUncoloredUnspentRequest) returns (ListUncoloredUnspentResponse);
16
+ rpc GetBalance(GetBalanceRequest) returns (GetBalanceResponse);
17
+ rpc GetTokenBalance(GetTokenBalanceRequest) returns (GetTokenBalanceResponse);
16
18
  }
17
19
 
18
20
  enum Operation {
@@ -186,6 +188,25 @@ message ListUncoloredUnspentResponse {
186
188
  repeated Utxo utxos = 1;
187
189
  }
188
190
 
191
+ message GetBalanceRequest {
192
+ string account_name = 1;
193
+ }
194
+
195
+ message GetBalanceResponse {
196
+ uint64 balance = 1;
197
+ }
198
+
199
+ message GetTokenBalanceRequest {
200
+ string account_name = 1;
201
+ uint32 asset_type = 4;
202
+ string asset_id = 5;
203
+ }
204
+
205
+ message GetTokenBalanceResponse {
206
+ uint64 token_balance = 1;
207
+ uint64 balance = 2;
208
+ }
209
+
189
210
  message EventTxConfirmed {
190
211
  uint32 request_id = 1;
191
212
  string tx_hash = 2;
@@ -247,4 +268,4 @@ message AssetOutput {
247
268
  uint32 block_height = 6;
248
269
  uint64 value = 7;
249
270
  string script_pubkey = 8;
250
- }
271
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoinrb-grpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hajime Yamaguchi
@@ -172,6 +172,8 @@ files:
172
172
  - config.yml
173
173
  - lib/bitcoin/grpc.rb
174
174
  - lib/bitcoin/grpc/api.rb
175
+ - lib/bitcoin/grpc/api/get_balance.rb
176
+ - lib/bitcoin/grpc/api/get_token_balance.rb
175
177
  - lib/bitcoin/grpc/api/list_colored_unspent.rb
176
178
  - lib/bitcoin/grpc/api/list_uncolored_unspent.rb
177
179
  - lib/bitcoin/grpc/api/list_unspent.rb