From 8257470deee1c37e14857d219a2b9986d157b3a2 Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Mon, 29 Jan 2024 23:38:57 +0000 Subject: [PATCH] feat: regtest node in nix flake This is not complete yet as there is some configuration required that is note defined in the flake. --- .gitignore | 1 + config.toml | 15 ++++++++------- flake.lock | 6 +++--- flake.nix | 24 +++++++++++++++++++++++- src/config.rs | 2 +- src/main.rs | 30 +++++++++++++++++++++++------- 6 files changed, 59 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 68f832e..505ee64 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ seed device_cert device_key TODO.md +/tmp diff --git a/config.toml b/config.toml index 9ef37fb..d8d4cbc 100644 --- a/config.toml +++ b/config.toml @@ -2,14 +2,15 @@ url = "https://example.com/" listen_host = "127.0.0.1" listen_port = 8085 -mnemonic = "supersecretprivatekey" +mnemonic = "inner strategy nasty verify camp bind avoid cause glue holiday dress bounce exotic husband hungry winter diet town spray team number hen upper seek" max_order = 32 +db_path = "./mint.redb" -[mint_info] -name = "test mint" -description = "A mint for testing" -description_long = "A longer mint for testing" -motd = "Hello world" +#[mint_info] +#name = "test mint" +#description = "A mint for testing" +#description_long = "A longer mint for testing" +#motd = "Hello world" [contact] email = "me@example.com" @@ -20,7 +21,7 @@ email = "me@example.com" ln_backend = "Cln" # CLN -cln_path = "~/.lightning/signet/lightning-rpc" +cln_path = "/home/thesimplekid/Documents/Development/cashu-rs-mint/tmp/ln_1/regtest/lightning-rpc" # Required to start greenlight for the first time # greenlight_invite_code = "" diff --git a/flake.lock b/flake.lock index af091dd..fcad736 100644 --- a/flake.lock +++ b/flake.lock @@ -175,11 +175,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1705331948, - "narHash": "sha256-qjQXfvrAT1/RKDFAMdl8Hw3m4tLVvMCc8fMqzJv0pP4=", + "lastModified": 1706098335, + "narHash": "sha256-r3dWjT8P9/Ah5m5ul4WqIWD8muj5F+/gbCdjiNVBKmU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b8dd8be3c790215716e7c12b247f45ca525867e2", + "rev": "a77ab169a83a4175169d78684ddd2e54486ac651", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 738567f..24acb7c 100644 --- a/flake.nix +++ b/flake.nix @@ -16,10 +16,32 @@ flake-utils.lib.eachDefaultSystem (system: let flakeboxLib = flakebox.lib.${system} { }; + pkgs = import nixpkgs { inherit system; }; in { devShells = flakeboxLib.mkShells { - packages = [ ]; + buildInputs = [ + pkgs.clightning + pkgs.bitcoind + ]; + shellHook = '' + + bitcoind -daemon -regtest + bitcoin-cli -regtest -rpcport=4000 -rpcpassword=bitcoin -rpcuser=bitcoin createwallet "testwallet" + address=`bitcoin-cli -regtest -rpcport=4000 -rpcpassword=bitcoin -rpcuser=bitcoin getnewaddress` + bitcoin-cli -regtest -rpcport=4000 -rpcpassword=bitcoin -rpcuser=bitcoin generatetoaddress 50 $address + bitcoin-cli -regtest -rpcport=4000 -rpcpassword=bitcoin -rpcuser=bitcoin getblockcount + + lightningd --daemon --network=regtest --lightning-dir=tmp/ln_1 --addr=127.0.0.1:19846 --autolisten=true --log-level=debug --log-file=./lig.log + echo "Started first" + lightningd --daemon --network=regtest --lightning-dir=tmp/ln_2 --addr=127.0.0.1:80888 --autolisten=true --log-level=debug --log-file=./lig_2.log + + alias btc="bitcoin-cli -regtest -rpcport=4000 -rpcpassword=bitcoin -rpcuser=bitcoin" + alias ln1="lightning-cli --lightning-dir=tmp/ln_1 --regtest" + alias ln2="lightning-cli --lightning-dir=tmp/ln_2 --regtest" + + ''; }; + }); } diff --git a/src/config.rs b/src/config.rs index 073af54..538aba5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -90,7 +90,7 @@ pub struct Ln { #[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct Settings { pub info: Info, - pub mint_info: MintInfo, + // pub mint_info: MintInfo, pub ln: Ln, } diff --git a/src/main.rs b/src/main.rs index 3b63fbd..ee56333 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ use futures::StreamExt; use ln_rs::Ln; use tokio::sync::Mutex; use tower_http::cors::CorsLayer; -use tracing::warn; +use tracing::{debug, warn}; use utils::unix_time; pub const CARGO_PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); @@ -55,6 +55,8 @@ async fn main() -> anyhow::Result<()> { None => "./config.toml".to_string(), }; + debug!("Path: {}", config_file_arg); + let settings = config::Settings::new(&Some(config_file_arg)); let db_path = match args.db { @@ -63,7 +65,8 @@ async fn main() -> anyhow::Result<()> { }; let localstore = RedbLocalStore::new(db_path.to_str().unwrap())?; - let mint_info = settings.mint_info.clone(); + let mint_info = MintInfo::default(); + //settings.mint_info.clone(); localstore.set_mint_info(&mint_info).await?; let mnemonic = Mnemonic::from_str(&settings.info.mnemonic)?; @@ -77,6 +80,8 @@ async fn main() -> anyhow::Result<()> { ) .await?; + println!("Mint created"); + let cln_socket = utils::expand_path( settings .ln @@ -90,9 +95,17 @@ async fn main() -> anyhow::Result<()> { let last_pay_path = settings.info.last_pay_path.clone(); - let last_pay = fs::read(settings.info.last_pay_path.clone())?; + let last_pay_path = "./last_pay"; + println!("last pay path: {}", last_pay_path); + + let last_pay = fs::read(last_pay_path)?; + + let last_pay_index = + u64::from_be_bytes(last_pay.try_into().unwrap_or([0, 0, 0, 0, 0, 0, 0, 0])); + + println!("last pay index: {}", last_pay_index); - let last_pay_index = u64::from_be_bytes(last_pay.try_into().unwrap()); + println!("cln: {}", cln_socket.display()); let cln = ln_rs::Cln::new(cln_socket, Some(last_pay_index)).await?; @@ -132,7 +145,7 @@ async fn main() -> anyhow::Result<()> { .route("/v1/keysets", get(get_keysets)) .route("/v1/keys/:keyset_id", get(get_keyset_pubkeys)) .route("/v1/swap", post(post_swap)) - .route("/v1/mint/quote/bolt11", get(get_mint_bolt11_quote)) + .route("/v1/mint/quote/bolt11", post(get_mint_bolt11_quote)) .route( "/v1/mint/quote/bolt11/:quote_id", get(get_check_mint_bolt11_quote), @@ -232,8 +245,11 @@ async fn get_mint_bolt11_quote( ln_rs::Amount::from_sat(u64::from(payload.amount)), "".to_string(), ) - .await - .unwrap(); + .await; + + println!("Invoice {:?}", invoice); + + let invoice = invoice.unwrap(); let quote = state .mint