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.upload_attachment 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.upload_attachment 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
metadata = 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", metadata.json.to_json
log metadata.json
end
|