keoken 0.2.1 → 0.2.2

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.
data/doc/method_list.html CHANGED
@@ -45,6 +45,14 @@
45
45
 
46
46
 
47
47
  <li class="odd ">
48
+ <div class="item">
49
+ <span class='object_link'><a href="Keoken/Parser.html#amount-instance_method" title="Keoken::Parser#amount (method)">#amount</a></span>
50
+ <small>Keoken::Parser</small>
51
+ </div>
52
+ </li>
53
+
54
+
55
+ <li class="even ">
48
56
  <div class="item">
49
57
  <span class='object_link'><a href="Keoken/Bitprim/Transaction.html#assets_by_address-instance_method" title="Keoken::Bitprim::Transaction#assets_by_address (method)">#assets_by_address</a></span>
50
58
  <small>Keoken::Bitprim::Transaction</small>
@@ -52,9 +60,17 @@
52
60
  </li>
53
61
 
54
62
 
63
+ <li class="odd ">
64
+ <div class="item">
65
+ <span class='object_link'><a href="Keoken/Backend/Base.html#bitprim_transaction-instance_method" title="Keoken::Backend::Base#bitprim_transaction (method)">#bitprim_transaction</a></span>
66
+ <small>Keoken::Backend::Base</small>
67
+ </div>
68
+ </li>
69
+
70
+
55
71
  <li class="even ">
56
72
  <div class="item">
57
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.build (method)">build</a></span>
73
+ <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#build (method)">#build</a></span>
58
74
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
59
75
  </div>
60
76
  </li>
@@ -62,15 +78,31 @@
62
78
 
63
79
  <li class="odd ">
64
80
  <div class="item">
65
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build_for_creation-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.build_for_creation (method)">build_for_creation</a></span>
81
+ <span class='object_link'><a href="Keoken/Backend/Trezor/Transaction.html#build_for_creation-instance_method" title="Keoken::Backend::Trezor::Transaction#build_for_creation (method)">#build_for_creation</a></span>
82
+ <small>Keoken::Backend::Trezor::Transaction</small>
83
+ </div>
84
+ </li>
85
+
86
+
87
+ <li class="even ">
88
+ <div class="item">
89
+ <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build_for_creation-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#build_for_creation (method)">#build_for_creation</a></span>
66
90
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
67
91
  </div>
68
92
  </li>
69
93
 
70
94
 
95
+ <li class="odd ">
96
+ <div class="item">
97
+ <span class='object_link'><a href="Keoken/Backend/Trezor/Transaction.html#build_for_send_amount-instance_method" title="Keoken::Backend::Trezor::Transaction#build_for_send_amount (method)">#build_for_send_amount</a></span>
98
+ <small>Keoken::Backend::Trezor::Transaction</small>
99
+ </div>
100
+ </li>
101
+
102
+
71
103
  <li class="even ">
72
104
  <div class="item">
73
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build_for_send_amount-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.build_for_send_amount (method)">build_for_send_amount</a></span>
105
+ <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#build_for_send_amount-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#build_for_send_amount (method)">#build_for_send_amount</a></span>
74
106
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
75
107
  </div>
76
108
  </li>
@@ -86,12 +118,28 @@
86
118
 
87
119
  <li class="even ">
88
120
  <div class="item">
89
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#create-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.create (method)">create</a></span>
121
+ <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#create-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#create (method)">#create</a></span>
90
122
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
91
123
  </div>
92
124
  </li>
93
125
 
94
126
 
127
+ <li class="odd ">
128
+ <div class="item">
129
+ <span class='object_link'><a href="Keoken/Parser.html#data-instance_method" title="Keoken::Parser#data (method)">#data</a></span>
130
+ <small>Keoken::Parser</small>
131
+ </div>
132
+ </li>
133
+
134
+
135
+ <li class="even ">
136
+ <div class="item">
137
+ <span class='object_link'><a href="Keoken/Token.html#data_script-instance_method" title="Keoken::Token#data_script (method)">#data_script</a></span>
138
+ <small>Keoken::Token</small>
139
+ </div>
140
+ </li>
141
+
142
+
95
143
  <li class="odd ">
96
144
  <div class="item">
97
145
  <span class='object_link'><a href="Keoken/Bitprim/Transaction.html#estimate_fee-instance_method" title="Keoken::Bitprim::Transaction#estimate_fee (method)">#estimate_fee</a></span>
@@ -124,6 +172,22 @@
124
172
  </li>
125
173
 
126
174
 
175
+ <li class="odd ">
176
+ <div class="item">
177
+ <span class='object_link'><a href="Keoken/Parser.html#initialize-instance_method" title="Keoken::Parser#initialize (method)">#initialize</a></span>
178
+ <small>Keoken::Parser</small>
179
+ </div>
180
+ </li>
181
+
182
+
183
+ <li class="even ">
184
+ <div class="item">
185
+ <span class='object_link'><a href="Keoken/Backend/Base.html#initialize-instance_method" title="Keoken::Backend::Base#initialize (method)">#initialize</a></span>
186
+ <small>Keoken::Backend::Base</small>
187
+ </div>
188
+ </li>
189
+
190
+
127
191
  <li class="odd ">
128
192
  <div class="item">
129
193
  <span class='object_link'><a href="Keoken/IdNotFound.html#initialize-instance_method" title="Keoken::IdNotFound#initialize (method)">#initialize</a></span>
@@ -142,29 +206,37 @@
142
206
 
143
207
  <li class="odd ">
144
208
  <div class="item">
145
- <span class='object_link'><a href="Keoken/OutputNotFound.html#initialize-instance_method" title="Keoken::OutputNotFound#initialize (method)">#initialize</a></span>
146
- <small>Keoken::OutputNotFound</small>
209
+ <span class='object_link'><a href="Keoken/DataNotParsed.html#initialize-instance_method" title="Keoken::DataNotParsed#initialize (method)">#initialize</a></span>
210
+ <small>Keoken::DataNotParsed</small>
147
211
  </div>
148
212
  </li>
149
213
 
150
214
 
151
215
  <li class="even ">
152
216
  <div class="item">
153
- <span class='object_link'><a href="Keoken/Token.html#name-instance_method" title="Keoken::Token#name (method)">#name</a></span>
154
- <small>Keoken::Token</small>
217
+ <span class='object_link'><a href="Keoken/OutputNotFound.html#initialize-instance_method" title="Keoken::OutputNotFound#initialize (method)">#initialize</a></span>
218
+ <small>Keoken::OutputNotFound</small>
155
219
  </div>
156
220
  </li>
157
221
 
158
222
 
159
223
  <li class="odd ">
160
224
  <div class="item">
161
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#output_length-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.output_length (method)">output_length</a></span>
162
- <small>Keoken::Backend::BitcoinRuby::Transaction</small>
225
+ <span class='object_link'><a href="Keoken/Backend/Base.html#inputs-instance_method" title="Keoken::Backend::Base#inputs (method)">#inputs</a></span>
226
+ <small>Keoken::Backend::Base</small>
163
227
  </div>
164
228
  </li>
165
229
 
166
230
 
167
231
  <li class="even ">
232
+ <div class="item">
233
+ <span class='object_link'><a href="Keoken/Parser.html#name-instance_method" title="Keoken::Parser#name (method)">#name</a></span>
234
+ <small>Keoken::Parser</small>
235
+ </div>
236
+ </li>
237
+
238
+
239
+ <li class="odd ">
168
240
  <div class="item">
169
241
  <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#raw-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#raw (method)">#raw</a></span>
170
242
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
@@ -172,7 +244,7 @@
172
244
  </li>
173
245
 
174
246
 
175
- <li class="odd ">
247
+ <li class="even ">
176
248
  <div class="item">
177
249
  <span class='object_link'><a href="Keoken/Token.html#send_amount-instance_method" title="Keoken::Token#send_amount (method)">#send_amount</a></span>
178
250
  <small>Keoken::Token</small>
@@ -180,15 +252,15 @@
180
252
  </li>
181
253
 
182
254
 
183
- <li class="even ">
255
+ <li class="odd ">
184
256
  <div class="item">
185
- <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#send_amount-class_method" title="Keoken::Backend::BitcoinRuby::Transaction.send_amount (method)">send_amount</a></span>
257
+ <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#send_amount-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#send_amount (method)">#send_amount</a></span>
186
258
  <small>Keoken::Backend::BitcoinRuby::Transaction</small>
187
259
  </div>
188
260
  </li>
189
261
 
190
262
 
191
- <li class="odd ">
263
+ <li class="even ">
192
264
  <div class="item">
193
265
  <span class='object_link'><a href="Keoken/Bitprim/Transaction.html#send_tx-instance_method" title="Keoken::Bitprim::Transaction#send_tx (method)">#send_tx</a></span>
194
266
  <small>Keoken::Bitprim::Transaction</small>
@@ -196,7 +268,7 @@
196
268
  </li>
197
269
 
198
270
 
199
- <li class="even ">
271
+ <li class="odd ">
200
272
  <div class="item">
201
273
  <span class='object_link'><a href="Bitcoin/Script.html#to_custom_script-class_method" title="Bitcoin::Script.to_custom_script (method)">to_custom_script</a></span>
202
274
  <small>Bitcoin::Script</small>
@@ -204,6 +276,30 @@
204
276
  </li>
205
277
 
206
278
 
279
+ <li class="even ">
280
+ <div class="item">
281
+ <span class='object_link'><a href="Keoken/Token.html#to_hash-instance_method" title="Keoken::Token#to_hash (method)">#to_hash</a></span>
282
+ <small>Keoken::Token</small>
283
+ </div>
284
+ </li>
285
+
286
+
287
+ <li class="odd ">
288
+ <div class="item">
289
+ <span class='object_link'><a href="Keoken/Token.html#to_json-instance_method" title="Keoken::Token#to_json (method)">#to_json</a></span>
290
+ <small>Keoken::Token</small>
291
+ </div>
292
+ </li>
293
+
294
+
295
+ <li class="even ">
296
+ <div class="item">
297
+ <span class='object_link'><a href="Keoken/Backend/Trezor/Transaction.html#to_json-instance_method" title="Keoken::Backend::Trezor::Transaction#to_json (method)">#to_json</a></span>
298
+ <small>Keoken::Backend::Trezor::Transaction</small>
299
+ </div>
300
+ </li>
301
+
302
+
207
303
  <li class="odd ">
208
304
  <div class="item">
209
305
  <span class='object_link'><a href="Keoken/Backend/BitcoinRuby/Transaction.html#to_json-instance_method" title="Keoken::Backend::BitcoinRuby::Transaction#to_json (method)">#to_json</a></span>
@@ -213,6 +309,14 @@
213
309
 
214
310
 
215
311
  <li class="even ">
312
+ <div class="item">
313
+ <span class='object_link'><a href="Keoken/Parser.html#transaction_type-instance_method" title="Keoken::Parser#transaction_type (method)">#transaction_type</a></span>
314
+ <small>Keoken::Parser</small>
315
+ </div>
316
+ </li>
317
+
318
+
319
+ <li class="odd ">
216
320
  <div class="item">
217
321
  <span class='object_link'><a href="Keoken/Bitprim/Transaction.html#tx-instance_method" title="Keoken::Bitprim::Transaction#tx (method)">#tx</a></span>
218
322
  <small>Keoken::Bitprim::Transaction</small>
@@ -220,7 +324,7 @@
220
324
  </li>
221
325
 
222
326
 
223
- <li class="odd ">
327
+ <li class="even ">
224
328
  <div class="item">
225
329
  <span class='object_link'><a href="Keoken/Bitprim/Transaction.html#utxos-instance_method" title="Keoken::Bitprim::Transaction#utxos (method)">#utxos</a></span>
226
330
  <small>Keoken::Bitprim::Transaction</small>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Fri Feb 1 15:17:04 2019 by
103
+ Generated on Tue Feb 5 12:51:34 2019 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.18 (ruby-2.3.3).
106
106
  </div>
@@ -14,7 +14,7 @@ module Keoken
14
14
  #
15
15
  def build_for_creation(address, path, script)
16
16
  build_inputs(address)
17
- total, fee = build_fee(type)
17
+ total, fee = build_fee(:create)
18
18
  output_amount = total - fee.to_i
19
19
  create(@inputs, path, address, output_amount, script)
20
20
  end
@@ -30,7 +30,7 @@ module Keoken
30
30
  #
31
31
  def build_for_send_amount(address, address_dest, path, script)
32
32
  build_inputs(address)
33
- total, fee = build_fee(type)
33
+ total, fee = build_fee(:send)
34
34
  output_amount = total - (fee.to_i * 2)
35
35
  output_amount_to_addr2 = fee.to_i
36
36
  send(@inputs, path, output_amount, address, output_amount_to_addr2, address_dest, script)
@@ -1,7 +1,9 @@
1
1
  module Keoken
2
- class DataNotParsed < StandardError
3
- def initialize(msg = 'Data can not be parsed')
4
- super
2
+ module Error
3
+ class DataNotParsed < StandardError
4
+ def initialize(msg = 'Data can not be parsed')
5
+ super
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  module Keoken
2
- class IdNotFound < StandardError
3
- def initialize(msg = 'Missing id')
4
- super
2
+ module Error
3
+ class IdNotFound < StandardError
4
+ def initialize(msg = 'Missing id')
5
+ super
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  module Keoken
2
- class NameNotFound < StandardError
3
- def initialize(msg = 'Missing name')
4
- super
2
+ module Error
3
+ class NameNotFound < StandardError
4
+ def initialize(msg = 'Missing name')
5
+ super
6
+ end
5
7
  end
6
8
  end
7
9
  end
@@ -1,7 +1,9 @@
1
1
  module Keoken
2
- class OutputNotFound < StandardError
3
- def initialize(msg = 'Missing output')
4
- super
2
+ module Error
3
+ class OutputNotFound < StandardError
4
+ def initialize(msg = 'Missing output')
5
+ super
6
+ end
5
7
  end
6
8
  end
7
9
  end
data/lib/keoken/parser.rb CHANGED
@@ -10,11 +10,11 @@ module Keoken
10
10
 
11
11
  # rubocop:disable Metrics/AbcSize
12
12
  def prefix
13
- raise Keoken::DataNotParsed, 'OP_RETURN missing' unless @data.slice!(0) == Bitcoin::Script::OP_RETURN.to_i
14
- raise Keoken::DataNotParsed, 'Prefix size missing' unless @data.slice!(0) == Keoken::PREFIX_SIZE.to_i
13
+ raise Keoken::Error::DataNotParsed, 'OP_RETURN missing' unless @data.slice!(0) == Bitcoin::Script::OP_RETURN.to_i
14
+ raise Keoken::Error::DataNotParsed, 'Prefix size missing' unless @data.slice!(0) == Keoken::PREFIX_SIZE.to_i
15
15
  result = @data.slice!(0..Keoken::PREFIX.htb.bytes.length - 1)
16
- raise Keoken::DataNotParsed, 'Prefix not provided' unless result == Keoken::PREFIX.htb.bytes
17
- raise Keoken::DataNotParsed, 'Bytesize not provided' unless @data.slice!(0) == @data.length
16
+ raise Keoken::Error::DataNotParsed, 'Prefix not provided' unless result == Keoken::PREFIX.htb.bytes
17
+ raise Keoken::Error::DataNotParsed, 'Bytesize not provided' unless @data.slice!(0) == @data.length
18
18
  end
19
19
  # rubocop:enable Metrics/AbcSize
20
20
 
@@ -26,7 +26,7 @@ module Keoken
26
26
  elsif result == Keoken::TYPE_SEND_TOKEN
27
27
  :send
28
28
  else
29
- raise Keoken::DataNotParsed, 'Transaction type not valid'
29
+ raise Keoken::Error::DataNotParsed, 'Transaction type not valid'
30
30
  end
31
31
  @transaction_type
32
32
  end
@@ -35,7 +35,7 @@ module Keoken
35
35
  name = []
36
36
  end_of_name = false
37
37
  loop do
38
- tmp = @data.slice!(0)
38
+ (tmp = @data.slice!(0)) || break
39
39
  end_of_name ||= tmp > 0
40
40
  next if tmp.zero? && !end_of_name
41
41
  break if tmp.zero? && end_of_name
data/lib/keoken/token.rb CHANGED
@@ -24,7 +24,7 @@ module Keoken
24
24
  # @return [Keoken::Token] An object with the data needed to crate the token.
25
25
  #
26
26
  def create(amount)
27
- raise Keoken::NameNotFound unless @name
27
+ raise Keoken::Error::NameNotFound unless @name
28
28
  @data_script =
29
29
  [
30
30
  Keoken::VERSION_NODE,
@@ -42,7 +42,7 @@ module Keoken
42
42
  # @return [Keoken::Token] An object with the data needed to send the amount.
43
43
  #
44
44
  def send_amount(amount)
45
- raise Keoken::IdNotFound unless @id
45
+ raise Keoken::Error::IdNotFound unless @id
46
46
  asset_length = Keoken::ASSET_ID_SIZE - @id.to_s.length - 1
47
47
  @data_script =
48
48
  [
@@ -1,3 +1,3 @@
1
1
  module Keoken
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
data/lib/keoken.rb CHANGED
@@ -1,14 +1,16 @@
1
1
  require 'bitcoin'
2
2
 
3
+ require 'keoken/errors/id_not_found'
4
+ require 'keoken/errors/name_not_found'
5
+ require 'keoken/errors/data_not_parsed'
6
+ require 'keoken/errors/output_not_found'
3
7
  require 'keoken/extensions/bitcoin/script'
4
8
  require 'keoken/parser'
5
9
  require 'keoken/token'
6
10
  require 'keoken/backend/base'
7
11
  require 'keoken/backend/bitcoin_ruby/transaction'
12
+ require 'keoken/backend/trezor/transaction'
8
13
  require 'keoken/bitprim/transaction'
9
- require 'keoken/errors/id_not_found'
10
- require 'keoken/errors/name_not_found'
11
- require 'keoken/errors/data_not_parsed'
12
14
 
13
15
  module Keoken
14
16
  PREFIX_SIZE = '04'.freeze
data/spec/keoken_spec.rb CHANGED
@@ -25,57 +25,14 @@ describe Keoken do
25
25
  )
26
26
  end
27
27
 
28
- it 'serialize the test-keoken token' do
29
- token = Keoken::Token.new(script: '6a0400004b501800000000746573742d6b656f6b656e0000000000000f4240')
30
- expect(token.to_json).to(
31
- eq('{"id":null,"name":"test-keoken","amount":1000000,"transaction_type":"create"}')
32
- )
33
- end
34
-
35
- it 'deserialize the test-keoken token' do
36
- token = Keoken::Token.new(script: '6a0400004b501800000000746573742d6b656f6b656e0000000000000f4240')
37
- expect(token.to_hash).to(
38
- eq(
39
- amount: 1_000_000,
40
- name: 'test-keoken',
41
- id: nil,
42
- transaction_type: :create
43
- )
44
- )
45
- end
46
-
47
- it 'deserialize the token with id' do
48
- token = Keoken::Token.new(script: '6a0400004b5010000000010000003400000000000f4240')
49
- expect(token.to_hash).to(
50
- eq(
51
- amount: 1_000_000,
52
- name: nil,
53
- id: '34',
54
- transaction_type: :send
55
- )
56
- )
57
- end
58
-
59
- it 'deserialize the Bitprim token' do
60
- token = Keoken::Token.new(script: '6a0400004b5014000000004269747072696d0000000000000f4240')
61
- expect(token.to_hash).to(
62
- eq(
63
- amount: 1_000_000,
64
- name: 'Bitprim',
65
- id: nil,
66
- transaction_type: :create
67
- )
68
- )
69
- end
70
-
71
28
  it 'raise an error when name is not provided' do
72
29
  token = Keoken::Token.new
73
- expect { token.create(1_000_000) }.to raise_error(Keoken::NameNotFound)
30
+ expect { token.create(1_000_000) }.to raise_error(Keoken::Error::NameNotFound)
74
31
  end
75
32
 
76
33
  it 'raise an error when id is not provided' do
77
34
  token = Keoken::Token.new
78
- expect { token.send_amount(1_000_000) }.to raise_error(Keoken::IdNotFound)
35
+ expect { token.send_amount(1_000_000) }.to raise_error(Keoken::Error::IdNotFound)
79
36
  end
80
37
 
81
38
  it 'send 1_000_000 to token with 34 id' do
@@ -86,6 +43,59 @@ describe Keoken do
86
43
  )
87
44
  end
88
45
 
46
+ describe 'parsing' do
47
+ it 'serialize the test-keoken token' do
48
+ token = Keoken::Token.new(script: '6a0400004b501800000000746573742d6b656f6b656e0000000000000f4240')
49
+ expect(token.to_json).to(
50
+ eq('{"id":null,"name":"test-keoken","amount":1000000,"transaction_type":"create"}')
51
+ )
52
+ end
53
+
54
+ it 'deserialize the test-keoken token' do
55
+ token = Keoken::Token.new(script: '6a0400004b501800000000746573742d6b656f6b656e0000000000000f4240')
56
+ expect(token.to_hash).to(
57
+ eq(
58
+ amount: 1_000_000,
59
+ name: 'test-keoken',
60
+ id: nil,
61
+ transaction_type: :create
62
+ )
63
+ )
64
+ end
65
+
66
+ it 'deserialize the token with id' do
67
+ token = Keoken::Token.new(script: '6a0400004b5010000000010000003400000000000f4240')
68
+ expect(token.to_hash).to(
69
+ eq(
70
+ amount: 1_000_000,
71
+ name: nil,
72
+ id: '34',
73
+ transaction_type: :send
74
+ )
75
+ )
76
+ end
77
+
78
+ it 'deserialize the Bitprim token' do
79
+ token = Keoken::Token.new(script: '6a0400004b5014000000004269747072696d0000000000000f4240')
80
+ expect(token.to_hash).to(
81
+ eq(
82
+ amount: 1_000_000,
83
+ name: 'Bitprim',
84
+ id: nil,
85
+ transaction_type: :create
86
+ )
87
+ )
88
+ end
89
+
90
+ it 'raise parsing errors' do
91
+ expect { Keoken::Token.new(script: '') }.to raise_error(Keoken::Error::DataNotParsed)
92
+ expect { Keoken::Token.new(script: '6a') }.to raise_error(Keoken::Error::DataNotParsed)
93
+ expect { Keoken::Token.new(script: '6a04') }.to raise_error(Keoken::Error::DataNotParsed)
94
+ expect { Keoken::Token.new(script: '6a0400004b50') }.to raise_error(Keoken::Error::DataNotParsed)
95
+ expect { Keoken::Token.new(script: '6a0400004b500400000004') }.to raise_error(Keoken::Error::DataNotParsed)
96
+ end
97
+ end
98
+
89
99
  describe 'creates token' do
90
100
  before(:each) do
91
101
  mock_requests
@@ -184,6 +194,43 @@ describe Keoken do
184
194
  expect(raw).to end_with('6a0400004b5010000000010000012300000000007a120000000000')
185
195
  end
186
196
  end
197
+
198
+ describe 'creates token with Trezor' do
199
+ it 'creates token' do
200
+ mock_requests
201
+ allow(ENV).to receive(:[]).with('KEOKEN_NODE').and_return('PRODUCTION')
202
+ token = Keoken::Token.new(name: 'test-keoken')
203
+ token.create(1_000_000)
204
+ script = token.hex
205
+ @transaction_token = Keoken::Backend::Trezor::Transaction.new
206
+ expect(@transaction_token.build_for_creation('17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX', [44, 145, 0, 0, 0], script)).to(
207
+ eq(
208
+ inputs:
209
+ [
210
+ {
211
+ address_n: [44, 145, 0, 0, 0],
212
+ amount: 8985999,
213
+ prev_hash: '448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da',
214
+ prev_index: 1
215
+ }
216
+ ],
217
+ outputs:
218
+ [
219
+ {
220
+ address: '17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX',
221
+ amount: 8757229,
222
+ script_type: 'PAYTOADDRESS'
223
+ },
224
+ {
225
+ amount: '0',
226
+ op_return_data: '6a0400004b501700000000746573742d6b656f6b656e00000000000f4240',
227
+ script_type: 'PAYTOOPRETURN'
228
+ }
229
+ ]
230
+ )
231
+ )
232
+ end
233
+ end
187
234
  end
188
235
 
189
236
  def mock_requests
@@ -197,15 +244,34 @@ def mock_requests
197
244
  }).
198
245
  to_return(:status => 200, :body => body_request, :headers => {})
199
246
 
247
+ body_request = "[{\"address\":\"17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX\",\"txid\":\"448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da\",\"vout\":1,\"scriptPubKey\":\"76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac\",\"amount\":0.08985999,\"satoshis\":8985999,\"height\":1282589,\"confirmations\":1356}]"
248
+ stub_request(:get, "https://bch.blockdozer.com/insight-api/addr/17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX/utxo").
249
+ with(:headers => {
250
+ "Accept" => "*/*",
251
+ "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
252
+ "Host" => "bch.blockdozer.com",
253
+ "User-Agent" => "Ruby",
254
+ }).
255
+ to_return(:status => 200, :body => body_request, :headers => {})
256
+
200
257
  body_request = "{\"txid\":\"448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da\",\"version\":1,\"locktime\":0,\"vin\":[{\"txid\":\"48c158109ca432e109971ca61e4bccbdc2b51053c02f8183f5ca7f60a55df4d0\",\"vout\":0,\"sequence\":4294967295,\"n\":0,\"scriptSig\":{\"hex\":\"483045022100a64b8798d783d1fb7ea306cfdc2aa09cae972cbfed3fcd92a4501e54035f869b022004da604a3dd52cecd8b89200065b96bdf7c3684e6ec983ed3dceed1bf8d3a480412102bd2af43b8c683f7bb5c5dc4aad7c5a2961252676d85c2547de9767e1a6252455\",\"asm\":\"3045022100a64b8798d783d1fb7ea306cfdc2aa09cae972cbfed3fcd92a4501e54035f869b022004da604a3dd52cecd8b89200065b96bdf7c3684e6ec983ed3dceed1bf8d3a480[ALL|FORKID] 02bd2af43b8c683f7bb5c5dc4aad7c5a2961252676d85c2547de9767e1a6252455\"},\"addr\":\"mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDA\",\"valueSat\":9991999,\"value\":0.09991999,\"doubleSpentTxID\":null}],\"vout\":[{\"value\":\"0.01000000\",\"n\":0,\"scriptPubKey\":{\"hex\":\"76a9141a53f3efae04708754ca1c5382085249c0ff597d88ac\",\"asm\":\"OP_DUP OP_HASH160 1a53f3efae04708754ca1c5382085249c0ff597d OP_EQUALVERIFY OP_CHECKSIG\",\"addresses\":[\"mhvASBxPioT6eLPtSA5u1SNoT49RsME3BJ\"],\"type\":\"pubkeyhash\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null},{\"value\":\"0.08985999\",\"n\":1,\"scriptPubKey\":{\"hex\":\"76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac\",\"asm\":\"OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG\",\"addresses\":[\"mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDA\"],\"type\":\"pubkeyhash\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null},{\"value\":\"0.00000000\",\"n\":2,\"scriptPubKey\":{\"hex\":\"6a0400004b501000000001000000170000000000000064\",\"asm\":\"OP_RETURN 1347092480 00000001000000170000000000000064\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null}],\"blockhash\":\"0000000000009505e41c238f88f5c9b5591e92f7eb68545962a5dd71cd075525\",\"blockheight\":1282589,\"confirmations\":1356,\"time\":1548360176,\"blocktime\":1548360176,\"valueOut\":0.09985999,\"size\":258,\"valueIn\":0.09991999,\"fees\":0.00006}"
201
258
  stub_request(:get, "https://tbch.blockdozer.com/insight-api/tx/448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da").
202
259
  with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'tbch.blockdozer.com', 'User-Agent'=>'Ruby'}).
203
260
  to_return(:status => 200, :body => body_request, :headers => {})
204
261
 
262
+ body_request = "{\"txid\":\"448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da\",\"version\":1,\"locktime\":0,\"vin\":[{\"txid\":\"48c158109ca432e109971ca61e4bccbdc2b51053c02f8183f5ca7f60a55df4d0\",\"vout\":0,\"sequence\":4294967295,\"n\":0,\"scriptSig\":{\"hex\":\"483045022100a64b8798d783d1fb7ea306cfdc2aa09cae972cbfed3fcd92a4501e54035f869b022004da604a3dd52cecd8b89200065b96bdf7c3684e6ec983ed3dceed1bf8d3a480412102bd2af43b8c683f7bb5c5dc4aad7c5a2961252676d85c2547de9767e1a6252455\",\"asm\":\"3045022100a64b8798d783d1fb7ea306cfdc2aa09cae972cbfed3fcd92a4501e54035f869b022004da604a3dd52cecd8b89200065b96bdf7c3684e6ec983ed3dceed1bf8d3a480[ALL|FORKID] 02bd2af43b8c683f7bb5c5dc4aad7c5a2961252676d85c2547de9767e1a6252455\"},\"addr\":\"17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX\",\"valueSat\":9991999,\"value\":0.09991999,\"doubleSpentTxID\":null}],\"vout\":[{\"value\":\"0.01000000\",\"n\":0,\"scriptPubKey\":{\"hex\":\"76a9141a53f3efae04708754ca1c5382085249c0ff597d88ac\",\"asm\":\"OP_DUP OP_HASH160 1a53f3efae04708754ca1c5382085249c0ff597d OP_EQUALVERIFY OP_CHECKSIG\",\"addresses\":[\"mhvASBxPioT6eLPtSA5u1SNoT49RsME3BJ\"],\"type\":\"pubkeyhash\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null},{\"value\":\"0.08985999\",\"n\":1,\"scriptPubKey\":{\"hex\":\"76a9147bb97684cc43e2f8ea0ed1d50dddce3ebf80063888ac\",\"asm\":\"OP_DUP OP_HASH160 7bb97684cc43e2f8ea0ed1d50dddce3ebf800638 OP_EQUALVERIFY OP_CHECKSIG\",\"addresses\":[\"17wrMVCa9EJUVVEC3c5CZZanjT1NtWU2mX\"],\"type\":\"pubkeyhash\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null},{\"value\":\"0.00000000\",\"n\":2,\"scriptPubKey\":{\"hex\":\"6a0400004b501000000001000000170000000000000064\",\"asm\":\"OP_RETURN 1347092480 00000001000000170000000000000064\"},\"spentTxId\":null,\"spentIndex\":null,\"spentHeight\":null}],\"blockhash\":\"0000000000009505e41c238f88f5c9b5591e92f7eb68545962a5dd71cd075525\",\"blockheight\":1282589,\"confirmations\":1356,\"time\":1548360176,\"blocktime\":1548360176,\"valueOut\":0.09985999,\"size\":258,\"valueIn\":0.09991999,\"fees\":0.00006}"
263
+ stub_request(:get, "https://bch.blockdozer.com/insight-api/tx/448a9356f6317eeaa9581f9a39d41431ac74aa2b73438c01e1d522543d14e8da").
264
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'bch.blockdozer.com', 'User-Agent'=>'Ruby'}).
265
+ to_return(:status => 200, :body => body_request, :headers => {})
266
+
205
267
  stub_request(:get, "https://tbch.blockdozer.com/insight-api/utils/estimatefee").
206
268
  with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'tbch.blockdozer.com', 'User-Agent'=>'Ruby'}).
207
269
  to_return(:status => 200, :body => "{\"2\":0.0001021}", :headers => {})
208
270
 
271
+ stub_request(:get, "https://bch.blockdozer.com/insight-api/utils/estimatefee").
272
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Host'=>'bch.blockdozer.com', 'User-Agent'=>'Ruby'}).
273
+ to_return(:status => 200, :body => "{\"2\":0.00000999}", :headers => {})
274
+
209
275
  body_response = "[{'amount': 100000, 'asset_creator': 'mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDA', 'asset_id': 123, 'asset_name': 'keoken-token'}]"
210
276
  stub_request(:get, "https://explorer.testnet.keoken.io/api/get_assets_by_address?address=mro9aqn4xCzXVS7jRFFuzT2ERKonvPdSDA")
211
277
  .with(
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bitex
@@ -130,13 +130,18 @@ files:
130
130
  - doc/Bitcoin/Script.html
131
131
  - doc/Keoken.html
132
132
  - doc/Keoken/Backend.html
133
+ - doc/Keoken/Backend/Base.html
133
134
  - doc/Keoken/Backend/BitcoinRuby.html
134
135
  - doc/Keoken/Backend/BitcoinRuby/Transaction.html
136
+ - doc/Keoken/Backend/Trezor.html
137
+ - doc/Keoken/Backend/Trezor/Transaction.html
135
138
  - doc/Keoken/Bitprim.html
136
139
  - doc/Keoken/Bitprim/Transaction.html
140
+ - doc/Keoken/DataNotParsed.html
137
141
  - doc/Keoken/IdNotFound.html
138
142
  - doc/Keoken/NameNotFound.html
139
143
  - doc/Keoken/OutputNotFound.html
144
+ - doc/Keoken/Parser.html
140
145
  - doc/Keoken/Token.html
141
146
  - doc/_index.html
142
147
  - doc/class_list.html