Skip to content
This repository has been archived by the owner on Oct 20, 2024. It is now read-only.

Commit

Permalink
feat: regtest node in nix flake
Browse files Browse the repository at this point in the history
This is not complete yet as there is some configuration required that
is note defined in the flake.
  • Loading branch information
thesimplekid committed Jan 29, 2024
1 parent 1f5dcfa commit 8257470
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ seed
device_cert
device_key
TODO.md
/tmp
15 changes: 8 additions & 7 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]"
Expand All @@ -20,7 +21,7 @@ email = "[email protected]"
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 = ""
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

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

24 changes: 23 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
'';
};

});
}
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
30 changes: 23 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand All @@ -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)?;
Expand All @@ -77,6 +80,8 @@ async fn main() -> anyhow::Result<()> {
)
.await?;

println!("Mint created");

let cln_socket = utils::expand_path(
settings
.ln
Expand All @@ -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?;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8257470

Please sign in to comment.