Skip to content

Commit

Permalink
feat: implement qr code for base node (#3977)
Browse files Browse the repository at this point in the history
Description
---

Create a QR code for the link `tari://base_nodes/add&name=NODE_ID&peer=PEER`
Where PEER is a formatted string: PublicKey::PublicAddress

Motivation and Context
---

Users should be able easy to add a base node just scanning the QR printed in base node console.

How Has This Been Tested?
---

Manually, running the `tari_base_node` and scanning the QR using the Aurora app.
The base node should be listed if everything is correct.
  • Loading branch information
alex1307 committed Mar 30, 2022
1 parent 4301706 commit 2f618a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -53,4 +53,7 @@ buildtools/Output/

# Ignore coverage profiling artifacts
*.profraw
/report/
/report/

# Ignore local history in Visual Studio Code
.lh
1 change: 1 addition & 0 deletions applications/tari_base_node/Cargo.toml
Expand Up @@ -33,6 +33,7 @@ crossterm = { version = "0.23.1", features = ["event-stream"] }
derive_more = "0.99.17"
either = "1.6.1"
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
qrcode = { version = "0.12" }
log = { version = "0.4.8", features = ["std"] }
log-mdc = "0.1.0"
num_cpus = "1"
Expand Down
24 changes: 24 additions & 0 deletions applications/tari_base_node/src/commands/command/whoami.rs
Expand Up @@ -23,6 +23,8 @@
use anyhow::Error;
use async_trait::async_trait;
use clap::Parser;
use qrcode::{render::unicode, QrCode};
use tari_utilities::hex::Hex;

use super::{CommandContext, HandleCommand};

Expand All @@ -42,6 +44,28 @@ impl CommandContext {
/// Function to process the whoami command
pub fn whoami(&self) -> Result<(), Error> {
println!("{}", self.base_node_identity);
let peer = format!(
"{}::{}",
self.base_node_identity.public_key().to_hex(),
self.base_node_identity.public_address()
);
let network = self.config.network;
let qr_link = format!(
"tari://{}/base_nodes/add?name={}&peer={}",
network,
self.base_node_identity.node_id(),
peer
);
let code = QrCode::new(qr_link).unwrap();
let image = code
.render::<unicode::Dense1x2>()
.dark_color(unicode::Dense1x2::Dark)
.light_color(unicode::Dense1x2::Light)
.build()
.lines()
.skip(1)
.fold("".to_string(), |acc, l| format!("{}{}\n", acc, l));
println!("{}", image);
Ok(())
}
}

0 comments on commit 2f618a2

Please sign in to comment.