onchain 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onchain/block_chain.rb +2 -2
- data/lib/onchain/providers/blockr_api.rb +13 -2
- data/lib/onchain/providers/chaincom_api.rb +73 -0
- metadata +23 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c43591ce46da772a3ec1c56907923a207bfbe07
|
4
|
+
data.tar.gz: bcfbb45149878319b72aeec55bf6fac0d1302ff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfeb8f3fd4326ff2958fe2badb30a25a466865ef9b9606fb23b24a1d6ec8314b324033579d5107e39e0e374b3ea7123816b4b6de2cdcd5fb80cea98a84cf22d7
|
7
|
+
data.tar.gz: 03c5d5316847740b77abeaa1255a4059099ece551c06aae8e08cfe743163723a6c6c95b44e2726e514f7a4b9c7e2413615b7a28e34dc08a237b6d470c6687058
|
data/lib/onchain/block_chain.rb
CHANGED
@@ -17,8 +17,8 @@ end
|
|
17
17
|
class OnChain::BlockChain
|
18
18
|
class << self
|
19
19
|
|
20
|
-
|
21
|
-
ALL_SUPPLIERS = [ :blockr, :blockinfo ]
|
20
|
+
ALL_SUPPLIERS = [:chaincom, :blockr, :blockinfo ]
|
21
|
+
#ALL_SUPPLIERS = [ :blockr, :blockinfo ]
|
22
22
|
|
23
23
|
def method_missing (method_name, *args, &block)
|
24
24
|
|
@@ -7,8 +7,19 @@ class OnChain::BlockChain
|
|
7
7
|
|
8
8
|
request = Net::HTTP::Post.new(uri.request_uri)
|
9
9
|
request.body = '{"hex":"' + tx_hex + '"}'
|
10
|
-
response = http.request(request)
|
11
|
-
|
10
|
+
response = http.request(request)
|
11
|
+
|
12
|
+
res = JSON.parse(response.body)
|
13
|
+
|
14
|
+
mess = res["message"]
|
15
|
+
stat = res["status"]
|
16
|
+
if stat == 'fail'
|
17
|
+
stat = 'failure'
|
18
|
+
end
|
19
|
+
|
20
|
+
tx_hash = res["data"]
|
21
|
+
ret = "{\"status\":\"#{stat}\",\"data\":\"#{tx_hash}\",\"code\":200,\"message\":\"#{mess}\"}"
|
22
|
+
return JSON.parse(ret)
|
12
23
|
end
|
13
24
|
|
14
25
|
def blockr_get_balance(address)
|
@@ -1,4 +1,77 @@
|
|
1
|
+
require 'chain'
|
2
|
+
|
1
3
|
class OnChain::BlockChain
|
2
4
|
class << self
|
5
|
+
|
6
|
+
def chaincom_send_tx(tx_hex)
|
7
|
+
|
8
|
+
begin
|
9
|
+
tx = Chain.send_transaction(tx_hex)
|
10
|
+
tx_hash = tx["transaction_hash"]
|
11
|
+
ret = "{\"status\":\"success\",\"data\":\"#{tx_hash}\",\"code\":200,\"message\":\"\"}"
|
12
|
+
return JSON.parse(ret)
|
13
|
+
rescue => e
|
14
|
+
ret = "{\"status\":\"failure\",\"data\":\"#{tx_hash}\",\"code\":200,\"message\":\"#{e.to_s}\"}"
|
15
|
+
return JSON.parse(ret)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def chaincom_get_balance(address)
|
20
|
+
if cache_read(address) == nil
|
21
|
+
|
22
|
+
addr = Chain.get_address(address)
|
23
|
+
bal = addr["balance"] / 100000000.0
|
24
|
+
cache_write(address, bal, BALANCE_CACHE_FOR)
|
25
|
+
|
26
|
+
end
|
27
|
+
return cache_read(address)
|
28
|
+
end
|
29
|
+
|
30
|
+
def chaincom_get_transactions(address)
|
31
|
+
|
32
|
+
txs = Chain.get_address_transactions(address)
|
33
|
+
|
34
|
+
unspent = []
|
35
|
+
|
36
|
+
txs.each do |data|
|
37
|
+
line = []
|
38
|
+
line << data['hash']
|
39
|
+
line << data['amount'] / 100000000.0
|
40
|
+
unspent << line
|
41
|
+
end
|
42
|
+
|
43
|
+
return unspent
|
44
|
+
end
|
45
|
+
|
46
|
+
def chaincom_get_unspent_outs(address)
|
47
|
+
|
48
|
+
uns = Chain.get_address_unspents(address)
|
49
|
+
|
50
|
+
unspent = []
|
51
|
+
|
52
|
+
uns.each do |data|
|
53
|
+
line = []
|
54
|
+
line << data['transaction_hash']
|
55
|
+
line << data['output_index']
|
56
|
+
line << data['script_hex']
|
57
|
+
line << data['value']
|
58
|
+
unspent << line
|
59
|
+
end
|
60
|
+
|
61
|
+
return unspent
|
62
|
+
end
|
63
|
+
|
64
|
+
def chaincom_get_all_balances(addresses)
|
65
|
+
|
66
|
+
res = Chain.get_addresses(addresses)
|
67
|
+
|
68
|
+
res.each do |address|
|
69
|
+
end
|
70
|
+
|
71
|
+
json['data'].each do |addr|
|
72
|
+
bal = addr["balance"] / 100000000.0
|
73
|
+
cache_write(address, bal, BALANCE_CACHE_FOR)
|
74
|
+
end
|
75
|
+
end
|
3
76
|
end
|
4
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onchain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Purton
|
@@ -14,14 +14,14 @@ dependencies:
|
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -30,40 +30,54 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.1.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: money-tree
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bitcoin-ruby
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chain-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
83
|
description: Call 3rd party API's but also switch API's if a 3rd party is down
|