From 5520bd4c5ac4f01c1f51656bed6ca008a9d2da05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BF=97=E5=AE=87?= Date: Thu, 15 May 2025 15:25:36 +1000 Subject: [PATCH] feat: Add `Wallet::apply_changeset` --- wallet/src/wallet/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wallet/src/wallet/mod.rs b/wallet/src/wallet/mod.rs index 277df8c0..f71c0be9 100644 --- a/wallet/src/wallet/mod.rs +++ b/wallet/src/wallet/mod.rs @@ -2249,6 +2249,23 @@ impl Wallet { Ok(()) } + /// Applies a changeset. + /// + /// # Warning + /// + /// Applying changesets out of order may leave your wallet in an inconsistent state. + pub fn apply_changeset(&mut self, changeset: ChangeSet) { + self.chain + .apply_changeset(&changeset.local_chain) + .expect("must not remove genesis block"); + self.indexed_graph + .apply_changeset(indexed_tx_graph::ChangeSet { + tx_graph: changeset.tx_graph.clone(), + indexer: changeset.indexer.clone(), + }); + self.stage.merge(changeset); + } + /// Get a reference of the staged [`ChangeSet`] that is yet to be committed (if any). pub fn staged(&self) -> Option<&ChangeSet> { if self.stage.is_empty() {