Class: TridentAssistant::CLI::Collectible
- Defined in:
- lib/trident_assistant/cli/collectible.rb
Overview
CLI to query Trident and Mixin APIs
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#api, #bot, #client, #keystore
Instance Method Summary collapse
- #airdrop(collection, token) ⇒ Object
- #bulkairdrop(dir) ⇒ Object
- #deposit(collection, token) ⇒ Object
- #index ⇒ Object
- #show(collection, token) ⇒ Object
- #transfer(collection, token, recipient) ⇒ Object
- #withdraw(collection, token) ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from TridentAssistant::CLI::Base
Instance Method Details
#airdrop(collection, token) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/trident_assistant/cli/collectible.rb', line 50 def airdrop(collection, token) log api.airdrop collection, token, receiver_id: [:receiver], start_at: [:start] log UI.fmt("{{v}} successfully transfer NFT") rescue StandardError => e log UI.fmt("{{x}} failed: #{e.inspect} #{e.backtrace.join("\n")}") end |
#bulkairdrop(dir) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/trident_assistant/cli/collectible.rb', line 68 def bulkairdrop(dir) raise "#{dir} is not a directory" unless Dir.exist?(dir) Dir.glob("#{dir}/*.json").each do |file| log "-" * 80 log UI.fmt("{{v}} found #{file}") data = TridentAssistant::Utils.parse_json file if data.dig("_airdrop", "hash").present? log UI.fmt("{{v}} NFT already transferred") next end = TridentAssistant::Utils. data log UI.fmt("{{v}} metadata parsed") .validate! log UI.fmt("{{v}} metadata validated") receiver_id = data.dig("_airdrop", "receiver_id") start_at = data.dig("_airdrop", "start_at") log UI.fmt("{{v}} airdrop receiver_id: #{receiver_id}") log UI.fmt("{{v}} airdrop start_at: #{start_at}") attempt = 0 r = begin attempt += 1 api.airdrop .collection["id"], .token["id"], receiver_id: receiver_id, start_at: start_at rescue Errno::ECONNRESET, OpenSSL::SSL::SSLError, MixinBot::HttpError => e log UI.fmt("{{x}} #{e.inspect}") log UI.fmt("Retrying #{attempt} times...") sleep 0.5 retry end log r["data"] data["_airdrop"] ||= {} data["_airdrop"]["hash"] = r["data"]["hash"] log UI.fmt("{{v}} successfully transfer NFT ##{metadata.token["id"]} #{metadata.collection["id"]}") rescue TridentAssistant::Utils::Metadata::InvalidFormatError, JSON::ParserError, Client::RequestError, MixinBot::Error, RuntimeError => e log UI.fmt("{{x}} #{file} failed to airdrop: #{e.inspect}") next ensure File.write file, data.to_json end end |
#deposit(collection, token) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/trident_assistant/cli/collectible.rb', line 39 def deposit(collection, token) log api.deposit collection, token log UI.fmt("{{v}} successfully transfer NFT") rescue StandardError => e log UI.fmt("{{x}} failed: #{e.inspect} #{e.backtrace.join("\n")}") end |
#index ⇒ Object
13 14 15 16 17 |
# File 'lib/trident_assistant/cli/collectible.rb', line 13 def index r = api.mixin_bot.collectibles state: [:state], limit: 500 log r["data"] end |
#show(collection, token) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/trident_assistant/cli/collectible.rb', line 21 def show(collection, token) token_id = MixinBot::Utils::Nfo.new(collection: collection, token: token).unique_token_id r = api.mixin_bot.collectible token_id log r["data"] end |
#transfer(collection, token, recipient) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/trident_assistant/cli/collectible.rb', line 30 def transfer(collection, token, recipient) log api.transfer collection, token, recipient log UI.fmt("{{v}} successfully transfer NFT") rescue StandardError => e log UI.fmt("{{x}} failed: #{e.inspect} #{e.backtrace.join("\n")}") end |
#withdraw(collection, token) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/trident_assistant/cli/collectible.rb', line 59 def withdraw(collection, token) log api.withdraw collection, token log UI.fmt("{{v}} successfully invoked withdraw") rescue StandardError => e log UI.fmt("{{x}} failed: #{e.inspect} #{e.backtrace.join("\n")}") end |