Class: NEAR::Network
- Inherits:
-
Object
- Object
- NEAR::Network
- Defined in:
- lib/near/network.rb
Overview
Represents a NEAR Protocol network.
Instance Method Summary collapse
-
#fetch(block) ⇒ NEAR::Block
Fetches the block at the given height.
-
#fetch_blocks(from: nil, to: nil) {|NEAR::Block| ... } ⇒ Enumerator
Fetches a block range.
-
#fetch_latest ⇒ NEAR::Block
Fetches the latest finalized block.
- #initialize(id) ⇒ void constructor
- #neardata_url ⇒ String
- #to_s ⇒ String
Constructor Details
#initialize(id) ⇒ void
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.
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.
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_latest ⇒ NEAR::Block
Fetches the latest finalized block.
The block data is fetched from the neardata.xyz API. The block is guaranteed to exist.
70 71 72 |
# File 'lib/near/network.rb', line 70 def fetch_latest self.fetch_neardata_block(:final) end |
#neardata_url ⇒ String
27 28 29 |
# File 'lib/near/network.rb', line 27 def neardata_url self.class.const_get(:NEARDATA_URL) end |
#to_s ⇒ String
23 |
# File 'lib/near/network.rb', line 23 def to_s; @id.to_s; end |