nft_checker 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +84 -0
- data/README.md +52 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/nft_checker/open_sea.rb +52 -0
- data/lib/nft_checker/version.rb +5 -0
- data/lib/nft_checker.rb +29 -0
- data/nft_checker.gemspec +44 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8153b19d92797310cd260ebdba17a6c11bdae0b9a3a0c86c182ba2e2047d2503
|
4
|
+
data.tar.gz: 1f20e9beb1b63cb0892b5182fbe48d85d5ed241b6aff57289343a5ddb23079d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f75b7bea25958aeca21abce0b3f7da30b4b09d03506279a8d50ac759924d7676e5a7ad11a0f666fe1c35aa27524d8015d1a560a5e1e012dcdd28df3c7ff09006
|
7
|
+
data.tar.gz: e9936d133831a60cdcd41d882e3e9abe0514bd72bb6ea4766919e1138aabb593771ab9c6947f47121bc953a7ee39fde8e701dc5c126b61eb92cd2a885cc75369
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.3
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in nft_checker.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "httparty", "~> 0.20.0"
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
gem "rubocop", "~> 1.21"
|
12
|
+
gem "rubocop-rake", "~> 0.6.0"
|
13
|
+
gem "rubocop-rspec", "~> 2.7"
|
14
|
+
gem "vcr", "~> 6.0"
|
15
|
+
gem "webmock", "~> 3.14"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nft_checker (0.1.0)
|
5
|
+
httparty (~> 0.20)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
ast (2.4.2)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
hashdiff (1.0.1)
|
17
|
+
httparty (0.20.0)
|
18
|
+
mime-types (~> 3.0)
|
19
|
+
multi_xml (>= 0.5.2)
|
20
|
+
mime-types (3.4.1)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2021.1115)
|
23
|
+
multi_xml (0.6.0)
|
24
|
+
parallel (1.21.0)
|
25
|
+
parser (3.0.3.2)
|
26
|
+
ast (~> 2.4.1)
|
27
|
+
public_suffix (4.0.6)
|
28
|
+
rainbow (3.0.0)
|
29
|
+
rake (13.0.6)
|
30
|
+
regexp_parser (2.2.0)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rspec (3.10.0)
|
33
|
+
rspec-core (~> 3.10.0)
|
34
|
+
rspec-expectations (~> 3.10.0)
|
35
|
+
rspec-mocks (~> 3.10.0)
|
36
|
+
rspec-core (3.10.1)
|
37
|
+
rspec-support (~> 3.10.0)
|
38
|
+
rspec-expectations (3.10.1)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.10.0)
|
41
|
+
rspec-mocks (3.10.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.10.0)
|
44
|
+
rspec-support (3.10.3)
|
45
|
+
rubocop (1.24.0)
|
46
|
+
parallel (~> 1.10)
|
47
|
+
parser (>= 3.0.0.0)
|
48
|
+
rainbow (>= 2.2.2, < 4.0)
|
49
|
+
regexp_parser (>= 1.8, < 3.0)
|
50
|
+
rexml
|
51
|
+
rubocop-ast (>= 1.15.0, < 2.0)
|
52
|
+
ruby-progressbar (~> 1.7)
|
53
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
54
|
+
rubocop-ast (1.15.1)
|
55
|
+
parser (>= 3.0.1.1)
|
56
|
+
rubocop-rake (0.6.0)
|
57
|
+
rubocop (~> 1.0)
|
58
|
+
rubocop-rspec (2.7.0)
|
59
|
+
rubocop (~> 1.19)
|
60
|
+
ruby-progressbar (1.11.0)
|
61
|
+
unicode-display_width (2.1.0)
|
62
|
+
vcr (6.0.0)
|
63
|
+
webmock (3.14.0)
|
64
|
+
addressable (>= 2.8.0)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
x86_64-darwin-21
|
70
|
+
x86_64-linux
|
71
|
+
|
72
|
+
DEPENDENCIES
|
73
|
+
httparty (~> 0.20.0)
|
74
|
+
nft_checker!
|
75
|
+
rake (~> 13.0)
|
76
|
+
rspec (~> 3.0)
|
77
|
+
rubocop (~> 1.21)
|
78
|
+
rubocop-rake (~> 0.6.0)
|
79
|
+
rubocop-rspec (~> 2.7)
|
80
|
+
vcr (~> 6.0)
|
81
|
+
webmock (~> 3.14)
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.2.32
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# NftChecker
|
2
|
+
|
3
|
+
NFT Checker is a utility to verify NFT ownership.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'nft_checker'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install nft_checker
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'nft_checker'
|
25
|
+
checker = NftChecker.init(:opensea)
|
26
|
+
# or, for testnets:
|
27
|
+
# checker = NftChecker.init(:opensea, testnet: true)
|
28
|
+
|
29
|
+
# List all "naturedivas" still owned by AleyArt
|
30
|
+
list = checker.list_nfts({slug: naturedivas}, "0x422699b0f5891c8ddd306c08d9856032264c5e8e" )
|
31
|
+
p list.map {|nft| nft["image_url"]} # [ "https://...", ... ]
|
32
|
+
|
33
|
+
# Verify that naturediva 016 is still owned by Thision
|
34
|
+
still_owned = checker.verify_owner(
|
35
|
+
{
|
36
|
+
contract_address: "0x495f947276749Ce646f68AC8c248420045cb7b5e",
|
37
|
+
token_id: "29920848932956748486580529385461081269564523998318357035541486687674930561025"
|
38
|
+
},
|
39
|
+
"0x3dec7052aa8d55b3b6b6ad2c6bce195a9acca404"
|
40
|
+
)
|
41
|
+
p still_owned # true
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/valthon/nft_checker.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "nft_checker"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
module NftChecker
|
5
|
+
###
|
6
|
+
# NFT Checker implementation for OpenSea
|
7
|
+
class OpenSea
|
8
|
+
# @param testnet Use OpenSea 'testnets' API (default false)
|
9
|
+
def initialize(testnet: false)
|
10
|
+
@url_base = testnet ? "https://testnets-api.opensea.io/" : "https://api.opensea.io/"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Verify that the NFT is owned by the given address
|
14
|
+
# @param nft_metadata - hash containing :contract_address and :token_id values
|
15
|
+
# @param owner_address - address of presumed NFT owner
|
16
|
+
def verify_owner(nft_metadata, owner_address)
|
17
|
+
contract, token = nft_metadata.slice(:contract_address, :token_id).values
|
18
|
+
rez = HTTParty.get(@url_base + "asset/#{contract}/#{token}/", query: { account_address: owner_address })
|
19
|
+
handle_response_codes(rez, not_found: false) do
|
20
|
+
ownership_data = rez.parsed_response["ownership"]
|
21
|
+
return false if ownership_data.nil?
|
22
|
+
|
23
|
+
ownership_data["owner"]["address"].casecmp(owner_address).zero? && ownership_data["quantity"].to_i.positive?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# List all NFTs in the collection owned by the given address
|
28
|
+
# @param collection_metadata - hash containing :slug for OpenSea collection
|
29
|
+
# @param owner_address - address to check for NFTs
|
30
|
+
def list_nfts(collection_metadata, owner_address)
|
31
|
+
rez = HTTParty.get("#{@url_base}assets", query: { owner: owner_address, collection: collection_metadata[:slug] })
|
32
|
+
handle_response_codes(rez, not_found: []) do
|
33
|
+
rez.parsed_response["assets"] || []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def handle_response_codes(rez, not_found: nil)
|
40
|
+
case rez.code
|
41
|
+
when 429
|
42
|
+
raise Throttled
|
43
|
+
when 400
|
44
|
+
not_found
|
45
|
+
when 200
|
46
|
+
yield
|
47
|
+
else
|
48
|
+
raise Error(rez.to_s)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/nft_checker.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "nft_checker/version"
|
4
|
+
require_relative "nft_checker/open_sea"
|
5
|
+
|
6
|
+
###
|
7
|
+
# NftChecker is a tool for verifying NFT ownership
|
8
|
+
#
|
9
|
+
# Use the `init` method to generate a checker for a given NFT source
|
10
|
+
# Currently supported sources:
|
11
|
+
# * OpenSea
|
12
|
+
#
|
13
|
+
# Checkers all support the following methods:
|
14
|
+
# * verify_owner(nft_metadata, owner_address): boolean
|
15
|
+
# * list_nfts(collection_metadata, owner_address): [<NFT ID>,...]
|
16
|
+
#
|
17
|
+
module NftChecker
|
18
|
+
class Error < StandardError; end
|
19
|
+
class Throttled < Error; end
|
20
|
+
|
21
|
+
def self.init(source, options = {})
|
22
|
+
case source.to_s
|
23
|
+
when /\Aopen\w?sea(.io)?\z/i
|
24
|
+
OpenSea.new(testnet: options[:testnet])
|
25
|
+
else
|
26
|
+
raise "Unknown source: #{source}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/nft_checker.gemspec
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/nft_checker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "nft_checker"
|
7
|
+
spec.version = NftChecker::VERSION
|
8
|
+
spec.authors = ["David J Parrott"]
|
9
|
+
spec.email = ["valthon@nothlav.net"]
|
10
|
+
|
11
|
+
spec.summary = "Utility to verify ownership of an NFT"
|
12
|
+
spec.homepage = "https://github.com/valthon/nft_checker"
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
16
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/valthon/nft_checker/blob/trunk/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
# Uncomment to register a new dependency of your gem
|
34
|
+
spec.add_dependency "httparty", "~> 0.20"
|
35
|
+
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "rubocop", "~> 1.21"
|
38
|
+
spec.add_development_dependency "rubocop-rake", "~> 0.6"
|
39
|
+
spec.add_development_dependency "rubocop-rspec", "~> 0.6"
|
40
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
41
|
+
spec.add_development_dependency "webmock", "~> 3.14"
|
42
|
+
# For more information and examples about making a new gem, checkout our
|
43
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nft_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David J Parrott
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.20'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.20'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.21'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.21'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '6.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.14'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.14'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- valthon@nothlav.net
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- ".ruby-version"
|
121
|
+
- CHANGELOG.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- lib/nft_checker.rb
|
129
|
+
- lib/nft_checker/open_sea.rb
|
130
|
+
- lib/nft_checker/version.rb
|
131
|
+
- nft_checker.gemspec
|
132
|
+
homepage: https://github.com/valthon/nft_checker
|
133
|
+
licenses: []
|
134
|
+
metadata:
|
135
|
+
rubygems_mfa_required: 'true'
|
136
|
+
homepage_uri: https://github.com/valthon/nft_checker
|
137
|
+
source_code_uri: https://github.com/valthon/nft_checker
|
138
|
+
changelog_uri: https://github.com/valthon/nft_checker/blob/trunk/CHANGELOG.md
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 2.6.0
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubygems_version: 3.2.32
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Utility to verify ownership of an NFT
|
158
|
+
test_files: []
|