onchain 2.6 → 2.7
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/block_chain.rb +2 -2
- data/lib/onchain/transaction.rb +22 -9
- 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: 5fd37bc684d309bb9c0a1fdacfbb066e61bfc0d0
|
|
4
|
+
data.tar.gz: dd377843c1479db0d1fdc5c98692cf94ecc367f9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 821744ea8ad3475efd1275ce2088c830c173af33603998405be8b1d55ed749e687a472cd6dca18f870e4e6fcb1fb002eda10c0066c9cca2687bed145bba2c8c9
|
|
7
|
+
data.tar.gz: 92de84981941cbfb00e1a98b01877b4a8d1abf623c9677b1ac3080850c2a802c74bc916a052e0d2289e677a043959672ec3333b9042947455d6f921dca003f49
|
data/lib/onchain/block_chain.rb
CHANGED
|
@@ -81,7 +81,7 @@ class OnChain::BlockChain
|
|
|
81
81
|
return ret
|
|
82
82
|
end
|
|
83
83
|
|
|
84
|
-
def get_unspent_for_amount(addresses, amount_in_satoshi)
|
|
84
|
+
def get_unspent_for_amount(addresses, amount_in_satoshi, network = :bitcoin)
|
|
85
85
|
|
|
86
86
|
unspents = []
|
|
87
87
|
indexes = []
|
|
@@ -93,7 +93,7 @@ class OnChain::BlockChain
|
|
|
93
93
|
break
|
|
94
94
|
end
|
|
95
95
|
|
|
96
|
-
unspent_outs = get_unspent_outs(address)
|
|
96
|
+
unspent_outs = get_unspent_outs(address, network)
|
|
97
97
|
|
|
98
98
|
unspent_outs.each do |spent|
|
|
99
99
|
|
data/lib/onchain/transaction.rb
CHANGED
|
@@ -40,7 +40,8 @@ class OnChain::Transaction
|
|
|
40
40
|
return true
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def create_single_address_transaction(orig_addr, dest_addr, amount,
|
|
43
|
+
def create_single_address_transaction(orig_addr, dest_addr, amount,
|
|
44
|
+
fee_percent, fee_addr, min_fee_satoshi, network = :bitcoin)
|
|
44
45
|
|
|
45
46
|
tx = Bitcoin::Protocol::Tx.new
|
|
46
47
|
|
|
@@ -49,7 +50,7 @@ class OnChain::Transaction
|
|
|
49
50
|
total_amount = amount + fee
|
|
50
51
|
|
|
51
52
|
unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(
|
|
52
|
-
[orig_addr], total_amount)
|
|
53
|
+
[orig_addr], total_amount, network)
|
|
53
54
|
indexes = nil
|
|
54
55
|
|
|
55
56
|
|
|
@@ -60,17 +61,17 @@ class OnChain::Transaction
|
|
|
60
61
|
txin.script_sig = OnChain.hex_to_bin(spent[2])
|
|
61
62
|
tx.add_in(txin)
|
|
62
63
|
end
|
|
63
|
-
txout = Bitcoin::Protocol::TxOut.new(amount,
|
|
64
|
+
txout = Bitcoin::Protocol::TxOut.new(amount, to_address_script(dest_addr, network))
|
|
64
65
|
|
|
65
66
|
tx.add_out(txout)
|
|
66
67
|
|
|
67
68
|
# Add wallet fee
|
|
68
|
-
add_fee_to_tx(fee, fee_addr, tx)
|
|
69
|
+
add_fee_to_tx(fee, fee_addr, tx, network)
|
|
69
70
|
|
|
70
71
|
# Send the change back.
|
|
71
72
|
if change > 0
|
|
72
73
|
|
|
73
|
-
txout = Bitcoin::Protocol::TxOut.new(change,
|
|
74
|
+
txout = Bitcoin::Protocol::TxOut.new(change, to_address_script(orig_addr, network))
|
|
74
75
|
|
|
75
76
|
tx.add_out(txout)
|
|
76
77
|
end
|
|
@@ -80,7 +81,19 @@ class OnChain::Transaction
|
|
|
80
81
|
return OnChain::bin_to_hex(tx.to_payload), inputs_to_sign
|
|
81
82
|
end
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
# The bitcoin ruby methods are not thread safe when switching between
|
|
85
|
+
# testnet and the bitcoin network.
|
|
86
|
+
def to_address_script(orig_addr, network = :bitcoin)
|
|
87
|
+
|
|
88
|
+
# TODO add thread safety.
|
|
89
|
+
Bitcoin.network = network
|
|
90
|
+
address = Bitcoin::Script.to_address_script(orig_addr)
|
|
91
|
+
Bitcoin.network = :bitcoin
|
|
92
|
+
|
|
93
|
+
return address
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def add_fee_to_tx(fee, fee_addr, tx, network = :bitcoin)
|
|
84
97
|
|
|
85
98
|
# Add wallet fee
|
|
86
99
|
if fee > 0 and (fee - 10000) > 0
|
|
@@ -91,12 +104,12 @@ class OnChain::Transaction
|
|
|
91
104
|
# Check for affiliate
|
|
92
105
|
if fee_addr.kind_of?(Array)
|
|
93
106
|
affil_fee = fee / 2
|
|
94
|
-
txout1 = Bitcoin::Protocol::TxOut.new(affil_fee,
|
|
95
|
-
txout2 = Bitcoin::Protocol::TxOut.new(affil_fee,
|
|
107
|
+
txout1 = Bitcoin::Protocol::TxOut.new(affil_fee, to_address_script(fee_addr[0], network))
|
|
108
|
+
txout2 = Bitcoin::Protocol::TxOut.new(affil_fee, to_address_script(fee_addr[1], network))
|
|
96
109
|
tx.add_out(txout1)
|
|
97
110
|
tx.add_out(txout2)
|
|
98
111
|
else
|
|
99
|
-
txout = Bitcoin::Protocol::TxOut.new(fee,
|
|
112
|
+
txout = Bitcoin::Protocol::TxOut.new(fee, to_address_script(fee_addr, network))
|
|
100
113
|
tx.add_out(txout)
|
|
101
114
|
end
|
|
102
115
|
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: '2.
|
|
4
|
+
version: '2.7'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ian Purton
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-02-
|
|
11
|
+
date: 2016-02-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|