Skip to content

Commit

Permalink
Merge pull request #9 from Electric-Coin-Company/add-missing-file
Browse files Browse the repository at this point in the history
Add missing file
  • Loading branch information
str4d authored Nov 15, 2023
2 parents 1f839cd + 2d1d211 commit f3449b6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 10 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI checks

on: [push, pull_request]

jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v4
- name: Build binary
run: cargo build
- name: Verify working directory is clean
run: git diff --exit-code

build-latest:
name: Build latest on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v4
- name: Remove lockfile to build with latest dependencies
run: rm Cargo.lock
- name: Build binary
run: cargo build
- name: Verify working directory is clean (excluding lockfile)
run: git diff --exit-code ':!Cargo.lock'

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Clippy
uses: auguwu/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ${{ inputs.target }}
deny: warnings

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check formatting
run: cargo fmt --all -- --check
8 changes: 5 additions & 3 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Command {

// Parse or create the wallet's mnemonic phrase.
let mnemonic = if let Some(phrase) = opts.phrase {
Mnemonic::from_phrase(&phrase)?
Mnemonic::from_phrase(phrase)?
} else {
Mnemonic::generate(Count::Words24)
};
Expand Down Expand Up @@ -90,8 +90,10 @@ impl Command {
let birthday = {
// Fetch the tree state corresponding to the last block prior to the wallet's
// birthday height. NOTE: THIS APPROACH LEAKS THE BIRTHDAY TO THE SERVER!
let mut request = service::BlockId::default();
request.height = birthday - 1;
let request = service::BlockId {
height: birthday - 1,
..Default::default()
};
let treestate = client.get_tree_state(request).await?.into_inner();
AccountBirthday::from_treestate(treestate, None).map_err(error::Error::from)?
};
Expand Down
6 changes: 3 additions & 3 deletions src/commands/list_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Command {
},
)? {
let tx = row?;
println!("");
println!();
tx.print();
}

Expand All @@ -94,6 +94,7 @@ struct WalletTx {
}

impl WalletTx {
#[allow(clippy::too_many_arguments)]
fn from_parts(
mined_height: Option<u32>,
txid: Vec<u8>,
Expand Down Expand Up @@ -151,8 +152,7 @@ impl WalletTx {
" Fee paid: {}",
self.fee_paid
.map(format_zec)
.as_ref()
.map(|s| s.as_str())
.as_deref()
.unwrap_or("Unknown"),
);
println!(
Expand Down
32 changes: 32 additions & 0 deletions src/commands/reset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use gumdrop::Options;

use zcash_primitives::consensus::Parameters;

use crate::{
data::{erase_wallet_state, get_wallet_seed_and_birthday},
remote::connect_to_lightwalletd,
};

// Options accepted for the `reset` command
#[derive(Debug, Options)]
pub(crate) struct Command {}

impl Command {
pub(crate) async fn run(
self,
params: impl Parameters + 'static,
wallet_dir: Option<String>,
) -> Result<(), anyhow::Error> {
// Connect to the client (for re-initializing the wallet).
let client = connect_to_lightwalletd().await?;

// Load the wallet seed and birthday from disk.
let (seed, birthday) = get_wallet_seed_and_birthday(wallet_dir.as_ref())?;

// Erase the wallet state (excluding key material).
erase_wallet_state(wallet_dir.as_ref()).await;

// Re-initialize the wallet state.
super::init::Command::init_dbs(client, params, wallet_dir, seed, birthday.into()).await
}
}
4 changes: 2 additions & 2 deletions src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ async fn download_blocks(
};

let encoded = block.encode_to_vec();
let mut block_file = File::create(get_block_path(&fsblockdb_root, &meta)).await?;
let mut block_file = File::create(get_block_path(fsblockdb_root, &meta)).await?;
block_file.write_all(&encoded).await?;

Ok(meta)
Expand Down Expand Up @@ -338,7 +338,7 @@ fn scan_blocks<P: Parameters + Send + 'static>(
sapling_outputs_count: 0,
orchard_actions_count: 0,
};
std::fs::remove_file(get_block_path(&fsblockdb_root, &meta))
std::fs::remove_file(get_block_path(fsblockdb_root, &meta))
.map_err(|e| ChainError::<(), _>::BlockSource(FsBlockDbError::Fs(e)))
})
.map_err(|e| anyhow!("{:?}", e))?;
Expand Down
2 changes: 1 addition & 1 deletion src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn init_wallet_keys<P: AsRef<Path>>(
.as_ref()
.map(|p| p.as_ref())
.unwrap_or(DEFAULT_WALLET_DIR.as_ref());
fs::create_dir_all(&wallet_dir)?;
fs::create_dir_all(wallet_dir)?;

// Write the mnemonic phrase to disk along with its birthday.
let mut keys_file = {
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const COIN: u64 = 1_0000_0000;

pub(crate) fn format_zec(value: impl Into<Amount>) -> String {
let value = i64::from(value.into());
let abs_value = value.abs() as u64;
let abs_value = value.unsigned_abs();
let abs_zec = abs_value / COIN;
let frac = abs_value % COIN;
let zec = if value.is_negative() {
Expand Down

0 comments on commit f3449b6

Please sign in to comment.