etherscan-lite 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b41ed7587e1e595ba013221b1e55534f1aa7cecd068b381ee9319b933b0e2efe
4
- data.tar.gz: 9d3ca86dea606bb1b00690e227f382d64e0d59d7eead1be4904701b54b253aa3
3
+ metadata.gz: edbdb29fdae2d064fbf9d6513b2747ecba5058ef8449d3e430c67be2a2aaa4da
4
+ data.tar.gz: febad888db3cf78c34e78f46ff09bea7555f2ad0ba030b6146172f5fab03e23d
5
5
  SHA512:
6
- metadata.gz: 3031b621d4d99ec39b6c73e45b5e714fe255b3dc54c621caec209d7f1ef47d7e8e2ecb60a774a90833c2480fa3d7adf69b80fa039091669f8677495e0b20848f
7
- data.tar.gz: '0657688b69115499b4c099efd6e8634b0a103a7b5cd6fdfc78b31b9175e66d05704f634b633f2620db1cf5ac3b51eb12311ea072d9d65799bb927e8e6c2f2dc5'
6
+ metadata.gz: 8a545c314b42eb7ed7531e79aac0b3a3d495cb3557fcd4f204421154f7b4a1742064552628045af78ff68573e69a44b4ba1e790461507ce26eed2b25990795f4
7
+ data.tar.gz: 5e66dd8e43960e491b0b2746a38dfeee2a37d6d1b5dfe5c62e1e1d9dd717f752c3973bbf1da4121ae4c7c58f8c87185f565e4ff45b259c0324c18f71383c4ec8
data/Manifest.txt CHANGED
@@ -5,4 +5,7 @@ Rakefile
5
5
  lib/etherscan-lite.rb
6
6
  lib/etherscan-lite/account.rb
7
7
  lib/etherscan-lite/base.rb
8
+ lib/etherscan-lite/contract.rb
9
+ lib/etherscan-lite/misc.rb
10
+ lib/etherscan-lite/proxy.rb
8
11
  lib/etherscan-lite/version.rb
@@ -2,36 +2,19 @@ module Etherscan
2
2
  BASE = 'https://api.etherscan.io/api'
3
3
 
4
4
 
5
-
6
-
7
5
  def self.call( src ) ## get response as (parsed) json (hash table)
8
- uri = URI.parse( src )
9
-
10
- http = Net::HTTP.new( uri.host, uri.port )
11
-
12
- puts "[debug] GET #{uri.request_uri} uri=#{uri}"
13
6
 
14
7
  headers = {
15
8
  # 'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
16
9
  'User-Agent' => "ruby v#{RUBY_VERSION}",
17
10
  }
18
11
 
12
+ response = Webclient.get( src, headers: headers )
19
13
 
20
- request = Net::HTTP::Get.new( uri.request_uri, headers )
21
- if uri.instance_of? URI::HTTPS
22
- http.use_ssl = true
23
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
24
- end
25
-
26
- response = http.request( request )
27
-
28
- if response.code == '200'
29
- puts "#{response.code} #{response.message} - content_type: #{response.content_type}, content_length: #{response.content_length}"
14
+ if response.status.ok?
15
+ puts "#{response.status.code} #{response.status.message} - content_type: #{response.content_type}, content_length: #{response.content_length}"
30
16
 
31
- text = response.body.to_s
32
- text = text.force_encoding( Encoding::UTF_8 )
33
-
34
- data = JSON.parse( text )
17
+ data = response.json
35
18
 
36
19
  ## note: "unwrap" result - and auto-check status/message e.g.
37
20
  ## {"status"=>"1",
@@ -46,19 +29,65 @@ module Etherscan
46
29
  ## "result":"Max rate limit reached, please use API Key for higher rate limit"
47
30
  ## }
48
31
 
49
- if data['status'] == '1' && data['message'] == 'OK'
50
- ## puts "#{data['status']} #{data['message']}"
51
- data['result']
32
+ ##
33
+ # note: add special error handling case for no transaction found!!
34
+ # ==> [8] query 0x01c59869B44F3Fc5420dbB9166a735CdC020E9Ae...
35
+ # [debug] GET /api?module=account&action=txlist&address=...
36
+ # 200 OK - content_type: application/json, content_length: 172
37
+ # !! ETHERSCAN API ERROR:
38
+ # 0 No transactions found - []
39
+
40
+ if data['status'] == '0' && data['message'] == 'No transactions found' && data['result'].empty?
41
+ data['result']
42
+ elsif data['status'] == '1' && data['message'] == 'OK'
43
+ ## puts "#{data['status']} #{data['message']}"
44
+ data['result']
52
45
  else
53
46
  puts "!! ETHERSCAN API ERROR:"
54
47
  puts "#{data['status']} #{data['message']} - #{data['result']}"
55
48
  exit 1
56
49
  end
57
50
  else
58
- puts "!! ERROR:"
59
- puts "#{response.code} #{response.message}"
51
+ puts "!! HTTP ERROR:"
52
+ puts "#{response.status.code} #{response.status.message}"
60
53
  exit 1
61
54
  end
62
55
  end
63
56
 
57
+
58
+ def self.proxy_call( src ) ## get response as (parsed) json (hash table)
59
+
60
+ headers = {
61
+ # 'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
62
+ 'User-Agent' => "ruby v#{RUBY_VERSION}",
63
+ }
64
+
65
+ response = Webclient.get( src, headers: headers )
66
+
67
+ if response.status.ok?
68
+ puts "#{response.status.code} #{response.status.message} - content_type: #{response.content_type}, content_length: #{response.content_length}"
69
+
70
+ ### check for {"jsonrpc"=>"2.0",
71
+ ## "id"=>1,
72
+ ## "result"=> ... }
73
+ data = response.json
74
+ ## pp data
75
+
76
+ if data['result']
77
+ data['result']
78
+ elsif data['error']
79
+ puts "!! ETHERSCAN API (PROXY JSON-RPC) ERROR:"
80
+ puts "#{data['error']}"
81
+ exit 1
82
+ else
83
+ puts "!! ETHERSCAN API (PROXY JSON-RPC) ERROR:"
84
+ puts " No response on request"
85
+ exit 1
86
+ end
87
+ else
88
+ puts "!! HTTP ERROR:"
89
+ puts "#{response.status.code} #{response.status.message}"
90
+ exit 1
91
+ end
92
+ end
64
93
  end # module Etherscan
@@ -0,0 +1,21 @@
1
+ module Etherscan
2
+
3
+
4
+ ###
5
+ ## Get Contract Creator and Creation Tx Hash
6
+ ## Returns a contract's deployer address and transaction hash
7
+ ## it was created, up to 5 at a time.
8
+ ## see https://docs.etherscan.io/api-endpoints/contracts#get-contract-creator-and-creation-tx-hash
9
+ def self.getcontractcreation_url( contractaddresses: )
10
+ src = "#{BASE}?module=contract&action=getcontractcreation" +
11
+ "&contractaddresses=#{contractaddresses.join(',')}" +
12
+ "&apikey=#{config.key}"
13
+ src
14
+ end
15
+
16
+ def self.getcontractcreation( **kwargs )
17
+ call( getcontractcreation_url( **kwargs ) )
18
+ end
19
+
20
+
21
+ end # module Etherscan
@@ -0,0 +1,48 @@
1
+
2
+ module Etherscan
3
+
4
+
5
+ ###############
6
+ # all-in-one helper for getting contract details
7
+ # note: requires (collects data via) three api calls
8
+
9
+ def self.getcontractdetails( contractaddress: )
10
+
11
+ delay_in_s = 0.5
12
+ puts " sleeping #{delay_in_s} sec(s)..."
13
+ sleep( delay_in_s )
14
+ data = getcontractcreation( contractaddresses: [contractaddress] )
15
+ ## pp data
16
+
17
+ # [{"contractAddress"=>"0x16f5a35647d6f03d5d3da7b35409d65ba03af3b2",
18
+ # "contractCreator"=>"0xc352b534e8b987e036a93539fd6897f53488e56a",
19
+ # "txHash"=>"0xc82aa34310c310463eb9fe7835471f7317ac4b5008034a78c93b2a8a237be228"}]
20
+
21
+ ## reuse hash from repsone - why? why not?
22
+ details = data[0]
23
+
24
+ puts " sleeping #{delay_in_s} sec(s)..."
25
+ sleep( delay_in_s )
26
+ data2 = gettransactionbyhash( txhash: details['txHash'] )
27
+ ## puts
28
+ ## pp data2
29
+ # {"blockHash"=>"0x07f9b4846ee2702da8d18b9eeead15912d977acc8886ab9bf5d760914cb37670",
30
+ # "blockNumber"=>"0x3f17d2",
31
+ # "from"=>"0xa97f8ffc8f8e354475880448334e4e99a0e7212f",
32
+ # "gas"=>"0x2c51d3",
33
+ # "gasPrice"=>"0x53c53dc33",
34
+ # "hash"=>"0x79d48c41b99f0ac8f735dbf4d048165542576862df2b05a80be9a4dbe233a623",
35
+ details['blockNumber'] = data2['blockNumber']
36
+
37
+ puts " sleeping #{delay_in_s} sec(s)..."
38
+ sleep( delay_in_s )
39
+ data3 = getblockbynumber( blocknumber: data2['blockNumber'] )
40
+ ## puts
41
+ ## pp data3
42
+
43
+ details['timestamp'] = data3['timestamp']
44
+ details
45
+ end
46
+
47
+
48
+ end # module Etherscan
@@ -0,0 +1,46 @@
1
+
2
+ module Etherscan
3
+
4
+
5
+
6
+ ###
7
+ ## eth_getTransactionByHash
8
+ ## Returns the information about a transaction requested
9
+ ## by transaction hash.
10
+ ## see https://docs.etherscan.io/api-endpoints/geth-parity-proxy#eth_gettransactionbyhash
11
+
12
+ def self.gettransactionbyhash_url( txhash: )
13
+ src = "#{BASE}?module=proxy&action=eth_getTransactionByHash" +
14
+ "&txhash=#{txhash}" +
15
+ "&apikey=#{config.key}"
16
+ src
17
+ end
18
+
19
+ def self.gettransactionbyhash( **kwargs )
20
+ ## note: requires proxy_call!!! - different return / response format in json!!
21
+ proxy_call( gettransactionbyhash_url( **kwargs ) )
22
+ end
23
+
24
+ #####
25
+ ## eth_getBlockByNumber
26
+ ## Returns information about a block by block number.
27
+ ## see https://docs.etherscan.io/api-endpoints/geth-parity-proxy#eth_getblockbynumber
28
+ ##
29
+ ## the boolean value to show full transaction objects.
30
+ ## when true, returns full transaction objects and their information,
31
+ ## when false only returns a list of transactions.
32
+ def self.getblockbynumber_url( blocknumber:, transactions: false )
33
+ src = "#{BASE}?module=proxy&action=eth_getBlockByNumber" +
34
+ "&tag=#{blocknumber}" + ## note - must be a hexstring !!! e.g. 0x10d4f
35
+ "&boolean=#{transactions}" + ## " note:must be true or false
36
+ "&apikey=#{config.key}"
37
+ src
38
+ end
39
+
40
+ def self.getblockbynumber( **kwargs )
41
+ ## note: requires proxy_call!!! - different return / response format in json!!
42
+ proxy_call( getblockbynumber_url( **kwargs ) )
43
+ end
44
+
45
+
46
+ end # module Etherscan
@@ -3,7 +3,7 @@
3
3
  module EtherscanLite
4
4
  MAJOR = 0
5
5
  MINOR = 1
6
- PATCH = 0
6
+ PATCH = 1
7
7
  VERSION = [MAJOR,MINOR,PATCH].join('.')
8
8
 
9
9
  def self.version
@@ -46,6 +46,9 @@ module Etherscan
46
46
 
47
47
  require_relative 'etherscan-lite/base'
48
48
  require_relative 'etherscan-lite/account'
49
+ require_relative 'etherscan-lite/contract'
50
+ require_relative 'etherscan-lite/proxy'
51
+ require_relative 'etherscan-lite/misc'
49
52
 
50
53
 
51
54
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etherscan-lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-15 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocos
@@ -75,6 +75,9 @@ files:
75
75
  - lib/etherscan-lite.rb
76
76
  - lib/etherscan-lite/account.rb
77
77
  - lib/etherscan-lite/base.rb
78
+ - lib/etherscan-lite/contract.rb
79
+ - lib/etherscan-lite/misc.rb
80
+ - lib/etherscan-lite/proxy.rb
78
81
  - lib/etherscan-lite/version.rb
79
82
  homepage: https://github.com/rubycocos/blockchain
80
83
  licenses: