Skip to content

Commit 9b80e2f

Browse files
authored
Merge pull request #43 from ben-kaufman/feat/boost-tx-ids
Feat: save boost tx ids in the activity DB
2 parents 1e23b32 + 00beff4 commit 9b80e2f

File tree

4 files changed

+55
-27
lines changed

4 files changed

+55
-27
lines changed

src/modules/activity/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func manageActivities() {
8383
confirmed: true,
8484
timestamp: 1234567890,
8585
is_boosted: false,
86+
boost_tx_ids: [],
8687
is_transfer: false,
8788
does_exist: true,
8889
confirm_timestamp: 1234568890,
@@ -281,6 +282,7 @@ try:
281282
confirmed=True,
282283
timestamp=1234567890,
283284
is_boosted=False,
285+
boost_tx_ids=[],
284286
is_transfer=False,
285287
does_exist=True,
286288
confirm_timestamp=1234568890,
@@ -396,6 +398,7 @@ except Exception as e:
396398
- `confirmed`: bool - Confirmation status
397399
- `timestamp`: u64 - Transaction timestamp in seconds since epoch
398400
- `is_boosted`: bool - RBF status
401+
- `boost_tx_ids`: Vec<String> - List of boost transaction IDs for boosted transactions (empty if not boosted)
399402
- `is_transfer`: bool - Internal transfer flag
400403
- `does_exist`: bool - Transaction existence flag
401404
- `confirm_timestamp`: Option<u64> - Confirmation timestamp (optional)

src/modules/activity/implementation.rs

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const CREATE_ONCHAIN_TABLE: &str = "
2424
fee INTEGER NOT NULL CHECK (fee >= 0),
2525
fee_rate INTEGER NOT NULL CHECK (fee_rate >= 0),
2626
is_boosted BOOLEAN NOT NULL,
27+
boost_tx_ids TEXT NOT NULL,
2728
is_transfer BOOLEAN NOT NULL,
2829
does_exist BOOLEAN NOT NULL,
2930
confirm_timestamp INTEGER CHECK (
@@ -260,12 +261,14 @@ impl ActivityDB {
260261
let onchain_sql = "
261262
INSERT INTO onchain_activity (
262263
id, tx_id, address, confirmed, value, fee, fee_rate, is_boosted,
263-
is_transfer, does_exist, confirm_timestamp,
264+
boost_tx_ids, is_transfer, does_exist, confirm_timestamp,
264265
channel_id, transfer_tx_id
265266
) VALUES (
266-
?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13
267+
?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12, ?13, ?14
267268
)";
268269

270+
let boost_tx_ids_str = activity.boost_tx_ids.join(",");
271+
269272
tx.execute(
270273
onchain_sql,
271274
(
@@ -277,6 +280,7 @@ impl ActivityDB {
277280
activity.fee,
278281
activity.fee_rate,
279282
activity.is_boosted,
283+
&boost_tx_ids_str,
280284
activity.is_transfer,
281285
activity.does_exist,
282286
activity.confirm_timestamp,
@@ -440,6 +444,7 @@ impl ActivityDB {
440444
o.address AS onchain_address,
441445
o.confirmed AS onchain_confirmed,
442446
o.is_boosted AS onchain_is_boosted,
447+
o.boost_tx_ids AS onchain_boost_tx_ids,
443448
o.is_transfer AS onchain_is_transfer,
444449
o.does_exist AS onchain_does_exist,
445450
o.confirm_timestamp AS onchain_confirm_timestamp,
@@ -480,7 +485,13 @@ impl ActivityDB {
480485
let value: i64 = row.get(7)?;
481486
let fee: i64 = row.get(8)?;
482487
let fee_rate: i64 = row.get(9)?;
483-
let confirm_timestamp: Option<i64> = row.get(15)?;
488+
let confirm_timestamp: Option<i64> = row.get(16)?;
489+
let boost_tx_ids_str: String = row.get(13)?;
490+
let boost_tx_ids: Vec<String> = if boost_tx_ids_str.is_empty() {
491+
Vec::new()
492+
} else {
493+
boost_tx_ids_str.split(',').map(|s| s.to_string()).collect()
494+
};
484495

485496
Ok(Activity::Onchain(OnchainActivity {
486497
id: row.get(0)?,
@@ -495,32 +506,33 @@ impl ActivityDB {
495506
address: row.get(10)?,
496507
confirmed: row.get(11)?,
497508
is_boosted: row.get(12)?,
498-
is_transfer: row.get(13)?,
499-
does_exist: row.get(14)?,
509+
boost_tx_ids,
510+
is_transfer: row.get(14)?,
511+
does_exist: row.get(15)?,
500512
confirm_timestamp: confirm_timestamp.map(|t| t as u64),
501-
channel_id: row.get(16)?,
502-
transfer_tx_id: row.get(17)?,
513+
channel_id: row.get(17)?,
514+
transfer_tx_id: row.get(18)?,
503515
}))
504516
}
505517
"lightning" => {
506518
let timestamp: i64 = row.get(3)?;
507519
let created_at: Option<i64> = row.get(4)?;
508520
let updated_at: Option<i64> = row.get(5)?;
509-
let value: i64 = row.get(19)?;
510-
let fee: Option<i64> = row.get(21)?;
521+
let value: i64 = row.get(20)?;
522+
let fee: Option<i64> = row.get(22)?;
511523

512524
Ok(Activity::Lightning(LightningActivity {
513525
id: row.get(0)?,
514526
tx_type: Self::parse_payment_type(row, 2)?,
515527
timestamp: timestamp as u64,
516528
created_at: created_at.map(|t| t as u64),
517529
updated_at: updated_at.map(|t| t as u64),
518-
invoice: row.get(18)?,
530+
invoice: row.get(19)?,
519531
value: value as u64,
520-
status: Self::parse_payment_state(row, 20)?,
532+
status: Self::parse_payment_state(row, 21)?,
521533
fee: fee.map(|f| f as u64),
522-
message: row.get(22)?,
523-
preimage: row.get(23)?,
534+
message: row.get(23)?,
535+
preimage: row.get(24)?,
524536
}))
525537
}
526538
_ => Err(rusqlite::Error::InvalidColumnType(
@@ -564,7 +576,7 @@ impl ActivityDB {
564576
SELECT
565577
a.id, a.tx_type, o.tx_id, o.value, o.fee, o.fee_rate,
566578
o.address, o.confirmed, a.timestamp, o.is_boosted,
567-
o.is_transfer, o.does_exist, o.confirm_timestamp,
579+
o.boost_tx_ids, o.is_transfer, o.does_exist, o.confirm_timestamp,
568580
o.channel_id, o.transfer_tx_id, a.created_at, a.updated_at
569581
FROM activities a
570582
JOIN onchain_activity o ON a.id = o.id
@@ -579,9 +591,15 @@ impl ActivityDB {
579591
let fee: i64 = row.get(4)?;
580592
let fee_rate: i64 = row.get(5)?;
581593
let timestamp: i64 = row.get(8)?;
582-
let confirm_timestamp: Option<i64> = row.get(12)?;
583-
let created_at: Option<i64> = row.get(15)?;
584-
let updated_at: Option<i64> = row.get(16)?;
594+
let confirm_timestamp: Option<i64> = row.get(13)?;
595+
let created_at: Option<i64> = row.get(16)?;
596+
let updated_at: Option<i64> = row.get(17)?;
597+
let boost_tx_ids_str: String = row.get(10)?;
598+
let boost_tx_ids: Vec<String> = if boost_tx_ids_str.is_empty() {
599+
Vec::new()
600+
} else {
601+
boost_tx_ids_str.split(',').map(|s| s.to_string()).collect()
602+
};
585603

586604
Ok(Activity::Onchain(OnchainActivity {
587605
id: row.get(0)?,
@@ -594,11 +612,12 @@ impl ActivityDB {
594612
confirmed: row.get(7)?,
595613
timestamp: timestamp as u64,
596614
is_boosted: row.get(9)?,
597-
is_transfer: row.get(10)?,
598-
does_exist: row.get(11)?,
615+
boost_tx_ids,
616+
is_transfer: row.get(11)?,
617+
does_exist: row.get(12)?,
599618
confirm_timestamp: confirm_timestamp.map(|t| t as u64),
600-
channel_id: row.get(13)?,
601-
transfer_tx_id: row.get(14)?,
619+
channel_id: row.get(14)?,
620+
transfer_tx_id: row.get(15)?,
602621
created_at: created_at.map(|t| t as u64),
603622
updated_at: updated_at.map(|t| t as u64),
604623
}))
@@ -693,12 +712,15 @@ impl ActivityDB {
693712
fee = ?5,
694713
fee_rate = ?6,
695714
is_boosted = ?7,
696-
is_transfer = ?8,
697-
does_exist = ?9,
698-
confirm_timestamp = ?10,
699-
channel_id = ?11,
700-
transfer_tx_id = ?12
701-
WHERE id = ?13";
715+
boost_tx_ids = ?8,
716+
is_transfer = ?9,
717+
does_exist = ?10,
718+
confirm_timestamp = ?11,
719+
channel_id = ?12,
720+
transfer_tx_id = ?13
721+
WHERE id = ?14";
722+
723+
let boost_tx_ids_str = activity.boost_tx_ids.join(",");
702724

703725
tx.execute(
704726
onchain_sql,
@@ -710,6 +732,7 @@ impl ActivityDB {
710732
activity.fee,
711733
activity.fee_rate,
712734
activity.is_boosted,
735+
&boost_tx_ids_str,
713736
activity.is_transfer,
714737
activity.does_exist,
715738
activity.confirm_timestamp,

src/modules/activity/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod tests {
2626
confirmed: true,
2727
timestamp: 1234567890,
2828
is_boosted: false,
29+
boost_tx_ids: vec![],
2930
is_transfer: false,
3031
does_exist: true,
3132
confirm_timestamp: Some(1234568890),

src/modules/activity/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub struct OnchainActivity {
8686
pub confirmed: bool,
8787
pub timestamp: u64,
8888
pub is_boosted: bool,
89+
pub boost_tx_ids: Vec<String>,
8990
pub is_transfer: bool,
9091
pub does_exist: bool,
9192
pub confirm_timestamp: Option<u64>,

0 commit comments

Comments
 (0)