onchain 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/onchain/transaction.rb +45 -2
  3. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad1b564c2170ae05098062caab20876992beb95
4
- data.tar.gz: 87e643424e44afdf817cd1fbb9e998fdb4f92e05
3
+ metadata.gz: f7bf91b8cade08cc1d03664aeb0d2268c2fada4e
4
+ data.tar.gz: 13201f56040e814f0ba7e910d8e1f820db50855a
5
5
  SHA512:
6
- metadata.gz: 8a9a73494d333d3114b03772704d261387f9a5672904d6ce3899dc17f1af28ae35bc4c9d7ac0060c45c56e6210892b1999c09bf243efe000248a1b2374a0fba9
7
- data.tar.gz: c4198d30b6dba4d6a4f67c376941099b6d2bde0b085058aaa157e89af4d0710adb4043149811b9e4e355d9a43b41c30c367a1b45778e7767a57cb484482d72ed
6
+ metadata.gz: c770c87ff320dd376b39f6cf3b3ac5795d8668a1ceb841af83efcc4a7a20a305a59b1e302c57979420d2535eec9be6fc55900ece56cb884b7c498025764454e2
7
+ data.tar.gz: 1496f4dd396f0cef797fb011e947c67d14718950481af8dc55cc3333a372a954abd38cc748509b14d642928c568d8d2f6709f11b71d5e9bd89bab40017bfb645
@@ -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.6
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-04 00:00:00.000000000 Z
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: '0'
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: '0'
82
+ version: 2.0.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: httparty
85
85
  requirement: !ruby/object:Gem::Requirement