Class: Hive::BlockApi

Inherits:
Api
  • Object
show all
Defined in:
lib/hive/block_api.rb

Overview

BlockApi is used to query values related to the block plugin. It can also be used to access a range of multiple blocks by using JSON-RPC 2.0 batch requests.

Also see: Block API Definitions

Constant Summary collapse

MAX_RANGE_SIZE =
50
MAX_NO_BATCH_RANGE_SIZE =
200
MAX_NO_BATCH_NO_RANGE_SIZE =
1

Constants inherited from Api

Api::DEFAULT_RPC_CLIENT_CLASS

Instance Attribute Summary

Attributes inherited from Api

#chain, #methods, #rpc_client

Instance Method Summary collapse

Methods inherited from Api

api_class_name, api_name, api_name=, default_rpc_client_class, #inspect, jsonrpc, jsonrpc=, register

Constructor Details

#initialize(options = {}) ⇒ BlockApi

Returns a new instance of BlockApi.


12
13
14
15
# File 'lib/hive/block_api.rb', line 12

def initialize(options = {})
  self.class.api_name = :block_api
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hive::Api

Instance Method Details

#get_block_headers(options = {block_range: (0..0)}, &block) ⇒ Object

Uses a batched requst on a range of block headers.

Parameters:

  • options (Hash) (defaults to: {block_range: (0..0)})

    The attributes to get a block range with.

Options Hash (options):

  • :block_range (Range)

    starting on one block number and ending on an higher block number.


21
22
23
# File 'lib/hive/block_api.rb', line 21

def get_block_headers(options = {block_range: (0..0)}, &block)
  get_block_objects(options.merge(object: :block_header), block)
end

#get_blocks(options = {block_range: (0..0), use_batch: false}, &block) ⇒ Object

Uses get_block_range (or batched requsts) on a range of blocks.

Parameters:

  • options (Hash) (defaults to: {block_range: (0..0), use_batch: false})

    The attributes to get a block range with.

Options Hash (options):

  • :block_range (Range)

    starting on one block number and ending on an higher block number.

  • :use_batch (Boolean)

    use json-rpc batch instead of get_block_range (preferred)


30
31
32
# File 'lib/hive/block_api.rb', line 30

def get_blocks(options = {block_range: (0..0), use_batch: false}, &block)
  get_block_objects(options.merge(object: :block), block)
end