-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Send/Receive Stores with a Database table
- Loading branch information
Showing
4 changed files
with
75 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,6 @@ impl Database { | |
Ok(was_seen_before) | ||
} | ||
} | ||
|
||
#[cfg(feature = "v2")] | ||
mod v2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use bitcoincore_rpc::jsonrpc::serde_json; | ||
use payjoin::receive::v2::Enrolled; | ||
use payjoin::send::RequestContext; | ||
use sled::IVec; | ||
|
||
use super::*; | ||
|
||
impl Database { | ||
pub fn insert_recv_session(&self, session: Enrolled) -> Result<()> { | ||
let key = &session.public_key().serialize(); | ||
let value = serde_json::to_string(&session)?; | ||
self.0.insert(key.as_slice(), IVec::from(value.as_str()))?; | ||
self.0.flush()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn get_recv_session(&self) -> Result<Option<Enrolled>> { | ||
if let Some(ivec) = self.0.get("recv_sessions")? { | ||
let session: Enrolled = serde_json::from_slice(&ivec)?; | ||
Ok(Some(session)) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
|
||
pub fn clear_recv_session(&self) -> Result<()> { | ||
self.0.remove("recv_sessions")?; | ||
self.0.flush()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn insert_send_session(&self, session: &mut RequestContext) -> Result<()> { | ||
let key = &session.public_key().serialize(); | ||
let value = serde_json::to_string(session)?; | ||
self.0.insert(key.as_slice(), IVec::from(value.as_str()))?; | ||
self.0.flush()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn get_send_session(&self) -> Result<Option<RequestContext>> { | ||
if let Some(ivec) = self.0.get("send_sessions")? { | ||
let session: RequestContext = serde_json::from_slice(&ivec)?; | ||
Ok(Some(session)) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
|
||
pub fn clear_send_session(&self) -> Result<()> { | ||
self.0.remove("send_sessions")?; | ||
self.0.flush()?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters