-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
liquid: fetch asset metadata from esplora
Signed-off-by: lvaccaro <[email protected]>
- Loading branch information
Showing
8 changed files
with
651 additions
and
14 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
[package] | ||
name = "btctipserver-liquid" | ||
version = "0.1.1-dev" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
edk = { git = "https://github.com/lvaccaro/edk.git" } | ||
dirs-next = "2.0.0" | ||
structopt = "0.3" | ||
hex = "0.4" | ||
reqwest = { version = "0.11.22", features = ["blocking", "json"] } | ||
serde = "1.0.114" | ||
serde_json = "1.0" | ||
serde_derive = "1.0.114" | ||
|
||
[features] | ||
electrum = ["edk/electrum"] | ||
electrum = ["edk/electrum"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use edk::bdk::Error; | ||
use serde_derive::Deserialize; | ||
use std::collections::HashMap; | ||
|
||
pub fn gen_err() -> Error { | ||
Error::Generic(format!("oh no!")) | ||
} | ||
|
||
#[derive(Deserialize, Clone, Debug)] | ||
pub struct Asset { | ||
pub asset_id: String, | ||
pub precision: u8, | ||
pub name: String, | ||
pub ticker: String, | ||
} | ||
|
||
pub struct EsploraRepository { | ||
pub assets: HashMap<String, Asset>, | ||
} | ||
|
||
impl EsploraRepository { | ||
pub fn get(&mut self, asset_id: String) -> Result<Asset, Error> { | ||
match self.assets.get(&asset_id).as_ref() { | ||
Some(&asset) => Ok(asset.clone()), | ||
None => self.fetch(asset_id), | ||
} | ||
} | ||
|
||
pub fn fetch(&mut self, asset_id: String) -> Result<Asset, Error> { | ||
let url = format!("https://blockstream.info/liquid/api/asset/{}", asset_id); | ||
let res = reqwest::blocking::get(url).map_err(|_| gen_err())?; | ||
let asset: Asset = res.json().map_err(|_| gen_err())?; | ||
println!("Asset: {:#?}", asset); | ||
self.assets.insert(asset_id, asset.clone()); | ||
Ok(asset) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters