This file contains hidden or 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
pub struct AssetSaver; | |
#[async_trait] | |
impl Persistable<Asset> for AssetSaver { | |
async fn persist_one(&self, asset: &Asset, pool: &Pool<Postgres>) { | |
let asset_result = &asset.result; | |
let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new( | |
"insert into asset (token_id, token_address, name, tier, solon, carbon, crypton, silicon, hydrogen, hyperion, landmark) ", | |
); |
This file contains hidden or 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
pub struct MintSaver; | |
#[async_trait] | |
impl Persistable<Mint> for MintSaver { | |
async fn persist_one(&self, mint: &Mint, pool: &Pool<Postgres>) { | |
let mint_result = &mint.result; | |
let mut query_builder: QueryBuilder<Postgres> = QueryBuilder::new( | |
"insert into mint (transaction_id, status, wallet, token_type, token_id, minted_on) ", | |
); |
This file contains hidden or 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
... | |
#[async_trait] | |
pub trait Persistable<T> { | |
async fn persist_one(&self, result: &T, pool: &Pool<Postgres>); | |
} |
This file contains hidden or 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
#[tokio::main] | |
pub async fn read() { | |
read_with_cursor_as::<Mint>(MINTS_URL).await; | |
read_with_cursor_as::<Asset>(ASSETS_URL).await; | |
} | |
async fn read_with_cursor_as<T: DeserializeOwned + PaginatedApi>( | |
url: &str, | |
) { | |
let pool = db_handler::open_connection().await; |
This file contains hidden or 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
#[derive(Deserialize, Debug)] | |
pub struct Asset { | |
pub result: Vec<TheResult>, | |
pub cursor: String, | |
} | |
impl PaginatedApi for Asset { | |
fn get_cursor(&self) -> String { | |
self.cursor.clone() | |
} |
This file contains hidden or 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
#[derive(Deserialize, Debug)] | |
pub struct Mint { | |
pub result: Vec<TheResult>, | |
pub cursor: String, | |
} | |
impl PaginatedApi for Mint { | |
fn get_cursor(&self) -> String { | |
self.cursor.clone() | |
} |
This file contains hidden or 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
const MINTS_URL: &str = "https://api.x.immutable.com/v1/mints?token_address=0x9e0d99b864e1ac12565125c5a82b59adea5a09cd&page_size=200"; | |
const ASSETS_URL: &str = "https://api.x.immutable.com/v1/assets?collection=0x9e0d99b864e1ac12565125c5a82b59adea5a09cd&page_size=200"; | |
#[tokio::main] | |
pub async fn read() { | |
read_with_cursor_as::<Mint>(MINTS_URL).await; | |
read_with_cursor_as::<Asset>(ASSETS_URL).await; | |
} | |
async fn read_with_cursor_as<T: DeserializeOwned>( |
This file contains hidden or 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
#[derive(Deserialize, Debug)] | |
pub struct Asset { | |
pub result: Vec<TheResult>, | |
pub cursor: String, | |
} | |
#[derive(Deserialize, Debug)] | |
pub struct TheResult { | |
pub token_id: String, | |
pub token_address: String, |
This file contains hidden or 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
pub fn as_parsed<T: FromStr>(key: &str) -> T | |
where | |
<T as FromStr>::Err: Debug, | |
{ | |
as_string(key) | |
.parse::<T>() | |
.expect(format!("{} should be a valid u16", key).as_str()) | |
} | |
pub fn as_string(key: &str) -> String { |