Module: MixinBot::API::Inscription

Included in:
MixinBot::API
Defined in:
lib/mixin_bot/api/inscription.rb

Instance Method Summary collapse

Instance Method Details

#collectible(hash) ⇒ Object



12
13
14
15
16
# File 'lib/mixin_bot/api/inscription.rb', line 12

def collectible(hash)
  path = "/safe/inscriptions/items/#{hash}"

  client.get path
end

#collectibles(members: [], access_token: nil) ⇒ Object



24
25
26
27
# File 'lib/mixin_bot/api/inscription.rb', line 24

def collectibles(members: [], access_token: nil)
  unspent_outputs = safe_outputs(state: :unspent, members:, access_token:)['data']
  unspent_outputs.select { |output| output['inscription_hash'].present? }
end

#collection(hash) ⇒ Object



6
7
8
9
10
# File 'lib/mixin_bot/api/inscription.rb', line 6

def collection(hash)
  path = "/safe/inscriptions/collections/#{hash}"

  client.get path
end

#collection_collectibles(hash, offset: 0) ⇒ Object



18
19
20
21
22
# File 'lib/mixin_bot/api/inscription.rb', line 18

def collection_collectibles(hash, offset: 0)
  path = "/safe/inscriptions/collections/#{hash}/items"

  client.get path, offset:
end

#create_collectible_transfer(utxo, **kwargs) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mixin_bot/api/inscription.rb', line 29

def create_collectible_transfer(utxo, **kwargs)
  # verify collectible
  utxo = utxo.with_indifferent_access
  raise MixinBot::ArgumentError, 'not a valid collectible' unless utxo['inscription_hash'].present?

  # verify members
  members = [kwargs[:members]].flatten.compact
  raise ArgumentError, 'members required' if members.blank?

  threshold = kwargs[:threshold] || members.length
  request_id = kwargs[:request_id] || kwargs[:trace_id] || SecureRandom.uuid

  memo = kwargs[:memo] || ''

  # build transaction
  tx = build_safe_transaction(
    utxos: [utxo],
    receivers: [{
      members:,
      threshold:,
      amount: utxo['amount']
    }],
    extra: memo
  )

  # encode transaction
  raw = MixinBot.utils.encode_raw_transaction tx

  # verify transaction
  request = create_safe_transaction_request(request_id, raw)['data']

  # sign transaction
  spend_key = MixinBot.utils.decode_key(kwargs[:spend_key]) || config.spend_key
  signed_raw = MixinBot.api.sign_safe_transaction(
    raw:,
    utxos: [utxo],
    request: request[0],
    spend_key:
  )

  # submit transaction
  send_safe_transaction(
    request_id,
    signed_raw
  )
end