Skip to content

Commit

Permalink
upgrade greenlight credentials before usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed May 30, 2024
1 parent 919d0fb commit 13c3bc7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libs/sdk-core/src/greenlight/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ impl From<TryFromIntError> for NodeError {
}
}

impl From<gl_client::credentials::Error> for NodeError {
fn from(value: gl_client::credentials::Error) -> Self {
NodeError::Credentials(value.to_string())
}
}

#[allow(clippy::invalid_regex)]
pub(crate) fn parse_cln_error(status: tonic::Status) -> Result<JsonRpcErrCode> {
let re: Regex = Regex::new(r"Some\((?<code>-?\d+)\)")?;
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk-core/src/greenlight/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl Greenlight {
// Persist the connection credentials for future use and return the node instance
match parsed_credentials {
Ok(creds) => {
let temp_scheduler = Scheduler::new(config.network.into(), creds.clone()).await?;
let creds = creds.upgrade(&temp_scheduler, &temp_signer).await?;
let encrypted_creds = sym_encrypt(encryption_key_slice, &creds.to_bytes());
match encrypted_creds {
Some(c) => {
Expand Down
3 changes: 3 additions & 0 deletions libs/sdk-core/src/node_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub type NodeResult<T, E = NodeError> = Result<T, E>;

#[derive(Debug, thiserror::Error)]
pub enum NodeError {
#[error("{0}")]
Credentials(String),

#[error("{0}")]
Generic(String),

Expand Down

0 comments on commit 13c3bc7

Please sign in to comment.