onchain 1.2.0 → 1.3.0
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/sweeper.rb +41 -1
- 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: 1df1d9f8e5f45a7a7c62c4af34d239203c976a92
|
4
|
+
data.tar.gz: 757c03fd2a78f94ce2f2445b401ab3247facdd4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12a947e15cb74473389e57f09c00f689536eb4ea47552a36259eb41b3a10011fe7028099ee569f2a05dd7c645f3076b9138393dbded5c16924badde61c8b1243
|
7
|
+
data.tar.gz: ff955c293ef7a2c9944f95caf32ba3f2163c2f11a1b777234d8de0a5194d1761497d78b7994560ce50db3a2e1e0fe0796adc401d21326c7fd36d73acc3bff298
|
data/lib/onchain/sweeper.rb
CHANGED
@@ -72,7 +72,12 @@ class OnChain::Sweeper
|
|
72
72
|
tx["outputs"].each do |output|
|
73
73
|
output["addresses"].each do |address|
|
74
74
|
if to_sweep[address] != nil
|
75
|
-
incoming_coins << [address,
|
75
|
+
incoming_coins << [address,
|
76
|
+
to_sweep[address],
|
77
|
+
output["value"],
|
78
|
+
output["transaction_hash"],
|
79
|
+
output["output_index"],
|
80
|
+
output["script"]]
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|
@@ -85,6 +90,41 @@ class OnChain::Sweeper
|
|
85
90
|
end
|
86
91
|
return incoming_coins, block_height_now
|
87
92
|
end
|
93
|
+
|
94
|
+
def create_payment_tx_from_sweep(incoming, destination_address)
|
95
|
+
|
96
|
+
tx = Bitcoin::Protocol::Tx.new
|
97
|
+
total_amount = 0
|
98
|
+
|
99
|
+
incoming.each do |output|
|
100
|
+
|
101
|
+
txin = Bitcoin::Protocol::TxIn.new
|
102
|
+
|
103
|
+
txin.prev_out = output[3].scan(/../).map { |x| x.hex }.pack('c*').reverse
|
104
|
+
txin.prev_out_index = output[4]
|
105
|
+
txin.script = Bitcoin::Script.binary_from_string(output[5])
|
106
|
+
|
107
|
+
tx.add_in(txin)
|
108
|
+
|
109
|
+
total_amount = total_amount + output[2].to_i
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
total_amount = total_amount - 100000
|
114
|
+
|
115
|
+
if total_amount < 0
|
116
|
+
return "Not enough coins to create a transaction."
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# Add an output and we're done.
|
121
|
+
txout = Bitcoin::Protocol::TxOut.new(total_amount,
|
122
|
+
Bitcoin::Script.to_address_script(destination_address))
|
123
|
+
|
124
|
+
tx.add_out(txout)
|
125
|
+
|
126
|
+
return tx
|
127
|
+
end
|
88
128
|
|
89
129
|
end
|
90
130
|
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: 1.
|
4
|
+
version: 1.3.0
|
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-10-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|