Skip to content

Commit 1b924ed

Browse files
authored
Merge pull request #90 from EthanYuan/raise-event-synced
feat: raise event WalletFirstSynced and TxBroadcasted
2 parents ce6e949 + 4e3322b commit 1b924ed

File tree

10 files changed

+101
-15
lines changed

10 files changed

+101
-15
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
override: true
2323
profile: minimal
2424

25-
- uses: actions/cache@v2
25+
- uses: actions/cache@v3
2626
with:
2727
path: |
2828
~/.cargo/registry

.github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v3
1313

14-
- uses: actions/cache@v2
14+
- uses: actions/cache@v3
1515
with:
1616
path: |
1717
~/.cargo/registry
@@ -53,7 +53,7 @@ jobs:
5353
with:
5454
version: 'v0.12.1'
5555

56-
- uses: actions/cache@v2
56+
- uses: actions/cache@v3
5757
with:
5858
path: |
5959
~/.cargo/registry
@@ -94,7 +94,7 @@ jobs:
9494
with:
9595
version: 'latest'
9696

97-
- uses: actions/cache@v2
97+
- uses: actions/cache@v3
9898
with:
9999
path: |
100100
~/.cargo/registry
@@ -130,7 +130,7 @@ jobs:
130130
with:
131131
version: 'latest'
132132

133-
- uses: actions/cache@v2
133+
- uses: actions/cache@v3
134134
with:
135135
path: |
136136
~/.cargo/registry
@@ -168,7 +168,7 @@ jobs:
168168
profile: minimal
169169
components: clippy
170170

171-
- uses: actions/cache@v2
171+
- uses: actions/cache@v3
172172
with:
173173
path: |
174174
~/.cargo/registry
@@ -216,7 +216,7 @@ jobs:
216216
profile: minimal
217217
components: clippy
218218

219-
- uses: actions/cache@v2
219+
- uses: actions/cache@v3
220220
with:
221221
path: |
222222
~/.cargo/registry
@@ -263,7 +263,7 @@ jobs:
263263
profile: minimal
264264
components: clippy
265265

266-
- uses: actions/cache@v2
266+
- uses: actions/cache@v3
267267
with:
268268
path: |
269269
~/.cargo/registry

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mutiny-core/src/keymanager.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,17 @@ mod tests {
344344
let xpriv = Xpriv::new_master(network, &mnemonic.to_seed("")).unwrap();
345345

346346
let wallet = Arc::new(
347-
OnChainWallet::new(xpriv, db, network, esplora, fees, stop, logger.clone()).unwrap(),
347+
OnChainWallet::new(
348+
xpriv,
349+
db,
350+
network,
351+
esplora,
352+
fees,
353+
stop,
354+
logger.clone(),
355+
None,
356+
)
357+
.unwrap(),
348358
);
349359

350360
let km = create_keys_manager(wallet.clone(), xpriv, 1, logger.clone()).unwrap();
@@ -392,7 +402,17 @@ mod tests {
392402
let xpriv = Xpriv::new_master(network, &mnemonic.to_seed("")).unwrap();
393403

394404
let wallet = Arc::new(
395-
OnChainWallet::new(xpriv, db, network, esplora, fees, stop, logger.clone()).unwrap(),
405+
OnChainWallet::new(
406+
xpriv,
407+
db,
408+
network,
409+
esplora,
410+
fees,
411+
stop,
412+
logger.clone(),
413+
None,
414+
)
415+
.unwrap(),
396416
);
397417

398418
let km = create_keys_manager(wallet.clone(), xpriv, 1, logger.clone()).unwrap();

mutiny-core/src/ldkstorage.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,19 @@ impl<S: MutinyStorage> Persist<InMemorySigner> for MutinyNodePersister<S> {
679679
update_id,
680680
};
681681

682+
log_debug!(
683+
self.logger,
684+
"persist_new_channel: (channel_id, latest_update_id, version, is_fully_resolved, claimable_balances, current_best_block): {:?}",
685+
(
686+
monitor.channel_id().to_string(),
687+
monitor.get_latest_update_id(),
688+
version,
689+
monitor.is_fully_resolved(self.logger.as_ref()),
690+
monitor.get_claimable_balances(),
691+
monitor.current_best_block(),
692+
)
693+
);
694+
682695
self.init_persist_monitor(key, monitor, version, update_id)
683696
}
684697

@@ -704,6 +717,19 @@ impl<S: MutinyStorage> Persist<InMemorySigner> for MutinyNodePersister<S> {
704717
update_id,
705718
};
706719

720+
log_debug!(
721+
self.logger,
722+
"update_persisted_channel: (channel_id, latest_update_id, version, is_fully_resolved, claimable_balances, current_best_block): {:?}",
723+
(
724+
monitor.channel_id(),
725+
monitor.get_latest_update_id(),
726+
version,
727+
monitor.is_fully_resolved(self.logger.as_ref()),
728+
monitor.get_claimable_balances(),
729+
monitor.current_best_block()
730+
)
731+
);
732+
707733
self.init_persist_monitor(key, monitor, version, update_id)
708734
}
709735

@@ -983,6 +1009,7 @@ mod test {
9831009
fees.clone(),
9841010
stop,
9851011
logger.clone(),
1012+
None,
9861013
)
9871014
.unwrap(),
9881015
);

mutiny-core/src/messagehandler.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ pub enum CommonLnEvent {
6565
payment_hash: String,
6666
amount_msat: u64,
6767
},
68+
// Wallet first synced
69+
WalletFirstSynced,
70+
// Transaction broadcasted
71+
TxBroadcasted {
72+
txid: String,
73+
hex_tx: String,
74+
},
6875
}
6976

7077
#[derive(Clone)]

mutiny-core/src/nodemanager.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::labels::LabelStorage;
22
use crate::ldkstorage::CHANNEL_CLOSURE_PREFIX;
33
use crate::logging::LOGGING_KEY;
44
use crate::lsp::voltage;
5-
use crate::messagehandler::CommonLnEventCallback;
5+
use crate::messagehandler::{CommonLnEvent, CommonLnEventCallback};
66
use crate::peermanager::PeerManager;
77
use crate::utils::sleep;
88
use crate::MutinyInvoice;
@@ -369,6 +369,7 @@ impl<S: MutinyStorage> NodeManagerBuilder<S> {
369369
fee_estimator.clone(),
370370
stop.clone(),
371371
logger.clone(),
372+
self.ln_event_callback.clone(),
372373
)?);
373374
log_trace!(logger, "finished creating on chain wallet");
374375

@@ -679,6 +680,12 @@ impl<S: MutinyStorage> NodeManager<S> {
679680
// if this is the first sync, set the done_first_sync flag
680681
let _ = nm.storage.set_done_first_sync();
681682
synced = true;
683+
684+
if let Some(cb) = nm.ln_event_callback.as_ref() {
685+
let event = CommonLnEvent::WalletFirstSynced {};
686+
cb.trigger(event);
687+
log_debug!(nm.logger, "Triggered WalletFirstSynced event");
688+
}
682689
}
683690

684691
// wait for next sync round, checking graceful shutdown check each second.

mutiny-core/src/onchain.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::error::MutinyError;
2929
use crate::fees::MutinyFeeEstimator;
3030
use crate::labels::*;
3131
use crate::logging::MutinyLogger;
32+
use crate::messagehandler::{CommonLnEvent, CommonLnEventCallback};
3233
use crate::storage::{
3334
IndexItem, MutinyStorage, KEYCHAIN_STORE_KEY, NEED_FULL_SYNC_KEY, ONCHAIN_PREFIX,
3435
};
@@ -48,9 +49,11 @@ pub struct OnChainWallet<S: MutinyStorage> {
4849
pub fees: Arc<MutinyFeeEstimator<S>>,
4950
pub(crate) stop: Arc<AtomicBool>,
5051
logger: Arc<MutinyLogger>,
52+
ln_event_callback: Option<CommonLnEventCallback>,
5153
}
5254

5355
impl<S: MutinyStorage> OnChainWallet<S> {
56+
#[allow(clippy::too_many_arguments)]
5457
pub fn new(
5558
xprivkey: Xpriv,
5659
db: S,
@@ -59,6 +62,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
5962
fees: Arc<MutinyFeeEstimator<S>>,
6063
stop: Arc<AtomicBool>,
6164
logger: Arc<MutinyLogger>,
65+
ln_event_callback: Option<CommonLnEventCallback>,
6266
) -> Result<OnChainWallet<S>, MutinyError> {
6367
let account_number = 0;
6468
let (receive_descriptor_template, change_descriptor_template) =
@@ -115,6 +119,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
115119
fees,
116120
stop,
117121
logger,
122+
ln_event_callback,
118123
})
119124
}
120125

@@ -130,7 +135,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
130135
)));
131136
} else if let Err(e) = self
132137
.insert_tx(
133-
tx,
138+
tx.clone(),
134139
ConfirmationTime::Unconfirmed {
135140
last_seen: now().as_secs(),
136141
},
@@ -141,6 +146,15 @@ impl<S: MutinyStorage> OnChainWallet<S> {
141146
log_warn!(self.logger, "ERROR: Could not sync broadcasted tx ({txid}), will be synced in next iteration: {e:?}");
142147
}
143148

149+
if let Some(cb) = self.ln_event_callback.as_ref() {
150+
let event = CommonLnEvent::TxBroadcasted {
151+
txid: format!("{:x}", txid),
152+
hex_tx: bitcoin::consensus::encode::serialize_hex(&tx),
153+
};
154+
cb.trigger(event);
155+
log_debug!(self.logger, "Triggered TxBroadcasted event");
156+
}
157+
144158
Ok(())
145159
}
146160

@@ -912,7 +926,17 @@ mod tests {
912926
let stop = Arc::new(AtomicBool::new(false));
913927
let xpriv = Xpriv::new_master(Network::Testnet, &mnemonic.to_seed("")).unwrap();
914928

915-
OnChainWallet::new(xpriv, db, Network::Testnet, esplora, fees, stop, logger).unwrap()
929+
OnChainWallet::new(
930+
xpriv,
931+
db,
932+
Network::Testnet,
933+
esplora,
934+
fees,
935+
stop,
936+
logger,
937+
None,
938+
)
939+
.unwrap()
916940
}
917941

918942
#[test]

mutiny-core/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub(crate) async fn create_node<S: MutinyStorage>(storage: S) -> Node<S> {
9292
fee_estimator.clone(),
9393
stop.clone(),
9494
logger.clone(),
95+
None,
9596
)
9697
.unwrap(),
9798
);

mutiny-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cargo-features = ["per-package-target"]
22

33
[package]
44
name = "mutiny-wasm"
5-
version = "1.11.2"
5+
version = "1.12.0"
66
edition = "2021"
77
authors = ["utxostack"]
88
forced-target = "wasm32-unknown-unknown"

0 commit comments

Comments
 (0)