onchain 3.03 → 3.04

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
  SHA1:
3
- metadata.gz: fd3dee9b9c3e89866a52611e36e4fec6c510675c
4
- data.tar.gz: dfec0707b7aa380e6c6189f7065ada17b991dd93
3
+ metadata.gz: 08143eaa0088555db570b1753e35296579d39d9f
4
+ data.tar.gz: 93ae2b84fa4ab2d904e0f68b212ecacef8ddeab7
5
5
  SHA512:
6
- metadata.gz: 4c363a289b43d919c7850de400ae48f3226fe8851cb770148b34ce084549cccb6f654538596a16bd0da586441273cc699696c2cc03772d23f7ef8e351aa31848
7
- data.tar.gz: 3a16f3eabf4e6306c89ed07fcae622cfd5d481afbb86676b50142293d6a0e2e48d753df0d699eb474d818f34a5c8d46d29e1e793ad85f3da31f5b3696d0aa1f8
6
+ metadata.gz: 6d6b4389413c6cfeffe25004dd6a42de12d0aede7065dd519814fcbc7899f84274b88143f9bf5c6c4bb2ba3a30a6a9cf5c0e7bc561fa58b64eb58cb9d53384f8
7
+ data.tar.gz: b9de2baff98ffbef86cb849a47a592a0959327ccfb2c7629ae0bca8873611dc2316c09333d909e892d3e16fbe22a5641ad73efa41b43f2a16661e15aaf4e52cb
@@ -62,17 +62,6 @@ class OnChain::BlockChain
62
62
  end
63
63
 
64
64
  end
65
-
66
- def get_history_for_addresses(addresses, network = :bitcoin)
67
- history = []
68
- addresses.each do |address|
69
- res = address_history(address, network)
70
- res.each do |r|
71
- history << r
72
- end
73
- end
74
- return history
75
- end
76
65
 
77
66
  # Given a list of addresses, return those
78
67
  # that don't have balances in the cahce.
@@ -5,14 +5,45 @@ class OnChain::BlockChain
5
5
 
6
6
  # Get last 20 transactions
7
7
  def bitcoind_address_history(address, network = :bitcoin)
8
-
9
- result = execute_remote_command('searchrawtransactions ' + address + ' 1 0 20 0', network)
8
+
9
+ if cache_read(network.to_s + ' history ' + address) == nil
10
+ result = execute_remote_command('searchrawtransactions ' + address + ' 1 0 20 0', network)
11
+ cache_write(network.to_s + ' history ' + address, result, BALANCE_CACHE_FOR)
12
+ end
13
+
14
+ result = cache_read(network.to_s + ' history ' + address)
10
15
 
11
16
  json = JSON.parse result
12
17
 
13
18
  return parse_bitcoind_address_tx(address, json, network)
14
19
 
15
20
  end
21
+
22
+ def bitcoind_get_history_for_addresses(addresses, network = :bitcoin)
23
+
24
+ commands = []
25
+ if cache_read(network.to_s + ' history ' + addresses[0]) == nil
26
+ addresses.each do |address|
27
+ commands << 'searchrawtransactions ' + address + ' 1 0 20 0'
28
+ end
29
+ histories = OnChain::BlockChain.execute_remote_command(commands, :zclassic)
30
+
31
+ index = 0
32
+ histories.each_line do |history|
33
+ cache_write(network.to_s + ' history ' + addresses[index], history, BALANCE_CACHE_FOR)
34
+ index = index + 1
35
+ end
36
+ end
37
+
38
+ history = []
39
+ addresses.each do |address|
40
+ res = bitcoind_address_history(address, network)
41
+ res.each do |r|
42
+ history << r
43
+ end
44
+ end
45
+ return history
46
+ end
16
47
 
17
48
  def parse_bitcoind_address_tx(address, json, network)
18
49
 
@@ -55,12 +86,10 @@ class OnChain::BlockChain
55
86
 
56
87
  def bitcoind_send_tx(tx_hex, network = :bitcoin)
57
88
 
58
- remote = execute_remote_command('sendrawtransaction ' + tx_hex, network)
59
-
60
- #res = JSON.parse(remote)
89
+ execute_remote_command('sendrawtransaction ' + tx_hex, network)
61
90
 
62
- mess = 'Unknown'
63
- stat = 'Unknown'
91
+ mess = 'Sent'
92
+ stat = 'Sent'
64
93
  tx_hash = 'Unknown'
65
94
 
66
95
  ret = "{\"status\":\"#{stat}\",\"data\":\"#{tx_hash}\",\"code\":200,\"message\":\"#{mess}\"}"
@@ -69,21 +98,14 @@ class OnChain::BlockChain
69
98
 
70
99
  def bitcoind_get_balance(address, network = :bitcoin)
71
100
 
72
- if cache_read(address) == nil
101
+ if cache_read(network.to_s + ' ' + address) == nil
73
102
 
74
- outs = bitcoind_get_unspent_outs(address, network)
103
+ bal = execute_remote_command('getallbalance ' + address + ' 0', network)
75
104
 
76
- puts outs.to_s
77
-
78
- bal = 0
79
- outs.each do |out|
80
- bal += out[3].to_i
81
- end
82
-
83
- cache_write(address, bal, BALANCE_CACHE_FOR)
105
+ cache_write(network.to_s + ' ' + address, bal.to_f, BALANCE_CACHE_FOR)
84
106
  end
85
107
 
86
- bal = cache_read(address)
108
+ bal = cache_read(network.to_s + ' ' + address)
87
109
  if bal.class == Fixnum
88
110
  bal = bal.to_f
89
111
  end
@@ -93,6 +115,22 @@ class OnChain::BlockChain
93
115
 
94
116
  def bitcoind_get_all_balances(addresses, network = :bitcoin)
95
117
 
118
+
119
+ # if first address is missing get them all.
120
+ commands = []
121
+ if cache_read(network.to_s + ' ' + addresses[0]) == nil
122
+ addresses.each do |address|
123
+ commands << 'getallbalance ' + address + ' 0'
124
+ end
125
+ balances = OnChain::BlockChain.execute_remote_command(commands, :zclassic)
126
+
127
+ index = 0
128
+ balances.each_line do |line|
129
+ cache_write(network.to_s + ' ' + addresses[index], line.to_f, BALANCE_CACHE_FOR)
130
+ index = index + 1
131
+ end
132
+ end
133
+
96
134
  addresses.each do |address|
97
135
  bitcoind_get_balance(address, network)
98
136
  end
@@ -100,7 +138,7 @@ class OnChain::BlockChain
100
138
 
101
139
  def bitcoind_get_unspent_outs(address, network = :bitcoin)
102
140
 
103
- result = execute_remote_command('listallunspent ' + address + ' 1', network)
141
+ result = execute_remote_command('listallunspent ' + address + ' 1 0', network)
104
142
 
105
143
  json = JSON.parse result
106
144
 
@@ -124,24 +162,34 @@ class OnChain::BlockChain
124
162
 
125
163
  # Run the command via ssh. For this to work you need
126
164
  # to create the follwing ENV vars.
127
- def execute_remote_command(cmd, network)
165
+ def execute_remote_command(commands, network)
128
166
 
129
167
  host = ENV[network.to_s.upcase + '_HOST']
130
168
  username = ENV[network.to_s.upcase + '_USER']
131
169
  password = ENV[network.to_s.upcase + '_PASSWORD']
132
- cmd = ENV[network.to_s.upcase + '_CLI_CMD'] + ' ' + cmd
170
+ prefix = ENV[network.to_s.upcase + '_CLI_CMD']
133
171
 
134
172
  stdout = ""
135
- stderr = ""
136
173
  begin
137
174
  Net::SSH.start(host, username,
138
175
  :password => password,
139
176
  :auth_methods => [ 'password' ],
140
177
  :number_of_password_prompts => 0) do |ssh|
178
+
179
+ if ! commands.is_a?(Array)
180
+ commands = [commands]
181
+ end
182
+
183
+ commands.each do |command|
184
+
185
+ cmdout = ""
186
+
187
+ ssh.exec! prefix + ' '+ command do |channel, stream, data|
188
+ cmdout << data if stream == :stdout
189
+ end
141
190
 
142
- ssh.exec! cmd do |channel, stream, data|
143
- stdout << data if stream == :stdout
144
- stderr << data if stream == :stderr
191
+ stdout << cmdout.tr("\n","")
192
+ stdout << "\n"
145
193
  end
146
194
  end
147
195
  rescue Timeout::Error
@@ -8,6 +8,17 @@ class OnChain::BlockChain
8
8
 
9
9
  blockinfo_parse_address_tx(address, json)
10
10
  end
11
+
12
+ def blockinfo_get_history_for_addresses(addresses, network = :bitcoin)
13
+ history = []
14
+ addresses.each do |address|
15
+ res = blockinfo_address_history(address, network)
16
+ res.each do |r|
17
+ history << r
18
+ end
19
+ end
20
+ return history
21
+ end
11
22
 
12
23
  def blockinfo_parse_address_tx(address, json)
13
24
 
@@ -14,6 +14,17 @@ class OnChain::BlockChain
14
14
 
15
15
  return parse_address_tx(address, json, network)
16
16
  end
17
+
18
+ def blockr_get_history_for_addresses(addresses, network = :bitcoin)
19
+ history = []
20
+ addresses.each do |address|
21
+ res = blockr_address_history(address, network)
22
+ res.each do |r|
23
+ history << r
24
+ end
25
+ end
26
+ return history
27
+ end
17
28
 
18
29
  def parse_address_tx(address, json, network)
19
30
 
@@ -18,6 +18,17 @@ class OnChain::BlockChain
18
18
  return parse_insight_address_tx(address, json, network)
19
19
 
20
20
  end
21
+
22
+ def insight_get_history_for_addresses(addresses, network = :bitcoin)
23
+ history = []
24
+ addresses.each do |address|
25
+ res = insight_address_history(address, network)
26
+ res.each do |r|
27
+ history << r
28
+ end
29
+ end
30
+ return history
31
+ end
21
32
 
22
33
  def parse_insight_address_tx(address, json, network)
23
34
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onchain
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.03'
4
+ version: '3.04'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Number 6
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-09 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake