Add a new method `read_chan_signer` to `KeysInterface`
[rust-lightning] / lightning / src / chain / keysinterface.rs
index 47ad84bbc596f1de3e0e387df7add2a67ad859a8..4a3a937a5c4586824ce0b875525b737ca39bdd67 100644 (file)
@@ -344,6 +344,14 @@ pub trait KeysInterface: Send + Sync {
        /// onion packets and for temporary channel IDs. There is no requirement that these be
        /// persisted anywhere, though they must be unique across restarts.
        fn get_secure_random_bytes(&self) -> [u8; 32];
+
+       /// Reads a `ChanKeySigner` for this `KeysInterface` from the given input stream.
+       /// This is only called during deserialization of other objects which contain
+       /// `ChannelKeys`-implementing objects (ie `ChannelMonitor`s and `ChannelManager`s).
+       /// The bytes are exactly those which `<Self::ChanKeySigner as Writeable>::write()` writes, and
+       /// contain no versioning scheme. You may wish to include your own version prefix and ensure
+       /// you've read all of the provided bytes to ensure no corruption occurred.
+       fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::ChanKeySigner, DecodeError>;
 }
 
 #[derive(Clone)]
@@ -809,4 +817,8 @@ impl KeysInterface for KeysManager {
                sha.input(b"Unique Secure Random Bytes Salt");
                Sha256::from_engine(sha).into_inner()
        }
+
+       fn read_chan_signer(&self, reader: &[u8]) -> Result<Self::ChanKeySigner, DecodeError> {
+               InMemoryChannelKeys::read(&mut std::io::Cursor::new(reader))
+       }
 }