onchain 2.1.5 → 2.1.6
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 +4 -4
- data/lib/onchain/transaction.rb +60 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6014ed705855da5a183a1d54b75017fa0cd431a7
|
4
|
+
data.tar.gz: c6e04256160aa7fefe43988ca500445bc75b6381
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 826d0fb3d913ac4b0c87bd0f39746ae4ca4225037a4e0888bca3144edd5eaf6c96c20a210b27f2585a5e86e0021d80113ace4247375a683e5cfd29cbf3ef568c
|
7
|
+
data.tar.gz: 57d80f07459e90b108654329bb7f047fdca060727007a467775dcabb04a3672f7c8a621b7288df49afc0e2cf9136242cf084886e5bc2eb689e9c4c45dd2daab3
|
data/lib/onchain/transaction.rb
CHANGED
@@ -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,
|
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
|
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.
|
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-
|
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.
|
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
|