Class: TridentAssistant::CLI::Metadata
- Defined in:
- lib/trident_assistant/cli/metadata.rb
Overview
CLI to generate metadata
Defined Under Namespace
Classes: InvalidError
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#api, #bot, #client, #keystore
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from TridentAssistant::CLI::Base
Instance Method Details
#new ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/trident_assistant/cli/metadata.rb', line 13 def new creator_id = api.mixin_bot.config.app_id creator_name = api.mixin_bot.me["full_name"] creator_royalty = UI.ask("Please input creator royalty, 0.0 ~ 0.1", default: "0.0") raise InvalidError, "Royalty must in 0.0 ~ 0.1" unless (0..0.1).include?(creator_royalty.to_f) collection_id = UI.ask("Please input collection ID") collection = api.collection collection_id raise InvalidError, "Cannot find collection #{collection_id}" if collection.blank? if collection["creator"]&.[]("id") != api.mixin_bot.config.app_id raise InvalidError, "Unauthorized to mint in #{collection_id}" end token_id = UI.ask("Please input token ID", default: "1") token_name = UI.ask("Please input token name") token_description = UI.ask("Please input token description") token_icon_url = UI.ask("Please input token icon url or local file dir") if File.file? token_icon_url begin file = File.open token_icon_url res = api.mixin_bot. file token_icon_url = res["view_url"] ensure file&.close end end token_media_url = UI.ask("Please input token media url or local file dir") if File.file? token_media_url begin file = File.open token_media_url res = api.mixin_bot. file token_media_url = res["view_url"] token_media_hash = SHA3::Digest::SHA256.hexdigest file.read ensure file&.close end elsif token_media_url =~ URI::DEFAULT_PARSER.make_regexp token_media_hash = TridentAssistant::Utils.hash_from_url(token_media_url) end = TridentAssistant::Utils::Metadata.new( creator: { id: creator_id, name: creator_name, royalty: creator_royalty }, collection: { id: collection_id, name: collection["name"], description: collection["description"], icon: { url: collection["icon"]&.[]("url") }, split: collection["split"].to_s }, token: { id: token_id, name: token_name, description: token_description, icon: { url: token_icon_url }, media: { url: token_media_url, hash: token_media_hash.to_s } }, checksum: { fields: ["creator.id", "creator.royalty", "collection.id", "collection.name", "collection.split", "token.id", "token.name", "token.media.hash"], algorithm: "sha256" } ) File.write "#{token_id}_#{collection_id}.json", .json.to_json log .json end |
#show(metahash) ⇒ Object
97 98 99 |
# File 'lib/trident_assistant/cli/metadata.rb', line 97 def show() log api. end |
#upload ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/trident_assistant/cli/metadata.rb', line 104 def upload = TridentAssistant::Utils. [:metadata] log UI.fmt("{{v}} metadata parsed") .validate! log UI.fmt("{{v}} metadata validated") # upload metadata api. metadata: .json, metahash: . log UI.fmt("{{v}} metadata uploaded: #{[:endpoint]}/api/collectibles/#{.}") rescue JSON::ParserError, Client::RequestError, InvalidError => e log UI.fmt("{{x}} #{e.inspect}") end |