lnd-tool 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6d5e1b2aa6a45fc2bc9f9e1fc3d3b5ac739c8deb0708a03beb95d372b0d8ba9
4
- data.tar.gz: cc803a39f5a7f95a98ba3b4dfd6a24fa79e863f1b6b74ddcd22dfa8134d74cb1
3
+ metadata.gz: 50c44439e83989cc928244de008729fdfcd9e7f22c09fb2ea26f67f3016cd187
4
+ data.tar.gz: b7e009f8bad91d4c6206a1616c8413640a004df2e13d314f40b2eda688bd9e70
5
5
  SHA512:
6
- metadata.gz: 381b5cdf5cc19157ab025feb2f2a4ec7c40ac5ca3b1af1c38e2786a470d52eadfe2f370cd707b826d0084e34061be18cdf3968936f51fbfa51760f56fbfa122d
7
- data.tar.gz: 450bfd39f6963e3c49ea70420fafb48d9acea6b392b4b180a16ed510b573c22493f0b080cc043975a6add3b32f460f9b5dd3e4723767598fd7856742856e75a4
6
+ metadata.gz: 6c8e2f7557ec6b2cb8dba8582bca88b2e4c122661f7447317dafd0bb70bd08f1ae9bb6ccb84bd633863ded21315f2ecfe376e979579098f0b33286fcd6d71c5d
7
+ data.tar.gz: 661dc0b47f6af4dc79481fae7f1b7cc4af0efccab93521718cceb595f63cf5dd7bfd00c5b75ed6d5af495edf2e56f953c69b96b0347d38569e0cd6bc6a661ef9
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # LND::Tool [![Build Status](https://github.com/azuchi/lnd-tool/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/azuchi/lnd-tool/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/lnd-tool.svg)](https://badge.fury.io/rb/lnd-tool) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
1
+ # LND::Tool [![Build Status](https://github.com/azuchi/lnd-tool/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/azuchi/lnd-tool/actions/workflows/main.yml) [![Gem Version](https://badge.fury.io/rb/lnd-tool.svg)](https://badge.fury.io/rb/lnd-tool) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE.txt)
2
2
 
3
3
  This is a tool for LND written in Ruby. Subscribe to htlc events in LND and save their contents to SQLite3.
4
4
 
@@ -83,4 +83,15 @@ Since it is a search to the database, it can be run even if the capture process
83
83
  The `query_htlc` command has the following options.
84
84
 
85
85
  * `event`: Option to specify the event type(`send`, `receive`, `forward`). e.g. `$ lnd-tool query_htlc --event=forward`
86
- * `limit`: Option to narrows down the number of data. e.g. `$lnd-tool query_htlc --limit=30`
86
+ * `limit`: Option to narrows down the number of data. e.g. `$lnd-tool query_htlc --limit=30`
87
+
88
+ ### Prune HTLC events
89
+
90
+ When the capture is running, the HTLC event is stored in the DB and the size of the DB grows.
91
+ Since v0.3.0, the `prune_htlc` command to prune(delete) DB records has been added.
92
+
93
+ The `prune_htlc` command should be executed with one of the following options:
94
+
95
+ * `max`: This is the maximum number of events to be retained in the DB.
96
+ Data exceeding this number will be pruned from the oldest data. (e.g.`$lnd-tool prune_htlc --max 10000`)
97
+ * `date`: Delete data prior to this date. (e.g.`$lnd-tool prune_htlc --date 2021-11-24`)
data/exe/lnd-tool CHANGED
@@ -83,6 +83,26 @@ class CLI < Thor
83
83
  puts table
84
84
  end
85
85
 
86
+ desc 'prune_htlc', 'Pruning the data for the HTLC event in DB. Run with either the max option or the date option.'
87
+ option :max, type: :numeric, desc:
88
+ 'This is the maximum number of data to be kept. Data exceeding this limit will be deleted in order of oldest to newest.'
89
+ option :date, type: :string, desc: 'Date in 2021-09-04 format. Delete data prior to this date.'
90
+ def prune_htlc
91
+ begin
92
+ store = LND::Tool::Store::HTLCEvent.new
93
+ if options['max']
94
+ store.prune_up_to(options['max'])
95
+ elsif options['date']
96
+ time = Date.parse(options['date']).to_time
97
+ store.prune_prior_to(time)
98
+ else
99
+ raise Thor::Error, 'Either the max or date option should be specified.'
100
+ end
101
+ puts "The current number of data is #{store.count}."
102
+ rescue Date::Error
103
+ raise Thor::Error, 'The format of the date option is invalid.'
104
+ end
105
+ end
86
106
  end
87
107
 
88
108
  CLI.start(ARGV)
@@ -80,6 +80,31 @@ module LND
80
80
  convert(db.query(query, bind))
81
81
  end
82
82
 
83
+ # Get record count.
84
+ # @return [Integer] record count.
85
+ def count
86
+ db.get_first_value('SELECT count(*) FROM HtlcEvent').to_i
87
+ end
88
+
89
+ # Pruning record up to +max+.
90
+ # @param [Integer] max Maximum number of records for this entity.
91
+ # @return [Integer] pruning count
92
+ def prune_up_to(max)
93
+ pruning_count = count - max
94
+ return 0 if pruning_count <= 0
95
+
96
+ query = 'DELETE FROM HtlcEvent ORDER BY created_datetime ASC LIMIT ?'
97
+ db.execute(query, [pruning_count])
98
+ pruning_count
99
+ end
100
+
101
+ # Pruning record prior to +Time+.
102
+ # @param [Time] time
103
+ def prune_prior_to(time)
104
+ query = 'DELETE FROM HtlcEvent WHERE timestamp_ns < ?'
105
+ db.execute(query, [time.to_i * 1_000_000_000])
106
+ end
107
+
83
108
  private
84
109
 
85
110
  def convert(recode_sets)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module LND
4
4
  module Tool
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lnd-tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-29 00:00:00.000000000 Z
11
+ date: 2021-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lnrpc