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

CI workflow and CLI improvements #13

Merged
merged 2 commits into from
Jan 25, 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
42 changes: 42 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libudev-dev
version: 1.0
- name: Build
run: cargo build --verbose
- name: Run tests
run: RUST_LOG=trace cargo test --verbose

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Format
run: cargo fmt --all --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libudev-dev
version: 1.0
- name: Run Clippy
run: cargo clippy
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Documentation](https://img.shields.io/docsrs/coldcard)](https://docs.rs/coldcard/latest/coldcard/)
[![Crates.io](https://img.shields.io/crates/v/coldcard.svg)](https://crates.io/crates/coldcard)
[![License](https://img.shields.io/crates/l/coldcard.svg)](https://github.com/alfred-hodler/rust-coldcard/blob/master/coldcard/LICENSE)
[![Test Status](https://github.com/alfred-hodler/rust-coldcard/actions/workflows/rust.yml/badge.svg?branch=master)](https://github.com/alfred-hodler/rust-coldcard/actions)

This is a workspace that contains crates used for interfacing with the [Coldcard](https://coldcard.com/) hardware wallet.

Expand All @@ -22,4 +23,4 @@ Contributions are welcome. Before making large changes, please open an issue fir

## Disclaimer

This is not an official project and comes with no warranty whatsoever.
This is not an official project and comes with no warranty whatsoever.
11 changes: 4 additions & 7 deletions coldcard-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "coldcard-cli"
version = "0.11.1"
version = "0.11.2"
edition = "2021"
authors = ["Alfred Hodler <[email protected]>"]
license = "MIT"
Expand All @@ -17,14 +17,11 @@ name = "coldcard"
path = "src/main.rs"

[dependencies]
bincode = "1.3.3"
coldcard = { version = "0.11.1", path = "../coldcard" }
dirs = "4.0.0"
base64 = "0.13.0"
clap = { version = "3.1.6", features = ["derive"] }
hex = "0.4.3"
hmac-sha256 = "1.1.2"
hmac-sha256 = "1.1.7"
json = "0.12.4"
rpassword = "6.0.1"
serde = "1.0.137"
env_logger = "0.9.1"
rpassword = "7.3.1"
env_logger = "0.11.0"
45 changes: 40 additions & 5 deletions coldcard-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ enum Command {
path: Option<PathBuf>,
},

/// Installs the udev file required to detect Coldcards on Linux.
#[cfg(target_os = "linux")]
InstallUdevRules,

/// List the serial numbers of connected Coldcards
List,

Expand Down Expand Up @@ -194,7 +198,7 @@ enum AuthMode {
HMAC,
}

#[derive(clap::ArgEnum, Clone, serde::Serialize, serde::Deserialize)]
#[derive(clap::ArgEnum, Clone)]
enum SignMode {
/// Visualize only, no signing
Visualize,
Expand Down Expand Up @@ -236,11 +240,39 @@ fn handle(cli: Cli) -> Result<(), Error> {
let mut api = coldcard::Api::new()?;
let serials = api.detect()?;

if let Command::List = cli.command {
for cc in serials {
println!("{}", cc.as_ref());
// Commands we can handle without a Coldcard connection.
match cli.command {
Command::List => {
for cc in serials {
println!("{}", cc.as_ref());
}

return Ok(());
}
return Ok(());

#[cfg(target_os = "linux")]
Command::InstallUdevRules => {
const UDEV_FILE: &str = "/etc/udev/rules.d/51-coinkite.rules";

if std::path::Path::new(UDEV_FILE).exists() {
eprintln!("udev rules already installed");
} else {
match std::fs::File::create(UDEV_FILE) {
Ok(mut file) => {
file.write_all(include_bytes!("../../51-coinkite.rules"))?;
eprintln!("udev rules installed");
}
Err(err) if err.kind() == std::io::ErrorKind::PermissionDenied => {
eprintln!("Permission denied. Try with sudo?");
}
Err(err) => eprintln!("error: {}", err),
}
}

return Ok(());
}

_ => {}
}

let sn = match cli.serial {
Expand Down Expand Up @@ -354,6 +386,9 @@ fn handle(cli: Cli) -> Result<(), Error> {
eprintln!("OK");
}

#[cfg(target_os = "linux")]
Command::InstallUdevRules => unreachable!("handled earlier"),

Command::List => unreachable!("handled earlier if no command"),

Command::LocalConf { psbt, next_code } => {
Expand Down
Loading
Loading