Skip to content

Commit

Permalink
Implement revoke.
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Sep 19, 2024
1 parent 0f61aca commit 7a0a46e
Show file tree
Hide file tree
Showing 8 changed files with 700 additions and 553 deletions.
6 changes: 3 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "cli"
version = "0.1.0"
name = "zhuli"
version = "1.0.0"
edition = "2021"

[dependencies]
bech32 = "0.11.0"
blockfrost = "1.0.1"
blockfrost-openapi = "0.0.3"
clap = "4.5.17"
clap = { version = "4.5.17", features = ["cargo"] }
color-print = "0.3.6"
hex = "0.4.3"
indoc = "2.0.5"
Expand Down
41 changes: 34 additions & 7 deletions cli/src/cardano.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use crate::pallas_extra::BuildParams;
use blockfrost::{BlockfrostAPI, Pagination};
use blockfrost_openapi::models::{
asset_history_inner::Action, tx_content_output_amount_inner::TxContentOutputAmountInner,
};
use pallas_addresses::Network;
use pallas_codec::{minicbor as cbor, utils::NonEmptyKeyValuePairs};
use pallas_primitives::conway::{
AssetName, PolicyId, PostAlonzoTransactionOutput, TransactionInput, Tx, Value,
AssetName, PolicyId, PostAlonzoTransactionOutput, TransactionInput, TransactionOutput, Tx,
Value,
};
use std::{collections::BTreeMap, env};
use uplc::tx::ResolvedInput;

pub struct Cardano {
api: BlockfrostAPI,
Expand Down Expand Up @@ -37,6 +40,17 @@ pub struct ProtocolParameters {
pub price_steps: f64,
}

impl From<&ProtocolParameters> for BuildParams {
fn from(params: &ProtocolParameters) -> BuildParams {
BuildParams {
fee_constant: params.fee_constant,
fee_coefficient: params.fee_coefficient,
price_mem: params.price_mem,
price_steps: params.price_steps,
}
}
}

impl Cardano {
pub fn new() -> Self {
let project_id =
Expand Down Expand Up @@ -175,7 +189,17 @@ impl Cardano {
}
}

pub async fn resolve(&self, input: &TransactionInput) -> Option<PostAlonzoTransactionOutput> {
pub async fn resolve_many(&self, inputs: &[&TransactionInput]) -> Vec<ResolvedInput> {
let mut resolved = vec![];
for i in inputs {
if let Some(r) = self.resolve(i).await {
resolved.push(r)
}
}
resolved
}

pub async fn resolve(&self, input: &TransactionInput) -> Option<ResolvedInput> {
let utxo = self
.api
.transactions_utxos(hex::encode(input.transaction_id).as_str())
Expand All @@ -202,11 +226,14 @@ impl Cardano {
"non-null datum hash about to be ignored"
);

PostAlonzoTransactionOutput {
address: from_bech32(&o.address).into(),
value: from_tx_content_output_amounts(&o.amount[..]),
datum_option: None,
script_ref: None,
ResolvedInput {
input: input.clone(),
output: TransactionOutput::PostAlonzo(PostAlonzoTransactionOutput {
address: from_bech32(&o.address).into(),
value: from_tx_content_output_amounts(&o.amount[..]),
datum_option: None,
script_ref: None,
}),
}
})
}
Expand Down
Loading

0 comments on commit 7a0a46e

Please sign in to comment.