onchain 1.0.2 → 1.0.3
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/payments.rb +61 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1ff0c8960ece90d655f5936994141258aec19a
|
4
|
+
data.tar.gz: 377e2a448d78d731ef2f47ca30bfa2efaaf4defe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31634e1cfe1bef167d96f1e9747a5c4fea620f5b966f4f92d7d911f478429de47997aac42d54d51a6a9a106ea68437b576fb5f792dd06a18f00172d3c9a84e87
|
7
|
+
data.tar.gz: a3fba350cbfa7ff904c9313354d4e209214aca1f27cb8a359a3b98d59bbe22d226c271b188cae88de55ee480a4b9c82a5a397306ecf58dec9e210b636541aee9
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class OnChain
|
2
|
+
class << self
|
3
|
+
|
4
|
+
|
5
|
+
# With a bunch of HD wallet paths, build a transaction
|
6
|
+
# That pays all the coins to a certain address
|
7
|
+
def create_payment_tx(fund_address, payments)
|
8
|
+
|
9
|
+
begin
|
10
|
+
|
11
|
+
tx = Bitcoin::Protocol::Tx.new
|
12
|
+
|
13
|
+
total_amount = 0
|
14
|
+
|
15
|
+
payments.each do |payment|
|
16
|
+
total_amount = total_amount + payment[1]
|
17
|
+
end
|
18
|
+
|
19
|
+
total_in_fund = get_balance_satoshi(fund_address)
|
20
|
+
|
21
|
+
# Do we have enough in the fund.
|
22
|
+
if(total_amount > total_in_fund)
|
23
|
+
return 'Balance is not enough to cover payment'
|
24
|
+
end
|
25
|
+
|
26
|
+
# OK, let's get some inputs
|
27
|
+
amount_so_far = 0
|
28
|
+
unspent = get_unspent_outs(fund_address)
|
29
|
+
unspent.each do |spent|
|
30
|
+
|
31
|
+
amount_so_far = amount_so_far + spent[3].to_i
|
32
|
+
if amount_so_far >= total_amount
|
33
|
+
next
|
34
|
+
end
|
35
|
+
|
36
|
+
txin = Bitcoin::Protocol::TxIn.new
|
37
|
+
|
38
|
+
txin.prev_out = spent[0]
|
39
|
+
txin.prev_out_index = spent[1]
|
40
|
+
|
41
|
+
tx.add_in(txin)
|
42
|
+
end
|
43
|
+
change = amount_so_far - total_amount
|
44
|
+
|
45
|
+
payments.each do |payment|
|
46
|
+
txout = Bitcoin::Protocol::TxOut.new(payment[1], Bitcoin::Script.from_string(
|
47
|
+
"OP_DUP OP_HASH160 #{payment[0]} " +
|
48
|
+
"OP_EQUALVERIFY OP_CHECKSIG").to_payload)
|
49
|
+
|
50
|
+
tx.add_out(txout)
|
51
|
+
end
|
52
|
+
|
53
|
+
return tx
|
54
|
+
|
55
|
+
rescue Exception => e
|
56
|
+
return 'Unable to parse payment :: ' + e.to_s
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: onchain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian Purton
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- lib/onchain.rb
|
77
77
|
- lib/onchain/block_chain.rb
|
78
|
+
- lib/onchain/payments.rb
|
78
79
|
- lib/onchain/sweeper.rb
|
79
80
|
homepage: https://github.com/onchain/onchain-gem
|
80
81
|
licenses: []
|