substrate-nft-tracker 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +104 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/pangolin +57 -0
- data/lib/.DS_Store +0 -0
- data/lib/erc1155.json +325 -0
- data/lib/erc721.json +348 -0
- data/lib/nft_helper.rb +106 -0
- data/lib/testnets/pangolin.rb +69 -0
- data/lib/testnets/pangolin_contract_helper.rb +29 -0
- data/lib/tracker/version.rb +5 -0
- data/lib/tracker.rb +28 -0
- data/substrate-nft-tracker.gemspec +34 -0
- metadata +117 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
class Pangolin
|
2
|
+
def initialize(rpc)
|
3
|
+
@substrate_client = SubstrateClient.new(rpc)
|
4
|
+
Scale::TypeRegistry.instance.custom_types = {
|
5
|
+
"ExitSucceed": {
|
6
|
+
"type": "enum",
|
7
|
+
"type_mapping": [
|
8
|
+
["Stopped", "Null"],
|
9
|
+
["Returned", "Null"],
|
10
|
+
["Suicided", "Null"]
|
11
|
+
]
|
12
|
+
},
|
13
|
+
"ExitError": {
|
14
|
+
"type": "enum",
|
15
|
+
"type_mapping": [
|
16
|
+
["StackUnderflow", "Null"],
|
17
|
+
["StackOverflow", "Null"],
|
18
|
+
["InvalidJump", "Null"],
|
19
|
+
["InvalidRange", "Null"],
|
20
|
+
["DesignatedInvalid", "Null"],
|
21
|
+
["CallTooDeep", "Null"],
|
22
|
+
["CreateCollision", "Null"],
|
23
|
+
["CreateContractLimit", "Null"],
|
24
|
+
["OutOfOffset", "Null"],
|
25
|
+
["OutOfGas", "Null"],
|
26
|
+
["OutOfFund", "Null"],
|
27
|
+
["PCUnderflow", "Null"],
|
28
|
+
["CreateEmpty", "Null"],
|
29
|
+
["Other", "String"]
|
30
|
+
]
|
31
|
+
},
|
32
|
+
"ExitRevert": {
|
33
|
+
"type": "enum",
|
34
|
+
"type_mapping": [
|
35
|
+
["Reverted", "Null"],
|
36
|
+
]
|
37
|
+
},
|
38
|
+
"ExitFatal": {
|
39
|
+
"type": "enum",
|
40
|
+
"type_mapping": [
|
41
|
+
["NotSupported", "Null"],
|
42
|
+
["UnhandledInterrupt", "Null"],
|
43
|
+
["CallErrorAsFatal", "ExitError"],
|
44
|
+
["Other", "String"],
|
45
|
+
]
|
46
|
+
},
|
47
|
+
"ExitReason": {
|
48
|
+
"type": "enum",
|
49
|
+
"type_mapping": [
|
50
|
+
["Succeed", "ExitSucceed"],
|
51
|
+
["Error","ExitError"],
|
52
|
+
["Revert","ExitRevert"],
|
53
|
+
["Fatal","ExitFatal"]
|
54
|
+
]
|
55
|
+
},
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_latest_block_number()
|
60
|
+
head = @substrate_client.chain_getFinalizedHead
|
61
|
+
header = @substrate_client.chain_getHeader head
|
62
|
+
header["number"].to_i(16)
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_events_by_block_number(block_number)
|
66
|
+
block_hash = @substrate_client.chain_getBlockHash(block_number)
|
67
|
+
@substrate_client.get_block_events(block_hash)[1]
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class PangolinContractHelper
|
2
|
+
def initialize()
|
3
|
+
@client = Ethereum::HttpClient.new("https://pangolin-rpc.darwinia.network")
|
4
|
+
end
|
5
|
+
|
6
|
+
def get_name_and_symbol(address)
|
7
|
+
contract = Ethereum::Contract.create(name: "Contract", address: address, abi: Tracker.get_erc721_abi, client: @client)
|
8
|
+
# Why set a sender?
|
9
|
+
# Because the Darwinia Pangolin Network checks the gas fee when it receives a message call.
|
10
|
+
# So, it need a `from` address with some tokens
|
11
|
+
# Is this a bug?
|
12
|
+
contract.sender = "0xC5c1C9c3cEA2f4A68E540b18e63310310FD8af57"
|
13
|
+
[contract.call.name(), contract.call.symbol]
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_token_uri(address, token_id)
|
17
|
+
contract = Ethereum::Contract.create(name: "Contract", address: address, abi: Tracker.get_erc721_abi, client: @client)
|
18
|
+
contract.sender = "0xC5c1C9c3cEA2f4A68E540b18e63310310FD8af57"
|
19
|
+
contract.call.token_uri(token_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_uri(address, token_id)
|
23
|
+
contract = Ethereum::Contract.create(name: "Contract", address: address, abi: Tracker.get_erc1155_abi, client: @client)
|
24
|
+
contract.sender = "0xC5c1C9c3cEA2f4A68E540b18e63310310FD8af57"
|
25
|
+
contract.call.uri(token_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
data/lib/tracker.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "tracker/version"
|
4
|
+
|
5
|
+
require "logger"
|
6
|
+
require "scale"
|
7
|
+
require "json"
|
8
|
+
require "testnets/pangolin"
|
9
|
+
require "testnets/pangolin_contract_helper"
|
10
|
+
require "nft_helper"
|
11
|
+
require "ethereum"
|
12
|
+
|
13
|
+
module Tracker
|
14
|
+
class <<self
|
15
|
+
attr_accessor :logger
|
16
|
+
|
17
|
+
def get_erc721_abi
|
18
|
+
file = File.join __dir__, "erc721.json"
|
19
|
+
File.open(file).read
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_erc1155_abi
|
23
|
+
file = File.join __dir__, "erc1155.json"
|
24
|
+
File.open(file).read
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/tracker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "substrate-nft-tracker"
|
7
|
+
spec.version = Tracker::VERSION
|
8
|
+
spec.authors = ["Aki Wu"]
|
9
|
+
spec.email = ["wuminzhe@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A substrate nft tracker using scale.rb"
|
12
|
+
spec.description = "A substrate nft tracker using scale.rb"
|
13
|
+
spec.homepage = "https://github.com/uni-arts-chain/substrate-nft-tracker"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
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 { |f| f.match(%r{\A(?:test|spec|features|exe)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = ["pangolin"]# spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "scale.rb", "~> 0.3.2"
|
32
|
+
spec.add_dependency 'sqlite3', '~> 1.4', '>= 1.4.2'
|
33
|
+
spec.add_dependency 'ethereum.rb', '~> 2.5'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: substrate-nft-tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aki Wu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: scale.rb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.4.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.4.2
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: ethereum.rb
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.5'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.5'
|
61
|
+
description: A substrate nft tracker using scale.rb
|
62
|
+
email:
|
63
|
+
- wuminzhe@gmail.com
|
64
|
+
executables:
|
65
|
+
- pangolin
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".DS_Store"
|
70
|
+
- ".gitignore"
|
71
|
+
- ".rspec"
|
72
|
+
- ".rubocop.yml"
|
73
|
+
- CODE_OF_CONDUCT.md
|
74
|
+
- Gemfile
|
75
|
+
- Gemfile.lock
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- bin/console
|
80
|
+
- bin/setup
|
81
|
+
- exe/pangolin
|
82
|
+
- lib/.DS_Store
|
83
|
+
- lib/erc1155.json
|
84
|
+
- lib/erc721.json
|
85
|
+
- lib/nft_helper.rb
|
86
|
+
- lib/testnets/pangolin.rb
|
87
|
+
- lib/testnets/pangolin_contract_helper.rb
|
88
|
+
- lib/tracker.rb
|
89
|
+
- lib/tracker/version.rb
|
90
|
+
- substrate-nft-tracker.gemspec
|
91
|
+
homepage: https://github.com/uni-arts-chain/substrate-nft-tracker
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata:
|
95
|
+
allowed_push_host: https://rubygems.org
|
96
|
+
homepage_uri: https://github.com/uni-arts-chain/substrate-nft-tracker
|
97
|
+
source_code_uri: https://github.com/uni-arts-chain/substrate-nft-tracker
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 2.3.0
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubygems_version: 3.1.4
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: A substrate nft tracker using scale.rb
|
117
|
+
test_files: []
|