cronos_explorer 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1fdd494b546057162a0b2a219bb3c4d3c6dfce2621f13dd3af7ff29b5b07835c
4
+ data.tar.gz: cfe311b6ec6fdd9a05563d04d8fc69c217539bdaa687975a3e40ba83143e93c6
5
+ SHA512:
6
+ metadata.gz: aa6106ea7635a3eef0b5eb0de642ceb62603975ed60212f3146c026def0ecc95a3451974cf243056bd2c0f393a206fbd50867c077e5b8eacf07f5c6beecf8753
7
+ data.tar.gz: 32d600c443a866ef5779984d6926ed2243feb5eac5ce535616e13b4769b7ffc5dbc68bfdbbe937239ef034fab89900ff1784e51250551418fb787e669e5bf634
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_explorer.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_explorer (0.1.1)
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_explorer!
26
+ minitest (~> 5.0)
27
+ rake (~> 13.0)
28
+
29
+ BUNDLED WITH
30
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # CronosExplorer
2
+
3
+ Cronos Chain Scanner
4
+
5
+ API: https://cronos.org/explorer/testnet3/api-docs
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cronos_explorer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cronos_explorer
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ # set your net first
27
+
28
+ CronosExplorer.net = 'testnet3' or CronosExplorer.net = 'main' (default)
29
+ ```
30
+
31
+ ```ruby
32
+ CronosExplorer::Blocks.eth_block_number
33
+
34
+ CronosExplorer::Contracts.listcontracts
35
+
36
+ CronosExplorer::Accounts.eth_get_balance(@address)
37
+ CronosExplorer::Accounts.balance(@address)
38
+ CronosExplorer::Accounts.txlist(@address, starttimestamp)
39
+ CronosExplorer::Accounts.tokenbalance(@contractaddress, @address)
40
+
41
+ CronosExplorer::Transactions.gettxinfo(@txhash)
42
+ CronosExplorer::Transactions.gettxreceiptstatus(@txhash)
43
+ CronosExplorer::Transactions.getstatus(@txhash)
44
+
45
+ CronosExplorer::Tokens.getToken(@contractaddress)
46
+
47
+ CronosExplorer::Contracts.listcontracts
48
+ ```
49
+
50
+ ## Development
51
+
52
+ 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.
53
+
54
+ 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).
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/menghuanwd/cronos_explorer.
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_explorer"
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_explorer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cronos_explorer"
7
+ spec.version = CronosExplorer::VERSION
8
+ spec.authors = ["menghuanwd"]
9
+ spec.email = ["651019063@qq.com"]
10
+
11
+ spec.summary = "A Ruby Gem For Cronos Chain"
12
+ spec.description = "An unofficial simple gem For Cronos Chain API"
13
+ spec.homepage = 'https://github.com/menghuanwd/cronos_explorer'
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_explorer'
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,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
4
+ class Accounts
5
+ class << self
6
+ DEFAULT_HASH = { module: 'account' }.freeze
7
+
8
+ # Mimics Ethereum JSON RPC's eth_getBalance. Returns the balance as of the provided block (defaults to latest)
9
+ def eth_get_balance(address)
10
+ hash = DEFAULT_HASH.merge(action: 'eth_get_balance', address: address)
11
+
12
+ Request.get hash
13
+ end
14
+
15
+ =begin
16
+ Get balance for address. Also available through a GraphQL 'addresses' query.
17
+ If the balance hasn't been updated in a long time,
18
+ we will double check with the node to fetch the absolute latest balance.
19
+ This will not be reflected in the current request, but once it is updated,
20
+ subsequent requests will show the updated balance.
21
+ If you want to know whether or not we are checking for another balance, use the `balancemulti` action.
22
+ That contains a property called `stale` that will let you know to recheck that balance in the near future.
23
+ =end
24
+ def balance(address)
25
+ hash = DEFAULT_HASH.merge(action: 'balance', address: address)
26
+
27
+ Request.get hash
28
+ end
29
+
30
+ # Get transactions by address. Up to a maximum of 10,000 transactions. Also available through a GraphQL 'address' query.
31
+ def txlist(address, starttimestamp = nil, sort = 'desc')
32
+ hash = DEFAULT_HASH.merge(action: 'txlist', address: address, starttimestamp: starttimestamp, sort: sort)
33
+
34
+ Request.get hash
35
+ end
36
+
37
+ # Get token transfer events by address. Up to a maximum of 10,000 token transfer events. Also available through a GraphQL 'token_transfers' query.
38
+ def tokentx(address)
39
+ hash = DEFAULT_HASH.merge(action: 'tokentx', address: address)
40
+
41
+ Request.get hash
42
+ end
43
+
44
+ # Get token account balance for token contract address.
45
+ def tokenbalance(contractaddress, address)
46
+ hash = DEFAULT_HASH.merge(action: 'tokenbalance', contractaddress: contractaddress, address: address)
47
+
48
+ Request.get hash
49
+ end
50
+
51
+ # Get list of tokens owned by address.
52
+ def tokenlist(address)
53
+ hash = DEFAULT_HASH.merge(action: 'tokenlist', address: address)
54
+
55
+ Request.get hash
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
4
+ class Blocks
5
+ class << self
6
+ DEFAULT_HASH = { module: 'block' }.freeze
7
+
8
+ # Mimics Ethereum JSON RPC's eth_blockNumber. Returns the lastest block number
9
+ def eth_block_number
10
+ hash = DEFAULT_HASH.merge(action: 'eth_block_number')
11
+
12
+ Request.get hash
13
+ end
14
+
15
+ # Get block reward by block number.
16
+ def getblockreward(blockno)
17
+ hash = DEFAULT_HASH.merge(action: 'getblockreward', blockno: blockno)
18
+
19
+ Request.get hash
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
4
+ class Contracts
5
+ class << self
6
+ DEFAULT_HASH = { module: 'contract' }.freeze
7
+
8
+ def listcontracts
9
+ hash = DEFAULT_HASH.merge(action: 'listcontracts')
10
+
11
+ Request.get hash
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ require 'oj'
2
+ require 'faraday'
3
+
4
+ module CronosExplorer
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: CronosExplorer.domain) do |faraday|
28
+ faraday.request :json
29
+ faraday.adapter Faraday.default_adapter
30
+ end
31
+ end
32
+
33
+ def params(hash)
34
+ '?' + URI.encode_www_form(hash)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
4
+ class Tokens
5
+ class << self
6
+ DEFAULT_HASH = { module: 'token' }.freeze
7
+
8
+ def getToken(contractaddress)
9
+ hash = DEFAULT_HASH.merge(action: 'getToken', contractaddress: contractaddress)
10
+
11
+ Request.get hash
12
+ end
13
+
14
+ def getTokenHolders(contractaddress)
15
+ hash = DEFAULT_HASH.merge(action: 'getTokenHolders', contractaddress: contractaddress)
16
+
17
+ Request.get hash
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
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
+
21
+ def getstatus(txhash)
22
+ hash = DEFAULT_HASH.merge(action: 'getstatus', txhash: txhash)
23
+
24
+ Request.get hash
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosExplorer
4
+ VERSION = "0.1.1"
5
+ end
6
+
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cronos_explorer/version"
4
+ require_relative "cronos_explorer/request"
5
+ require_relative "cronos_explorer/accounts"
6
+ require_relative "cronos_explorer/transactions"
7
+ require_relative "cronos_explorer/blocks"
8
+ require_relative "cronos_explorer/contracts"
9
+ require_relative "cronos_explorer/tokens"
10
+
11
+ module CronosExplorer
12
+ class Error < StandardError; end
13
+ # Your code goes here...
14
+
15
+ class << self
16
+ # attr_reader :net
17
+ attr_writer :net
18
+
19
+ def domain
20
+ case @net
21
+ when 'main'
22
+ 'https://cronos.org/explorer/api'
23
+ when 'testnet3'
24
+ 'https://cronos.org/explorer/testnet3/api'
25
+ else
26
+ raise 'error net, only testnet3 and main'
27
+ end
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronos_explorer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - menghuanwd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-09 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: An unofficial simple gem For Cronos Chain API
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_explorer.gemspec
97
+ - lib/cronos_explorer.rb
98
+ - lib/cronos_explorer/accounts.rb
99
+ - lib/cronos_explorer/blocks.rb
100
+ - lib/cronos_explorer/contracts.rb
101
+ - lib/cronos_explorer/request.rb
102
+ - lib/cronos_explorer/tokens.rb
103
+ - lib/cronos_explorer/transactions.rb
104
+ - lib/cronos_explorer/version.rb
105
+ homepage: https://github.com/menghuanwd/cronos_explorer
106
+ licenses: []
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ homepage_uri: https://github.com/menghuanwd/cronos_explorer
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 2.4.0
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Ruby Gem For Cronos Chain
129
+ test_files: []