Class: Radiator::SSC::Stream

Inherits:
Blockchain show all
Defined in:
lib/radiator/ssc/stream.rb

Overview

Constant Summary collapse

MIN_BLOCK_PRODUCTION =

Block production on the sidechain is no faster than 3 seconds, but can be indefinately longer than 3 seconds if there are no pending transactions.

3.0

Constants inherited from BaseSteemSmartContractRPC

BaseSteemSmartContractRPC::MAX_BACKOFF, BaseSteemSmartContractRPC::POST_HEADERS

Instance Method Summary collapse

Methods inherited from Blockchain

#block_info, #latest_block_info, #transaction_info

Methods inherited from BaseSteemSmartContractRPC

#shutdown

Constructor Details

#initialize(options = {}) ⇒ Stream

Returns a new instance of Stream.

Parameters:

  • options (::Hash) (defaults to: {})

    The attributes

Options Hash (options):



15
16
17
# File 'lib/radiator/ssc/stream.rb', line 15

def initialize(options = {})
  super
end

Instance Method Details

#blocks(options = {}, &block) ⇒ Object

Stream each block on the side-chain.

stream = Radiator::SSC::Stream.new
stream.blocks do |block|
  puts "Block: #{block}"
end

Parameters:

  • options (::Hash) (defaults to: {})

    The attributes

Options Hash (options):

  • :at_block_num (Integer)

    start stream at this block number



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/radiator/ssc/stream.rb', line 28

def blocks(options = {}, &block)
  at_block_num = options[:at_block_num] || latest_block_info.blockNumber
  
  loop do
    block = block_info(at_block_num)
    
    if block.nil?
      sleep MIN_BLOCK_PRODUCTION and next
    end
    
    at_block_num += 1
    
    yield block, block.blockNumber
  end
end

#transactions(options = {}, &block) ⇒ Object

Stream each transaction on the side-chain.

stream = Radiator::SSC::Stream.new
stream.transactions do |trx|
  puts "Transaction: #{trx}"
end

Parameters:

  • options (::Hash) (defaults to: {})

    The attributes

Options Hash (options):

  • :at_block_num (Integer)

    start stream at this block number



53
54
55
56
57
58
59
# File 'lib/radiator/ssc/stream.rb', line 53

def transactions(options = {}, &block)
  blocks(options) do |block, block_num|
    block.transactions.each do |transaction|
      yield transaction, transaction.transactionId, block_num
    end
  end
end