Class: LND::Tool::Store::HTLCEvent
- Inherits:
-
SQLiteBase
- Object
- SQLiteBase
- LND::Tool::Store::HTLCEvent
- Defined in:
- lib/lnd/tool/store/htlc_event.rb
Overview
HTLC event store
Instance Attribute Summary
Attributes inherited from SQLiteBase
Instance Method Summary collapse
-
#all ⇒ Enumerator::Lazy
Query all data.
-
#count ⇒ Integer
Get record count.
-
#prune_prior_to(time) ⇒ Object
Pruning record prior to
Time
. -
#prune_up_to(max) ⇒ Integer
Pruning record up to
max
. - #query(event_type: nil, limit: nil) ⇒ Array
-
#save(event) ⇒ Object
Save htlc event.
-
#setup ⇒ Object
Setup table.
Methods inherited from SQLiteBase
Constructor Details
This class inherits a constructor from LND::Tool::Store::SQLiteBase
Instance Method Details
#all ⇒ Enumerator::Lazy
Query all data.
52 53 54 55 56 57 58 59 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 52 def all query = <<~SQL SELECT incoming_channel_id, outgoing_channel_id, incoming_htlc_id, outgoing_htlc_id, timestamp_ns, event_type, forward_event, forward_fail_event, settle_event, link_fail_event FROM HtlcEvent ORDER BY created_datetime DESC SQL convert(db.query(query)) end |
#count ⇒ Integer
Get record count.
85 86 87 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 85 def count db.get_first_value('SELECT count(*) FROM HtlcEvent').to_i end |
#prune_prior_to(time) ⇒ Object
Pruning record prior to Time
.
103 104 105 106 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 103 def prune_prior_to(time) query = 'DELETE FROM HtlcEvent WHERE timestamp_ns < ?' db.execute(query, [time.to_i * 1_000_000_000]) end |
#prune_up_to(max) ⇒ Integer
Pruning record up to max
.
92 93 94 95 96 97 98 99 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 92 def prune_up_to(max) pruning_count = count - max return 0 if pruning_count <= 0 query = 'DELETE FROM HtlcEvent ORDER BY created_datetime ASC LIMIT ?' db.execute(query, [pruning_count]) pruning_count end |
#query(event_type: nil, limit: nil) ⇒ Array
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 64 def query(event_type: nil, limit: nil) query = <<~SQL SELECT incoming_channel_id, outgoing_channel_id, incoming_htlc_id, outgoing_htlc_id, timestamp_ns, event_type, forward_event, forward_fail_event, settle_event, link_fail_event FROM HtlcEvent SQL bind = [] if event_type query << ' WHERE event_type = ?' bind << event_type end query << ' ORDER BY created_datetime DESC' if limit query << ' LIMIT ?' bind << limit end convert(db.query(query, bind)) end |
#save(event) ⇒ Object
Save htlc event.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 29 def save(event) query = <<~SQL INSERT INTO HtlcEvent (incoming_channel_id, outgoing_channel_id, incoming_htlc_id, outgoing_htlc_id, timestamp_ns, event_type, forward_event, forward_fail_event, settle_event, link_fail_event) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) SQL values = [ event.incoming_channel_id, event.outgoing_channel_id, event.incoming_htlc_id, event.outgoing_htlc_id, event., event.event_type.to_s, event.forward_event ? Routerrpc::ForwardEvent.encode_json(event.forward_event) : nil, event.forward_fail_event ? Routerrpc::ForwardFailEvent.encode_json(event.forward_fail_event) : nil, event.settle_event ? Routerrpc::SettleEvent.encode_json(event.settle_event) : nil, event.link_fail_event ? Routerrpc::LinkFailEvent.encode_json(event.link_fail_event) : nil ] db.execute(query, values) end |
#setup ⇒ Object
Setup table.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lnd/tool/store/htlc_event.rb', line 8 def setup query = <<~SQL CREATE TABLE IF NOT EXISTS HtlcEvent( id INTEGER PRIMARY KEY, incoming_channel_id INTEGER, outgoing_channel_id INTEGER, incoming_htlc_id INTEGER, outgoing_htlc_id INTEGER, timestamp_ns INTEGER, event_type TEXT, forward_event TEXT, forward_fail_event TEXT, settle_event TEXT, link_fail_event TEXT, created_datetime TIMESTAMP DEFAULT (datetime(CURRENT_TIMESTAMP,'localtime'))) SQL db.execute(query) end |