Skip to content

Commit

Permalink
refactor[py]: Update Node sig to soley use creds
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet committed Jan 28, 2024
1 parent bc623b6 commit 3ccea07
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
4 changes: 1 addition & 3 deletions libs/gl-client-py/glclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ def __init__(self, node_id: bytes, network: str, grpc_uri: str, creds: Credentia
node_id=node_id,
network=network,
grpc_uri=grpc_uri,
tls=None,
rune=None,
creds=creds.to_bytes()
creds=creds._inner
)
self.logger = logging.getLogger("glclient.Node")

Expand Down
4 changes: 1 addition & 3 deletions libs/gl-client-py/glclient/glclient.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ class Node:
node_id: bytes,
network: str,
grpc_uri: str,
tls: Optional[TlsConfig] = None,
rune: Optional[str] = None,
creds: Optional[bytes] = None
creds: Credentials,
) -> None: ...
def stop(self) -> None: ...
def call(self, method: str, request: bytes) -> bytes: ...
Expand Down
10 changes: 5 additions & 5 deletions libs/gl-client-py/glclient/rpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was generated by `genrpcstubs` from the CLN JSON-Schema.
# Do not edit this file.
from .tls import TlsConfig
from .credentials import Credentials
from . import glclient as native
import logging
from pyln import grpc as clnpb
Expand All @@ -11,16 +12,15 @@ def __init__(
self,
node_id: bytes,
network: str,
tls: TlsConfig,
grpc_uri: str
grpc_uri: str,
creds: Credentials,
):
self.tls = tls
self.grpc_uri = grpc_uri
self.inner = native.Node(
node_id=node_id,
network=network,
tls=tls.inner,
grpc_uri=grpc_uri
grpc_uri=grpc_uri,
creds=creds._inner,
)
self.logger = logging.getLogger("glclient.rpc.Node")

Expand Down
36 changes: 6 additions & 30 deletions libs/gl-client-py/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::lsps::LspClient;
use crate::runtime::exec;
use crate::tls::TlsConfig;
use crate::Credentials;
use gl_client as gl;
use gl_client::bitcoin::Network;
use gl_client::pb;
Expand All @@ -23,40 +23,16 @@ impl Node {
node_id: Vec<u8>,
network: String,
grpc_uri: String,
tls: Option<TlsConfig>,
rune: Option<String>,
creds: Option<Vec<u8>>,
creds: &Credentials,
) -> PyResult<Self> {
let network: Network = match network.parse() {
Ok(v) => v,
Err(_) => return Err(PyValueError::new_err("unknown network")),
};

match creds {
Some(creds) => {
let creds = gl::credentials::Builder::from_bytes(&creds[..])
.map_err(|e| PyValueError::new_err(e.to_string()))?
.build()
.map_err(|e| PyValueError::new_err(e.to_string()))?;
let mut node_builder = gl::node::Node::builder_from_creds(node_id, network, creds)
.map_err(|e| PyValueError::new_err(e.to_string()))?;
if let Some(tls) = tls {
node_builder = node_builder.with_tls(tls.inner);
}
if let Some(rune) = rune {
node_builder = node_builder.with_rune(&rune);
}
let inner = node_builder.build();
return node_from_inner(inner, grpc_uri);
}
None => {
let tls = tls.ok_or(PyValueError::new_err("TLS configuration is missing"))?;
let rune = rune.ok_or(PyValueError::new_err("Rune is missing"))?;
let inner =
gl::node::Node::builder_from_parts(node_id, network, tls.inner, &rune).build();
return node_from_inner(inner, grpc_uri);
}
};
let tls = creds.tls_config()?;
let rune = creds.rune()?;
let inner = gl::node::Node::builder_from_parts(node_id, network, tls.inner, &rune).build();
return node_from_inner(inner, grpc_uri);
}

fn call(&self, method: &str, payload: Vec<u8>) -> PyResult<Vec<u8>> {
Expand Down

0 comments on commit 3ccea07

Please sign in to comment.