Skip to content

Commit

Permalink
Remove fake_bobtimus and make the faucet a compile time feature.
Browse files Browse the repository at this point in the history
This simplifies our code-base as we now have only one binary to maintain. Also, the exchange rate in the UI are now real world values.

Signed-off-by: Philipp Hoenisch <[email protected]>
  • Loading branch information
bonomat committed Jul 29, 2021
1 parent b12dc9c commit 8a520b6
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 150 deletions.
4 changes: 4 additions & 0 deletions bobtimus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ warp = { version = "0.3", default-features = false, features = [ "tls" ] }

[dev-dependencies]
testcontainers = "0.12"

[features]
default = [ ]
faucet = [ ]
91 changes: 90 additions & 1 deletion bobtimus/src/bin/bobtimus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,28 @@ async fn main() -> Result<()> {
});

let http = http.map(|listen_http| {
warp::serve(http::routes(bobtimus, subscription)).run(listen_http)
let filter = http::routes(bobtimus.clone(), subscription);

#[cfg(feature = "faucet")]
let filter = {
use elements::Address;
use warp::Filter;

let cors = warp::cors().allow_any_origin();

let cloned_bobtimus = bobtimus.clone();
let maybe_faucet = warp::post()
.and(warp::path!("api" / "faucet" / Address))
.and_then(move |address| {
let bobtimus = cloned_bobtimus.clone();
async move {
let mut bobtimus = bobtimus.lock().await;
faucet::faucet(&mut bobtimus, address).await
}
});
filter.or(maybe_faucet).with(cors)
};
warp::serve(filter).run(listen_http)
});

match (http, https) {
Expand Down Expand Up @@ -79,3 +100,71 @@ async fn main() -> Result<()> {

Ok(())
}

#[cfg(feature = "faucet")]
mod faucet {
use super::*;
use bobtimus::{elements_rpc::ElementsRpc, LiquidUsdt};
use elements::{bitcoin::Amount, Address};
use warp::{Rejection, Reply};

pub(crate) async fn faucet<R, RS>(
bobtimus: &mut Bobtimus<R, RS>,
address: Address,
) -> Result<impl Reply, Rejection> {
let mut txids = Vec::new();
for (asset_id, amount) in &[
(bobtimus.btc_asset_id, Amount::from_sat(1_000_000_000)),
(
bobtimus.usdt_asset_id,
LiquidUsdt::from_str_in_dollar("200000.0")
.expect("valid dollars")
.into(),
),
] {
let txid = bobtimus
.elementsd
.send_asset_to_address(&address, *amount, Some(*asset_id))
.await
.map_err(|e| {
tracing::error!(
"could not fund address {} with asset {}: {}",
address,
asset_id,
e
);
warp::reject::reject()
})?;

txids.push(txid);
}

let _ = bobtimus
.elementsd
.reissueasset(bobtimus.usdt_asset_id, 200000.0)
.await
.map_err(|e| {
tracing::error!("could not reissue asset: {}", e);
warp::reject::reject()
})?;

let address = bobtimus
.elementsd
.get_new_segwit_confidential_address()
.await
.map_err(|e| {
tracing::error!("could not get new address: {}", e);
warp::reject::reject()
})?;
bobtimus
.elementsd
.generatetoaddress(1, &address)
.await
.map_err(|e| {
tracing::error!("could not generate block: {}", e);
warp::reject::reject()
})?;

Ok(warp::reply::json(&txids))
}
}
145 changes: 0 additions & 145 deletions bobtimus/src/bin/fake_bobtimus.rs

This file was deleted.

4 changes: 2 additions & 2 deletions e2e_tests/e2e_test_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ echo "Bitcoin Asset ID: "$btc_asset_id

cd ../

cargo build --bin fake_bobtimus
RUST_LOG=debug,hyper=info,reqwest=info cargo run --bin fake_bobtimus -- \
cargo build --bin bobtimus --features faucet
RUST_LOG=debug,hyper=info,reqwest=info cargo run --bin bobtimus --features faucet -- \
start \
--http 127.0.0.1:3030 \
--elementsd http://admin1:123@localhost:18884 \
Expand Down
4 changes: 2 additions & 2 deletions waves-scripts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ start_bobtimus () {
__ensure_log_dir
__read_env_file

cargo build --bin fake_bobtimus
cargo build --bin bobtimus --features faucet

local -r elementsd_rpc_user="admin1"
local -r elementsd_rpc_password="123"

RUST_LOG=debug,hyper=info,reqwest=info cargo run --bin fake_bobtimus -- \
RUST_LOG=debug,hyper=info,reqwest=info cargo run --bin bobtimus --features faucet -- \
start \
--http 127.0.0.1:3030 \
--elementsd http://$elementsd_rpc_user:$elementsd_rpc_password@127.0.0.1:$LIQUID_NODE_PORT \
Expand Down

0 comments on commit 8a520b6

Please sign in to comment.