cronos_chain_scanner 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52ca3f4634f77d69344ce1c5d25903d1b2836374935bc77a71ba7585af86dba6
4
+ data.tar.gz: 4d9f22b0c2fdb360b82aaa115734e3fa70349f2376cacc00bdf074c55af1b991
5
+ SHA512:
6
+ metadata.gz: 4c497250023771f2959580ad97f8956b92924cf6e668cff637206207ac62d8e3d49db5bf024ee5126be68edcb1f1afe206c514bc4cda949f34974d81230ee0ce
7
+ data.tar.gz: e7ef49920c33ae5ea4f1b7a65da3afd4e7d1c872e4079f358c443849cce899f39847682e8bc322e979c2f6fbcfb9b192c5558bebdb564e6f7de4ded02c37adc6
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in cronos_chain_scanner.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cronos_chain_scanner (0.1.4)
5
+ faraday (~> 2.0)
6
+ oj (~> 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ faraday (2.2.0)
12
+ faraday-net_http (~> 2.0)
13
+ ruby2_keywords (>= 0.0.4)
14
+ faraday-net_http (2.0.1)
15
+ minitest (5.15.0)
16
+ oj (3.13.11)
17
+ rake (13.0.6)
18
+ ruby2_keywords (0.0.5)
19
+
20
+ PLATFORMS
21
+ x86_64-darwin-19
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 2.0)
25
+ cronos_chain_scanner!
26
+ minitest (~> 5.0)
27
+ rake (~> 13.0)
28
+
29
+ BUNDLED WITH
30
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # CronosChainScanner
2
+
3
+ Cronos Chain Scanner
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'cronos_chain_scanner'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cronos_chain_scanner
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ CronosChainScanner.net = 'testnet3' or CronosChainScanner.net = 'main' (default)
25
+ ```
26
+
27
+ ```ruby
28
+ CronosChainScanner::Blocks.eth_block_number
29
+
30
+ CronosChainScanner::Accounts.eth_get_balance(@address)
31
+ CronosChainScanner::Accounts.txlist(@address, starttimestamp)
32
+ CronosChainScanner::Accounts.tokenbalance(@contractaddress, @address)
33
+
34
+ CronosChainScanner::Transactions.gettxinfo(@txhash)
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/menghuanwd/cronos_chain_scanner.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
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 "cronos_chain_scanner"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/cronos_chain_scanner/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cronos_chain_scanner"
7
+ spec.version = CronosChainScanner::VERSION
8
+ spec.authors = ["menghuanwd"]
9
+ spec.email = ["651019063@qq.com"]
10
+
11
+ spec.summary = "Write a short summary, because RubyGems requires one."
12
+ spec.description = "Write a longer description or delete this line."
13
+ spec.homepage = 'https://github.com/menghuanwd/cronos_chain_scanner'
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
17
+
18
+ spec.metadata["homepage_uri"] = 'https://github.com/menghuanwd/cronos_chain_scanner'
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "faraday", "~> 2.0"
32
+ spec.add_dependency "oj", "~> 3.0"
33
+
34
+ spec.add_development_dependency "bundler", "~> 2.0"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "minitest", "~> 5.0"
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ # spec.add_dependency "example-gem", "~> 1.0"
40
+
41
+ # For more information and examples about making a new gem, checkout our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosChainScanner
4
+ class Accounts
5
+ class << self
6
+ DEFAULT_HASH = { module: 'account' }.freeze
7
+
8
+ def eth_get_balance(address)
9
+ hash = DEFAULT_HASH.merge(action: 'eth_get_balance', address: address)
10
+
11
+ Request.get hash
12
+ end
13
+
14
+ def txlist(address, starttimestamp = nil, sort = 'desc')
15
+ hash = DEFAULT_HASH.merge(action: 'txlist', address: address, starttimestamp: starttimestamp, sort: sort)
16
+
17
+ Request.get hash
18
+ end
19
+
20
+ def tokenbalance(contractaddress, address)
21
+ hash = DEFAULT_HASH.merge(action: 'tokenbalance', contractaddress: contractaddress, address: address)
22
+
23
+ Request.get hash
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosChainScanner
4
+ class Blocks
5
+ class << self
6
+ DEFAULT_HASH = { module: 'block' }.freeze
7
+
8
+ def eth_block_number
9
+ hash = DEFAULT_HASH.merge(action: 'eth_block_number')
10
+
11
+ Request.get hash
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require 'oj'
2
+ require 'faraday'
3
+
4
+ module CronosChainScanner
5
+ class Request
6
+ class << self
7
+ def get(hash)
8
+ res = connect.get do |req|
9
+ req.url params(hash)
10
+ req.headers['Content-Type'] = 'application/json'
11
+ end.body
12
+
13
+ Oj.load(res)
14
+ end
15
+
16
+ def post(hash)
17
+ res = connect.post do |req, params|
18
+ req.url params(hash)
19
+ req.headers['Content-Type'] = 'application/json'
20
+ req.params params
21
+ end.body
22
+
23
+ Oj.load(res)
24
+ end
25
+
26
+ def connect
27
+ Faraday.new(url: CronosChainScanner.domain) do |faraday|
28
+ faraday.request :json
29
+ faraday.adapter Faraday.default_adapter
30
+ end
31
+ end
32
+
33
+ def params(hash)
34
+ puts URI.encode_www_form(hash)
35
+ '?' + URI.encode_www_form(hash)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosChainScanner
4
+ class Transactions
5
+
6
+ class << self
7
+ DEFAULT_HASH = { module: 'transaction' }.freeze
8
+
9
+ def gettxreceiptstatus(txhash)
10
+ hash = DEFAULT_HASH.merge(action: 'gettxreceiptstatus', txhash: txhash, tag: 'latest')
11
+
12
+ Request.get hash
13
+ end
14
+
15
+ def gettxinfo(txhash)
16
+ hash = DEFAULT_HASH.merge(action: 'gettxinfo', txhash: txhash)
17
+
18
+ Request.get hash
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosChainScanner
4
+ VERSION = "0.1.4"
5
+ end
6
+
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cronos_chain_scanner/version"
4
+ require_relative "cronos_chain_scanner/request"
5
+ require_relative "cronos_chain_scanner/accounts"
6
+ require_relative "cronos_chain_scanner/transactions"
7
+ require_relative "cronos_chain_scanner/blocks"
8
+
9
+ module CronosChainScanner
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+
13
+ class << self
14
+ # attr_reader :net
15
+ attr_writer :net
16
+
17
+ def domain
18
+ case @net
19
+ when 'main'
20
+ 'https://cronos.org/explorer/api'
21
+ when 'testnet3'
22
+ 'https://cronos.org/explorer/testnet3/api'
23
+ else
24
+ raise 'error net, only testnet3 and main'
25
+ end
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronos_chain_scanner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - menghuanwd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Write a longer description or delete this line.
84
+ email:
85
+ - 651019063@qq.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - cronos_chain_scanner.gemspec
97
+ - lib/cronos_chain_scanner.rb
98
+ - lib/cronos_chain_scanner/accounts.rb
99
+ - lib/cronos_chain_scanner/blocks.rb
100
+ - lib/cronos_chain_scanner/request.rb
101
+ - lib/cronos_chain_scanner/transactions.rb
102
+ - lib/cronos_chain_scanner/version.rb
103
+ homepage: https://github.com/menghuanwd/cronos_chain_scanner
104
+ licenses: []
105
+ metadata:
106
+ allowed_push_host: https://rubygems.org
107
+ homepage_uri: https://github.com/menghuanwd/cronos_chain_scanner
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.4.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.6
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Write a short summary, because RubyGems requires one.
127
+ test_files: []