From 9440b238526e71a888b5d964694833027cfee2dd Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 19 Feb 2018 14:01:42 +0100 Subject: [PATCH] wallet: Add primitive to roll back to a specific height Signed-off-by: Christian Decker --- wallet/wallet.c | 8 ++++++++ wallet/wallet.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/wallet/wallet.c b/wallet/wallet.c index 89e3346b6..8e35ee4ee 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -1689,3 +1689,11 @@ void wallet_block_remove(struct wallet *w, struct block *b) assert(sqlite3_step(stmt) == SQLITE_DONE); sqlite3_finalize(stmt); } + +void wallet_blocks_rollback(struct wallet *w, u32 height) +{ + sqlite3_stmt *stmt = db_prepare(w->db, "DELETE FROM blocks " + "WHERE height >= ?"); + sqlite3_bind_int(stmt, 1, height); + db_exec_prepared(w->db, stmt); +} diff --git a/wallet/wallet.h b/wallet/wallet.h index a3f66fd7a..3ce1fcb4d 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -695,5 +695,9 @@ void wallet_block_add(struct wallet *w, struct block *b); */ void wallet_block_remove(struct wallet *w, struct block *b); +/** + * wallet_blocks_rollback - Roll the blockchain back to the given height + */ +void wallet_blocks_rollback(struct wallet *w, u32 height); #endif /* WALLET_WALLET_H */