onchain 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/onchain/transaction.rb +45 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7bf91b8cade08cc1d03664aeb0d2268c2fada4e
|
4
|
+
data.tar.gz: 13201f56040e814f0ba7e910d8e1f820db50855a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c770c87ff320dd376b39f6cf3b3ac5795d8668a1ceb841af83efcc4a7a20a305a59b1e302c57979420d2535eec9be6fc55900ece56cb884b7c498025764454e2
|
7
|
+
data.tar.gz: 1496f4dd396f0cef797fb011e947c67d14718950481af8dc55cc3333a372a954abd38cc748509b14d642928c568d8d2f6709f11b71d5e9bd89bab40017bfb645
|
data/lib/onchain/transaction.rb
CHANGED
@@ -1,6 +1,51 @@
|
|
1
1
|
class OnChain::Transaction
|
2
2
|
class << self
|
3
3
|
|
4
|
+
def create_single_address_transaction(orig_addr, dest_addr, amount, fee_percent, fee_addr)
|
5
|
+
|
6
|
+
tx = Bitcoin::Protocol::Tx.new
|
7
|
+
|
8
|
+
total_amount = amount + calculate_fee(amount, fee_percent)
|
9
|
+
|
10
|
+
unspents, indexes, change = OnChain::BlockChain.get_unspent_for_amount(
|
11
|
+
[orig_addr], total_amount)
|
12
|
+
|
13
|
+
|
14
|
+
# Process the unpsent outs.
|
15
|
+
unspents.each_with_index do |spent, index|
|
16
|
+
|
17
|
+
txin = Bitcoin::Protocol::TxIn.new([ spent[0] ].pack('H*').reverse, spent[1])
|
18
|
+
txin.script_sig = Bitcoin::Script.to_pubkey_script(orig_addr)
|
19
|
+
tx.add_in(txin)
|
20
|
+
end
|
21
|
+
|
22
|
+
txout = Bitcoin::Protocol::TxOut.new(amount, Bitcoin::Script.to_address_script(dest_addr))
|
23
|
+
|
24
|
+
tx.add_out(txout)
|
25
|
+
|
26
|
+
# Send the change back.
|
27
|
+
if change > 0
|
28
|
+
|
29
|
+
txout = Bitcoin::Protocol::TxOut.new(change,
|
30
|
+
Bitcoin::Script.to_address_script(orig_addr))
|
31
|
+
|
32
|
+
tx.add_out(txout)
|
33
|
+
end
|
34
|
+
|
35
|
+
return OnChain::bin_to_hex(tx.to_payload)
|
36
|
+
end
|
37
|
+
|
38
|
+
def calculate_fee(amount, fee_percent)
|
39
|
+
|
40
|
+
fee = (amount * (fee_percent / 100.0)).to_i
|
41
|
+
|
42
|
+
if fee < 10000
|
43
|
+
return 0
|
44
|
+
end
|
45
|
+
|
46
|
+
return fee
|
47
|
+
end
|
48
|
+
|
4
49
|
# Given a send address and an amount produce a transaction
|
5
50
|
# and a list of hashes that need to be signed.
|
6
51
|
#
|
@@ -17,8 +62,6 @@ class OnChain::Transaction
|
|
17
62
|
#
|
18
63
|
def create_transaction(redemption_scripts, address, amount_in_satoshi, miners_fee)
|
19
64
|
|
20
|
-
tx = Bitcoin::Protocol::Tx.new
|
21
|
-
|
22
65
|
total_amount = miners_fee
|
23
66
|
|
24
67
|
total_amount = total_amount + amount_in_satoshi
|
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.0
|
4
|
+
version: 2.1.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-12-
|
11
|
+
date: 2014-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: chain-ruby
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.0.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.0.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: httparty
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|