class Blockchain::BlockExplorer
Attributes
client[R]
Public Class Methods
new(base_url = nil, api_code = nil)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 14 def initialize(base_url = nil, api_code = nil) @client = Client.new(base_url, api_code) end
Public Instance Methods
get_address_by_base58(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 55 def get_address_by_base58(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE) return get_address(address, limit, offset, filter) end
get_address_by_hash160(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 50 def get_address_by_hash160(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE) return get_address(address, limit, offset, filter) end
get_block_by_hash(block_hash)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 29 def get_block_by_hash(block_hash) return get_block(block_hash) end
get_block_by_index(index)
click to toggle source
Deprecated. Please use get_block_by_hash
whenever possible.
# File lib/blockchain/blockexplorer.rb, line 24 def get_block_by_index(index) warn "[DEPRECATED] `get_block_by_index` is deprecated. Please use `get_block_by_hash` whenever possible." return get_block(index.to_s) end
get_block_height(height)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 43 def get_block_height(height) params = { 'format' => 'json' } resource = "block-height/#{height}" response = @client.call_api(resource, method: 'get', data: params) return JSON.parse(response)['blocks'].map{ |b| Block.new(b) } end
get_blocks(time = nil, pool_name = nil)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 98 def get_blocks(time = nil, pool_name = nil) params = { 'format' => 'json' } resource = "blocks/" if !time.nil? resource += time.to_s elsif !pool_name.nil? resource += pool_name end response = @client.call_api(resource, method: 'get', data: params) return JSON.parse(response)['blocks'].map{ |b| SimpleBlock.new(b) } end
get_latest_block()
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 85 def get_latest_block() resource = 'latestblock' response = @client.call_api(resource, method: 'get') return LatestBlock.new(JSON.parse(response)) end
get_multi_address(address_array, limit = MAX_TRANSACTIONS_PER_MULTI_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 68 def get_multi_address(address_array, limit = MAX_TRANSACTIONS_PER_MULTI_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE) params = { 'active' => address_array.join("|"), 'format' => 'json', 'limit' => limit, 'offset' => offset, 'filter' => filter } resource = 'multiaddr' response = @client.call_api(resource, method: 'get', data: params) return MultiAddress.new(JSON.parse(response)) end
get_tx_by_hash(tx_hash)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 39 def get_tx_by_hash(tx_hash) return get_tx(tx_hash) end
get_tx_by_index(tx_index)
click to toggle source
Deprecated. Please use get_tx_by_hash
whenever possible.
# File lib/blockchain/blockexplorer.rb, line 34 def get_tx_by_index(tx_index) warn "[DEPRECATED] `get_tx_by_index` is deprecated. Please use `get_tx_by_hash` whenever possible." return get_tx(tx_index.to_s) end
get_unconfirmed_tx()
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 91 def get_unconfirmed_tx() params = { 'format' => 'json' } resource = 'unconfirmed-transactions' response = @client.call_api(resource, method: 'get', data: params) return JSON.parse(response)['txs'].map{ |t| Transaction.new(t) } end
get_unspent_outputs(address_array, limit = DEFAULT_UNSPENT_TRANSACTIONS_PER_REQUEST, confirmations = 0)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 76 def get_unspent_outputs(address_array, limit = DEFAULT_UNSPENT_TRANSACTIONS_PER_REQUEST, confirmations = 0) params = { 'active' => address_array.join("|"), 'limit' => limit, 'confirmations' => confirmations } resource = 'unspent' response = @client.call_api(resource, method: 'get', data: params) return JSON.parse(response)['unspent_outputs'].map{ |o| UnspentOutput.new(o) } end
get_xpub(xpub, limit = MAX_TRANSACTIONS_PER_MULTI_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 60 def get_xpub(xpub, limit = MAX_TRANSACTIONS_PER_MULTI_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE) params = { 'active' => xpub, 'format' => 'json', 'limit' => limit, 'offset' => offset, 'filter' => filter } resource = 'multiaddr' response = @client.call_api(resource, method: 'get', data: params) return Xpub.new(JSON.parse(response)) end
proxy(method_name, *args)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 18 def proxy(method_name, *args) warn "[DEPRECATED] avoid use of static methods, use an instance of BlockExplorer class instead." send(method_name, *args) end
Private Instance Methods
get_address(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 125 def get_address(address, limit = MAX_TRANSACTIONS_PER_REQUEST, offset = 0, filter = FilterType::REMOVE_UNSPENDABLE) params = { 'format' => 'json', 'limit' => limit, 'offset' => offset, 'filter' => filter } resource = 'rawaddr/' + address response = @client.call_api(resource, method: 'get', data: params) return Address.new(JSON.parse(response)) end
get_block(hash_or_index)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 111 def get_block(hash_or_index) resource = 'rawblock/' + hash_or_index response = @client.call_api(resource, method: 'get') return Block.new(JSON.parse(response)) end
get_tx(hash_or_index)
click to toggle source
# File lib/blockchain/blockexplorer.rb, line 118 def get_tx(hash_or_index) resource = 'rawtx/' + hash_or_index response = @client.call_api(resource, method: 'get') return Transaction.new(JSON.parse(response)) end