Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
SupernaviX committed Nov 15, 2024
1 parent 7214418 commit 70c810a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
5 changes: 1 addition & 4 deletions firefly-cardanoconnect/src/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::{path::PathBuf, sync::Arc};

use anyhow::{bail, Result};
use balius_runtime::{
ledgers::Ledger,
Response, Runtime, Store,
};
use balius_runtime::{ledgers::Ledger, Response, Runtime, Store};
use ledger::BlockfrostLedger;
use serde::Deserialize;
use serde_json::{json, Value};
Expand Down
30 changes: 15 additions & 15 deletions firefly-cardanoconnect/src/contracts/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct BlockfrostLedger {
impl BlockfrostLedger {
pub fn new(key: &str) -> Self {
Self {
client: BlockfrostAPI::new(key, BlockFrostSettings::new())
client: BlockfrostAPI::new(key, BlockFrostSettings::new()),
}
}
}
Expand Down Expand Up @@ -43,7 +43,9 @@ impl CustomLedger for BlockfrostLedger {
max_items: u32,
) -> Result<UtxoPage, LedgerError> {
if pattern.asset.is_some() {
return Err(LedgerError::Internal("querying by asset is not implemented".into()));
return Err(LedgerError::Internal(
"querying by asset is not implemented".into(),
));
}
let Some(address) = pattern.address else {
return Err(LedgerError::Internal("address is required".into()));
Expand All @@ -52,8 +54,10 @@ impl CustomLedger for BlockfrostLedger {
.and_then(|a| a.to_bech32())
.map_err(|err| LedgerError::Internal(err.to_string()))?;
let page = match start {
Some(s) => s.parse::<usize>().map_err(|e| LedgerError::Internal(e.to_string()))?,
None => 1
Some(s) => s
.parse::<usize>()
.map_err(|e| LedgerError::Internal(e.to_string()))?,
None => 1,
};

let pagination = Pagination::new(blockfrost::Order::Asc, page, max_items as usize);
Expand All @@ -66,8 +70,8 @@ impl CustomLedger for BlockfrostLedger {
let mut utxos = vec![];
let mut txs = TxDict::new(&mut self.client);
for utxo in query {
let raw_tx_hash = hex::decode(&utxo.tx_hash)
.map_err(|e| LedgerError::Upstream(e.to_string()))?;
let raw_tx_hash =
hex::decode(&utxo.tx_hash).map_err(|e| LedgerError::Upstream(e.to_string()))?;
let ref_ = TxoRef {
tx_hash: raw_tx_hash,
tx_index: utxo.tx_index as u32,
Expand All @@ -78,7 +82,7 @@ impl CustomLedger for BlockfrostLedger {
let Some(txo) = tx.output_at(utxo.tx_index as usize) else {
return Err(LedgerError::NotFound(ref_));
};

utxos.push(Utxo {
ref_,
body: txo.encode(),
Expand All @@ -91,10 +95,7 @@ impl CustomLedger for BlockfrostLedger {
None
};

Ok(UtxoPage {
utxos,
next_token,
})
Ok(UtxoPage { utxos, next_token })
}
}

Expand All @@ -119,16 +120,15 @@ impl<'a> TxDict<'a> {
.transactions_cbor(entry.key())
.await
.map_err(|e| LedgerError::Upstream(e.to_string()))?;
let bytes = hex::decode(&tx.cbor)
.map_err(|e| LedgerError::Internal(e.to_string()))?;
let bytes =
hex::decode(&tx.cbor).map_err(|e| LedgerError::Internal(e.to_string()))?;

Ok(entry.insert(bytes))
}
}
}

fn decode_tx(bytes: &[u8]) -> Result<MultiEraTx<'_>, LedgerError> {
MultiEraTx::decode(bytes)
.map_err(|e| LedgerError::Internal(e.to_string()))
MultiEraTx::decode(bytes).map_err(|e| LedgerError::Internal(e.to_string()))
}
}

0 comments on commit 70c810a

Please sign in to comment.