Module: TridentAssistant::API::Collectible

Included in:
TridentAssistant::API
Defined in:
lib/trident_assistant/api/collectible.rb

Overview

api for collectible

Constant Summary collapse

EXCHANGE_ASSET_ID =
"965e5c6e-434c-3fa9-b780-c50f43cd955c"
MINIMUM_AMOUNT =
0.000_000_01

Instance Method Summary collapse

Instance Method Details

#airdrop(collection, token, **kwargs) ⇒ Object

Raises:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/trident_assistant/api/collectible.rb', line 54

def airdrop(collection, token, **kwargs)
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
  collectible = find_collectible(:unspent, token_id)
  collectible ||= find_collectible(:signed, token_id)
  raise ForbiddenError, "Cannot find collectible in wallet" if collectible.blank?

  memo =
    TridentAssistant::Utils::Memo.new(
      type: "AD",
      receiver_id: kwargs[:receiver_id],
      start_at: kwargs[:start_at]
    ).encode
  nfo = MixinBot::Utils::Nfo.new(extra: memo.unpack1("H*")).encode.hex

  _transfer_nft(
    collectible,
    nfo,
    receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
    threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
  )
end

#collectibles(**kwargs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/trident_assistant/api/collectible.rb', line 10

def collectibles(**kwargs)
  client
    .get(
      "api/collectibles",
      {
        collection_id: kwargs[:collection_id],
        type: kwargs[:type],
        page: kwargs[:page],
        query: kwargs[:query]
      },
      {
        Authorization: "Bearer #{mixin_bot.access_token("GET", "/me", "")}"
      }
    )
end

#deposit(collection, token) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/trident_assistant/api/collectible.rb', line 26

def deposit(collection, token)
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
  collectible = find_collectible(:unspent, token_id)
  collectible ||= find_collectible(:signed, token_id)
  raise ForbiddenError, "Cannot find collectible" if collectible.blank?

  nfo = MixinBot::Utils::Nfo.new(extra: "deposit".unpack1("H*")).encode.hex
  _transfer_nft(
    collectible,
    nfo,
    receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
    threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold]
  )
end

#transfer(collection, token, recipient, **kwargs) ⇒ Object

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/trident_assistant/api/collectible.rb', line 76

def transfer(collection, token, recipient, **kwargs)
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
  collectible = find_collectible(:unspent, token_id)
  collectible ||= find_collectible(:signed, token_id)
  raise ForbiddenError, "Cannot find collectible in wallet" if collectible.blank?

  memo = kwargs[:memo] || "TRANSFER"
  nfo = MixinBot::Utils::Nfo.new(extra: memo.unpack1("H*")).encode.hex

  _transfer_nft(
    collectible,
    nfo,
    receivers: [recipient],
    threshold: 1
  )
end

#withdraw(collection, token) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trident_assistant/api/collectible.rb', line 41

def withdraw(collection, token)
  token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id
  mixin_bot.create_multisig_transaction(
    keystore[:pin],
    asset_id: EXCHANGE_ASSET_ID,
    amount: MINIMUM_AMOUNT,
    receivers: TridentAssistant::Utils::TRIDENT_MTG[:members],
    threshold: TridentAssistant::Utils::TRIDENT_MTG[:threshold],
    memo: TridentAssistant::Utils::Memo.new(type: "W", token_id: token_id).encode,
    trace_id: SecureRandom.uuid
  )
end