mixin_bot 0.4.0 → 0.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 769e68c946637d91db6a89c5583ab7c49763193ca8c7088fbd95038cb2bf5f20
4
- data.tar.gz: 31405213d094fb3a3d39c4f2e1b2f4e51ce7555c591148c539eb669c7b9d7ccb
3
+ metadata.gz: 1439e4f59c5ca53c83c1a897050bcb9ae236b930607d6c1dde62d558ce613ee3
4
+ data.tar.gz: 96a586f0bf29d839e997dd1a0eca16ab47055d2e6cf696d9d692fcf37052db74
5
5
  SHA512:
6
- metadata.gz: 1105ff54db0cb2eef406ebeaed844227fbb009006ddc71c4ca96bd45967b87fadd8e4a596c2f383e6c4f37558c22fec33111aa051546abf046a2944f0a3d100e
7
- data.tar.gz: 5bfce8c2db0ddfc6f204babffd5314988055a59529634d16657943c69373130640e706bb25c339c2dbb8e5f6045b796e636b76cea870746db04d3548086a52d4
6
+ metadata.gz: e15f7d07d619ab3221172b369cd77b159719de186a18fddfd8f91689f9d8c6b86c6ac23c7ecc8cb08a46f1555108d4a48abbd10138e915f842f812a554d7b737
7
+ data.tar.gz: 043f8dab94962e4b9bcbf507867b803bc8afac226de9c6edd1b19ee1fa9daa729205e949f9d7b1213985bc117450af7234bfc11f14eaaec1ff53d322e979eed0
@@ -21,6 +21,27 @@ module MixinBot
21
21
  client.post(path, headers: { 'Authorization': authorization }, json: {})
22
22
  end
23
23
 
24
+ def upload_attachment(file)
25
+ raise 'not a File' unless file.is_a?(File)
26
+
27
+ attachment = create_attachment['data']
28
+
29
+ HTTP
30
+ .timeout(connect: 5, write: 5, read: 5)
31
+ .request(
32
+ :put,
33
+ attachment.delete('upload_url'),
34
+ {
35
+ body: file,
36
+ headers: {
37
+ 'x-amz-acl': 'public-read',
38
+ 'Content-Type': 'application/octet-stream',
39
+ }
40
+ })
41
+
42
+ attachment
43
+ end
44
+
24
45
  def read_attachment(attachment_id)
25
46
  path = format('/attachments/%<id>s', id: attachment_id)
26
47
  access_token ||= access_token('GET', path, '')
@@ -276,6 +276,14 @@ module MixinBot
276
276
  send_message plain_text(options)
277
277
  end
278
278
 
279
+ def send_image_message(options)
280
+ send_message plain_image(options)
281
+ end
282
+
283
+ def send_file_message(options)
284
+ send_message plain_data(options)
285
+ end
286
+
279
287
  def send_post_message(options)
280
288
  send_message plain_post(options)
281
289
  end
@@ -197,7 +197,7 @@ module MixinBot
197
197
  threshold: threshold,
198
198
  state: 'unspent',
199
199
  access_token: access_token
200
- ).filter(
200
+ )['data'].filter(
201
201
  &lambda { |utxo|
202
202
  utxo['asset_id'] == kwargs[:asset_id]
203
203
  }
@@ -255,7 +255,7 @@ module MixinBot
255
255
  extra: extra
256
256
  }
257
257
 
258
- build_transaction tx.to_json
258
+ tx.to_json
259
259
  end
260
260
 
261
261
  def str_to_bin(str)
@@ -23,7 +23,7 @@ module MixinBot
23
23
  threshold: threshold
24
24
  },
25
25
  pin: encrypted_pin,
26
- amount: amount.to_s,
26
+ amount: format('%.8f', amount),
27
27
  trace_id: trace_id,
28
28
  memo: memo
29
29
  }
@@ -50,7 +50,7 @@ module MixinBot
50
50
  asset_id: asset_id,
51
51
  opponent_key: opponent_key,
52
52
  pin: encrypted_pin,
53
- amount: amount.to_s,
53
+ amount: format('%.8f', amount),
54
54
  trace_id: trace_id,
55
55
  memo: memo
56
56
  }
@@ -9,7 +9,7 @@ module MixinBot
9
9
 
10
10
  asset_id = options[:asset_id]
11
11
  opponent_id = options[:opponent_id]
12
- amount = options[:amount]
12
+ amount = options[:amount].to_f
13
13
  memo = options[:memo]
14
14
  trace_id = options[:trace_id] || SecureRandom.uuid
15
15
  encrypted_pin = options[:encrypted_pin] || encrypt_pin(pin)
@@ -19,7 +19,7 @@ module MixinBot
19
19
  asset_id: asset_id,
20
20
  opponent_id: opponent_id,
21
21
  pin: encrypted_pin,
22
- amount: amount.to_s,
22
+ amount: format('%.8f', amount),
23
23
  trace_id: trace_id,
24
24
  memo: memo
25
25
  }
data/lib/mixin_bot/api.rb CHANGED
@@ -44,7 +44,7 @@ module MixinBot
44
44
  end
45
45
 
46
46
  # Use a mixin software to implement transaction build
47
- def build_transaction(json)
47
+ def sign_raw_transaction(json)
48
48
  ensure_mixin_command_exist
49
49
  command = format("mixin signrawtransaction --raw '%<arg>s'", arg: json)
50
50
 
@@ -55,13 +55,35 @@ module MixinBot
55
55
  # 500 500 Internal Server Error.
56
56
  # 500 7000 Blaze server error.
57
57
  # 500 7001 The blaze operation timeout.
58
+ # 202 10002 Illegal request paramters.
59
+ # 202 20117 Insufficient balance。
60
+ # 202 20118 PIN format error.
61
+ # 202 20119 PIN error.
62
+ # 202 20120 Transfer amount is too small.
63
+ # 202 20121 Authorization code has expired.
64
+ # 202 20124 Insufficient withdrawal fee.
65
+ # 202 20125 The transfer has been paid by someone else.
66
+ # 202 20127 The withdrawal amount is too small.
67
+ # 202 20131 Withdrawal Memo format error.
68
+ # 500 30100 The current asset's public chain synchronization error.
69
+ # 500 30101 Wrong private key.
70
+ # 500 30102 Wrong withdrawal address.
71
+ # 500 30103 Insufficient pool.
72
+ # 500 7000 WebSocket server error.
73
+ # 500 7001 WebSocket operation timeout.
58
74
  case result['error']['code']
59
- when 401
75
+ when 401, 20121
60
76
  raise UnauthorizedError, errmsg
61
- when 403, 20116
77
+ when 403, 20116, 10002, 429
62
78
  raise ForbiddenError, errmsg
63
- when 400, 404, 429, 10006, 20133, 500, 7000, 7001
79
+ when 400, 404, 10006, 20133, 500, 7000, 7001
64
80
  raise ResponseError, errmsg
81
+ when 20117
82
+ raise InsufficientBalanceError, errmsg
83
+ when 20118, 20119
84
+ raise PinError, errmsg
85
+ when 30103
86
+ raise InsufficientPoolError, errmsg
65
87
  else
66
88
  raise ResponseError, errmsg
67
89
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.4'
5
5
  end
data/lib/mixin_bot.rb CHANGED
@@ -31,4 +31,7 @@ module MixinBot
31
31
  class ResponseError < StandardError; end
32
32
  class UnauthorizedError < StandardError; end
33
33
  class ForbiddenError < StandardError; end
34
+ class InsufficientBalanceError < StandardError; end
35
+ class InsufficientPoolError < StandardError; end
36
+ class PinError < StandardError; end
34
37
  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.4.0
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-08 00:00:00.000000000 Z
11
+ date: 2021-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: fastimage
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.2.5
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.2.5
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: pry
155
169
  requirement: !ruby/object:Gem::Requirement