onchain 2.1.0 → 2.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/providers/blockchaininfo_api.rb +3 -3
- data/lib/onchain/transaction.rb +32 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e22f8353705d9cf0ae2c8809117b989b29196d37
|
4
|
+
data.tar.gz: b4a4a4e5b8a14348c48100b1b243300ec267135d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5a0ee70ae399e72d2b6a4594329b4a9e57e9380ecdbf7db203c9d7ab81ea4ae0fd11c321e305d3c64404bead27e0dedb69a9c5039533d7042c179416683c06b
|
7
|
+
data.tar.gz: 9e29cce99b2d3d63a5c982befaaa6d45f5562bd27e92b9c45cf64c154765a11550869f582b75eb216e0961982e3499699a61919b6d50904e3cd6557a8378c95f
|
@@ -15,7 +15,7 @@ class OnChain::BlockChain
|
|
15
15
|
|
16
16
|
def blockinfo_address_history(address)
|
17
17
|
|
18
|
-
base_url = "
|
18
|
+
base_url = "https://blockchain.info/address/#{address}?format=json"
|
19
19
|
json = fetch_response(base_url, true)
|
20
20
|
|
21
21
|
blockinfo_parse_address_tx(address, json)
|
@@ -81,7 +81,7 @@ class OnChain::BlockChain
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def blockinfo_get_unspent_outs(address)
|
84
|
-
base_url = "
|
84
|
+
base_url = "https://blockchain.info/unspent?active=#{address}"
|
85
85
|
json = fetch_response(base_url, true)
|
86
86
|
|
87
87
|
unspent = []
|
@@ -116,7 +116,7 @@ class OnChain::BlockChain
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def block_chain(cmd, address, params = "")
|
119
|
-
base_url = "
|
119
|
+
base_url = "https://blockchain.info/#{cmd}/#{address}?format=json" + params
|
120
120
|
|
121
121
|
fetch_response(base_url, true)
|
122
122
|
end
|
data/lib/onchain/transaction.rb
CHANGED
@@ -31,8 +31,10 @@ class OnChain::Transaction
|
|
31
31
|
|
32
32
|
tx.add_out(txout)
|
33
33
|
end
|
34
|
+
|
35
|
+
inputs_to_sign = get_inputs_to_sign(tx)
|
34
36
|
|
35
|
-
return OnChain::bin_to_hex(tx.to_payload)
|
37
|
+
return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
|
36
38
|
end
|
37
39
|
|
38
40
|
def calculate_fee(amount, fee_percent)
|
@@ -46,6 +48,34 @@ class OnChain::Transaction
|
|
46
48
|
return fee
|
47
49
|
end
|
48
50
|
|
51
|
+
def get_public_keys_from_script(script)
|
52
|
+
|
53
|
+
if script.is_pubkey?
|
54
|
+
return [script.get_pubkey]
|
55
|
+
end
|
56
|
+
|
57
|
+
return script.get_multisig_pubkeys
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_inputs_to_sign(tx)
|
61
|
+
inputs_to_sign = []
|
62
|
+
tx.in.each_with_index do |txin, index|
|
63
|
+
hash = tx.signature_hash_for_input(index, txin.script, 1)
|
64
|
+
|
65
|
+
script = Bitcoin::Script.new txin.script
|
66
|
+
|
67
|
+
pubkeys = get_public_keys_from_script(script)
|
68
|
+
pubkeys.each do |key|
|
69
|
+
|
70
|
+
if inputs_to_sign[index] == nil
|
71
|
+
inputs_to_sign[index] = {}
|
72
|
+
end
|
73
|
+
inputs_to_sign[index][OnChain.bin_to_hex(key)] = {'hash' => OnChain::bin_to_hex(hash)}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
return inputs_to_sign
|
77
|
+
end
|
78
|
+
|
49
79
|
# Given a send address and an amount produce a transaction
|
50
80
|
# and a list of hashes that need to be signed.
|
51
81
|
#
|
@@ -106,19 +136,7 @@ class OnChain::Transaction
|
|
106
136
|
tx.add_out(txout)
|
107
137
|
end
|
108
138
|
|
109
|
-
inputs_to_sign =
|
110
|
-
tx.in.each_with_index do |txin, index|
|
111
|
-
hash = tx.signature_hash_for_input(index, txin.script, 1)
|
112
|
-
|
113
|
-
rsscript = Bitcoin::Script.new txin.script
|
114
|
-
rsscript.get_multisig_pubkeys.each do |key|
|
115
|
-
|
116
|
-
if inputs_to_sign[index] == nil
|
117
|
-
inputs_to_sign[index] = {}
|
118
|
-
end
|
119
|
-
inputs_to_sign[index][OnChain.bin_to_hex(key)] = {'hash' => OnChain::bin_to_hex(hash)}
|
120
|
-
end
|
121
|
-
end
|
139
|
+
inputs_to_sign = get_inputs_to_sign tx
|
122
140
|
|
123
141
|
return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
|
124
142
|
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.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Purton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|