Skip to content

Commit

Permalink
Wrap up delegate cmd, and implement re-delegate one.
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Sep 18, 2024
1 parent 74555fb commit 36b2d97
Show file tree
Hide file tree
Showing 2 changed files with 388 additions and 43 deletions.
47 changes: 40 additions & 7 deletions cli/src/cardano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ pub struct Cardano {

const UNIT_LOVELACE: &str = "lovelace";

const MAINNET_PREFIX: &str = "mainnet";

const ENV_PROJECT_ID: &str = "BLOCKFROST_PROJECT_ID";

#[derive(Debug)]
pub struct ProtocolParameters {
pub collateral_percent: f64,
pub cost_model_v3: Vec<i64>,
pub drep_deposit: u64,
pub fee_constant: u64,
pub fee_coefficient: u64,
pub min_utxo_deposit_coefficient: u64,
pub price_mem: f64,
pub price_steps: f64,
}
Expand All @@ -33,7 +37,7 @@ impl Cardano {
let api = BlockfrostAPI::new(project_id.as_str(), Default::default());
Cardano {
api,
network: if project_id.starts_with("mainnet") {
network: if project_id.starts_with(MAINNET_PREFIX) {
Network::Mainnet
} else {
Network::Testnet
Expand All @@ -58,16 +62,45 @@ impl Cardano {
.expect("protocol parameters are missing collateral percent")
as f64)
/ 1e2,
// NOTE: Blockfrost returns cost models out of order. They must be ordered by their
// "ParamName" according to how Plutus defines it, but they are usually found ordered
// by ascending keys, unfortunately. Given that they are unlikely to change anytime
// soon, I am going to bundle them as-is.
cost_model_v3: vec![
100788, 420, 1, 1, 1000, 173, 0, 1, 1000, 59957, 4, 1, 11183, 32, 201305, 8356, 4,
16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 16000, 100, 100, 100,
16000, 100, 94375, 32, 132994, 32, 61462, 4, 72010, 178, 0, 1, 22151, 32, 91189,
769, 4, 2, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 1, 1000, 42921,
4, 2, 24548, 29498, 38, 1, 898148, 27279, 1, 51775, 558, 1, 39184, 1000, 60594, 1,
141895, 32, 83150, 32, 15299, 32, 76049, 1, 13169, 4, 22100, 10, 28999, 74, 1,
28999, 74, 1, 43285, 552, 1, 44749, 541, 1, 33852, 32, 68246, 32, 72362, 32, 7243,
32, 7391, 32, 11546, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1,
90434, 519, 0, 1, 74433, 32, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1,
1, 85848, 123203, 7305, -900, 1716, 549, 57, 85848, 0, 1, 955506, 213312, 0, 2,
270652, 22588, 4, 1457325, 64566, 4, 20467, 1, 4, 0, 141992, 32, 100788, 420, 1, 1,
81663, 32, 59498, 32, 20142, 32, 24588, 32, 20744, 32, 25933, 32, 24623, 32,
43053543, 10, 53384111, 14333, 10, 43574283, 26308, 10, 16000, 100, 16000, 100,
962335, 18, 2780678, 6, 442008, 1, 52538055, 3756, 18, 267929, 18, 76433006, 8868,
18, 52948122, 18, 1995836, 36, 3227919, 12, 901022, 1, 166917843, 4307, 36, 284546,
36, 158221314, 26549, 36, 74698472, 36, 333849714, 1, 254006273, 72, 2174038, 72,
2261318, 64571, 4, 207616, 8310, 4, 1293828, 28716, 63, 0, 1, 1006041, 43623, 251,
0, 1,
],
drep_deposit: 500_000_000, // NOTE: Missing from Blockfrost
fee_constant: params.min_fee_b as u64,
fee_coefficient: params.min_fee_a as u64,
min_utxo_deposit_coefficient: params
.coins_per_utxo_size
.expect("protocol parameters are missing min utxo deposit coefficient")
.parse()
.unwrap(),
price_mem: params
.price_mem
.expect("protocol parameters are missing price mem") as f64,
price_steps: params
.price_step
.expect("protocol parameters are missing price step")
as f64,
fee_constant: params.min_fee_b as u64,
fee_coefficient: params.min_fee_a as u64,
}
}

Expand All @@ -93,10 +126,10 @@ impl Cardano {
"non-null reference script about to be ignored"
);

// assert!(
// o.data_hash.is_none(),
// "non-null datum hash about to be ignored"
// );
assert!(
o.data_hash.is_none(),
"non-null datum hash about to be ignored"
);

PostAlonzoTransactionOutput {
address: from_bech32(&o.address).into(),
Expand Down
Loading

0 comments on commit 36b2d97

Please sign in to comment.