Skip to content

Commit 5715da1

Browse files
committed
feat: mempool url parametrized as env var
1 parent 067e79e commit 5715da1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

fmo_server/src/federation/observer.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ pub struct DbMigration {
5858
pub struct FederationObserver {
5959
connection_pool: deadpool_postgres::Pool,
6060
admin_auth: String,
61+
mempool_url: String,
6162
task_group: TaskGroup,
6263
}
6364

6465
impl FederationObserver {
65-
pub async fn new(database: &str, admin_auth: &str) -> anyhow::Result<FederationObserver> {
66+
pub async fn new(
67+
database: &str,
68+
admin_auth: &str,
69+
mempool_url: &str,
70+
) -> anyhow::Result<FederationObserver> {
6671
let connection_pool = {
6772
let pool_config = deadpool_postgres::Config {
6873
url: Some(database.to_owned()),
@@ -74,6 +79,7 @@ impl FederationObserver {
7479
let slf = FederationObserver {
7580
connection_pool,
7681
admin_auth: admin_auth.to_owned(),
82+
mempool_url: mempool_url.to_owned(),
7783
task_group: Default::default(),
7884
};
7985

@@ -503,7 +509,7 @@ impl FederationObserver {
503509
}
504510

505511
async fn fetch_block_times_inner(&self) -> anyhow::Result<()> {
506-
let builder = esplora_client::Builder::new("https://mempool.space/api");
512+
let builder = esplora_client::Builder::new(&self.mempool_url);
507513
let esplora_client = builder.build_async()?;
508514

509515
// TODO: find a better way to pre-seed the DB so we don't have to bother
@@ -679,6 +685,7 @@ impl FederationObserver {
679685
item_idx as u64,
680686
item.peer,
681687
module_ci,
688+
&self.mempool_url,
682689
)
683690
.await?;
684691
}
@@ -1085,6 +1092,7 @@ impl FederationObserver {
10851092
item_index: u64,
10861093
peer_id: PeerId,
10871094
ci: DynModuleConsensusItem,
1095+
mempool_url: &str,
10881096
) -> Result<(), tokio_postgres::Error> {
10891097
let kind = instance_to_kind(config, ci.module_instance_id());
10901098

@@ -1238,7 +1246,7 @@ impl FederationObserver {
12381246
let esplora_txid = esplora_client::Txid::from_str(peg_out_txid.as_str())
12391247
.expect("Couldn't create esplora txid");
12401248

1241-
let builder = esplora_client::Builder::new("https://mempool.space/api");
1249+
let builder = esplora_client::Builder::new(mempool_url);
12421250
let client = builder
12431251
.build_async()
12441252
.expect("Failed to build esplora client");

fmo_server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ async fn main() -> anyhow::Result<()> {
5757
federation_observer: FederationObserver::new(
5858
&dotenv::var("FO_DATABASE").context("No FO_DATABASE provided")?,
5959
&dotenv::var("FO_ADMIN_AUTH").context("No FO_ADMIN_AUTH provided")?,
60+
&dotenv::var("FO_MEMPOOL_URL").context("No FO_MEMPOOL_URL provided")?,
6061
)
6162
.await?,
6263
});

sample.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ FO_BIND="127.0.0.1:3000"
33
# provide as a query param (`?host=`) or percent-encode (`%2F`)
44
FO_DATABASE="postgres://${PGUSER}@/${PGDATABASE}?host=${PGHOST}&port=${PGPORT}"
55
FO_ADMIN_AUTH="foobar"
6+
FO_MEMPOOL_URL="https://mempool.space/api"

0 commit comments

Comments
 (0)