Skip to content

Commit

Permalink
plugin: support liquid network
Browse files Browse the repository at this point in the history
Supporting the liquid network inside the esplora backend
and remove the contraint to required a fallback backend.

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Dec 17, 2023
1 parent ce37d34 commit e31ac4d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
3 changes: 3 additions & 0 deletions folgore-esplora/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ impl TryFrom<&str> for Network {
.to_owned(),
)),
"signet" => Ok(Self::Testnet("https://mempool.space/signet/api".to_owned())),
"liquid" => Ok(Self::Liquid(
"https://blockstream.info/liquid/api".to_owned(),
)),
_ => Err(error!("network {value} not supported")),
}
}
Expand Down
60 changes: 30 additions & 30 deletions folgore-plugin/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ fn get_chain_info(plugin: &mut Plugin<PluginState>, request: Value) -> Result<Va
"Client must be not null at this point, please report a bug"
))?;
// FIXME: make this not null
let fallback = plg
.state
.fallback
.as_mut()
.ok_or(error!("Fallback must be not null"))?;
let fallback = plg.state.fallback.as_mut();
plugin.log(LogLevel::Info, &format!("cln request {request}"));
let request: GetChainInfo = serde_json::from_value(request)?;

let mut result: Result<Value, PluginError> = Err(error!("result undefined"));
for client in [client, fallback] {
for client in [Some(client), fallback] {
if client.is_none() {
continue;
}
let client = client.unwrap();
result = client.sync_chain_info(plugin, request.height.clone());
let Ok(ref result) = result else {
plugin.log(
Expand Down Expand Up @@ -252,13 +252,13 @@ fn estimate_fees(plugin: &mut Plugin<PluginState>, _: Value) -> Result<Value, Pl
.client
.clone()
.ok_or(error!("client must be not null at this point"))?;
let fallback = plugin
.state
.fallback
.clone()
.ok_or(error!("fallback backend must be not null"))?;
let fallback = plugin.state.fallback.clone();
let mut result: Result<Value, PluginError> = Err(error!("the result is null"));
for client in [client, fallback] {
for client in [Some(client), fallback] {
if client.is_none() {
continue;
}
let client = client.unwrap();
result = client.sync_estimate_fees(plugin);
let Ok(ref result) = result else {
plugin.log(
Expand Down Expand Up @@ -291,15 +291,15 @@ fn get_raw_block_by_height(
.client
.clone()
.ok_or(error!("Client must be null at this point"))?;
let fallback = plugin
.state
.fallback
.clone()
.ok_or(error!("Fallback must be not null at this point"))?;
let fallback = plugin.state.fallback.clone();
plugin.log(LogLevel::Info, &format!("cln request {request}"));
let request: BlockByHeight = serde_json::from_value(request)?;
let mut result: Result<Value, PluginError> = Err(error!("result never init"));
for client in [client, fallback] {
for client in [Some(client), fallback] {
if client.is_none() {
continue;
}
let client = client.unwrap();
result = client.sync_block_by_height(plugin, request.height);
let Ok(ref result) = result else {
plugin.log(
Expand Down Expand Up @@ -328,15 +328,15 @@ fn getutxout(plugin: &mut Plugin<PluginState>, request: Value) -> Result<Value,
.client
.clone()
.ok_or(error!("Client must be not null at this point"))?;
let fallback = plugin
.state
.fallback
.clone()
.ok_or(error!("Fallback client must be not null at this point"))?;
let fallback = plugin.state.fallback.clone();
plugin.log(LogLevel::Info, &format!("cln request: {request}"));
let request: GetUTxo = serde_json::from_value(request)?;
let mut result: Result<Value, PluginError> = Err(error!("result never init"));
for client in [client, fallback] {
for client in [Some(client), fallback] {
if client.is_none() {
continue;
}
let client = client.unwrap();
result = client.sync_get_utxo(plugin, &request.txid, request.vout);
let Ok(ref result) = result else {
plugin.log(
Expand Down Expand Up @@ -369,16 +369,16 @@ fn send_rawtransaction(
.client
.clone()
.ok_or(error!("Client must be not null at this point"))?;
let fallback = plugin
.state
.fallback
.clone()
.ok_or(error!("Fallback client must be not null at this point"))?;
let fallback = plugin.state.fallback.clone();
plugin.log(LogLevel::Info, &format!("cln request: {request}"));
let request: SendRawTx = serde_json::from_value(request)?;

let mut result: Result<Value, PluginError> = Err(error!("result never init"));
for client in [client, fallback] {
for client in [Some(client), fallback] {
if client.is_none() {
continue;
}
let client = client.unwrap();
result = client.sync_send_raw_transaction(plugin, &request.tx, request.allowhighfees);
let Ok(ref result) = result else {
plugin.log(
Expand Down

0 comments on commit e31ac4d

Please sign in to comment.