onchain 2.3 → 2.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034458f790aa11b634b8bb69124f656c0eda1f9b
|
4
|
+
data.tar.gz: 183a2755af1208eb7dc3c0a985986d4e5f592095
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b257a25e848762377438c1cde57b3fc9e34d2e2329c8f9b38ee3bae30b4238e9ff7282b85681096178b40935cee8593e66f5f291b7a77df9c44b10d99f5bc11
|
7
|
+
data.tar.gz: 2f4da8dda8a8b4476817a0491f01a64720f34a63868099936c72dcb464207138ca6b4815d94f3a6bd1e7b93277e00db3931d586c397abb95f28ab1ac53bb4858
|
@@ -126,6 +126,11 @@ class OnChain::BlockChain
|
|
126
126
|
end
|
127
127
|
return bal
|
128
128
|
end
|
129
|
+
|
130
|
+
def blockinfo_get_transaction(txhash)
|
131
|
+
base = "https://blockchain.info/rawtx/#{txhash}?format=hex"
|
132
|
+
return fetch_response(URI::encode(base))
|
133
|
+
end
|
129
134
|
|
130
135
|
def block_chain(cmd, address, params = "")
|
131
136
|
base_url = "https://blockchain.info/#{cmd}/#{address}?format=json" + params
|
@@ -101,6 +101,11 @@ class OnChain::BlockChain
|
|
101
101
|
cache_write(addr, bal, BALANCE_CACHE_FOR)
|
102
102
|
end
|
103
103
|
end
|
104
|
+
|
105
|
+
def blockr_get_transaction(txhash)
|
106
|
+
base = "https://blockr.io/api/v1/tx/raw/" + txhash
|
107
|
+
return fetch_response(URI::encode(base))['data']['tx']['hex']
|
108
|
+
end
|
104
109
|
|
105
110
|
def blockr(cmd, address, params = "")
|
106
111
|
|
data/lib/onchain/transaction.rb
CHANGED
@@ -1,6 +1,37 @@
|
|
1
1
|
class OnChain::Transaction
|
2
2
|
class << self
|
3
3
|
|
4
|
+
# Check a transactions inputs only spend enough to cover fees and amount
|
5
|
+
# Basically if onchain creates an incorrect transaction the client
|
6
|
+
# can identify it here.
|
7
|
+
def check_integrity(txhex, amount, orig_addresses, dest_addr, tolerence)
|
8
|
+
|
9
|
+
tx = Bitcoin::Protocol::Tx.new OnChain::hex_to_bin(txhex)
|
10
|
+
|
11
|
+
input_amount = 0
|
12
|
+
# Let's add up the value of all the inputs.
|
13
|
+
tx.in.each_with_index do |txin, index|
|
14
|
+
prev_hash = txin.to_hash['prev_out']['hash']
|
15
|
+
prev_index = txin.to_hash['prev_out']['n']
|
16
|
+
|
17
|
+
# Get the amount for the previous output
|
18
|
+
prevhex = OnChain::BlockChain.get_transaction(prev_hash)
|
19
|
+
prev_tx = Bitcoin::Protocol::Tx.new OnChain::hex_to_bin(prevhex)
|
20
|
+
input_amount += prev_tx.out[prev_index].value
|
21
|
+
|
22
|
+
if ! orig_addresses.include? prev_tx.out[prev_index].parsed_script.get_hash160_address
|
23
|
+
raise "One of the inputs is not from from our list of valid originating addresses"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
tolerence = (amount * (1 + tolerence))
|
28
|
+
if input_amount > tolerence
|
29
|
+
raise "Transaction has more input value (#{input_amount}) than the tolerence #{tolerence}"
|
30
|
+
end
|
31
|
+
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
|
4
35
|
def create_single_address_transaction(orig_addr, dest_addr, amount, fee_percent, fee_addr, min_fee_satoshi)
|
5
36
|
|
6
37
|
tx = Bitcoin::Protocol::Tx.new
|
@@ -11,6 +42,7 @@ class OnChain::Transaction
|
|
11
42
|
|
12
43
|
unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(
|
13
44
|
[orig_addr], total_amount)
|
45
|
+
indexes = nil
|
14
46
|
|
15
47
|
|
16
48
|
# Process the unpsent outs.
|
@@ -66,7 +98,7 @@ class OnChain::Transaction
|
|
66
98
|
# Like create_single_address_transaction but for multi sig wallets.
|
67
99
|
def create_transaction_with_fee(redemption_scripts, address, amount, fee_percent, fee_addr)
|
68
100
|
|
69
|
-
fee = calculate_fee(amount, fee_percent)
|
101
|
+
fee = calculate_fee(amount, fee_percent, 10000)
|
70
102
|
|
71
103
|
total_amount = amount + fee
|
72
104
|
|
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.4'
|
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-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|