onchain 2.5 → 2.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
  SHA1:
3
- metadata.gz: 75e5c8220374d307aa3f82bdb6e216c06d2f587c
4
- data.tar.gz: a889f8795cd4958e2f4ff95fb105e721d12857d3
3
+ metadata.gz: 2193dbde4c0d67e834351acccd08a750e43fd728
4
+ data.tar.gz: 5c0198213f4943b4a9c227ebbc585a7badbf24d0
5
5
  SHA512:
6
- metadata.gz: 9bd3003993dca0e2378427eeab184b2175acf477b89a0316bbd082f3c828d20867630792f2279f8093387198f7463d1fec8ec30e9b559439d5c8b2cffb633c5b
7
- data.tar.gz: 2987be8bced4ef31dc15781f642f39f7b512ccf8db1385e20b0782ce571da1e1017099ac59d50cf0dd9149bddc02eaa89b1eb25a74ce0c3a1624208977ed9cdf
6
+ metadata.gz: 0aee998b0737e7884dc33dd4e1d8d77b775e6d3e9a7d06f724cc277de77a7eb35d762c3ab53ab59961e6acda3891df010daaae0a9daf55426d6cd781b814748d
7
+ data.tar.gz: 808d0da5669a5b473e3359ee79a0973eb22774544ffa10b2b8bf5842fa5bcab47359db6fa271c4e5e65444b93d6566cdf18ea29d6300b8f85a35d6129c4d9d3a
@@ -40,7 +40,14 @@ class OnChain::BlockChain
40
40
  end
41
41
  end
42
42
 
43
- get_available_suppliers(method_name).each do |supplier|
43
+ network = :bitcoin
44
+ if args.length > 0
45
+ if args[args.length - 1] == :testnet3
46
+ network = :testnet3
47
+ end
48
+ end
49
+
50
+ get_available_suppliers(method_name, network).each do |supplier|
44
51
 
45
52
  real_method = "#{supplier.to_s}_#{method_name}"
46
53
  begin
@@ -109,11 +116,15 @@ class OnChain::BlockChain
109
116
  return (get_balance(address).to_f * 100000000).to_i
110
117
  end
111
118
 
112
- def get_available_suppliers(method_name)
119
+ def get_available_suppliers(method_name, network)
113
120
  available = []
114
121
  ALL_SUPPLIERS.each do |supplier|
115
122
  if cache_read(supplier.to_s) == nil
116
123
 
124
+ if supplier == :blockinfo and network == :testnet3
125
+ next
126
+ end
127
+
117
128
  if supplier == :blockinfo and method_name.to_s == 'send_tx'
118
129
  next
119
130
  end
@@ -1,8 +1,15 @@
1
1
  class OnChain::BlockChain
2
2
  class << self
3
3
 
4
- def blockr_send_tx(tx_hex)
5
- uri = URI.parse("http://btc.blockr.io/api/v1/tx/push")
4
+ def get_url(network)
5
+ if network == :bitcoin
6
+ return "http://btc.blockr.io/api/v1/"
7
+ end
8
+ return "http://tbtc.blockr.io/api/v1/"
9
+ end
10
+
11
+ def blockr_send_tx(tx_hex, network = :bitcoin)
12
+ uri = URI.parse(get_url(network) + "tx/push")
6
13
  http = Net::HTTP.new(uri.host, uri.port)
7
14
 
8
15
  request = Net::HTTP::Post.new(uri.request_uri)
@@ -22,9 +29,9 @@ class OnChain::BlockChain
22
29
  return JSON.parse(ret)
23
30
  end
24
31
 
25
- def blockr_get_balance(address)
32
+ def blockr_get_balance(address, network = :bitcoin)
26
33
  if cache_read(address) == nil
27
- json = blockr('address/balance', address)
34
+ json = blockr('address/balance', address, network)
28
35
  if json.key?('data')
29
36
  bal = json['data']['balance'].to_f
30
37
  cache_write(address, bal, BALANCE_CACHE_FOR)
@@ -35,9 +42,9 @@ class OnChain::BlockChain
35
42
  return cache_read(address)
36
43
  end
37
44
 
38
- def blockr_get_address_info(address)
45
+ def blockr_get_address_info(address, network = :bitcoin)
39
46
 
40
- json = blockr('address/balance', address)
47
+ json = blockr('address/balance', address, network)
41
48
 
42
49
  return { received: json[address]['total_received'],
43
50
  balance: json[address]['final_balance'],
@@ -45,8 +52,8 @@ class OnChain::BlockChain
45
52
 
46
53
  end
47
54
 
48
- def blockr_get_transactions(address)
49
- base_url = "http://btc.blockr.io/api/v1/address/txs/#{address}"
55
+ def blockr_get_transactions(address, network = :bitcoin)
56
+ base_url = get_url(network) + "address/txs/#{address}"
50
57
  json = fetch_response(base_url, true)
51
58
 
52
59
  unspent = []
@@ -61,8 +68,8 @@ class OnChain::BlockChain
61
68
  return unspent
62
69
  end
63
70
 
64
- def blockr_get_unspent_outs(address)
65
- base_url = "http://btc.blockr.io/api/v1/address/unspent/#{address}"
71
+ def blockr_get_unspent_outs(address, network = :bitcoin)
72
+ base_url = get_url(network) + "address/unspent/#{address}"
66
73
  json = fetch_response(base_url, true)
67
74
 
68
75
  unspent = []
@@ -79,7 +86,7 @@ class OnChain::BlockChain
79
86
  return unspent
80
87
  end
81
88
 
82
- def blockr_get_all_balances(addresses)
89
+ def blockr_get_all_balances(addresses, network = :bitcoin)
83
90
 
84
91
  addr = get_uncached_addresses(addresses)
85
92
 
@@ -87,7 +94,7 @@ class OnChain::BlockChain
87
94
  return
88
95
  end
89
96
 
90
- base = "https://blockr.io/api/v1/address/balance/"
97
+ base = get_url(network) + "address/balance/"
91
98
 
92
99
  addr.each do |address|
93
100
  base = base + address + ','
@@ -102,14 +109,14 @@ class OnChain::BlockChain
102
109
  end
103
110
  end
104
111
 
105
- def blockr_get_transaction(txhash)
106
- base = "https://blockr.io/api/v1/tx/raw/" + txhash
112
+ def blockr_get_transaction(txhash, network = :bitcoin)
113
+ base = get_url(network) + "tx/raw/" + txhash
107
114
  return fetch_response(URI::encode(base))['data']['tx']['hex']
108
115
  end
109
116
 
110
- def blockr(cmd, address, params = "")
117
+ def blockr(cmd, address, network, params = "")
111
118
 
112
- base_url = "http://blockr.io/api/v1/#{cmd}/#{address}" + params
119
+ base_url = get_url(network) + "#{cmd}/#{address}" + params
113
120
  fetch_response(base_url, true)
114
121
 
115
122
  end
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: '2.5'
4
+ version: '2.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian Purton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake