onchain 2.1.0 → 2.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7bf91b8cade08cc1d03664aeb0d2268c2fada4e
4
- data.tar.gz: 13201f56040e814f0ba7e910d8e1f820db50855a
3
+ metadata.gz: e22f8353705d9cf0ae2c8809117b989b29196d37
4
+ data.tar.gz: b4a4a4e5b8a14348c48100b1b243300ec267135d
5
5
  SHA512:
6
- metadata.gz: c770c87ff320dd376b39f6cf3b3ac5795d8668a1ceb841af83efcc4a7a20a305a59b1e302c57979420d2535eec9be6fc55900ece56cb884b7c498025764454e2
7
- data.tar.gz: 1496f4dd396f0cef797fb011e947c67d14718950481af8dc55cc3333a372a954abd38cc748509b14d642928c568d8d2f6709f11b71d5e9bd89bab40017bfb645
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 = "http://blockchain.info/address/#{address}?format=json"
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 = "http://blockchain.info/unspent?active=#{address}"
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 = "http://blockchain.info/#{cmd}/#{address}?format=json" + params
119
+ base_url = "https://blockchain.info/#{cmd}/#{address}?format=json" + params
120
120
 
121
121
  fetch_response(base_url, true)
122
122
  end
@@ -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.0
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-13 00:00:00.000000000 Z
11
+ date: 2014-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake