nft_checker 0.1.0 → 0.2.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 +4 -4
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +14 -3
- data/lib/nft_checker/errors.rb +6 -0
- data/lib/nft_checker/open_sea.rb +44 -10
- data/lib/nft_checker/version.rb +1 -1
- data/lib/nft_checker.rb +1 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee63a9ddf05b513bb829ce69142bc73b6227350eb1e9619e6ad333ddec0f211d
|
4
|
+
data.tar.gz: 9e3333116358163185d059a8fd08ec4e819a3f6908a17f9ab0bb5e784628d583
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742a33fc52f8216b48097e079bdb2cca07d7d1bdd01231db1b56a2b48f5640be15a28f5040ab693ae5c099945ee8dbc77967a1999cdb0902017693fe92b8855d
|
7
|
+
data.tar.gz: b460ab9eae89f5276f218649acf73b1b28c7546cbfdc0308a831e38bbcf8d3e0c431e9a3b4cc98407a898775fd5a8f784ad5885696882e49729d8dc01d9efe0e
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.0] - 2021-12-31
|
4
|
+
|
5
|
+
Iterate on public API for easier use
|
6
|
+
- Add `owner?` and `in_collection?` methods
|
7
|
+
- Deprecated `verify_owner` (in favor of `owner?`)
|
8
|
+
|
3
9
|
## [0.1.0] - 2021-12-30
|
4
10
|
|
5
11
|
Initial release with support for OpenSea NFTs
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -31,14 +31,25 @@ list = checker.list_nfts({slug: naturedivas}, "0x422699b0f5891c8ddd306c08d985603
|
|
31
31
|
p list.map {|nft| nft["image_url"]} # [ "https://...", ... ]
|
32
32
|
|
33
33
|
# Verify that naturediva 016 is still owned by Thision
|
34
|
-
still_owned = checker.
|
34
|
+
still_owned = checker.owner?(
|
35
|
+
"0x3dec7052aa8d55b3b6b6ad2c6bce195a9acca404",
|
35
36
|
{
|
36
37
|
contract_address: "0x495f947276749Ce646f68AC8c248420045cb7b5e",
|
37
38
|
token_id: "29920848932956748486580529385461081269564523998318357035541486687674930561025"
|
38
|
-
}
|
39
|
-
"0x3dec7052aa8d55b3b6b6ad2c6bce195a9acca404"
|
39
|
+
}
|
40
40
|
)
|
41
41
|
p still_owned # true
|
42
|
+
|
43
|
+
# Verify that naturediva 016 is part of the naturediva collection
|
44
|
+
verified = checker.in_collection?(
|
45
|
+
{slug: naturedivas},
|
46
|
+
{
|
47
|
+
contract_address: "0x495f947276749Ce646f68AC8c248420045cb7b5e",
|
48
|
+
token_id: "29920848932956748486580529385461081269564523998318357035541486687674930561025"
|
49
|
+
}
|
50
|
+
)
|
51
|
+
p verified # true
|
52
|
+
|
42
53
|
```
|
43
54
|
|
44
55
|
## Development
|
data/lib/nft_checker/open_sea.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "httparty"
|
4
|
+
require_relative "errors"
|
5
|
+
|
4
6
|
module NftChecker
|
5
7
|
###
|
6
8
|
# NFT Checker implementation for OpenSea
|
@@ -11,17 +13,30 @@ module NftChecker
|
|
11
13
|
end
|
12
14
|
|
13
15
|
# Verify that the NFT is owned by the given address
|
16
|
+
# @param address - address of presumed NFT owner
|
14
17
|
# @param nft_metadata - hash containing :contract_address and :token_id values
|
15
|
-
|
16
|
-
|
17
|
-
|
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?
|
18
|
+
def owner?(address, nft_metadata)
|
19
|
+
!fetch_nft_for_owner(address, nft_metadata).nil?
|
20
|
+
end
|
22
21
|
|
23
|
-
|
22
|
+
# Verify that the NFT is part of the referenced collection
|
23
|
+
# @param collection_metadata - hash containing :slug for OpenSea collection
|
24
|
+
# @param nft_metadata - hash containing :contract_address and :token_id values
|
25
|
+
def in_collection?(collection_metadata, nft_metadata)
|
26
|
+
nft = fetch_nft(nft_metadata)
|
27
|
+
return false if nft.nil?
|
28
|
+
|
29
|
+
collection_metadata.each_key do |key|
|
30
|
+
return false unless nft["collection"][key.to_s].casecmp(collection_metadata[key]).zero?
|
24
31
|
end
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
# [Deprecated] Verify that the NFT is owned by the given address
|
36
|
+
# @param nft_metadata - hash containing :contract_address and :token_id values
|
37
|
+
# @param owner_address - address of presumed NFT owner
|
38
|
+
def verify_owner(nft_metadata, owner_address)
|
39
|
+
owner?(owner_address, nft_metadata)
|
25
40
|
end
|
26
41
|
|
27
42
|
# List all NFTs in the collection owned by the given address
|
@@ -36,16 +51,35 @@ module NftChecker
|
|
36
51
|
|
37
52
|
private
|
38
53
|
|
54
|
+
def fetch_nft(nft_metadata)
|
55
|
+
contract, token = nft_metadata.slice(:contract_address, :token_id).values
|
56
|
+
rez = HTTParty.get(@url_base + "asset/#{contract}/#{token}/")
|
57
|
+
handle_response_codes(rez, not_found: nil) do
|
58
|
+
rez.parsed_response
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def fetch_nft_for_owner(owner_address, nft_metadata)
|
63
|
+
contract, token = nft_metadata.slice(:contract_address, :token_id).values
|
64
|
+
rez = HTTParty.get(@url_base + "asset/#{contract}/#{token}/", query: { account_address: owner_address })
|
65
|
+
handle_response_codes(rez, not_found: nil) do
|
66
|
+
data = rez.parsed_response
|
67
|
+
data if data["ownership"] &&
|
68
|
+
data["ownership"]["owner"]["address"].casecmp(owner_address).zero? &&
|
69
|
+
data["ownership"]["quantity"].to_i.positive?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
39
73
|
def handle_response_codes(rez, not_found: nil)
|
40
74
|
case rez.code
|
41
75
|
when 429
|
42
76
|
raise Throttled
|
43
|
-
when
|
77
|
+
when 404
|
44
78
|
not_found
|
45
79
|
when 200
|
46
80
|
yield
|
47
81
|
else
|
48
|
-
raise Error
|
82
|
+
raise Error, rez.to_s
|
49
83
|
end
|
50
84
|
end
|
51
85
|
end
|
data/lib/nft_checker/version.rb
CHANGED
data/lib/nft_checker.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "nft_checker/version"
|
4
|
+
require_relative "nft_checker/errors"
|
4
5
|
require_relative "nft_checker/open_sea"
|
5
6
|
|
6
7
|
###
|
@@ -15,9 +16,6 @@ require_relative "nft_checker/open_sea"
|
|
15
16
|
# * list_nfts(collection_metadata, owner_address): [<NFT ID>,...]
|
16
17
|
#
|
17
18
|
module NftChecker
|
18
|
-
class Error < StandardError; end
|
19
|
-
class Throttled < Error; end
|
20
|
-
|
21
19
|
def self.init(source, options = {})
|
22
20
|
case source.to_s
|
23
21
|
when /\Aopen\w?sea(.io)?\z/i
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nft_checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David J Parrott
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- bin/console
|
127
127
|
- bin/setup
|
128
128
|
- lib/nft_checker.rb
|
129
|
+
- lib/nft_checker/errors.rb
|
129
130
|
- lib/nft_checker/open_sea.rb
|
130
131
|
- lib/nft_checker/version.rb
|
131
132
|
- nft_checker.gemspec
|