bitcoinrb-grpc 0.1.1 → 0.1.2
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 +4 -4
- data/bin/bitcoinrbd +4 -5
- data/lib/bitcoin/grpc/grpc_pb.rb +34 -22
- data/lib/bitcoin/grpc/server.rb +21 -16
- data/lib/bitcoin/grpc/version.rb +1 -1
- data/lib/bitcoin/grpc.rb +6 -7
- data/lib/bitcoin/wallet/asset_feature.rb +3 -2
- data/lib/bitcoin/wallet/asset_handler.rb +24 -16
- data/lib/bitcoin/wallet/signer.rb +11 -27
- data/lib/bitcoin/wallet/utxo_handler.rb +6 -4
- data/lib/extensions/bitcoin/rpc/request_handler.rb +1 -1
- data/lib/extensions/bitcoin/wallet/db.rb +23 -0
- data/proto/bitcoin/grpc/grpc.proto +34 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 677bca9b3f8c6b63540308e3eca6fb1f8e0d38b00abc033907504656f40f612c
|
4
|
+
data.tar.gz: 8a37c022c194330448fc81abd3530988c2c5d12d644b6abc238f60d89567fcbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f59c34104147dbbee08615de7c70187465250066661ac722f6f44fb1249c747184e7f75f91e834f695293ca8bcb0c4a1ac3c52f7415aa9a793ca7a0ff5953964
|
7
|
+
data.tar.gz: 2f48e8413444283df0052173cb37d47aeba8921abaa2f854c035863e0d623b0f5211d827e327c285700f6c17081ab44411698d22234c7edb89b9d3ab033405b8
|
data/bin/bitcoinrbd
CHANGED
@@ -7,16 +7,12 @@ require 'bitcoin'
|
|
7
7
|
require 'thor'
|
8
8
|
require 'daemon_spawn'
|
9
9
|
|
10
|
+
|
10
11
|
class BitcoinDaemon < DaemonSpawn::Base
|
11
12
|
def start(args)
|
12
13
|
puts "Bitcoinrb daemon start : #{Time.now} #{args}"
|
13
14
|
conf = Bitcoin::Node::Configuration.new(network: args.first[:network])
|
14
15
|
|
15
|
-
require 'bitcoin/grpc'
|
16
|
-
require 'extensions/bitcoin/rpc/request_handler'
|
17
|
-
require 'extensions/bitcoin/wallet/base'
|
18
|
-
require 'extensions/bitcoin/tx'
|
19
|
-
|
20
16
|
refresh_wallet
|
21
17
|
node = Bitcoin::Node::SPV.new(conf)
|
22
18
|
Thread.new { Bitcoin::Grpc::Server.run(node) }
|
@@ -41,6 +37,9 @@ class Bitcoinrbd < Thor
|
|
41
37
|
def start
|
42
38
|
network = options['network'] ? options['network'].to_sym : :mainnet
|
43
39
|
Bitcoin.chain_params = network
|
40
|
+
|
41
|
+
require 'bitcoin/grpc'
|
42
|
+
|
44
43
|
FileUtils.mkdir_p(Bitcoin.base_dir)
|
45
44
|
execute_daemon(['start', network: network])
|
46
45
|
end
|
data/lib/bitcoin/grpc/grpc_pb.rb
CHANGED
@@ -5,30 +5,36 @@ require 'google/protobuf'
|
|
5
5
|
|
6
6
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
7
7
|
add_message "bitcoin.grpc.WatchTxConfirmedRequest" do
|
8
|
-
optional :
|
9
|
-
optional :
|
8
|
+
optional :id, :uint32, 1
|
9
|
+
optional :tx_hash, :string, 2
|
10
|
+
optional :confirmations, :uint32, 3
|
10
11
|
end
|
11
12
|
add_message "bitcoin.grpc.WatchTxConfirmedResponse" do
|
13
|
+
optional :id, :uint32, 1
|
12
14
|
oneof :event do
|
13
|
-
optional :confirmed, :message,
|
15
|
+
optional :confirmed, :message, 2, "bitcoin.grpc.EventTxConfirmed"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
add_message "bitcoin.grpc.WatchUtxoRequest" do
|
19
|
+
optional :id, :uint32, 1
|
17
20
|
end
|
18
21
|
add_message "bitcoin.grpc.WatchUtxoResponse" do
|
22
|
+
optional :id, :uint32, 1
|
19
23
|
oneof :event do
|
20
|
-
optional :registered, :message,
|
21
|
-
optional :spent, :message,
|
24
|
+
optional :registered, :message, 2, "bitcoin.grpc.EventUtxoRegistered"
|
25
|
+
optional :spent, :message, 3, "bitcoin.grpc.EventUtxoSpent"
|
22
26
|
end
|
23
27
|
end
|
24
28
|
add_message "bitcoin.grpc.WatchTokenRequest" do
|
25
|
-
optional :
|
29
|
+
optional :id, :uint32, 1
|
30
|
+
optional :asset_type, :bytes, 2
|
26
31
|
end
|
27
32
|
add_message "bitcoin.grpc.WatchTokenResponse" do
|
33
|
+
optional :id, :uint32, 1
|
28
34
|
oneof :event do
|
29
|
-
optional :issued, :message,
|
30
|
-
optional :transfered, :message,
|
31
|
-
optional :burned, :message,
|
35
|
+
optional :issued, :message, 2, "bitcoin.grpc.EventTokenIssued"
|
36
|
+
optional :transfered, :message, 3, "bitcoin.grpc.EventTokenTransfered"
|
37
|
+
optional :burned, :message, 4, "bitcoin.grpc.EventTokenBurned"
|
32
38
|
end
|
33
39
|
end
|
34
40
|
add_message "bitcoin.grpc.WatchAssetIdAssignedRequest" do
|
@@ -36,30 +42,36 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
36
42
|
optional :tx_payload, :string, 2
|
37
43
|
end
|
38
44
|
add_message "bitcoin.grpc.EventTxConfirmed" do
|
39
|
-
optional :
|
40
|
-
optional :
|
41
|
-
optional :
|
42
|
-
optional :
|
43
|
-
optional :
|
45
|
+
optional :request_id, :uint32, 1
|
46
|
+
optional :tx_hash, :string, 2
|
47
|
+
optional :tx_payload, :string, 3
|
48
|
+
optional :block_height, :uint32, 4
|
49
|
+
optional :tx_index, :uint32, 5
|
50
|
+
optional :confirmations, :uint32, 6
|
44
51
|
end
|
45
52
|
add_message "bitcoin.grpc.EventUtxoRegistered" do
|
46
|
-
optional :
|
47
|
-
optional :
|
48
|
-
optional :
|
53
|
+
optional :request_id, :uint32, 1
|
54
|
+
optional :tx_hash, :string, 2
|
55
|
+
optional :tx_payload, :string, 3
|
56
|
+
optional :utxo, :message, 4, "bitcoin.grpc.Utxo"
|
49
57
|
end
|
50
58
|
add_message "bitcoin.grpc.EventUtxoSpent" do
|
51
|
-
optional :
|
52
|
-
optional :
|
53
|
-
optional :
|
59
|
+
optional :request_id, :uint32, 1
|
60
|
+
optional :tx_hash, :string, 2
|
61
|
+
optional :tx_payload, :string, 3
|
62
|
+
optional :utxo, :message, 4, "bitcoin.grpc.Utxo"
|
54
63
|
end
|
55
64
|
add_message "bitcoin.grpc.EventTokenIssued" do
|
56
|
-
optional :
|
65
|
+
optional :request_id, :uint32, 1
|
66
|
+
optional :asset, :message, 2, "bitcoin.grpc.AssetOutput"
|
57
67
|
end
|
58
68
|
add_message "bitcoin.grpc.EventTokenTransfered" do
|
69
|
+
optional :request_id, :uint32, 1
|
59
70
|
optional :asset, :message, 2, "bitcoin.grpc.AssetOutput"
|
60
71
|
end
|
61
72
|
add_message "bitcoin.grpc.EventTokenBurned" do
|
62
|
-
optional :
|
73
|
+
optional :request_id, :uint32, 1
|
74
|
+
optional :asset, :message, 4, "bitcoin.grpc.AssetOutput"
|
63
75
|
end
|
64
76
|
add_message "bitcoin.grpc.Utxo" do
|
65
77
|
optional :tx_hash, :string, 1
|
data/lib/bitcoin/grpc/server.rb
CHANGED
@@ -23,7 +23,7 @@ module Bitcoin
|
|
23
23
|
logger.info("watch_tx_confirmed: #{request}")
|
24
24
|
utxo_handler << request
|
25
25
|
channel = Concurrent::Channel.new
|
26
|
-
Receiver.spawn(:receiver, channel, publisher, [Bitcoin::Grpc::EventTxConfirmed])
|
26
|
+
Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventTxConfirmed])
|
27
27
|
ResponseEnum.new(request, channel, WatchTxConfirmedResponseBuilder).each
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ module Bitcoin
|
|
31
31
|
logger.info("watch_utxo: #{request}")
|
32
32
|
utxo_handler << request
|
33
33
|
channel = Concurrent::Channel.new
|
34
|
-
Receiver.spawn(:receiver, channel, publisher, [Bitcoin::Grpc::EventUtxoRegistered, Bitcoin::Grpc::EventUtxoSpent])
|
34
|
+
Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventUtxoRegistered, Bitcoin::Grpc::EventUtxoSpent])
|
35
35
|
ResponseEnum.new(request, channel, WatchUtxoResponseBuilder).each
|
36
36
|
end
|
37
37
|
|
@@ -39,13 +39,13 @@ module Bitcoin
|
|
39
39
|
logger.info("watch_token: #{request}")
|
40
40
|
utxo_handler << request
|
41
41
|
channel = Concurrent::Channel.new
|
42
|
-
Receiver.spawn(:receiver, channel, publisher, [Bitcoin::Grpc::EventTokenIssued, Bitcoin::Grpc::EventTokenTransfered])
|
42
|
+
Receiver.spawn(:receiver, channel, request, publisher, [Bitcoin::Grpc::EventTokenIssued, Bitcoin::Grpc::EventTokenTransfered])
|
43
43
|
ResponseEnum.new(request, channel, WatchTokenResponseBuilder).each
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
class WatchTxConfirmedResponseBuilder
|
48
|
-
def self.build(event)
|
48
|
+
def self.build(id, event)
|
49
49
|
case event
|
50
50
|
when Bitcoin::Grpc::EventTxConfirmed
|
51
51
|
Bitcoin::Grpc::WatchTxConfirmedResponse.new(confirmed: event)
|
@@ -54,25 +54,25 @@ module Bitcoin
|
|
54
54
|
end
|
55
55
|
|
56
56
|
class WatchUtxoResponseBuilder
|
57
|
-
def self.build(event)
|
57
|
+
def self.build(id, event)
|
58
58
|
case event
|
59
59
|
when Bitcoin::Grpc::EventUtxoRegistered
|
60
|
-
Bitcoin::Grpc::WatchUtxoResponse.new(registered: event)
|
60
|
+
Bitcoin::Grpc::WatchUtxoResponse.new(id: id, registered: event)
|
61
61
|
when Bitcoin::Grpc::EventUtxoSpent
|
62
|
-
Bitcoin::Grpc::WatchUtxoResponse.new(spent: event)
|
62
|
+
Bitcoin::Grpc::WatchUtxoResponse.new(id: id, spent: event)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
class WatchTokenResponseBuilder
|
68
|
-
def self.build(event)
|
68
|
+
def self.build(id, event)
|
69
69
|
case event
|
70
70
|
when Bitcoin::Grpc::EventTokenIssued
|
71
|
-
Bitcoin::Grpc::WatchTokenResponse.new(issued: event)
|
71
|
+
Bitcoin::Grpc::WatchTokenResponse.new(id: id, issued: event)
|
72
72
|
when Bitcoin::Grpc::EventTokenTransfered
|
73
|
-
Bitcoin::Grpc::WatchTokenResponse.new(transfered: event)
|
73
|
+
Bitcoin::Grpc::WatchTokenResponse.new(id: id, transfered: event)
|
74
74
|
when Bitcoin::Grpc::EventTokenBurned
|
75
|
-
Bitcoin::Grpc::WatchTokenResponse.new(burned: event)
|
75
|
+
Bitcoin::Grpc::WatchTokenResponse.new(id: id, burned: event)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -80,14 +80,18 @@ module Bitcoin
|
|
80
80
|
class Receiver < Concurrent::Actor::Context
|
81
81
|
include Concurrent::Concern::Logging
|
82
82
|
|
83
|
-
attr_reader :channel
|
84
|
-
|
83
|
+
attr_reader :channel, :request
|
84
|
+
|
85
|
+
def initialize(channel, request, publisher, classes)
|
85
86
|
@channel = channel
|
87
|
+
@request = request
|
86
88
|
classes.each {|c| publisher << [:subscribe, c] }
|
87
89
|
end
|
88
90
|
def on_message(message)
|
89
|
-
|
90
|
-
|
91
|
+
if request.id == message.request_id
|
92
|
+
log(::Logger::DEBUG, "Receiver#on_message:#{message}")
|
93
|
+
channel << message
|
94
|
+
end
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
@@ -105,7 +109,8 @@ module Bitcoin
|
|
105
109
|
logger.info("ResponseEnum#each")
|
106
110
|
return enum_for(:each) unless block_given?
|
107
111
|
loop do
|
108
|
-
|
112
|
+
event = channel.take
|
113
|
+
yield wrapper_classs.build(event.request_id, event)
|
109
114
|
end
|
110
115
|
end
|
111
116
|
end
|
data/lib/bitcoin/grpc/version.rb
CHANGED
data/lib/bitcoin/grpc.rb
CHANGED
@@ -5,19 +5,18 @@ require 'concurrent'
|
|
5
5
|
require 'concurrent-edge'
|
6
6
|
require 'leveldb'
|
7
7
|
|
8
|
-
require 'extensions/bitcoin/rpc/request_handler'
|
9
|
-
require 'extensions/bitcoin/wallet/base'
|
10
|
-
require 'extensions/bitcoin/tx'
|
11
|
-
|
12
8
|
module Bitcoin
|
13
|
-
|
14
|
-
|
15
9
|
module Grpc
|
16
10
|
class Error < StandardError; end
|
17
11
|
|
18
12
|
require 'bitcoin/grpc/grpc_pb'
|
19
13
|
require 'bitcoin/grpc/grpc_services_pb'
|
20
14
|
|
15
|
+
require 'extensions/bitcoin/rpc/request_handler'
|
16
|
+
require 'extensions/bitcoin/wallet/base'
|
17
|
+
require 'extensions/bitcoin/wallet/db'
|
18
|
+
require 'extensions/bitcoin/tx'
|
19
|
+
|
21
20
|
autoload :OapService, 'bitcoin/grpc/oap_service'
|
22
21
|
autoload :Server, 'bitcoin/grpc/server'
|
23
22
|
end
|
@@ -32,4 +31,4 @@ module Bitcoin
|
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
Concurrent.use_simple_logger Logger::DEBUG
|
34
|
+
# Concurrent.use_simple_logger Logger::DEBUG
|
@@ -119,8 +119,9 @@ module Bitcoin
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def list_unspent_assets_by_script_pubkeys(asset_type, asset_id, current_block_height, min: 0, max: 9999999, script_pubkeys: [])
|
122
|
-
max_height = current_block_height - min
|
123
|
-
min_height = current_block_height - max
|
122
|
+
max_height = [current_block_height - min, 0].max
|
123
|
+
min_height = [current_block_height - max, 0].max
|
124
|
+
|
124
125
|
script_pubkeys.map do |key|
|
125
126
|
from = KEY_PREFIX[:asset_script_pubkey] + [asset_type].pack('C').bth + key + '000000000000000000000000000000000000000000000000000000000000000000000000'
|
126
127
|
to = KEY_PREFIX[:asset_script_pubkey] + [asset_type].pack('C').bth + key + 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
@@ -25,24 +25,32 @@ module Bitcoin
|
|
25
25
|
case
|
26
26
|
when tx.open_assets?
|
27
27
|
outputs = Bitcoin::Grpc::OapService.outputs_with_open_asset_id(message.tx_hash)
|
28
|
-
|
29
|
-
outputs
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
begin
|
29
|
+
if outputs
|
30
|
+
outputs.each do |output|
|
31
|
+
asset_id = output['asset_id']
|
32
|
+
next unless asset_id
|
33
|
+
asset_id_as_hex = Bitcoin::Base58.decode(asset_id)
|
34
|
+
asset_quantity = output['asset_quantity']
|
35
|
+
oa_output_type = output['oa_output_type']
|
36
|
+
|
37
|
+
out_point = Bitcoin::OutPoint.new(tx.tx_hash, output['n'])
|
38
|
+
utxo = utxo_db.get_utxo(out_point)
|
39
|
+
next unless utxo
|
40
|
+
asset_output = utxo_db.save_token(AssetFeature::AssetType::OPEN_ASSETS, asset_id_as_hex, asset_quantity, utxo)
|
41
|
+
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)
|
46
|
+
end
|
43
47
|
end
|
48
|
+
else
|
49
|
+
raise 'can not get asset_id'
|
44
50
|
end
|
45
|
-
|
51
|
+
rescue => e
|
52
|
+
log(::Logger::DEBUG, e.message)
|
53
|
+
log(::Logger::DEBUG, e.backtrace)
|
46
54
|
task = Concurrent::TimerTask.new(execution_interval: 60) do
|
47
55
|
self << message
|
48
56
|
task.shutdown
|
@@ -3,12 +3,12 @@
|
|
3
3
|
module Bitcoin
|
4
4
|
module Wallet
|
5
5
|
module Signer
|
6
|
-
def self.sign(
|
7
|
-
account = find_account(
|
6
|
+
def self.sign(wallet, account_name, tx)
|
7
|
+
account = find_account(wallet, account_name)
|
8
8
|
return unless account
|
9
9
|
|
10
10
|
tx.inputs.each.with_index do |input, index|
|
11
|
-
spec = input_spec(
|
11
|
+
spec = input_spec(wallet, account, tx, index)
|
12
12
|
next unless spec
|
13
13
|
sign_tx_for_p2wpkh(tx, index, spec[0], spec[1])
|
14
14
|
end
|
@@ -17,38 +17,22 @@ module Bitcoin
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
-
def self.input_spec(
|
20
|
+
def self.input_spec(wallet, account, tx, index)
|
21
21
|
input = tx.inputs[index]
|
22
22
|
return unless input
|
23
|
-
utxo =
|
23
|
+
utxo = wallet.utxo_db.get_utxo(input.out_point)
|
24
24
|
return unless utxo
|
25
25
|
script_pubkey = utxo.script_pubkey
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
temp_key = node.wallet.master_key.derive(path).key
|
31
|
-
if to_p2wpkh(temp_key).to_payload.bth == script_pubkey
|
32
|
-
key = temp_key
|
33
|
-
break
|
34
|
-
end
|
35
|
-
end
|
36
|
-
unless key
|
37
|
-
(0..account.change_depth + 1).reverse_each do |key_index|
|
38
|
-
path = [account.path, 1, key_index].join('/')
|
39
|
-
temp_key = node.wallet.master_key.derive(path).key
|
40
|
-
if to_p2wpkh(temp_key).to_payload.bth == script_pubkey
|
41
|
-
key = temp_key
|
42
|
-
break
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
26
|
+
_, _, key_purpose, key_index = wallet.db.get_key_index(script_pubkey)
|
27
|
+
return unless key_index
|
28
|
+
path = [account.path, key_purpose, key_index].join('/')
|
29
|
+
key = wallet.master_key.derive(path).key
|
46
30
|
return unless key
|
47
31
|
[key, utxo.value]
|
48
32
|
end
|
49
33
|
|
50
|
-
def self.find_account(
|
51
|
-
|
34
|
+
def self.find_account(wallet, account_name)
|
35
|
+
wallet.accounts.find{|a| a.name == account_name}
|
52
36
|
end
|
53
37
|
|
54
38
|
def self.sign_tx_for_p2wpkh(tx, index, key, amount)
|
@@ -37,12 +37,12 @@ module Bitcoin
|
|
37
37
|
next unless watch_targets.find { |target| output.script_pubkey == Bitcoin::Script.to_p2wpkh(target) }
|
38
38
|
out_point = Bitcoin::OutPoint.new(tx.tx_hash, index)
|
39
39
|
utxo = utxo_db.save_utxo(out_point, output.value, output.script_pubkey.to_payload.bth, block_height)
|
40
|
-
publisher << Bitcoin::Grpc::EventUtxoRegistered.new(tx_hash: tx.tx_hash, tx_payload: tx.to_payload.bth, utxo: utxo) if utxo
|
40
|
+
publisher << Bitcoin::Grpc::EventUtxoRegistered.new(request_id: 0, tx_hash: tx.tx_hash, tx_payload: tx.to_payload.bth, utxo: utxo) if utxo
|
41
41
|
end
|
42
42
|
|
43
43
|
tx.inputs.each do |input|
|
44
44
|
utxo = utxo_db.delete_utxo(input.out_point)
|
45
|
-
publisher << Bitcoin::Grpc::EventUtxoSpent.new(tx_hash: tx.tx_hash, tx_payload: tx.to_payload.bth, utxo: utxo) if utxo
|
45
|
+
publisher << Bitcoin::Grpc::EventUtxoSpent.new(request_id: 0, tx_hash: tx.tx_hash, tx_payload: tx.to_payload.bth, utxo: utxo) if utxo
|
46
46
|
end
|
47
47
|
|
48
48
|
utxo_db.save_tx(tx.tx_hash, tx.to_payload.bth)
|
@@ -75,10 +75,12 @@ module Bitcoin
|
|
75
75
|
case item
|
76
76
|
when Bitcoin::Grpc::WatchTxConfirmedRequest
|
77
77
|
height, tx_index, tx_payload = utxo_db.get_tx(item.tx_hash)
|
78
|
-
log(::Logger::DEBUG, "UtxoHandler#header:#{[height, tx_index]}")
|
78
|
+
log(::Logger::DEBUG, "UtxoHandler#header:#{[block_height, height, tx_index, item.confirmations]}")
|
79
|
+
log(::Logger::DEBUG, "UtxoHandler#header:#{item.inspect}")
|
79
80
|
next unless (height || tx_index)
|
80
81
|
if block_height >= height + item.confirmations
|
81
|
-
|
82
|
+
log(::Logger::DEBUG, "UtxoHandler#header:publish")
|
83
|
+
publisher << Bitcoin::Grpc::EventTxConfirmed.new(request_id: item.id, tx_hash: item.tx_hash, tx_payload: tx_payload, block_height: height, tx_index: tx_index, confirmations: item.confirmations)
|
82
84
|
watchings.delete(item)
|
83
85
|
end
|
84
86
|
else
|
@@ -91,7 +91,7 @@ module Bitcoin
|
|
91
91
|
|
92
92
|
def signrawtransaction(account_name, payload)
|
93
93
|
tx = Bitcoin::Tx.parse_from_payload(payload.htb)
|
94
|
-
signed_tx = Bitcoin::Wallet::Signer.sign(node, account_name, tx)
|
94
|
+
signed_tx = Bitcoin::Wallet::Signer.sign(node.wallet, account_name, tx)
|
95
95
|
{ hex: signed_tx.to_payload.bth }
|
96
96
|
end
|
97
97
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Bitcoin
|
2
|
+
module Wallet
|
3
|
+
class DB
|
4
|
+
def save_key(account, purpose, index, key)
|
5
|
+
pubkey = key.pub
|
6
|
+
id = [account.purpose, account.index, purpose, index].pack('I*').bth
|
7
|
+
k = KEY_PREFIX[:key] + id
|
8
|
+
script_pubkey = Bitcoin::Script.to_p2wpkh(Bitcoin.hash160(pubkey)).to_payload.bth
|
9
|
+
k2 = 'p' + script_pubkey
|
10
|
+
level_db.put(k, pubkey)
|
11
|
+
level_db.put(k2, id)
|
12
|
+
key
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_key_index(script_pubkey)
|
16
|
+
k = 'p' + script_pubkey
|
17
|
+
id = level_db.get(k)
|
18
|
+
return unless id
|
19
|
+
id.htb.unpack('I*')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -10,35 +10,41 @@ service Blockchain {
|
|
10
10
|
}
|
11
11
|
|
12
12
|
message WatchTxConfirmedRequest {
|
13
|
-
|
14
|
-
|
13
|
+
uint32 id = 1;
|
14
|
+
string tx_hash = 2;
|
15
|
+
uint32 confirmations = 3;
|
15
16
|
}
|
16
17
|
|
17
18
|
message WatchTxConfirmedResponse {
|
19
|
+
uint32 id = 1;
|
18
20
|
oneof event {
|
19
|
-
EventTxConfirmed confirmed =
|
21
|
+
EventTxConfirmed confirmed = 2;
|
20
22
|
}
|
21
23
|
}
|
22
24
|
|
23
25
|
message WatchUtxoRequest {
|
26
|
+
uint32 id = 1;
|
24
27
|
}
|
25
28
|
|
26
29
|
message WatchUtxoResponse {
|
30
|
+
uint32 id = 1;
|
27
31
|
oneof event {
|
28
|
-
EventUtxoRegistered registered =
|
29
|
-
EventUtxoSpent spent =
|
32
|
+
EventUtxoRegistered registered = 2;
|
33
|
+
EventUtxoSpent spent = 3;
|
30
34
|
}
|
31
35
|
}
|
32
36
|
|
33
37
|
message WatchTokenRequest {
|
34
|
-
|
38
|
+
uint32 id = 1;
|
39
|
+
bytes asset_type = 2;
|
35
40
|
}
|
36
41
|
|
37
42
|
message WatchTokenResponse {
|
43
|
+
uint32 id = 1;
|
38
44
|
oneof event {
|
39
|
-
EventTokenIssued issued =
|
40
|
-
EventTokenTransfered transfered =
|
41
|
-
EventTokenBurned burned =
|
45
|
+
EventTokenIssued issued = 2;
|
46
|
+
EventTokenTransfered transfered = 3;
|
47
|
+
EventTokenBurned burned = 4;
|
42
48
|
}
|
43
49
|
}
|
44
50
|
|
@@ -48,35 +54,41 @@ message WatchAssetIdAssignedRequest {
|
|
48
54
|
}
|
49
55
|
|
50
56
|
message EventTxConfirmed {
|
51
|
-
|
52
|
-
string
|
53
|
-
|
54
|
-
uint32
|
55
|
-
uint32
|
57
|
+
uint32 request_id = 1;
|
58
|
+
string tx_hash = 2;
|
59
|
+
string tx_payload = 3;
|
60
|
+
uint32 block_height = 4;
|
61
|
+
uint32 tx_index = 5;
|
62
|
+
uint32 confirmations = 6;
|
56
63
|
}
|
57
64
|
|
58
65
|
message EventUtxoRegistered {
|
59
|
-
|
60
|
-
string
|
61
|
-
|
66
|
+
uint32 request_id = 1;
|
67
|
+
string tx_hash = 2;
|
68
|
+
string tx_payload = 3;
|
69
|
+
Utxo utxo = 4;
|
62
70
|
}
|
63
71
|
|
64
72
|
message EventUtxoSpent {
|
65
|
-
|
66
|
-
string
|
67
|
-
|
73
|
+
uint32 request_id = 1;
|
74
|
+
string tx_hash = 2;
|
75
|
+
string tx_payload = 3;
|
76
|
+
Utxo utxo = 4;
|
68
77
|
}
|
69
78
|
|
70
79
|
message EventTokenIssued {
|
71
|
-
|
80
|
+
uint32 request_id = 1;
|
81
|
+
AssetOutput asset = 2;
|
72
82
|
}
|
73
83
|
|
74
84
|
message EventTokenTransfered {
|
85
|
+
uint32 request_id = 1;
|
75
86
|
AssetOutput asset = 2;
|
76
87
|
}
|
77
88
|
|
78
89
|
message EventTokenBurned {
|
79
|
-
|
90
|
+
uint32 request_id = 1;
|
91
|
+
AssetOutput asset = 4;
|
80
92
|
}
|
81
93
|
|
82
94
|
message Utxo {
|
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.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hajime Yamaguchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/extensions/bitcoin/rpc/request_handler.rb
|
184
184
|
- lib/extensions/bitcoin/tx.rb
|
185
185
|
- lib/extensions/bitcoin/wallet/base.rb
|
186
|
+
- lib/extensions/bitcoin/wallet/db.rb
|
186
187
|
- proto/bitcoin/grpc/grpc.proto
|
187
188
|
homepage: ''
|
188
189
|
licenses: []
|