Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Fixed syntax for code examples in getting-started. #401

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions docs/src/getting-started/recover.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ In order to recover access all you need to do is recover the `seed` from the BIP

=== "Rust"
```rust
use gl_client::{Signer, TlsConfig, Scheduler, Bitcoin};
use gl_client::{signer::Signer, tls::TlsConfig, scheduler::Scheduler, bitcoin::Network};

let cert = ...; // Your developer certificate (client.crt)
let key = ...; // Your developer key (client-key.pem)
let seed = ...; // Load seed from file

let tls = TlsConfig().identity(cert, key);
let signer = Signer(seed, Network::Bitcoin, tls);
let scheduler = Scheduler::new(signer.node_id(), Network::Bitcoin).await;

let res = scheduler.recover(&signer).await?;
let tls = TlsConfig::new()
.unwrap()
.identity(cert, key);

let signer =
Signer::new(seed, Network::Bitcoin, tls).unwrap();

let scheduler = Scheduler::new(
signer.node_id(),
Network::Bitcoin
)
.await
.unwrap();

let res = scheduler.recover(&signer).await.unwrap();
```

=== "Python"
Expand All @@ -29,11 +40,12 @@ In order to recover access all you need to do is recover the `seed` from the BIP

cert = ... // Your developer certificate
key = ... // Your developer key
seed = ... // Load seed from file

tls = TlsConfig().identity(cert, key);
signer = Signer(seed, network="bitcoin", tls=tls)
scheduler = Scheduler(
node_id=signer.node_id(),
node_id=signer.node_id(),
network="bitcoin",
tls=tls,
)
Expand Down
18 changes: 10 additions & 8 deletions docs/src/getting-started/register.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ phrase and then convert it into a seed secret we can use:

// Prompt user to safely store the phrase

let seed = m.to_seed("")[0..32]; // Only need the first 32 bytes
let seed = &m.to_seed("")[0..32]; // Only need the first 32 bytes

let secret = seed[0..32].to_vec();

Expand Down Expand Up @@ -97,10 +97,10 @@ nodes.
```rust
use gl_client::tls::TlsConfig;

# Creating a new `TlsConfig` object using your developer certificate
# - cert: contains the content of `client.crt`
# - key: contains the content of `client-key.pem`
let tls = TlsConfig::new().identity(cert, key);
// Creating a new `TlsConfig` object using your developer certificate
// cert: contains the content of `client.crt`
// key: contains the content of `client-key.pem`
let tls = TlsConfig::new().unwrap().identity(cert, key);
```

=== "Python"
Expand Down Expand Up @@ -193,8 +193,9 @@ going forward to talk to the scheduler and the node itself.

// Use the configured `tls` instance when creating `Scheduler` and `Signer`
// instance going forward
let signer = Signer(seed, Network::Bitcoin, tls);
let scheduler = Scheduler::with(signer.node_id(), Network::Bitcoin, "uri", &tls).await?;
let signer = Signer::new(seed.to_vec(), Network::Bitcoin, tls.clone()).unwrap();
let scheduler = Scheduler::with(signer.node_id(), Network::Bitcoin, "uri".to_string(), &tls).await.unwrap();
let mut node: ClnClient = scheduler.schedule(tls.clone()).await.unwrap();
```

=== "Python"
Expand All @@ -204,7 +205,8 @@ going forward to talk to the scheduler and the node itself.
# Use the configured `tls` instance when creating `Scheduler` and `Signer`
# instance going forward
signer = Signer(seed, network="bitcoin", tls=tls)
node = Scheduler(node_id=signer.node_id(), network="bitcoin", tls=tls).node()
scheduler = Scheduler(node_id=signer.node_id(), network="bitcoin", tls=tls)
node = scheduler.node()
```

If you get an error about a certificate verification failure when
Expand Down
30 changes: 17 additions & 13 deletions docs/src/getting-started/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ Greenlight infrastructure:
=== "Rust"
```rust
use hex;
let node_id = hex::decode("02058e8b6c2ad363ec59aa136429256d745164c2bdc87f98f0a68690ec2c5c9b0b")?;
let network = "testnet";
use gl_client::bitcoin::Network;
use gl_client::{tls::TlsConfig, scheduler::Scheduler, node::ClnClient};

let node_id = hex::decode("02058e8b6c2ad363ec59aa136429256d745164c2bdc87f98f0a68690ec2c5c9b0b").unwrap();
let network = Network::Testnet;

let tls = TlsConfig::new().unwrap().identity(device_cert, device_key);

let scheduler = gl_client::scheduler::Scheduler(node_id, network)?;
let node: gl_client::node::ClnClient = scheduler.schedule(tls).await?;
let scheduler = Scheduler::new(node_id, network).await.unwrap();
let mut node: ClnClient = scheduler.schedule(tls).await.unwrap();
```

=== "Python"
```python
from glclient import TlsConfig, Scheduler,
from glclient import TlsConfig, Scheduler
cert, key = b'...', b'...'
node_id = bytes.fromhex("02058e8b6c2ad363ec59aa136429256d745164c2bdc87f98f0a68690ec2c5c9b0b")
network = "testnet"
Expand All @@ -53,7 +56,7 @@ Once we have an instance of the `Node` we can start interacting with it via the
=== "Rust"
```rust
use gl_client::pb::cln;
let info = node.get_info(cln::GetinfoRequest::default()).await?;
let info = node.getinfo(cln::GetinfoRequest::default()).await?;
let peers = node.list_peers(gl_client::pb::cln::ListpeersRequest::default()).await?;
```
=== "Python"
Expand All @@ -74,8 +77,8 @@ only component with access to your key.
node.invoice(cln::InvoiceRequest {
label: "label".to_string(),
description: "description".to_string(),
..Default::default(),
}).await?;
..Default::default()
}).await.unwrap();
```

=== "Python"
Expand Down Expand Up @@ -104,11 +107,12 @@ in the last chapter, instantiate the signer with it and then start it.
let (cert, key) = ... // Load the cert and key you got from the `register` call

// The signer task will run until we send a shutdown signal on this channel
// Note: The sender 'tx' must be kept alive or the channel will be closed
let (tx, mut rx) = tokio::sync::mpsc::channel(1);

let tls = TlsConfig().identity(cert, key);
signer = Signer(seed, Network::Bitcoin, tls);
signer.run_forever(rx).await?;
let tls = TlsConfig::new().unwrap().identity(device_cert, device_key);
let signer = Signer::new(seed, Network::Bitcoin, tls).unwrap();
signer.run_forever(rx).await.unwrap();
```

Notice that `signer.run_forever()` returns a `Future` which you can spawn a
Expand All @@ -120,8 +124,8 @@ in the last chapter, instantiate the signer with it and then start it.
seed = ... # Load from wherever you stored it
cert, key = ... // Load the cert and key you got from the `register` call

tls = TlsConfig().identity(cert, key)
signer = Signer::new(secret, Network::Bitcoin, tls)
tls = TlsConfig().identity(device_cert, device_key)
signer = Signer(seed, network="bitcoin", tls=tls)
signer.run_in_thread()
```

Expand Down
Loading