Class: Etherscan::Call
- Inherits:
-
Object
- Object
- Etherscan::Call
- Defined in:
- lib/etherscan/call.rb
Constant Summary collapse
- CHAINS =
{ mainnet: 'http://api.etherscan.io/api?', ropsten: 'https://ropsten.etherscan.io/api?', kovan: 'https://kovan.etherscan.io/api?', rinkeby: 'https://rinkeby.etherscan.io/api?' }
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#address ⇒ Object
Returns the value of attribute address.
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#blockno ⇒ Object
Returns the value of attribute blockno.
-
#blocktype ⇒ Object
Returns the value of attribute blocktype.
-
#boolean ⇒ Object
Returns the value of attribute boolean.
-
#chain ⇒ Object
Returns the value of attribute chain.
-
#data ⇒ Object
Returns the value of attribute data.
-
#endblock ⇒ Object
Returns the value of attribute endblock.
-
#fromBlock ⇒ Object
Returns the value of attribute fromBlock.
-
#gas ⇒ Object
Returns the value of attribute gas.
-
#gasPrice ⇒ Object
Returns the value of attribute gasPrice.
-
#hex ⇒ Object
Returns the value of attribute hex.
-
#index ⇒ Object
Returns the value of attribute index.
-
#mod ⇒ Object
Returns the value of attribute mod.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#page ⇒ Object
Returns the value of attribute page.
-
#position ⇒ Object
Returns the value of attribute position.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#startblock ⇒ Object
Returns the value of attribute startblock.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#to ⇒ Object
Returns the value of attribute to.
-
#toBlock ⇒ Object
Returns the value of attribute toBlock.
-
#topics ⇒ Object
Returns the value of attribute topics.
-
#txhash ⇒ Object
Returns the value of attribute txhash.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(chain, mod, action) ⇒ Call
constructor
A new instance of Call.
- #to_s ⇒ Object
Constructor Details
#initialize(chain, mod, action) ⇒ Call
Returns a new instance of Call.
40 41 42 43 44 45 46 |
# File 'lib/etherscan/call.rb', line 40 def initialize(chain, mod, action) @chain = chain.to_sym @base = CHAINS[chain.to_sym] @mod = mod @action = action @api_key = false end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def action @action end |
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def address @address end |
#api_key ⇒ Object
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def api_key @api_key end |
#blockno ⇒ Object
Returns the value of attribute blockno.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def blockno @blockno end |
#blocktype ⇒ Object
Returns the value of attribute blocktype.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def blocktype @blocktype end |
#boolean ⇒ Object
Returns the value of attribute boolean.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def boolean @boolean end |
#chain ⇒ Object
Returns the value of attribute chain.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def chain @chain end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def data @data end |
#endblock ⇒ Object
Returns the value of attribute endblock.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def endblock @endblock end |
#fromBlock ⇒ Object
Returns the value of attribute fromBlock.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def fromBlock @fromBlock end |
#gas ⇒ Object
Returns the value of attribute gas.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def gas @gas end |
#gasPrice ⇒ Object
Returns the value of attribute gasPrice.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def gasPrice @gasPrice end |
#hex ⇒ Object
Returns the value of attribute hex.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def hex @hex end |
#index ⇒ Object
Returns the value of attribute index.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def index @index end |
#mod ⇒ Object
Returns the value of attribute mod.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def mod @mod end |
#offset ⇒ Object
Returns the value of attribute offset.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def offset @offset end |
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def page @page end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def position @position end |
#sort ⇒ Object
Returns the value of attribute sort.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def sort @sort end |
#startblock ⇒ Object
Returns the value of attribute startblock.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def startblock @startblock end |
#tag ⇒ Object
Returns the value of attribute tag.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def tag @tag end |
#to ⇒ Object
Returns the value of attribute to.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def to @to end |
#toBlock ⇒ Object
Returns the value of attribute toBlock.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def toBlock @toBlock end |
#topics ⇒ Object
Returns the value of attribute topics.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def topics @topics end |
#txhash ⇒ Object
Returns the value of attribute txhash.
5 6 7 |
# File 'lib/etherscan/call.rb', line 5 def txhash @txhash end |
Instance Method Details
#fetch ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/etherscan/call.rb', line 48 def fetch query_url = to_s Etherscan.logger.debug query_url res = Faraday.get(query_url).body Etherscan.logger.debug res data = JSON.parse(res) return [:error, data['error']] if data['error'] return [:error, data['message']] if (data['status'] && data['status'] != '1') return [:ok, data['result']] rescue => e Etherscan.logger.error "Error: #{e}" Etherscan.logger.error e.backtrace[0, 20].join("\n") return [:error, e.] end |
#to_s ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/etherscan/call.rb', line 63 def to_s uri = 'module=' + mod + '&action=' + action uri += '&apikey=' + api_key if api_key uri += address_fragment uri += '&startblock=' + startblock.to_s if startblock uri += '&endblock=' + endblock.to_s if endblock uri += '&blocktype=' + blocktype if blocktype uri += '&txhash=' + txhash if txhash uri += '&blockno=' + blockno.to_s if blockno uri += '&offset=' + offset.to_s if offset uri += '&sort=' + sort if sort uri += '&page=' + page.to_s if page uri += '&tag=' + tag if tag uri += '&hex=' + hex if hex uri += '&boolean=' + boolean if boolean uri += '&data=' + data if data uri += '&to=' + to if to uri += '&index=' + index if index uri += '&position=' + position if position uri += '&gasPrice=' + gasPrice if gasPrice uri += '&fromBlock=' + fromBlock if fromBlock uri += '&toBlock=' + toBlock if toBlock if topics topics.each do |topic| uri += "&#{topic['name']}=" + topic['value'] end end @base + uri end |