Skip to content

Commit c23a0d0

Browse files
fix: Add a default Asteria and don't filter Tokens (#142)
* fix: Add a default Asteria and don't filter Tokens * Remove dbg statementes
1 parent 1cafa77 commit c23a0d0

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

backend/src/main.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,7 @@ impl TryFrom<(TokenInput, AddressUtxoContentInner)> for Token {
305305
let position_y = datum_int(&datum_json, 1)?;
306306
let spacetime_policy = datum_bytes(&datum_json, 2)?;
307307

308-
let unit = format!("{}{}", token.policy_id, token.asset_name);
309-
let raw_amount = asset_amount_for_unit(&utxo.amount, &unit)?;
308+
let raw_amount = asset_amount_for_unit(&utxo.amount, &token.policy_id)?;
310309
let scaled_amount = scale_token_amount(raw_amount, token.decimals)?;
311310

312311
Ok(Token {
@@ -353,7 +352,7 @@ pub struct Data {
353352
pub asteria: Asteria,
354353
}
355354

356-
#[derive(Clone, SimpleObject)]
355+
#[derive(Clone, SimpleObject, Debug)]
357356
pub struct Asset {
358357
pub policy_id: String,
359358
pub name: String,
@@ -425,7 +424,7 @@ pub struct AsteriaState {
425424
reward: i64,
426425
}
427426

428-
#[derive(Clone, SimpleObject)]
427+
#[derive(Clone, SimpleObject, Debug)]
429428
pub struct Token {
430429
id: ID,
431430
amount: i32,
@@ -439,13 +438,13 @@ pub struct Token {
439438
assets: Vec<Asset>,
440439
}
441440

442-
#[derive(Clone, SimpleObject)]
441+
#[derive(Clone, SimpleObject, Debug)]
443442
pub struct Position {
444443
x: i32,
445444
y: i32,
446445
}
447446

448-
#[derive(Clone, SimpleObject)]
447+
#[derive(Clone, SimpleObject, Debug)]
449448
pub struct PolicyId {
450449
id: ID,
451450
}
@@ -551,6 +550,7 @@ impl QueryRoot {
551550
.map_err(|e| Error::new(e.message))?;
552551

553552
let mut map_objects = Vec::new();
553+
let mut has_asteria = false;
554554

555555
for utxo in fetch_utxos_by_policy(api, &spacetime_address, &spacetime_policy_id).await? {
556556
let ship =
@@ -595,6 +595,18 @@ impl QueryRoot {
595595
}
596596

597597
map_objects.push(PositionalInterface::Asteria(asteria));
598+
has_asteria = true;
599+
}
600+
601+
if !has_asteria {
602+
map_objects.push(PositionalInterface::Asteria(Asteria {
603+
id: ID::from("fallback-asteria"),
604+
position: Position { x: 0, y: 0 },
605+
total_rewards: 0,
606+
class: "Asteria".to_string(),
607+
datum: "{}".to_string(),
608+
assets: vec![],
609+
}));
598610
}
599611

600612
if let Some(tokens) = tokens {
@@ -806,15 +818,12 @@ async fn rocket() -> _ {
806818
std::collections::HashMap::from([("dmtr-api-key".to_string(), dmtr_api_key)]);
807819
}
808820

809-
let project_id = std::env::var("BLOCKFROST_PROJECT_ID")
810-
.unwrap_or("asteria-backend".to_string());
821+
let project_id =
822+
std::env::var("BLOCKFROST_PROJECT_ID").unwrap_or("asteria-backend".to_string());
811823

812-
let client = BlockfrostAPI::new_with_client(
813-
&project_id,
814-
settings,
815-
Client::builder().use_rustls_tls(),
816-
)
817-
.expect("failed to create Blockfrost client");
824+
let client =
825+
BlockfrostAPI::new_with_client(&project_id, settings, Client::builder().use_rustls_tls())
826+
.expect("failed to create Blockfrost client");
818827

819828
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
820829
.register_output_type::<PositionalInterface>()

0 commit comments

Comments
 (0)