mixin_bot 0.12.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mixin_bot/api/address.rb +21 -0
  3. data/lib/mixin_bot/api/app.rb +5 -11
  4. data/lib/mixin_bot/api/asset.rb +9 -16
  5. data/lib/mixin_bot/api/attachment.rb +27 -22
  6. data/lib/mixin_bot/api/auth.rb +34 -56
  7. data/lib/mixin_bot/api/blaze.rb +4 -3
  8. data/lib/mixin_bot/api/conversation.rb +29 -49
  9. data/lib/mixin_bot/api/encrypted_message.rb +19 -19
  10. data/lib/mixin_bot/api/inscription.rb +71 -0
  11. data/lib/mixin_bot/api/legacy_collectible.rb +140 -0
  12. data/lib/mixin_bot/api/legacy_multisig.rb +87 -0
  13. data/lib/mixin_bot/api/legacy_output.rb +50 -0
  14. data/lib/mixin_bot/api/legacy_payment.rb +31 -0
  15. data/lib/mixin_bot/api/legacy_snapshot.rb +39 -0
  16. data/lib/mixin_bot/api/legacy_transaction.rb +173 -0
  17. data/lib/mixin_bot/api/legacy_transfer.rb +42 -0
  18. data/lib/mixin_bot/api/me.rb +13 -17
  19. data/lib/mixin_bot/api/message.rb +13 -10
  20. data/lib/mixin_bot/api/multisig.rb +17 -222
  21. data/lib/mixin_bot/api/output.rb +48 -0
  22. data/lib/mixin_bot/api/payment.rb +9 -20
  23. data/lib/mixin_bot/api/pin.rb +57 -65
  24. data/lib/mixin_bot/api/rpc.rb +12 -14
  25. data/lib/mixin_bot/api/snapshot.rb +15 -29
  26. data/lib/mixin_bot/api/tip.rb +43 -0
  27. data/lib/mixin_bot/api/transaction.rb +295 -60
  28. data/lib/mixin_bot/api/transfer.rb +69 -31
  29. data/lib/mixin_bot/api/user.rb +88 -53
  30. data/lib/mixin_bot/api/withdraw.rb +52 -53
  31. data/lib/mixin_bot/api.rb +81 -46
  32. data/lib/mixin_bot/cli/api.rb +149 -5
  33. data/lib/mixin_bot/cli/utils.rb +14 -4
  34. data/lib/mixin_bot/cli.rb +13 -10
  35. data/lib/mixin_bot/client.rb +74 -127
  36. data/lib/mixin_bot/configuration.rb +98 -0
  37. data/lib/mixin_bot/nfo.rb +174 -0
  38. data/lib/mixin_bot/transaction.rb +524 -0
  39. data/lib/mixin_bot/utils/address.rb +121 -0
  40. data/lib/mixin_bot/utils/crypto.rb +218 -0
  41. data/lib/mixin_bot/utils/decoder.rb +56 -0
  42. data/lib/mixin_bot/utils/encoder.rb +63 -0
  43. data/lib/mixin_bot/utils.rb +8 -109
  44. data/lib/mixin_bot/uuid.rb +41 -0
  45. data/lib/mixin_bot/version.rb +1 -1
  46. data/lib/mixin_bot.rb +39 -14
  47. data/lib/mvm/bridge.rb +2 -19
  48. data/lib/mvm/client.rb +11 -33
  49. data/lib/mvm/nft.rb +4 -4
  50. data/lib/mvm/registry.rb +9 -9
  51. data/lib/mvm/scan.rb +3 -5
  52. data/lib/mvm.rb +5 -6
  53. metadata +77 -103
  54. data/lib/mixin_bot/api/collectible.rb +0 -138
  55. data/lib/mixin_bot/utils/nfo.rb +0 -176
  56. data/lib/mixin_bot/utils/transaction.rb +0 -478
  57. data/lib/mixin_bot/utils/uuid.rb +0 -43
data/lib/mvm/nft.rb CHANGED
@@ -6,14 +6,14 @@ module MVM
6
6
 
7
7
  def initialize(rpc_url: MVM::RPC_URL, mirror_address: MVM::MIRROR_ADDRESS)
8
8
  @rpc = Eth::Client.create rpc_url
9
- @mirror = Eth::Contract.from_abi name: 'Mirror', address: mirror_address, abi: File.open(File.expand_path('./abis/mirror.json', __dir__)).read
9
+ @mirror = Eth::Contract.from_abi name: 'Mirror', address: mirror_address, abi: File.read(File.expand_path('./abis/mirror.json', __dir__))
10
10
  end
11
11
 
12
12
  def collection_from_contract(address)
13
13
  collection = @rpc.call @mirror, 'collections', address
14
14
  return if collection.zero?
15
15
 
16
- MixinBot::Utils::UUID.new(hex: collection.to_fs(16)).unpacked
16
+ MixinBot::UUID.new(hex: collection.to_fs(16)).unpacked
17
17
  end
18
18
 
19
19
  def contract_from_collection(uuid)
@@ -29,7 +29,7 @@ module MVM
29
29
  address = contract_from_collection collection_id
30
30
  return if address.blank? || address.to_i(16).zero?
31
31
 
32
- contract = Eth::Contract.from_abi name: 'Collectible', address: address, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
32
+ contract = Eth::Contract.from_abi name: 'Collectible', address:, abi: File.read(File.expand_path('./abis/erc721.json', __dir__))
33
33
  owner = @rpc.call contract, 'ownerOf', token_id.to_i
34
34
  address = Eth::Address.new owner
35
35
  return unless address.valid?
@@ -40,7 +40,7 @@ module MVM
40
40
  end
41
41
 
42
42
  def token_of_owner_by_index(contract, owner, index)
43
- contract = Eth::Contract.from_abi name: 'Collectible', address: contract, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
43
+ contract = Eth::Contract.from_abi name: 'Collectible', address: contract, abi: File.read(File.expand_path('./abis/erc721.json', __dir__))
44
44
 
45
45
  @rpc.call contract, 'tokenOfOwnerByIndex', owner, index
46
46
  rescue IOError
data/lib/mvm/registry.rb CHANGED
@@ -6,12 +6,12 @@ module MVM
6
6
 
7
7
  def initialize(rpc_url: MVM::RPC_URL, registry_address: MVM::REGISTRY_ADDRESS)
8
8
  @rpc = Eth::Client.create rpc_url
9
- @registry = Eth::Contract.from_abi name: 'Registry', address: registry_address, abi: File.open(File.expand_path('./abis/registry.json', __dir__)).read
9
+ @registry = Eth::Contract.from_abi name: 'Registry', address: registry_address, abi: File.read(File.expand_path('./abis/registry.json', __dir__))
10
10
  end
11
11
 
12
12
  def pid
13
13
  hex = @rpc.call(@registry, 'PID').to_s(16)
14
- MixinBot::Utils::UUID.new(hex: hex).unpacked
14
+ MixinBot::UUID.new(hex:).unpacked
15
15
  end
16
16
 
17
17
  def version
@@ -20,7 +20,7 @@ module MVM
20
20
 
21
21
  def asset_from_contract(contract)
22
22
  hex = @rpc.call(@registry, 'assets', contract).to_s(16)
23
- MixinBot::Utils::UUID.new(hex: hex).unpacked
23
+ MixinBot::UUID.new(hex:).unpacked
24
24
  end
25
25
 
26
26
  def users_from_contract(contract)
@@ -28,12 +28,12 @@ module MVM
28
28
  members = []
29
29
  length = bytes.shift(2).reverse.pack('C*').unpack1('S*')
30
30
  length.times do
31
- members << MixinBot::Utils::UUID.new(raw: bytes.shift(16).pack('C*')).unpacked
31
+ members << MixinBot::UUID.new(raw: bytes.shift(16).pack('C*')).unpacked
32
32
  end
33
33
  threshold = bytes.shift(2).reverse.pack('C*').unpack1('S*')
34
34
  {
35
- members: members,
36
- threshold: threshold
35
+ members:,
36
+ threshold:
37
37
  }.with_indifferent_access
38
38
  end
39
39
 
@@ -52,9 +52,9 @@ module MVM
52
52
 
53
53
  def contract_from_multisig(user_ids, threshold)
54
54
  bytes = []
55
- bytes += MixinBot::Utils.encode_int(user_ids.length)
56
- bytes += [user_ids.sort.join('').gsub('-', '')].pack('H*').bytes
57
- bytes += MixinBot::Utils.encode_int(threshold)
55
+ bytes += MixinBot.utils.encode_uint16(user_ids.length)
56
+ bytes += [user_ids.sort.join.gsub('-', '')].pack('H*').bytes
57
+ bytes += MixinBot.utils.encode_uint16(threshold)
58
58
 
59
59
  hash = Eth::Util.bin_to_prefixed_hex(Eth::Util.keccak256(bytes.pack('C*')))
60
60
  @rpc.call @registry, 'contracts', hash.to_i(16)
data/lib/mvm/scan.rb CHANGED
@@ -12,11 +12,9 @@ module MVM
12
12
  path = '/api'
13
13
  r = client.get(
14
14
  path,
15
- params: {
16
- address: address,
17
- action: 'tokenlist',
18
- module: 'account'
19
- }
15
+ address:,
16
+ action: 'tokenlist',
17
+ module: 'account'
20
18
  )['result']
21
19
 
22
20
  r = r.filter(&->(token) { token['type'] == type }) if type.present?
data/lib/mvm.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'active_support/all'
4
- require 'http'
5
4
  require 'eth'
6
5
 
7
- require_relative './mvm/bridge'
8
- require_relative './mvm/client'
9
- require_relative './mvm/nft'
10
- require_relative './mvm/registry'
11
- require_relative './mvm/scan'
6
+ require_relative 'mvm/bridge'
7
+ require_relative 'mvm/client'
8
+ require_relative 'mvm/nft'
9
+ require_relative 'mvm/registry'
10
+ require_relative 'mvm/scan'
12
11
 
13
12
  module MVM
14
13
  RPC_URL = 'https://geth.mvm.dev'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-12 00:00:00.000000000 Z
11
+ date: 2024-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5'
26
+ version: '7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: awesome_print
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,243 +39,201 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bcrypt
42
+ name: base58
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '0.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.1'
54
+ version: '0.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: cli-ui
56
+ name: bcrypt
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: '3.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: '3.1'
69
69
  - !ruby/object:Gem::Dependency
70
- name: eth
70
+ name: blake3-rb
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0.5'
75
+ version: '1.5'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0.5'
83
- - !ruby/object:Gem::Dependency
84
- name: faye-websocket
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0.11'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0.11'
82
+ version: '1.5'
97
83
  - !ruby/object:Gem::Dependency
98
- name: http
84
+ name: cli-ui
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: '4.1'
89
+ version: '2.2'
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: '4.1'
96
+ version: '2.2'
111
97
  - !ruby/object:Gem::Dependency
112
- name: jose
98
+ name: eth
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: '1.1'
103
+ version: '0.5'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: '1.1'
110
+ version: '0.5'
125
111
  - !ruby/object:Gem::Dependency
126
- name: msgpack
112
+ name: faraday
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '1.3'
117
+ version: '2'
132
118
  type: :runtime
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '1.3'
124
+ version: '2'
139
125
  - !ruby/object:Gem::Dependency
140
- name: rbnacl
126
+ name: faraday-multipart
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: '7.1'
131
+ version: '1'
146
132
  type: :runtime
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: '7.1'
138
+ version: '1'
153
139
  - !ruby/object:Gem::Dependency
154
- name: sha3
140
+ name: faraday-retry
155
141
  requirement: !ruby/object:Gem::Requirement
156
142
  requirements:
157
143
  - - "~>"
158
144
  - !ruby/object:Gem::Version
159
- version: '1.0'
145
+ version: '2'
160
146
  type: :runtime
161
147
  prerelease: false
162
148
  version_requirements: !ruby/object:Gem::Requirement
163
149
  requirements:
164
150
  - - "~>"
165
151
  - !ruby/object:Gem::Version
166
- version: '1.0'
152
+ version: '2'
167
153
  - !ruby/object:Gem::Dependency
168
- name: thor
154
+ name: faye-websocket
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '1.0'
159
+ version: '0.11'
174
160
  type: :runtime
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
164
  - - "~>"
179
165
  - !ruby/object:Gem::Version
180
- version: '1.0'
181
- - !ruby/object:Gem::Dependency
182
- name: fastimage
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 2.2.5
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: 2.2.5
195
- - !ruby/object:Gem::Dependency
196
- name: pry
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 0.13.1
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 0.13.1
166
+ version: '0.11'
209
167
  - !ruby/object:Gem::Dependency
210
- name: rake
168
+ name: jose
211
169
  requirement: !ruby/object:Gem::Requirement
212
170
  requirements:
213
171
  - - "~>"
214
172
  - !ruby/object:Gem::Version
215
- version: '13.0'
216
- type: :development
173
+ version: '1.1'
174
+ type: :runtime
217
175
  prerelease: false
218
176
  version_requirements: !ruby/object:Gem::Requirement
219
177
  requirements:
220
178
  - - "~>"
221
179
  - !ruby/object:Gem::Version
222
- version: '13.0'
180
+ version: '1.1'
223
181
  - !ruby/object:Gem::Dependency
224
- name: rspec
182
+ name: msgpack
225
183
  requirement: !ruby/object:Gem::Requirement
226
184
  requirements:
227
185
  - - "~>"
228
186
  - !ruby/object:Gem::Version
229
- version: '3.8'
230
- type: :development
187
+ version: '1.3'
188
+ type: :runtime
231
189
  prerelease: false
232
190
  version_requirements: !ruby/object:Gem::Requirement
233
191
  requirements:
234
192
  - - "~>"
235
193
  - !ruby/object:Gem::Version
236
- version: '3.8'
194
+ version: '1.3'
237
195
  - !ruby/object:Gem::Dependency
238
- name: rubocop
196
+ name: rbnacl
239
197
  requirement: !ruby/object:Gem::Requirement
240
198
  requirements:
241
199
  - - "~>"
242
200
  - !ruby/object:Gem::Version
243
- version: '0.72'
244
- type: :development
201
+ version: '7.1'
202
+ type: :runtime
245
203
  prerelease: false
246
204
  version_requirements: !ruby/object:Gem::Requirement
247
205
  requirements:
248
206
  - - "~>"
249
207
  - !ruby/object:Gem::Version
250
- version: '0.72'
208
+ version: '7.1'
251
209
  - !ruby/object:Gem::Dependency
252
- name: rubocop-rspec
210
+ name: sha3
253
211
  requirement: !ruby/object:Gem::Requirement
254
212
  requirements:
255
213
  - - "~>"
256
214
  - !ruby/object:Gem::Version
257
- version: '1.33'
258
- type: :development
215
+ version: '1.0'
216
+ type: :runtime
259
217
  prerelease: false
260
218
  version_requirements: !ruby/object:Gem::Requirement
261
219
  requirements:
262
220
  - - "~>"
263
221
  - !ruby/object:Gem::Version
264
- version: '1.33'
222
+ version: '1.0'
265
223
  - !ruby/object:Gem::Dependency
266
- name: simplecov
224
+ name: thor
267
225
  requirement: !ruby/object:Gem::Requirement
268
226
  requirements:
269
227
  - - "~>"
270
228
  - !ruby/object:Gem::Version
271
- version: 0.18.2
272
- type: :development
229
+ version: '1.0'
230
+ type: :runtime
273
231
  prerelease: false
274
232
  version_requirements: !ruby/object:Gem::Requirement
275
233
  requirements:
276
234
  - - "~>"
277
235
  - !ruby/object:Gem::Version
278
- version: 0.18.2
236
+ version: '1.0'
279
237
  description: An API wrapper for Mixin Nexwork
280
238
  email:
281
239
  - an.lee.work@gmail.com
@@ -288,21 +246,31 @@ files:
288
246
  - bin/mixinbot
289
247
  - lib/mixin_bot.rb
290
248
  - lib/mixin_bot/api.rb
249
+ - lib/mixin_bot/api/address.rb
291
250
  - lib/mixin_bot/api/app.rb
292
251
  - lib/mixin_bot/api/asset.rb
293
252
  - lib/mixin_bot/api/attachment.rb
294
253
  - lib/mixin_bot/api/auth.rb
295
254
  - lib/mixin_bot/api/blaze.rb
296
- - lib/mixin_bot/api/collectible.rb
297
255
  - lib/mixin_bot/api/conversation.rb
298
256
  - lib/mixin_bot/api/encrypted_message.rb
257
+ - lib/mixin_bot/api/inscription.rb
258
+ - lib/mixin_bot/api/legacy_collectible.rb
259
+ - lib/mixin_bot/api/legacy_multisig.rb
260
+ - lib/mixin_bot/api/legacy_output.rb
261
+ - lib/mixin_bot/api/legacy_payment.rb
262
+ - lib/mixin_bot/api/legacy_snapshot.rb
263
+ - lib/mixin_bot/api/legacy_transaction.rb
264
+ - lib/mixin_bot/api/legacy_transfer.rb
299
265
  - lib/mixin_bot/api/me.rb
300
266
  - lib/mixin_bot/api/message.rb
301
267
  - lib/mixin_bot/api/multisig.rb
268
+ - lib/mixin_bot/api/output.rb
302
269
  - lib/mixin_bot/api/payment.rb
303
270
  - lib/mixin_bot/api/pin.rb
304
271
  - lib/mixin_bot/api/rpc.rb
305
272
  - lib/mixin_bot/api/snapshot.rb
273
+ - lib/mixin_bot/api/tip.rb
306
274
  - lib/mixin_bot/api/transaction.rb
307
275
  - lib/mixin_bot/api/transfer.rb
308
276
  - lib/mixin_bot/api/user.rb
@@ -312,10 +280,15 @@ files:
312
280
  - lib/mixin_bot/cli/node.rb
313
281
  - lib/mixin_bot/cli/utils.rb
314
282
  - lib/mixin_bot/client.rb
283
+ - lib/mixin_bot/configuration.rb
284
+ - lib/mixin_bot/nfo.rb
285
+ - lib/mixin_bot/transaction.rb
315
286
  - lib/mixin_bot/utils.rb
316
- - lib/mixin_bot/utils/nfo.rb
317
- - lib/mixin_bot/utils/transaction.rb
318
- - lib/mixin_bot/utils/uuid.rb
287
+ - lib/mixin_bot/utils/address.rb
288
+ - lib/mixin_bot/utils/crypto.rb
289
+ - lib/mixin_bot/utils/decoder.rb
290
+ - lib/mixin_bot/utils/encoder.rb
291
+ - lib/mixin_bot/uuid.rb
319
292
  - lib/mixin_bot/version.rb
320
293
  - lib/mvm.rb
321
294
  - lib/mvm/abis/bridge.json
@@ -331,7 +304,8 @@ files:
331
304
  homepage: https://github.com/an-lee/mixin_bot
332
305
  licenses:
333
306
  - MIT
334
- metadata: {}
307
+ metadata:
308
+ rubygems_mfa_required: 'true'
335
309
  post_install_message:
336
310
  rdoc_options: []
337
311
  require_paths:
@@ -340,15 +314,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
340
314
  requirements:
341
315
  - - ">="
342
316
  - !ruby/object:Gem::Version
343
- version: 2.6.0
317
+ version: 3.2.0
344
318
  required_rubygems_version: !ruby/object:Gem::Requirement
345
319
  requirements:
346
320
  - - ">="
347
321
  - !ruby/object:Gem::Version
348
322
  version: '0'
349
323
  requirements: []
350
- rubygems_version: 3.4.2
324
+ rubygems_version: 3.5.9
351
325
  signing_key:
352
326
  specification_version: 4
353
- summary: An API wrapper for Mixin Nexwork
327
+ summary: A Ruby SDK for Mixin Nexwork
354
328
  test_files: []
@@ -1,138 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MixinBot
4
- class API
5
- module Collectible
6
- NFT_ASSET_MIXIN_ID = '1700941284a95f31b25ec8c546008f208f88eee4419ccdcdbe6e3195e60128ca'
7
-
8
- def collectible(id, access_token: nil)
9
- path = "/collectibles/tokens/#{id}"
10
- access_token ||= access_token('GET', path, '')
11
- authorization = format('Bearer %<access_token>s', access_token: access_token)
12
- client.get(path, headers: { 'Authorization': authorization })
13
- end
14
-
15
- def collection(id, access_token: nil)
16
- path = "/collectibles/collections/#{id}"
17
- access_token ||= access_token('GET', path, '')
18
- authorization = format('Bearer %<access_token>s', access_token: access_token)
19
- client.get(path, headers: { 'Authorization': authorization })
20
- end
21
-
22
- def collectible_outputs(**kwargs)
23
- limit = kwargs[:limit] || 100
24
- offset = kwargs[:offset] || ''
25
- state = kwargs[:state] || ''
26
- members = kwargs[:members] || [client_id]
27
- threshold = kwargs[:threshold] || 1
28
- access_token = kwargs[:access_token]
29
- members = SHA3::Digest::SHA256.hexdigest(members&.sort&.join)
30
-
31
- path = format(
32
- '/collectibles/outputs?limit=%<limit>s&offset=%<offset>s&state=%<state>s&members=%<members>s&threshold=%<threshold>s',
33
- limit: limit,
34
- offset: offset,
35
- state: state,
36
- members: members,
37
- threshold: threshold
38
- )
39
- access_token ||= access_token('GET', path, '')
40
- authorization = format('Bearer %<access_token>s', access_token: access_token)
41
- client.get(path, headers: { 'Authorization': authorization })
42
- end
43
- alias collectibles collectible_outputs
44
-
45
- COLLECTABLE_REQUEST_ACTIONS = %i[sign unlock].freeze
46
- def create_collectible_request(action, raw, access_token: nil)
47
- raise ArgumentError, "request action is limited in #{COLLECTABLE_REQUEST_ACTIONS.join(', ')}" unless COLLECTABLE_REQUEST_ACTIONS.include? action.to_sym
48
-
49
- path = '/collectibles/requests'
50
- payload = {
51
- action: action,
52
- raw: raw
53
- }
54
- access_token ||= access_token('POST', path, payload.to_json)
55
- authorization = format('Bearer %<access_token>s', access_token: access_token)
56
- client.post(path, headers: { 'Authorization': authorization }, json: payload)
57
- end
58
-
59
- def create_sign_collectible_request(raw, access_token: nil)
60
- create_collectible_request 'sign', raw, access_token: access_token
61
- end
62
-
63
- def create_unlock_collectible_request(raw, access_token: nil)
64
- create_collectible_request 'unlock', raw, access_token: access_token
65
- end
66
-
67
- def sign_collectible_request(request_id, pin)
68
- path = format('/collectibles/requests/%<request_id>s/sign', request_id: request_id)
69
- payload = {
70
- pin: encrypt_pin(pin)
71
- }
72
- access_token ||= access_token('POST', path, payload.to_json)
73
- authorization = format('Bearer %<access_token>s', access_token: access_token)
74
- client.post(path, headers: { 'Authorization': authorization }, json: payload)
75
- end
76
-
77
- def unlock_collectible_request(request_id, pin)
78
- path = format('/collectibles/requests/%<request_id>s/unlock', request_id: request_id)
79
- payload = {
80
- pin: encrypt_pin(pin)
81
- }
82
- access_token ||= access_token('POST', path, payload.to_json)
83
- authorization = format('Bearer %<access_token>s', access_token: access_token)
84
- client.post(path, headers: { 'Authorization': authorization }, json: payload)
85
- end
86
-
87
- def cancel_collectible_request(request_id, pin)
88
- path = format('/collectibles/requests/%<request_id>s/cancel', request_id: request_id)
89
- payload = {
90
- pin: encrypt_pin(pin)
91
- }
92
- access_token ||= access_token('POST', path, payload.to_json)
93
- authorization = format('Bearer %<access_token>s', access_token: access_token)
94
- client.post(path, headers: { 'Authorization': authorization }, json: payload)
95
- end
96
- end
97
-
98
- # collectible = {
99
- # type: 'non_fungible_output',
100
- # user_id: '',
101
- # output_id: '',
102
- # token_id: '',
103
- # transaction_hash: '',
104
- # output_index: '',
105
- # amount: 1,
106
- # senders: [],
107
- # sender_threshold: 1,
108
- # receivers: [],
109
- # receivers_threshold: 1,
110
- # state: 'unspent'
111
- # }
112
- COLLECTIBLE_TRANSACTION_ARGUMENTS = %i[collectible nfo receivers receivers_threshold].freeze
113
- def build_collectible_transaction(**kwargs)
114
- raise ArgumentError, "#{COLLECTIBLE_TRANSACTION_ARGUMENTS.join(', ')} are needed for build collectible transaction" unless COLLECTIBLE_TRANSACTION_ARGUMENTS.all? { |param| kwargs.keys.include? param }
115
-
116
- kwargs = kwargs.with_indifferent_access
117
- collectible = kwargs['collectible']
118
- raise 'collectible is spent' if collectible['state'] == 'spent'
119
-
120
- build_raw_transaction(
121
- utxos: [collectible],
122
- senders: collectible['receivers'],
123
- senders_threshold: collectible['receivers_threshold'],
124
- receivers: kwargs['receivers'],
125
- receivers_threshold: kwargs['receivers_threshold'],
126
- extra: kwargs['nfo'],
127
- amount: 1,
128
- asset_mixin_id: NFT_ASSET_MIXIN_ID,
129
- access_token: kwargs['access_token'],
130
- hint: kwargs['hint']
131
- )
132
- end
133
-
134
- def nft_memo(collection, token_id, meta)
135
- MixinBot::Utils.nft_memo collection, token_id, meta
136
- end
137
- end
138
- end