Class: Chain::TransactionFeed
- Inherits:
-
ResponseObject
- Object
- ResponseObject
- Chain::TransactionFeed
- Defined in:
- lib/chain/transaction_feed.rb
Defined Under Namespace
Classes: ClientModule, Query
Instance Attribute Summary collapse
- #after ⇒ String readonly
-
#alias ⇒ String
readonly
User specified, unique identifier.
- #filter ⇒ String readonly
-
#id ⇒ String
readonly
Unique transaction feed identifier.
Instance Method Summary collapse
- #ack ⇒ Object
- #consume(timeout: 24*60*60) {|Transaction| ... } ⇒ void
-
#initialize(raw_attribs, base_conn) ⇒ TransactionFeed
constructor
A new instance of TransactionFeed.
Methods inherited from ResponseObject
Constructor Details
#initialize(raw_attribs, base_conn) ⇒ TransactionFeed
Returns a new instance of TransactionFeed.
30 31 32 33 34 35 36 |
# File 'lib/chain/transaction_feed.rb', line 30 def initialize(raw_attribs, base_conn) super(raw_attribs) # The consume/ack cycle should run on its own thread, so make a copy of # the base connection so this feed has an exclusive HTTP connection. @conn = Connection.new(base_conn.opts) end |
Instance Attribute Details
#after ⇒ String (readonly)
28 |
# File 'lib/chain/transaction_feed.rb', line 28 attrib :after |
#alias ⇒ String (readonly)
User specified, unique identifier.
20 |
# File 'lib/chain/transaction_feed.rb', line 20 attrib :alias |
#filter ⇒ String (readonly)
24 |
# File 'lib/chain/transaction_feed.rb', line 24 attrib :filter |
#id ⇒ String (readonly)
Unique transaction feed identifier.
15 |
# File 'lib/chain/transaction_feed.rb', line 15 attrib :id |
Instance Method Details
#ack ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chain/transaction_feed.rb', line 69 def ack raise 'ack must be called at most once per cycle in a consume loop' unless @next_after @conn.request( 'update-transaction-feed', id: id, after: @next_after, previous_after: after, ) self.after = @next_after @next_after = nil end |
#consume(timeout: 24*60*60) {|Transaction| ... } ⇒ void
This method returns an undefined value.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chain/transaction_feed.rb', line 42 def consume(timeout: 24*60*60) query = { filter: filter, after: after, timeout: (timeout * 1000).to_i, # milliseconds ascending_with_long_poll: true } longpoll = Connection.new(@conn.opts.merge(read_timeout: timeout)) loop do page = longpoll.request('list-transactions', query) query = page['next'] page['items'].each do |raw_tx| tx = Transaction.new(raw_tx) # Memoize the cursor value for this transaction in case the user # decides to ack. The format of the cursor value is specified in the # core/query package. @next_after = "#{tx.block_height}:#{tx.position}-#{MAX_BLOCK_HEIGHT}" yield tx end end end |