cronos_chain 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4698f9db95ef675a240646b2a754961aa3f37921a99a59514b8fcb6f3592ac05
4
- data.tar.gz: f3f8735f5f2f47a08d5d6eae34f081ab99289c44a55b700fc5940a92054da486
3
+ metadata.gz: f748e3258068199b06b985b5bbd96a260d6db92f1e6985be23f32742ff9a2493
4
+ data.tar.gz: 799dd44f14a6187ed7f0f85c3e4ecc274893fcb0e0d2f09ae30edb14345f0c20
5
5
  SHA512:
6
- metadata.gz: d44b109acda0eef4167fecb93bd3717d52ee70f2776449804f0d5693e2071adf37d45bc4f926775b489293d969981c6b5c62ce2af37333cc554ca3f6adf6dead
7
- data.tar.gz: f1091bd8da88bcfa053ce67a56af9f2cbaa204696c0b20eba3324f364464ab0fdf22401164701f52b0079fe571bccd63ee36a2e3d7b3db4e59b7a5d370d3241d
6
+ metadata.gz: b88832c3913b01be82efa6ce1bb1cad6f7f71640c6e0a0b38686a6748b92cbb8477ed6820500837b6b4cd1b80084881809e91eecc9719a559cab29fb7bab94b3
7
+ data.tar.gz: da137ef26506f9ad820b1c77bd74ada6449a9839d9e87377a0d9e0c67535fd7972c2921aca629b5b9bb5eaf1f71d54c3d22e5a53dd2019e86d61f7437c7f8b6a
data/Gemfile.lock CHANGED
@@ -1,18 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cronos_chain (0.1.3)
4
+ cronos_chain (0.1.4)
5
+ faraday (~> 2.0)
6
+ oj (~> 3.0)
5
7
 
6
8
  GEM
7
9
  remote: https://rubygems.org/
8
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)
9
17
  rake (13.0.6)
18
+ ruby2_keywords (0.0.5)
10
19
 
11
20
  PLATFORMS
12
21
  x86_64-darwin-19
13
22
 
14
23
  DEPENDENCIES
24
+ bundler (~> 2.0)
15
25
  cronos_chain!
26
+ minitest (~> 5.0)
16
27
  rake (~> 13.0)
17
28
 
18
29
  BUNDLED WITH
data/README.md CHANGED
@@ -22,7 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ CronosChain.net = 'testnet3'
26
+ CronosChain.net = 'main' (default)
27
+
28
+ CronosChain::Blocks.eth_block_number
29
+
30
+ CronosChain::Accounts.eth_get_balance(@address)
31
+ CronosChain::Accounts.txlist(@address, starttimestamp)
32
+ CronosChain::Accounts.tokenbalance(@contractaddress, @address)
33
+
34
+ CronosChain::Transactions.gettxinfo(@txhash)
26
35
 
27
36
  ## Development
28
37
 
@@ -32,4 +41,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
41
 
33
42
  ## Contributing
34
43
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cronos_chain.
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/menghuanwd/cronos_chain.
data/cronos_chain.gemspec CHANGED
@@ -16,8 +16,6 @@ Gem::Specification.new do |spec|
16
16
  spec.metadata["allowed_push_host"] = 'https://rubygems.org'
17
17
 
18
18
  spec.metadata["homepage_uri"] = 'https://github.com/menghuanwd/cronos_chain'
19
- # spec.metadata["source_code_uri"] = 'https://github.com/menghuanwd/cronos_chain'
20
- # spec.metadata["changelog_uri"] = 'https://github.com/menghuanwd/cronos_chain'
21
19
 
22
20
  # Specify which files should be added to the gem when it is released.
23
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -30,10 +28,16 @@ Gem::Specification.new do |spec|
30
28
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
29
  spec.require_paths = ["lib"]
32
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
+
33
38
  # Uncomment to register a new dependency of your gem
34
39
  # spec.add_dependency "example-gem", "~> 1.0"
35
40
 
36
41
  # For more information and examples about making a new gem, checkout our
37
42
  # guide at: https://bundler.io/guides/creating_gem.html
38
43
  end
39
-
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CronosChain
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 CronosChain
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 CronosChain
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: CronosChain.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 CronosChain
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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CronosChain
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
+
data/lib/cronos_chain.rb CHANGED
@@ -1,8 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "cronos_chain/version"
4
+ require_relative "cronos_chain/request"
5
+ require_relative "cronos_chain/accounts"
6
+ require_relative "cronos_chain/transactions"
7
+ require_relative "cronos_chain/blocks"
4
8
 
5
9
  module CronosChain
6
10
  class Error < StandardError; end
7
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
8
28
  end
metadata CHANGED
@@ -1,15 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronos_chain
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - menghuanwd
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
12
- dependencies: []
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'
13
83
  description: Write a longer description or delete this line.
14
84
  email:
15
85
  - 651019063@qq.com
@@ -25,6 +95,10 @@ files:
25
95
  - bin/setup
26
96
  - cronos_chain.gemspec
27
97
  - lib/cronos_chain.rb
98
+ - lib/cronos_chain/accounts.rb
99
+ - lib/cronos_chain/blocks.rb
100
+ - lib/cronos_chain/request.rb
101
+ - lib/cronos_chain/transactions.rb
28
102
  - lib/cronos_chain/version.rb
29
103
  homepage: https://github.com/menghuanwd/cronos_chain
30
104
  licenses: []