onchain 2.0.3 → 2.0.4

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: 49b42c93865c3b3eefc04fe602688c83f1258276
4
- data.tar.gz: 52c1908b9da43e4e895b8aff732b21e08a48a96a
3
+ metadata.gz: ca958c4252ca9f068ac5df9f81af86e77de79626
4
+ data.tar.gz: 737de01dc291cabf7482cb9e8cf615ca1d7680ae
5
5
  SHA512:
6
- metadata.gz: 3f94f83d9ab3f9d80e677295ade5e2001e22f9fdff31c824863abd318508751c22690756bef692bb97ee2d81611d1c164e47acc81f765a69460c05c98eb8a564
7
- data.tar.gz: 0983bc72478e28ffbec912b02365a73dd40ccb4e55bf3d729c427e02e27ed67ef02a861faef3acb77426672af30b5db0cf49f64e9995220cdf48fabc692806a1
6
+ metadata.gz: 07b53ce9964d06414eb86f019e7450ea61cc848b6ceb9b8beb0d2c0ff758946260638db15163c8630f191a45d72b25000ba3c3c3730b83c24fe4efb5d88f495b
7
+ data.tar.gz: 6f20cec8401bad068e0f088e4ca70994004bee2d658ca97cf0cbbd1248811391a738aaa2fcba11150b2bc20bac10e787605d09f50fc4e048a3d010a47220055c
@@ -1,4 +1,5 @@
1
1
  require 'chain'
2
+ require 'time'
2
3
 
3
4
  class OnChain::BlockChain
4
5
  class << self
@@ -21,7 +22,7 @@ class OnChain::BlockChain
21
22
  hist = []
22
23
  txs.each do |tx|
23
24
  row = {}
24
- row[:time] = Date.parse(tx["block_time"]).to_s
25
+ row[:time] = Time.parse(tx["block_time"]).to_i
25
26
  row[:addr] = {}
26
27
  row[:outs] = {}
27
28
 
@@ -5,14 +5,14 @@ class OnChain::Sweeper
5
5
 
6
6
  # Turn a bunch of master keys into a redemption scriopt
7
7
  # i.e. derive the path.
8
- def multi_sig_address_from_mpks(mpks, path)
8
+ def multi_sig_address_from_mpks(minimum_sigs, mpks, path)
9
9
 
10
- rs = generate_redemption_script_from_mpks(mpks, path)
10
+ rs = generate_redemption_script_from_mpks(minimum_sigs, mpks, path)
11
11
 
12
12
  return generate_address_of_redemption_script(rs)
13
13
  end
14
14
 
15
- def generate_redemption_script_from_mpks(mpks, path)
15
+ def generate_redemption_script_from_mpks(minimum_sigs, mpks, path)
16
16
 
17
17
  addresses = []
18
18
  mpks.each do |mpk|
@@ -21,23 +21,12 @@ class OnChain::Sweeper
21
21
  addresses << m.public_key.to_hex
22
22
  end
23
23
 
24
- return generate_redemption_script(addresses)
24
+ return generate_redemption_script(minimum_sigs, addresses)
25
25
  end
26
26
 
27
- def generate_redemption_script(addresses)
28
-
29
- rs = (80 + addresses.length).to_s(16)
30
-
31
- addresses.each do |address|
32
- rs = rs + (address.length / 2).to_s(16)
33
- rs = rs + address
34
- end
35
-
36
- rs = rs + (80 + addresses.length).to_s(16)
37
-
38
- rs = rs + 'ae'
39
-
40
- return rs
27
+ def generate_redemption_script(minimum_sigs, addresses)
28
+ address, redeem_script = Bitcoin.pubkeys_to_p2sh_multisig_address(minimum_sigs, *addresses)
29
+ return redeem_script.hth
41
30
  end
42
31
 
43
32
  def generate_address_of_redemption_script(redemption_script)
@@ -52,7 +41,7 @@ class OnChain::Sweeper
52
41
 
53
42
  # With a bunch of HD wallet paths, build a transaction
54
43
  # That pays all the coins to a certain address
55
- def sweep(mpks, path, limit, last_block_checked)
44
+ def sweep(minimum_sigs, mpks, path, limit, last_block_checked)
56
45
 
57
46
  block_height_now = get_block_height
58
47
 
@@ -60,7 +49,7 @@ class OnChain::Sweeper
60
49
  # Get all the addresses we are interested in.
61
50
  for i in 0..limit do
62
51
  r = path.sub('#{index}', i.to_s)
63
- a = multi_sig_address_from_mpks(mpks, r)
52
+ a = multi_sig_address_from_mpks(minimum_sigs, mpks, r)
64
53
  # store address as lookup for path.
65
54
  to_sweep[a] = r
66
55
  end
@@ -98,7 +87,7 @@ class OnChain::Sweeper
98
87
  return incoming_coins, block_height_now
99
88
  end
100
89
 
101
- def create_payment_tx_from_sweep(incoming, destination_address, mpks)
90
+ def create_payment_tx_from_sweep(minimum_sigs, incoming, destination_address, mpks)
102
91
 
103
92
  tx = Bitcoin::Protocol::Tx.new
104
93
  total_amount = 0
@@ -107,7 +96,7 @@ class OnChain::Sweeper
107
96
 
108
97
  txin = Bitcoin::Protocol::TxIn.new
109
98
 
110
- rs = generate_redemption_script_from_mpks(mpks, output[1])
99
+ rs = generate_redemption_script_from_mpks(minimum_sigs, mpks, output[1])
111
100
 
112
101
  txin.prev_out = OnChain.hex_to_bin(output[3]).reverse
113
102
  txin.prev_out_index = output[4]
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.0.3
4
+ version: 2.0.4
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-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake