keoken 0.2.6 → 0.2.7

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
  SHA256:
3
- metadata.gz: 29d51ac3b604a27b5362f52d8f2ba9e3f81f65d0d2e0c3baa673ebfc258b93cf
4
- data.tar.gz: 9882d25399c16a712b3696b0a14a72c2dc5309c72221cd7b27ecbf5a2d74dcd2
3
+ metadata.gz: 14e0efe0081278e084d03fe333a3dbc852dd5b6c219e7b4c45198c69944a24b0
4
+ data.tar.gz: a8c4681e653efe43ad9dd2aac60e8c168ab767c03226e0758bed791180bf4ca6
5
5
  SHA512:
6
- metadata.gz: 66d5484853ad4caeb69ed2a7e5962458d28b5ec194ae11eae5ecfe0bd617baad8742512fc5cd5b7d2252a0ccff7b3e162b7cf8735edeb3e1bfaeace74d9a5e4c
7
- data.tar.gz: a0cd9a77f78f8206156ebbdf7ccc83d592637517578482a1dc64f54277d9fcb91808cf98ffe74114f4fbb8faa70578a886695631df098548c980469711640c4b
6
+ metadata.gz: ec05b3fe77a60e3fe07dd94004d8c775e82e292e71736bcfb8b35323a604e69003adc30975124e2dbf6fdecb2955d193107fea5a8ed4edcb1d0b2389899acf13
7
+ data.tar.gz: 540bac210aae1f70ed8f25d5706cec7adcd4cd343efb18283a1616d64408c25d51a261c31006b623cbb76987da6b1d10ca176ca925b8f9b238d0e9df646fadc3
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- keoken (0.2.5)
10
+ keoken (0.2.6)
11
11
  bitcoin-ruby (~> 0.0.18)
12
12
 
13
13
  GEM
@@ -1,7 +1,7 @@
1
1
  module Keoken
2
2
  module Backend
3
3
  class Base
4
- attr_accessor :inputs, :bitprim_transaction
4
+ attr_accessor :inputs, :bitprim_transaction, :total_inputs_amount
5
5
 
6
6
  def initialize
7
7
  @inputs = []
@@ -12,31 +12,30 @@ module Keoken
12
12
 
13
13
  def build_inputs(address)
14
14
  utxos = bitprim_transaction.utxos(address)
15
+ @total_inputs_amount = 0
15
16
  utxos.each do |utxo|
16
17
  txid = utxo['txid']
17
18
  transaction = bitprim_transaction.tx(txid)
18
19
  outputs = transaction['vout'].select do |vout|
19
20
  addresses = vout['scriptPubKey']['addresses']
20
- if addresses
21
- addresses.any? { |vout_address| vout_address == address }
22
- end
21
+ addresses.any? { |vout_address| vout_address == address } if addresses
23
22
  end
24
23
  raise Keoken::Error::OutputNotFound if outputs.empty?
25
24
  output = outputs.first
25
+ amount = output['value'].sub!(/\./, '').sub!(/^0+/, '').to_i
26
26
  @inputs.push(
27
27
  tx_id: txid,
28
28
  position: output['n'],
29
29
  input_script: output['scriptPubKey']['hex'],
30
- input_amount: output['value'].sub!(/\./, '').sub!(/^0+/, '').to_i
30
+ input_amount: amount
31
31
  )
32
+ @total_inputs_amount += amount
32
33
  end
33
34
  end
34
35
 
35
36
  def build_fee(type)
36
- total = @inputs.map { |input| input[:input_amount].to_i }.inject(:+)
37
- estimate_fee = @bitprim_transaction.estimate_fee.to_f
38
- [total,
39
- ((10 + 149 * @inputs.length + 35 * output_length(type)) * estimate_fee)
37
+ [@total_inputs_amount,
38
+ ((10 * @inputs.length + 35 * output_length(type)) * @bitprim_transaction.estimate_fee.to_f)
40
39
  .to_s[0..9].sub!(/\./, '').sub!(/0+/, '')]
41
40
  end
42
41
 
@@ -1,3 +1,3 @@
1
1
  module Keoken
2
- VERSION = '0.2.6'.freeze
2
+ VERSION = '0.2.7'.freeze
3
3
  end
data/spec/keoken_spec.rb CHANGED
@@ -114,7 +114,7 @@ describe Keoken do
114
114
  eq(
115
115
  [
116
116
  {
117
- "value" => "0.08752190",
117
+ "value" => "0.08977831",
118
118
  "scriptPubKey" => "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG",
119
119
  },
120
120
  {
@@ -172,11 +172,11 @@ describe Keoken do
172
172
  eq(
173
173
  [
174
174
  {
175
- "value" => "0.00269544",
175
+ "value" => "0.00117415",
176
176
  "scriptPubKey" => "OP_DUP OP_HASH160 4c2791f07c046ef21d688f12296f91ad7b44d2bb OP_EQUALVERIFY OP_CHECKSIG",
177
177
  },
178
178
  {
179
- "value" => "0.08446911",
179
+ "value" => "0.08751169",
180
180
  "scriptPubKey" => "OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG",
181
181
  },
182
182
  {
@@ -218,7 +218,7 @@ describe Keoken do
218
218
  [
219
219
  {
220
220
  address: 'bitcoincash:qpxrq63y6kz2wphm2nfsh6z23yvjmz7avcc5wsgruw',
221
- amount: '8757229',
221
+ amount: '8906080',
222
222
  script_type: 'PAYTOADDRESS'
223
223
  },
224
224
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keoken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitex