Skip to content

Commit

Permalink
feat: functional L1 signet faucet + TOML config
Browse files Browse the repository at this point in the history
also:
- justfile for scripts
- sats_per_claim is now 10m
- moved background tasks around
- POW now uses `[u8; 8]` instead of a u64
- switch from matches to map_errs
  • Loading branch information
Zk2u committed Sep 17, 2024
1 parent 18da8d2 commit ae140bd
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 199 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ target/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
faucet.*
faucet.seed
faucet.sqlite
108 changes: 85 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "faucet-api"
name = "alpen-faucet"
version = "0.1.0"
edition = "2021"

Expand All @@ -19,6 +19,7 @@ bdk_esplora = { version = "0.18.0", features = [
bdk_wallet = { version = "1.0.0-beta.4", features = ["rusqlite"] }
colored = "2.1.0"
concurrent-map = "5.0.37"
config = { version = "0.14.0", features = ["toml"], default-features = false }
parking_lot = "0.12.3"
rand = "0.8.5"
serde = { version = "1.0.210", features = ["derive"] }
Expand Down
8 changes: 8 additions & 0 deletions faucet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
host = "127.0.0.1"
port = 3000
ip_src = "ConnectInfo"
seed_file = "faucet.seed"
sqlite_file = "faucet.sqlite"
network = "signet"
esplora = "https://explorer.bc-2.jp/api"
sats_per_claim = 10_000_000
13 changes: 13 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
t:
cargo t

fmt:
rustfmt +nightly **/*.rs

clippy:
cargo clippy --all-features -- -D warnings

enable-hooks:
echo "#!/bin/sh\njust pre-commit" > .git/hooks/pre-commit

pre-commit: fmt clippy t
15 changes: 14 additions & 1 deletion src/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
use std::ops::{Deref, DerefMut};

use crate::err;
use axum::{body::Body, http::Response, response::IntoResponse};
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
use terrors::OneOf;

use crate::err;

pub struct Hex<T: AsRef<[u8]>>(pub T);

impl<T: AsRef<[u8]>> IntoResponse for Hex<T> {
Expand Down Expand Up @@ -38,6 +39,18 @@ impl<'de> Deserialize<'de> for Hex<Vec<u8>> {
}
}

impl<'de, const N: usize> Deserialize<'de> for Hex<[u8; N]> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let hex_string = String::deserialize(deserializer)?;
let mut buf = [0; N];
decode(&hex_string, &mut buf).map_err(|e| de::Error::custom(format!("{e:?}")))?;
Ok(Hex(buf))
}
}

impl<T: AsRef<[u8]>> Deref for Hex<T> {
type Target = T;

Expand Down
Loading

0 comments on commit ae140bd

Please sign in to comment.