keoken 0.2.6 → 0.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/Gemfile.lock +1 -1
- data/lib/keoken/backend/base.rb +8 -9
- data/lib/keoken/version.rb +1 -1
- data/spec/keoken_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14e0efe0081278e084d03fe333a3dbc852dd5b6c219e7b4c45198c69944a24b0
|
4
|
+
data.tar.gz: a8c4681e653efe43ad9dd2aac60e8c168ab767c03226e0758bed791180bf4ca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec05b3fe77a60e3fe07dd94004d8c775e82e292e71736bcfb8b35323a604e69003adc30975124e2dbf6fdecb2955d193107fea5a8ed4edcb1d0b2389899acf13
|
7
|
+
data.tar.gz: 540bac210aae1f70ed8f25d5706cec7adcd4cd343efb18283a1616d64408c25d51a261c31006b623cbb76987da6b1d10ca176ca925b8f9b238d0e9df646fadc3
|
data/Gemfile.lock
CHANGED
data/lib/keoken/backend/base.rb
CHANGED
@@ -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:
|
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
|
-
|
37
|
-
|
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
|
|
data/lib/keoken/version.rb
CHANGED
data/spec/keoken_spec.rb
CHANGED
@@ -114,7 +114,7 @@ describe Keoken do
|
|
114
114
|
eq(
|
115
115
|
[
|
116
116
|
{
|
117
|
-
"value" => "0.
|
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.
|
175
|
+
"value" => "0.00117415",
|
176
176
|
"scriptPubKey" => "OP_DUP OP_HASH160 4c2791f07c046ef21d688f12296f91ad7b44d2bb OP_EQUALVERIFY OP_CHECKSIG",
|
177
177
|
},
|
178
178
|
{
|
179
|
-
"value" => "0.
|
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: '
|
221
|
+
amount: '8906080',
|
222
222
|
script_type: 'PAYTOADDRESS'
|
223
223
|
},
|
224
224
|
{
|