Class: ArtQ::Tool
- Inherits:
-
Object
- Object
- ArtQ::Tool
- Defined in:
- lib/artq.rb
Class Method Summary collapse
- .do_info(contract_address) ⇒ Object
- .do_layers(contract_address, outdir:) ⇒ Object
- .do_tokens(contract_address, outdir:) ⇒ Object
- .is_addr?(str) ⇒ Boolean
- .main(args = ARGV) ⇒ Object
Class Method Details
.do_info(contract_address) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/artq.rb', line 104 def self.do_info( contract_address ) puts "==> query info for art collection contract @ >#{contract_address}<:" c = Contract.new( contract_address ) name = c.name symbol = c.symbol totalSupply = c.totalSupply recs = [] tokenIds = (0..2) tokenIds.each do |tokenId| tokenURI = c.tokenURI( tokenId ) recs << [tokenId, tokenURI] end puts " name: >#{name}<" puts " symbol: >#{symbol}<" puts " totalSupply: >#{totalSupply}<" puts puts " tokenURIs #{tokenIds}:" recs.each do |tokenId, tokenURI| puts " tokenId #{tokenId}:" = Meta.parse( tokenURI ) if .data.empty? ## assume "off-blockchain" if no "on-blockchain" data found puts " #{tokenURI}" else ## assume "on-blockchain" data pp .data puts puts " image_data:" puts .image_data end end end |
.do_layers(contract_address, outdir:) ⇒ Object
141 142 143 144 145 146 |
# File 'lib/artq.rb', line 141 def self.do_layers( contract_address, outdir: ) puts "==> query layers for art collection contract @ >#{contract_address}<:" ArtQ.download_layers( contract_address, outdir: outdir ) end |
.do_tokens(contract_address, outdir:) ⇒ Object
148 149 150 151 152 |
# File 'lib/artq.rb', line 148 def self.do_tokens( contract_address, outdir: ) puts "==> query inline 'on-blockchain' token metadata & images for art collection contract @ >#{contract_address}<:" ArtQ.download_tokens( contract_address, outdir: outdir ) end |
.is_addr?(str) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/artq.rb', line 18 def self.is_addr?( str ) ## e.g. ## must for now start with 0x (or 0X) ## and than 40 hexdigits (20 bytes) ## e.g. 0xe21ebcd28d37a67757b9bc7b290f4c4928a430b1 str.match( /\A0x[0-9a-f]{40}\z/i ) end |
.main(args = ARGV) ⇒ Object
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 94 95 96 97 98 |
# File 'lib/artq.rb', line 28 def self.main( args=ARGV ) puts "==> welcome to artq tool with args:" pp args = { } parser = OptionParser.new do |opts| opts.on("--rpc STRING", "JSON RPC Host (default: nil)") do |str| [ :rpc] = str end opts.on("-h", "--help", "Prints this help") do puts opts exit end end parser.parse!( args ) puts "options:" pp puts "args:" pp args if args.size < 1 puts "!! ERROR - no collection found - use <collection> <command>..." puts "" exit end ## todo/check - use collection_name/slug or such? contract_address = nil outdir = nil if is_addr?( args[0] ) ## do nothing; it's an address contract_address = args[0] outdir = "./tmp/#{contract_address}" else ## try reading collection.yml config config_path = "./#{args[0]}/collection.yml" if File.exist?( config_path ) config = read_yaml( config_path ) contract_address = config['token']['contract'] outdir = "./#{args[0]}" else puts "!! ERROR - no config found for collection >#{contract_address}<; sorry" exit 1 end end command = args[1] || 'info' if ['i','inf','info'].include?( command ) do_info( contract_address ) elsif ['l', 'layer', 'layers'].include?( command ) ## note: outdir - save into cache for now do_layers( contract_address, outdir: outdir ) elsif ['t', 'token', 'tokens'].include?( command ) ## note: outdir - saves into token (metadata) & token-i (images) do_tokens( contract_address, outdir: outdir ) else puts "!! ERROR - unknown command >#{command}<, sorry" end puts "bye" end |