mixin_bot 0.7.9 → 0.7.12

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: c89684bcccabf1621b82773b9d017e8ec47faac2402ddc6b7238d591c9099705
4
- data.tar.gz: 05d1e90439562b61ba03b3874945168fa4f838f5d48b57fbacb1738cf648a9ff
3
+ metadata.gz: 13c4f9ce40bbee325eed32c0a8a3c928911e3f3f2fc1acf3481b8a483d768e0d
4
+ data.tar.gz: 916d23e4ddc9bcc9f7eea588b9b00cd46a099cbc5d7ed955f74ec45077c41f00
5
5
  SHA512:
6
- metadata.gz: f689d32c959651bbf71426f1c68942bc1ad0d17147885f42cfa5606e5a1ffecbf02416e57f8c8aa13cac214e2124bc207f6c51adb91e3962adc474d2e251e029
7
- data.tar.gz: 3d99fd38161f4c1d326b7a32d63400270df4a3c7128070ed7d8abe8bb6f9947c31522963fb967ca4ae30b86d0a38882f911da79e639d7184ded9e36ce31df5a5
6
+ metadata.gz: 5283924b083f585b4a49486f39ecf668db803b3a3f975293bd421d5edbf92c370decaa113fc3893f2c79eaffc9f78c45aa2257d93ec4b1ee0eabcd5163c1cada
7
+ data.tar.gz: 72208f22e2b8a9a26814ca2a4bc2f260e461cc25f9231746ede4fbd638519242b8fada5604e325b467acd16be05eb88809053300067d7f54d0b56cd140033b46
@@ -11,13 +11,7 @@ module MixinBot
11
11
 
12
12
  desc 'unique UUIDS', 'generate unique UUID for two or more UUIDs'
13
13
  def unique(*uuids)
14
- uuids.sort
15
- r = uuids.first
16
- uuids.each_with_index do |uuid, i|
17
- r = MixinBot::Utils.unique_uuid(r, uuid) if i.positive?
18
- end
19
-
20
- log r
14
+ log MixinBot::Utils.unique_uuid *uuids
21
15
  end
22
16
 
23
17
  desc 'generatetrace HASH', 'generate trace ID from Tx hash'
@@ -76,7 +76,9 @@ module MixinBot
76
76
  raise UnauthorizedError, errmsg
77
77
  when 403, 20116, 10002, 429
78
78
  raise ForbiddenError, errmsg
79
- when 400, 404, 10006, 20133, 500, 7000, 7001
79
+ when 404
80
+ raise NotFoundError, errmsg
81
+ when 400, 10006, 20133, 500, 7000, 7001
80
82
  raise ResponseError, errmsg
81
83
  when 20117
82
84
  raise InsufficientBalanceError, errmsg
@@ -17,7 +17,7 @@ module MixinBot
17
17
  NFT_MASK = 0x00
18
18
  NULL_UUID = '00000000-0000-0000-0000-000000000000'
19
19
 
20
- def unique_uuid(uuid_1, uuid_2)
20
+ def generate_unique_uuid(uuid_1, uuid_2)
21
21
  md5 = Digest::MD5.new
22
22
  md5 << [uuid_1, uuid_2].min
23
23
  md5 << [uuid_1, uuid_2].max
@@ -37,6 +37,16 @@ module MixinBot
37
37
  )
38
38
  end
39
39
 
40
+ def unique_uuid(*uuids)
41
+ uuids.sort
42
+ r = uuids.first
43
+ uuids.each_with_index do |uuid, i|
44
+ r = MixinBot::Utils.generate_unique_uuid(r, uuid) if i.positive?
45
+ end
46
+
47
+ r
48
+ end
49
+
40
50
  def generate_trace_from_hash(hash, output_index = 0)
41
51
  md5 = Digest::MD5.new
42
52
  md5 << hash
@@ -57,7 +67,7 @@ module MixinBot
57
67
  if tx.is_a? String
58
68
  tx = JSON.parse tx
59
69
  end
60
- raise "#{tx} is not a valid json" unless tx.is_a? Hash
70
+ raise ArgumentError, "#{tx} is not a valid json" unless tx.is_a? Hash
61
71
 
62
72
  tx = tx.with_indifferent_access
63
73
  bytes = []
@@ -99,7 +109,7 @@ module MixinBot
99
109
  tx = {}
100
110
 
101
111
  magic = bytes.shift(2)
102
- raise 'Not valid raw' unless magic == MAGIC
112
+ raise ArgumentError, 'Not valid raw' unless magic == MAGIC
103
113
 
104
114
  version = bytes.shift(2)
105
115
  tx['version'] = bytes_to_int version
@@ -121,7 +131,7 @@ module MixinBot
121
131
  # aggregated
122
132
  aggregated = {}
123
133
 
124
- raise 'invalid aggregated' unless bytes.shift(2).reverse.pack('C*').unpack1('S*') == AGGREGATED_SIGNATURE_PREFIX
134
+ raise ArgumentError, 'invalid aggregated' unless bytes.shift(2).reverse.pack('C*').unpack1('S*') == AGGREGATED_SIGNATURE_PREFIX
125
135
 
126
136
  aggregated['signature'] = bytes.shift(64).pack('C*').unpack1('H*')
127
137
 
@@ -162,7 +172,7 @@ module MixinBot
162
172
 
163
173
  def nft_memo_hash(collection, token_id, hash)
164
174
  collection = NULL_UUID if collection.empty?
165
- raise 'hash must be 256-bit string' unless hash.is_a?(String) && hash.size == 64
175
+ raise ArgumentError, 'hash must be 256-bit string' unless hash.is_a?(String) && hash.size == 64
166
176
 
167
177
  memo = {
168
178
  prefix: NFT_MEMO_PREFIX,
@@ -171,14 +181,14 @@ module MixinBot
171
181
  chain: NFT_MEMO_DEFAULT_CHAIN,
172
182
  class: NFT_MEMO_DEFAULT_CLASS,
173
183
  collection: collection,
174
- token: token_id.to_s,
184
+ token: token_id.to_i,
175
185
  extra: hash
176
186
  }
177
187
 
178
188
  mark = [0]
179
189
  mark.map do |index|
180
190
  if index >= 64
181
- raise "invalid NFO memo index #{index}"
191
+ raise ArgumentError, "invalid NFO memo index #{index}"
182
192
  end
183
193
  memo[:mask] = memo[:mask] ^ (1 << index)
184
194
  end
@@ -252,8 +262,8 @@ module MixinBot
252
262
  private
253
263
 
254
264
  def encode_int(int)
255
- raise "only support int #{int}" unless int.is_a?(Integer)
256
- raise "int #{int} is larger than MAX_ENCODE_INT #{MAX_ENCODE_INT}" if int > MAX_ENCODE_INT
265
+ raise ArgumentError, "only support int #{int}" unless int.is_a?(Integer)
266
+ raise ArgumentError,"int #{int} is larger than MAX_ENCODE_INT #{MAX_ENCODE_INT}" if int > MAX_ENCODE_INT
257
267
 
258
268
  [int].pack('S*').bytes.reverse
259
269
  end
@@ -263,7 +273,7 @@ module MixinBot
263
273
  end
264
274
 
265
275
  def bytes_of(int)
266
- raise 'not integer' unless int.is_a?(Integer)
276
+ raise ArgumentError, 'not integer' unless int.is_a?(Integer)
267
277
 
268
278
  bytes = []
269
279
  loop do
@@ -427,8 +437,8 @@ module MixinBot
427
437
  bytes += NULL_BYTES
428
438
  else
429
439
  signers.each do |sig, i|
430
- raise 'signers not sorted' if i > 0 && sig <= signers[i - 1]
431
- raise 'signers not sorted' if sig > MAX_ENCODE_INT
440
+ raise ArgumentError, 'signers not sorted' if i > 0 && sig <= signers[i - 1]
441
+ raise ArgumentError, 'signers not sorted' if sig > MAX_ENCODE_INT
432
442
  end
433
443
 
434
444
  max = signers.last
@@ -458,7 +468,7 @@ module MixinBot
458
468
  0
459
469
  end
460
470
 
461
- raise 'signatures overflow' if sl == MAX_ENCODE_INT
471
+ raise ArgumentError, 'signatures overflow' if sl == MAX_ENCODE_INT
462
472
  bytes += encode_int sl
463
473
 
464
474
  if sl > 0
@@ -493,7 +503,7 @@ module MixinBot
493
503
 
494
504
  if bytes[...2] != NULL_BYTES
495
505
  magic = bytes.shift(2)
496
- raise 'Not valid input' unless magic == MAGIC
506
+ raise ArgumentError, 'Not valid input' unless magic == MAGIC
497
507
 
498
508
  deposit = {}
499
509
  deposit['chain'] = bytes.shift(32).pack('C*').unpack1('H*')
@@ -516,7 +526,7 @@ module MixinBot
516
526
 
517
527
  if bytes[...2] != NULL_BYTES
518
528
  magic = bytes.shift(2)
519
- raise 'Not valid input' unless magic == MAGIC
529
+ raise ArgumentError, 'Not valid input' unless magic == MAGIC
520
530
 
521
531
  mint = {}
522
532
  if bytes[...2] != NULL_BYTES
@@ -567,7 +577,7 @@ module MixinBot
567
577
 
568
578
  if bytes[...2] != NULL_BYTES
569
579
  magic = bytes.shift(2)
570
- raise 'Not valid output' unless magic == MAGIC
580
+ raise ArgumentError, 'Not valid output' unless magic == MAGIC
571
581
 
572
582
  withdraw = {}
573
583
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.7.9'
4
+ VERSION = '0.7.12'
5
5
  end
data/lib/mixin_bot.rb CHANGED
@@ -31,9 +31,11 @@ module MixinBot
31
31
  end
32
32
 
33
33
  class Error < StandardError; end
34
+ class ArgumentError < StandardError; end
34
35
  class HttpError < Error; end
35
36
  class RequestError < Error; end
36
37
  class ResponseError < Error; end
38
+ class NotFoundError < Error; end
37
39
  class UnauthorizedError < Error; end
38
40
  class ForbiddenError < Error; end
39
41
  class InsufficientBalanceError < Error; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-22 00:00:00.000000000 Z
11
+ date: 2022-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport