Skip to content

Commit 3269923

Browse files
committed
Merge #619: Fix index out of bound error
d9b9b3d Fix InvalidColumnIndex error (Philipp Hoenisch) Pull request description: This query returns 7 rows, so last row is index 6 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### Bugfixes: * [x] I've added tests to reproduce the issue which are now passing ACKs for top commit: danielabrozzoni: tACK d9b9b3d rajarshimaitra: tACK d9b9b3d Tree-SHA512: 8a3d8a291daa4af86a2a2eacc31f002972dd9cdb9bf300a4b09e2e015c4a967dc4fa7e925afbcce8b104a01e1d7f7c8cb0badda8e1ac5ade511681f490c719d5
2 parents 8fbe40a + d9b9b3d commit 3269923

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/database/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,34 @@ pub mod test {
376376
);
377377
}
378378

379+
pub fn test_list_transaction<D: Database>(mut tree: D) {
380+
let hex_tx = Vec::<u8>::from_hex("0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000").unwrap();
381+
let tx: Transaction = deserialize(&hex_tx).unwrap();
382+
let txid = tx.txid();
383+
let mut tx_details = TransactionDetails {
384+
transaction: Some(tx),
385+
txid,
386+
received: 1337,
387+
sent: 420420,
388+
fee: Some(140),
389+
confirmation_time: Some(BlockTime {
390+
timestamp: 123456,
391+
height: 1000,
392+
}),
393+
};
394+
395+
tree.set_tx(&tx_details).unwrap();
396+
397+
// get raw tx
398+
assert_eq!(tree.iter_txs(true).unwrap(), vec![tx_details.clone()]);
399+
400+
// now get without raw tx
401+
tx_details.transaction = None;
402+
403+
// get not raw tx
404+
assert_eq!(tree.iter_txs(false).unwrap(), vec![tx_details.clone()]);
405+
}
406+
379407
pub fn test_last_index<D: Database>(mut tree: D) {
380408
tree.set_last_index(KeychainKind::External, 1337).unwrap();
381409

src/database/sqlite.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl SqliteDatabase {
400400
let sent: u64 = row.get(3)?;
401401
let fee: Option<u64> = row.get(4)?;
402402
let height: Option<u32> = row.get(5)?;
403-
let raw_tx: Option<Vec<u8>> = row.get(7)?;
403+
let raw_tx: Option<Vec<u8>> = row.get(6)?;
404404
let tx: Option<Transaction> = match raw_tx {
405405
Some(raw_tx) => {
406406
let tx: Transaction = deserialize(&raw_tx)?;
@@ -1030,4 +1030,9 @@ pub mod test {
10301030
fn test_sync_time() {
10311031
crate::database::test::test_sync_time(get_database());
10321032
}
1033+
1034+
#[test]
1035+
fn test_txs() {
1036+
crate::database::test::test_list_transaction(get_database());
1037+
}
10331038
}

0 commit comments

Comments
 (0)