Class: NEAR::Network

Inherits:
Object
  • Object
show all
Defined in:
lib/near/network.rb

Overview

Represents a NEAR Protocol network.

Direct Known Subclasses

Mainnet, Testnet

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ void

Parameters:

  • id (Symbol, #to_sym)


17
18
19
# File 'lib/near/network.rb', line 17

def initialize(id)
  @id = id.to_sym
end

Instance Method Details

#fetch(block) ⇒ NEAR::Block

Fetches the block at the given height.

The block data is fetched from the neardata.xyz API.

Parameters:

Returns:

Raises:



59
60
61
# File 'lib/near/network.rb', line 59

def fetch(block)
  self.fetch_neardata_block(block.to_i)
end

#fetch_blocks(from: nil, to: nil) {|NEAR::Block| ... } ⇒ Enumerator

Fetches a block range.

The block data is fetched from the neardata.xyz API.

Parameters:

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (Enumerator)


42
43
44
45
46
47
48
49
# File 'lib/near/network.rb', line 42

def fetch_blocks(from: nil, to: nil, &)
  return enum_for(:fetch_blocks) unless block_given?
  from = self.fetch_latest.height unless from
  from, to = from.to_i, to&.to_i
  (from..to).each do |block_height|
    yield self.fetch(block_height)
  end
end

#fetch_latestNEAR::Block

Fetches the latest finalized block.

The block data is fetched from the neardata.xyz API. The block is guaranteed to exist.

Returns:



70
71
72
# File 'lib/near/network.rb', line 70

def fetch_latest
  self.fetch_neardata_block(:final)
end

#neardata_urlString

Returns:

  • (String)


27
28
29
# File 'lib/near/network.rb', line 27

def neardata_url
  self.class.const_get(:NEARDATA_URL)
end

#to_sString

Returns:

  • (String)


23
# File 'lib/near/network.rb', line 23

def to_s; @id.to_s; end