onchain 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onchain/transaction.rb +60 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da08e99a19308739fd1b094c0f49fdc77a3a3a47
4
- data.tar.gz: e18db7ffc4b67db018bac4d56dca017027e60c3e
3
+ metadata.gz: 6014ed705855da5a183a1d54b75017fa0cd431a7
4
+ data.tar.gz: c6e04256160aa7fefe43988ca500445bc75b6381
5
5
  SHA512:
6
- metadata.gz: 265ecdb23042caa3d317f15c7be60297298f52b1f19d5e9fa2fbc685bd21a4a29268ca85a6c62164db97aa65d44244d3821c70ec9359cd1def352fb008822a37
7
- data.tar.gz: 1e8245a12f81f9f916769b426a58ff89189203cf2cb7f95fef680582ccdc970bd3fdcd7bb9ac37c27eca6b259dfaa5023aec14f7b087b2f403dcb1c82129c765
6
+ metadata.gz: 826d0fb3d913ac4b0c87bd0f39746ae4ca4225037a4e0888bca3144edd5eaf6c96c20a210b27f2585a5e86e0021d80113ace4247375a683e5cfd29cbf3ef568c
7
+ data.tar.gz: 57d80f07459e90b108654329bb7f047fdca060727007a467775dcabb04a3672f7c8a621b7288df49afc0e2cf9136242cf084886e5bc2eb689e9c4c45dd2daab3
@@ -24,6 +24,24 @@ class OnChain::Transaction
24
24
 
25
25
  tx.add_out(txout)
26
26
 
27
+ # Add wallet fee
28
+ add_fee_to_tx(fee, fee_addr, tx)
29
+
30
+ # Send the change back.
31
+ if change > 0
32
+
33
+ txout = Bitcoin::Protocol::TxOut.new(change, Bitcoin::Script.to_address_script(orig_addr))
34
+
35
+ tx.add_out(txout)
36
+ end
37
+
38
+ inputs_to_sign = get_inputs_to_sign(tx)
39
+
40
+ return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
41
+ end
42
+
43
+ def add_fee_to_tx(fee, fee_addr, tx)
44
+
27
45
  # Add wallet fee
28
46
  if fee > 0 and (fee - 10000) > 0
29
47
 
@@ -42,17 +60,55 @@ class OnChain::Transaction
42
60
  tx.add_out(txout)
43
61
  end
44
62
  end
63
+
64
+ end
65
+
66
+ # Like create_single_address_transaction but for multi sig wallets.
67
+ def create_transaction_with_fee(redemption_scripts, address, amount, fee_percent, fee_addr)
68
+
69
+ fee = calculate_fee(amount, fee_percent)
70
+
71
+ total_amount = amount + fee
72
+
73
+ addresses = redemption_scripts.map { |rs|
74
+ OnChain::Sweeper.generate_address_of_redemption_script(rs)
75
+ }
76
+
77
+ unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(addresses, total_amount)
78
+
79
+ # OK, let's build a transaction.
80
+ tx = Bitcoin::Protocol::Tx.new
81
+
82
+ # Process the unpsent outs.
83
+ unspents.each_with_index do |spent, index|
84
+
85
+ script = redemption_scripts[indexes[index]]
86
+
87
+ txin = Bitcoin::Protocol::TxIn.new([ spent[0] ].pack('H*').reverse, spent[1])
88
+ txin.script_sig = OnChain::hex_to_bin(script)
89
+ tx.add_in(txin)
90
+ end
91
+
92
+ # Add wallet fee
93
+ add_fee_to_tx(fee, fee_addr, tx)
94
+
95
+ txout = Bitcoin::Protocol::TxOut.new(amount, Bitcoin::Script.to_address_script(address))
96
+
97
+ tx.add_out(txout)
98
+
99
+ change_address = addresses[0]
45
100
 
46
101
  # Send the change back.
47
102
  if change > 0
48
-
49
- txout = Bitcoin::Protocol::TxOut.new(change, Bitcoin::Script.to_address_script(orig_addr))
103
+
104
+ txout = Bitcoin::Protocol::TxOut.new(change,
105
+ Bitcoin::Script.to_address_script(change_address))
50
106
 
51
107
  tx.add_out(txout)
52
108
  end
53
109
 
54
- inputs_to_sign = get_inputs_to_sign(tx)
55
-
110
+ inputs_to_sign = get_inputs_to_sign tx
111
+
56
112
  return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
57
113
  end
58
114
 
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.5
4
+ version: 2.1.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: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.4.3
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: Ruby wrapper for various 3rd-party bitcoin APIs