lnp/channel/shared_ext/
bip96.rs

1// LNP/BP Core Library implementing LNPBP specifications & standards
2// Written in 2020-2022 by
3//     Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
4//
5// To the extent possible under law, the author(s) have dedicated all
6// copyright and related and neighboring rights to this software to
7// the public domain worldwide. This software is distributed without
8// any warranty.
9//
10// You should have received a copy of the MIT License
11// along with this software.
12// If not, see <https://opensource.org/licenses/MIT>.
13
14use lnp2p::bolt::Messages;
15use wallet::lex_order::LexOrder;
16
17use crate::channel::bolt::{BoltExt, ChannelState, Error};
18use crate::channel::tx_graph::TxGraph;
19use crate::{channel, extension, ChannelExtension, Extension};
20
21#[derive(Debug, Default)]
22pub struct Bip96;
23
24impl Extension<BoltExt> for Bip96 {
25    #[inline]
26    fn identity(&self) -> BoltExt {
27        BoltExt::Bip96
28    }
29
30    fn update_from_local(&mut self, _message: &()) -> Result<(), Error> {
31        // Nothing to do here so far
32        Ok(())
33    }
34
35    #[inline]
36    fn update_from_peer(&mut self, _: &Messages) -> Result<(), Error> {
37        // Nothing to do here: peers can't tell us anything that will be related
38        // to the stateless lexicographic output ordering. So ignoring their
39        // messages all together
40        Ok(())
41    }
42
43    fn load_state(&mut self, _state: &ChannelState) {
44        // Nothing to do here
45    }
46
47    fn store_state(&self, _state: &mut ChannelState) {
48        // Nothing to do here
49    }
50}
51
52impl<N> ChannelExtension<N> for Bip96
53where
54    Self: Extension<N>,
55    N: channel::Nomenclature,
56    N::State: channel::State,
57{
58    #[inline]
59    fn new() -> Box<dyn ChannelExtension<N>>
60    where
61        Self: Sized,
62    {
63        Box::new(Bip96::default())
64    }
65
66    #[inline]
67    fn build_graph(
68        &self,
69        tx_graph: &mut TxGraph,
70        _as_remote_node: bool,
71    ) -> Result<(), <N as extension::Nomenclature>::Error> {
72        tx_graph.cmt_outs.lex_order();
73        tx_graph
74            .vec_mut()
75            .into_iter()
76            .for_each(|(_, _, tx)| tx.lex_order());
77        Ok(())
78    }
79}