Skip to content

Commit 9ac80db

Browse files
author
Alex Woods
committed
Merge branch 'ajw/164-tx-blockfrost-api'
2 parents 3e5c9a1 + 48ceddc commit 9ac80db

File tree

25 files changed

+1680
-146
lines changed

25 files changed

+1680
-146
lines changed

Cargo.lock

Lines changed: 19 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[workspace]
44
members = [
55
# Global message and common definitions
6+
"cardano",
67
"codec",
78
"common",
89

@@ -52,6 +53,7 @@ config = "0.15.11"
5253
dashmap = "6.1.0"
5354
hex = "0.4"
5455
imbl = { version = "5.0.0", features = ["serde"] }
56+
minicbor = { version = "0.25.1", features = ["alloc", "std", "derive"] }
5557
opentelemetry = { version = "0.30.0", features = ["trace"] }
5658
opentelemetry-otlp = { version = "0.30.0", features = ["grpc-tonic", "trace", "tls"] }
5759
opentelemetry_sdk = { version = "0.30.0", features = ["rt-tokio"] }

cardano/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "acropolis_cardano"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
acropolis_common = { version = "0.3.0", path = "../common" }
8+
anyhow.workspace = true

cardano/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod transaction;

cardano/src/transaction.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use acropolis_common::{Lovelace, protocol_params::ProtocolParams};
2+
use anyhow::{Error, anyhow};
3+
4+
pub fn calculate_transaction_fee(
5+
recorded_fee: &Option<Lovelace>,
6+
inputs: &[Lovelace],
7+
outputs: &[Lovelace],
8+
) -> Lovelace {
9+
match recorded_fee {
10+
Some(fee) => *fee,
11+
None => inputs.iter().sum::<Lovelace>() - outputs.iter().sum::<Lovelace>(),
12+
}
13+
}
14+
15+
pub fn calculate_deposit(
16+
pool_update_count: u64,
17+
stake_cert_count: u64,
18+
params: &ProtocolParams,
19+
) -> Result<Lovelace, Error> {
20+
match &params.shelley {
21+
Some(shelley) => Ok(stake_cert_count * shelley.protocol_params.key_deposit
22+
+ pool_update_count * shelley.protocol_params.pool_deposit),
23+
None => {
24+
if pool_update_count > 0 || stake_cert_count > 0 {
25+
Err(anyhow!("No Shelley params, but deposits present"))
26+
} else {
27+
Ok(0)
28+
}
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)