mixin_bot 1.1.0 → 1.2.0

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: 4257bfdffc20e27ffab5ce9da23080be113a552623f5022775f3cc8a6cc6db0c
4
- data.tar.gz: 7f29a034845b45715e33b3b51e28be996408fcff145538025a243fb74d42b482
3
+ metadata.gz: 2162191a7068afafb913aa9b898c7915c133b732c25b785c1ec8cbf672fd3edd
4
+ data.tar.gz: 31303c5e3c9dfb3759c943c63d74a67f7efb7a9cbdfbee9a823ba6f7dc7c6ab2
5
5
  SHA512:
6
- metadata.gz: 18e9d94005f235f827ce4e7598a2b2ddf13f48b296d9af46e4d6b2550e795c30f805c40b815352c159f7f2aa7b35c0a4e93ea0787889175c373e931720b5dc17
7
- data.tar.gz: 56e0c4651199912fd4ed4bef7eb96cc22de1cd30842b7d8e767811ece926e880984a0f2734db19d4f1c48464c037e3b3d9c22b61be204c8a83ffd0f926203e37
6
+ metadata.gz: 9cef773f5bde48f7d1697b5be99251ec6b4d2dcd5dd15c1d9b7aa60d90089a3476f8b696b5f9e7c93acbbf464d35583519b51d7fdff70cd842c9a97d7a4b2100
7
+ data.tar.gz: 2a16d609f841f1f2c0b85b217254e5368e042e0e2dc78817f7bee89774e90b12f674c8b3c67c4c73644ef02ff8f2a616109cd0659f63e8bed128cae50431152d
@@ -15,6 +15,12 @@ module MixinBot
15
15
  client.get path
16
16
  end
17
17
 
18
+ def collection_collectibles(hash, offset: 0)
19
+ path = "/safe/inscriptions/collections/#{hash}/items"
20
+
21
+ client.get path, offset:
22
+ end
23
+
18
24
  def collectibles(members: [], access_token: nil)
19
25
  unspent_outputs = safe_outputs(state: :unspent, members:, access_token:)['data']
20
26
  unspent_outputs.select { |output| output['inscription_hash'].present? }
@@ -4,7 +4,7 @@ module MixinBot
4
4
  class API
5
5
  module LegacyTransfer
6
6
  TRANSFER_ARGUMENTS = %i[asset_id opponent_id amount].freeze
7
- def create_transfer(pin, **kwargs)
7
+ def create_legacy_transfer(pin, **kwargs)
8
8
  raise ArgumentError, "#{TRANSFER_ARGUMENTS.join(', ')} are needed for create transfer" unless TRANSFER_ARGUMENTS.all? { |param| kwargs.keys.include? param }
9
9
 
10
10
  asset_id = kwargs[:asset_id]
@@ -33,7 +33,7 @@ module MixinBot
33
33
  client.post path, **payload
34
34
  end
35
35
 
36
- def transfer(trace_id, access_token: nil)
36
+ def legacy_transfer(trace_id, access_token: nil)
37
37
  path = format('/transfers/trace/%<trace_id>s', trace_id:)
38
38
  client.get path, access_token:
39
39
  end
@@ -11,7 +11,7 @@ module MixinBot
11
11
  memo = kwargs[:memo] || ''
12
12
  trace_id = kwargs[:trace_id] || SecureRandom.uuid
13
13
 
14
- mix_address = MixinBot.utils.build_mix_address(members, threshold)
14
+ mix_address = MixinBot.utils.build_mix_address(members:, threshold:)
15
15
 
16
16
  "https://mixin.one/pay/#{mix_address}?amount=#{amount}&asset=#{asset_id}&memo=#{memo}&trace=#{trace_id}"
17
17
  end
@@ -30,7 +30,7 @@ module MixinBot
30
30
 
31
31
  # https://developers.mixin.one/api/alpha-mixin-network/create-pin/
32
32
  def update_pin(pin:, old_pin: nil)
33
- old_pin ||= MixinBot.config.pin
33
+ # old_pin ||= MixinBot.config.pin
34
34
  raise ArgumentError, 'invalid old pin' if old_pin.present? && old_pin.length != 6
35
35
 
36
36
  path = '/pin/update'
@@ -4,7 +4,7 @@ module MixinBot
4
4
  class API
5
5
  module Rpc
6
6
  def rpc_proxy(method, params = [], access_token: nil)
7
- path = '/external/proxy'
7
+ path = '/external/kernel'
8
8
  payload = {
9
9
  method:,
10
10
  params:
@@ -269,7 +269,7 @@ module MixinBot
269
269
 
270
270
  receivers = kwargs[:receivers].presence || [config.app_id]
271
271
  receivers_threshold = kwargs[:receivers_threshold] || receivers.length
272
- recipient = MixinBot.utils.build_mix_address(receivers, receivers_threshold)
272
+ recipient = MixinBot.utils.build_mix_address(members: receivers, threshold: receivers_threshold)
273
273
 
274
274
  content = kwargs[:content]
275
275
  collection_hash = kwargs[:collection_hash]
@@ -15,8 +15,17 @@ module MixinBot
15
15
  # spend_key: string / nil,
16
16
  # }
17
17
  def create_safe_transfer(**kwargs)
18
- asset_id = kwargs[:asset_id]
19
- raise ArgumentError, 'asset_id required' if asset_id.blank?
18
+ utxos = kwargs[:utxos]
19
+ raise ArgumentError, 'utxos must be array' if utxos.present? && !utxos.is_a?(Array)
20
+
21
+ asset_id =
22
+ if utxos.present?
23
+ utxos.first['asset_id']
24
+ else
25
+ kwargs[:asset_id]
26
+ end
27
+
28
+ raise ArgumentError, 'utxos or asset_id required' if utxos.blank? && asset_id.blank?
20
29
 
21
30
  amount = kwargs[:amount]&.to_d
22
31
  raise ArgumentError, 'amount required' if amount.blank?
@@ -29,7 +38,7 @@ module MixinBot
29
38
  memo = kwargs[:memo] || ''
30
39
 
31
40
  # step 1: select inputs
32
- utxos = build_utxos(asset_id:, amount:)
41
+ utxos ||= build_utxos(asset_id:, amount:)
33
42
 
34
43
  # step 2: build transaction
35
44
  tx = build_safe_transaction(
@@ -61,6 +70,7 @@ module MixinBot
61
70
  signed_raw
62
71
  )
63
72
  end
73
+ alias create_transfer create_safe_transfer
64
74
 
65
75
  def build_utxos(asset_id:, amount:)
66
76
  outputs = safe_outputs(state: 'unspent', asset: asset_id, limit: 500)['data'].sort_by { |o| o['amount'].to_d }
@@ -49,9 +49,9 @@ module MixinBot
49
49
  keystore = {
50
50
  app_id: user['data']['user_id'],
51
51
  session_id: user['data']['session_id'],
52
- private_key:,
53
- pin_token: user['data']['pin_token_base64'],
54
- spend_key: spend_keypair[1].unpack1('H*')
52
+ session_private_key: private_key,
53
+ server_public_key: user['data']['pin_token_base64'],
54
+ spend_key:
55
55
  }
56
56
  user_api = MixinBot::API.new(**keystore)
57
57
 
@@ -60,7 +60,7 @@ module MixinBot
60
60
  # wait for tip pin update in server
61
61
  sleep 1
62
62
 
63
- user_api.safe_register spend_key
63
+ user_api.safe_register keystore[:spend_key]
64
64
 
65
65
  keystore
66
66
  end
@@ -31,7 +31,7 @@ module MixinBot
31
31
  payload
32
32
  end
33
33
 
34
- def build_mix_address(members, threshold)
34
+ def build_mix_address(members:, threshold:)
35
35
  raise ArgumentError, 'members should be an array' unless members.is_a? Array
36
36
  raise ArgumentError, 'members should not be empty' if members.empty?
37
37
  raise ArgumentError, 'members length should less than 256' if members.length > 255
@@ -61,24 +61,24 @@ module MixinBot
61
61
 
62
62
  data = address[MIX_ADDRESS_PREFIX.length..]
63
63
  data = Base58.base58_to_binary data, :bitcoin
64
- raise ArgumentError, 'invalid address' if data.length < 3 + 16 + 4
64
+ raise ArgumentError, 'invalid address, length invalid' if data.length < 3 + 16 + 4
65
65
 
66
66
  msg = data[...-4]
67
67
  checksum = SHA3::Digest::SHA256.digest((MIX_ADDRESS_PREFIX + msg))[0...4]
68
68
 
69
- raise ArgumentError, 'invalid address' unless checksum[0...4] == data[-4..]
69
+ raise ArgumentError, 'invalid address, checksum invalid' unless checksum[0...4] == data[-4..]
70
70
 
71
71
  version = data[0].ord
72
- raise ArgumentError, 'invalid address' unless version == MIX_ADDRESS_VERSION
72
+ raise ArgumentError, 'invalid address, version invalid' unless version == MIX_ADDRESS_VERSION
73
73
 
74
74
  threshold = data[1].ord
75
75
  members_count = data[2].ord
76
76
 
77
- if data[3..].length == members_count * 16
78
- members = data[3..].scan(/.{16}/)
77
+ if data[3...-4].length == members_count * 16
78
+ members = data[3...-4].chars.each_slice(16).map(&:join)
79
79
  members = members.map(&->(member) { MixinBot::UUID.new(raw: member).unpacked })
80
80
  else
81
- members = data[3..].scan(/.{64}/)
81
+ members = data[3...-4].chars.each_slice(64).map(&:join)
82
82
  members = members.map(&->(member) { build_main_address(member) })
83
83
  end
84
84
 
@@ -100,7 +100,7 @@ module MixinBot
100
100
  members:,
101
101
  threshold:,
102
102
  amount:,
103
- mix_address: build_mix_address(members, threshold)
103
+ mix_address: build_mix_address(members:, threshold:)
104
104
  }
105
105
  end
106
106
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MixinBot
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  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: 1.1.0
4
+ version: 1.2.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: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
321
  - !ruby/object:Gem::Version
322
322
  version: '0'
323
323
  requirements: []
324
- rubygems_version: 3.5.9
324
+ rubygems_version: 3.5.10
325
325
  signing_key:
326
326
  specification_version: 4
327
327
  summary: A Ruby SDK for Mixin Nexwork