cli builds with things excluded
This commit is contained in:
parent
7d96313386
commit
28b7e67277
|
@ -1230,6 +1230,8 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"bech32 0.11.0",
|
||||
"cardano-connect",
|
||||
"cardano-connect-blockfrost",
|
||||
"cardano-tx-builder",
|
||||
"clap",
|
||||
"cryptoxide 0.5.1",
|
||||
|
|
|
@ -5,6 +5,7 @@ use super::plutus_data::PlutusData;
|
|||
|
||||
/// Datum
|
||||
/// As it may appear on a utxo
|
||||
#[derive(Debug)]
|
||||
pub enum Datum {
|
||||
None,
|
||||
Hash([u8; 32]), // Check this
|
||||
|
|
|
@ -6,6 +6,7 @@ use super::script::Script;
|
|||
use super::value::Value;
|
||||
|
||||
/// Output
|
||||
#[derive(Debug)]
|
||||
pub struct Output {
|
||||
pub address: Address,
|
||||
pub value: Value,
|
||||
|
|
|
@ -5,6 +5,7 @@ use pallas_primitives::PlutusScript;
|
|||
/// Script.
|
||||
/// There is no support for native scripts,
|
||||
/// and we only really care about V3.
|
||||
#[derive(Debug)]
|
||||
pub enum Script {
|
||||
V1(Vec<u8>),
|
||||
V2(Vec<u8>),
|
||||
|
|
|
@ -3,6 +3,7 @@ use super::output::Output;
|
|||
|
||||
/// Utxo
|
||||
/// Aka resolved input.
|
||||
#[derive(Debug)]
|
||||
pub struct Utxo {
|
||||
pub input: Input,
|
||||
pub output: Output,
|
||||
|
|
|
@ -27,4 +27,6 @@ serde = { version = "1.0.213", features = ["derive"] }
|
|||
serde_json = "1.0.138"
|
||||
tokio = { version = "1.47.1", features = ["full"] }
|
||||
cardano-tx-builder = { path = "../cardano-tx-builder" }
|
||||
cardano-connect = { path = "../cardano-connect" }
|
||||
cardano-connect-blockfrost = { path = "../cardano-connect-blockfrost" }
|
||||
minicbor = "2.1.1"
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
pub use cardano_connect::CardanoConnect;
|
||||
use cardano_connect_blockfrost::{Blockfrost, Config};
|
||||
|
||||
const PREFIX: &str = "cardano_";
|
||||
|
||||
pub fn from_env(env: &HashMap<String, String>) -> impl CardanoConnect {
|
||||
let cardano_env: HashMap<String, String> = env
|
||||
.iter()
|
||||
.filter_map(|(k, v)| k.strip_prefix(PREFIX).map(|k| (k.to_string(), v.clone())))
|
||||
.collect();
|
||||
match env.get("cardano") {
|
||||
None => panic!("Expect cardano connection details in env"),
|
||||
Some(s) if s == "blockfrost" => {
|
||||
let config = Config::from_env(&cardano_env);
|
||||
Blockfrost::new(config.project_id)
|
||||
}
|
||||
Some(_s) => panic!("Unkown cardano connection"),
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
use clap::Subcommand;
|
||||
|
||||
mod cardano;
|
||||
mod data;
|
||||
// mod data;
|
||||
// mod tx;
|
||||
mod wallet;
|
||||
|
||||
|
@ -10,8 +10,8 @@ pub enum Cmd {
|
|||
/// Txs
|
||||
// #[command(subcommand)]
|
||||
// Tx(tx::Cmd),
|
||||
#[command(subcommand)]
|
||||
Data(data::Cmd),
|
||||
// #[command(subcommand)]
|
||||
// Data(data::Cmd),
|
||||
#[command(subcommand)]
|
||||
Cardano(cardano::Cmd),
|
||||
#[command(subcommand)]
|
||||
|
@ -21,7 +21,7 @@ pub enum Cmd {
|
|||
pub fn handle(cmd: Cmd) {
|
||||
match cmd {
|
||||
// Cmd::Tx(inner) => tx::handle(inner),
|
||||
Cmd::Data(inner) => data::handle(inner),
|
||||
// Cmd::Data(inner) => data::handle(inner),
|
||||
Cmd::Cardano(inner) => cardano::handle(inner),
|
||||
Cmd::Wallet(inner) => wallet::handle(inner),
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use clap::Subcommand;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use crate::cardano::{cardano::Cardano, from_env};
|
||||
use cardano_connect::CardanoConnect;
|
||||
use crate::cardano_connect;
|
||||
use crate::env::get_env;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
|
@ -15,7 +16,7 @@ pub fn handle(cmd: Cmd) {
|
|||
match cmd {
|
||||
Cmd::Health => {
|
||||
let env = get_env();
|
||||
let conn = from_env(&env);
|
||||
let conn = cardano_connect::from_env(&env);
|
||||
let rt = Runtime::new().expect("Failed to create Tokio runtime");
|
||||
rt.block_on(async {
|
||||
println!("{:?}", conn.health().await);
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
use clap::Subcommand;
|
||||
use pallas_addresses::{
|
||||
Address, Network, ShelleyAddress, ShelleyDelegationPart, ShelleyPaymentPart,
|
||||
};
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
use crate::cardano;
|
||||
use crate::cardano::cardano::Cardano;
|
||||
use cardano_connect::CardanoConnect;
|
||||
use cardano_tx_builder::{Address, Network};
|
||||
use crate::cardano_connect;
|
||||
|
||||
use crate::env::get_env;
|
||||
use crate::wallet::{from_env, generate, Wallet};
|
||||
use crate::wallet::{from_env, generate};
|
||||
|
||||
#[derive(Subcommand)]
|
||||
/// Wallet Api
|
||||
|
@ -23,36 +22,28 @@ pub enum Cmd {
|
|||
pub fn handle(cmd: Cmd) {
|
||||
match cmd {
|
||||
Cmd::Gen => {
|
||||
println!("KONDUIT_WALLET_KEY={}", hex::encode(generate()));
|
||||
println!("KONDUIT_WALLET_SKEY={}", hex::encode(generate()));
|
||||
}
|
||||
Cmd::Show => {
|
||||
let env = get_env();
|
||||
let w = from_env(&env);
|
||||
let payment_cred = ShelleyPaymentPart::Key(w.key_hash());
|
||||
let stake_cred = ShelleyDelegationPart::Null;
|
||||
let addr_main =
|
||||
ShelleyAddress::new(Network::Mainnet, payment_cred.clone(), stake_cred.clone());
|
||||
let addr_test =
|
||||
ShelleyAddress::new(Network::Testnet, payment_cred.clone(), stake_cred.clone());
|
||||
println!("VKEY={}", hex::encode(w.vkey()));
|
||||
println!("PAYMENT_CRED={:?}", payment_cred.to_bech32());
|
||||
let cred = w.credential();
|
||||
let addr_main = Address::new(Network::Mainnet, cred.clone(), None);
|
||||
let addr_test = Address::new(Network::Testnet, cred.clone(), None);
|
||||
println!("VKEY={}", hex::encode(w.skey.vkey().0));
|
||||
// println!("PAYMENT_CRED={:?}", cred.into().to_bech32());
|
||||
println!("ADDRESS_MAINNET={:?}", addr_main.to_bech32());
|
||||
println!("ADDRESS_TESTNET={:?}", addr_test.to_bech32());
|
||||
}
|
||||
Cmd::Utxos => {
|
||||
let env = get_env();
|
||||
let w = from_env(&env);
|
||||
let payment_cred = w.payment_credential();
|
||||
let stake_cred = ShelleyDelegationPart::Null;
|
||||
let conn = cardano::from_env(&env);
|
||||
let w = from_env(&env);
|
||||
let cred = w.credential();
|
||||
let conn = cardano_connect::from_env(&env);
|
||||
let rt = Runtime::new().expect("Failed to create Tokio runtime");
|
||||
rt.block_on(async {
|
||||
let addr = ShelleyAddress::new(
|
||||
conn.network_id(),
|
||||
payment_cred.clone(),
|
||||
stake_cred.clone(),
|
||||
);
|
||||
println!("{:?}", conn.utxos_at(&w.payment_credential()).await);
|
||||
println!("{:?}", conn.utxos_at(&w.credential(), &None).await);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
|
|
@ -14,4 +14,3 @@ pub fn get_env() -> HashMap<String, String> {
|
|||
}
|
||||
env
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
pub mod cardano;
|
||||
pub mod cardano_connect;
|
||||
pub mod cmd;
|
||||
pub mod data;
|
||||
pub mod env;
|
||||
pub mod tx;
|
||||
pub mod utils;
|
||||
pub mod wallet;
|
||||
pub mod cardano_types;
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use crate::cardano;
|
||||
use crate::cardano::cardano::Cardano;
|
||||
use ::cardano_connect::CardanoConnect;
|
||||
|
||||
use crate::cardano_connect;
|
||||
use crate::wallet;
|
||||
|
||||
pub mod context;
|
||||
pub mod send;
|
||||
// pub mod send;
|
||||
|
||||
pub fn from_env(env: &HashMap<String, String>) -> context::TxContext<impl Cardano> {
|
||||
pub fn from_env(env: &HashMap<String, String>) -> context::TxContext<impl CardanoConnect> {
|
||||
context::TxContext {
|
||||
cardano: cardano::from_env(env),
|
||||
cardano: cardano_connect::from_env(env),
|
||||
wallet: wallet::from_env(env),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
use crate::{cardano::cardano::Cardano, wallet::Wallet};
|
||||
use anyhow::Result;
|
||||
use pallas_addresses::{ShelleyAddress, ShelleyDelegationPart};
|
||||
use uplc::tx::ResolvedInput;
|
||||
use cardano_connect::CardanoConnect;
|
||||
use cardano_tx_builder::{Address, BuildParameters, Utxo};
|
||||
|
||||
use super::plutus::BuildParams;
|
||||
use crate::wallet::Wallet;
|
||||
|
||||
pub struct TxContext<CardanoT> {
|
||||
pub cardano: CardanoT,
|
||||
pub wallet: Wallet,
|
||||
}
|
||||
|
||||
impl<T: Cardano> TxContext<T> {
|
||||
pub async fn build_parameters(&self) -> BuildParams {
|
||||
impl<T: CardanoConnect> TxContext<T> {
|
||||
pub async fn build_parameters(&self) -> BuildParameters {
|
||||
self.cardano.build_parameters().await
|
||||
}
|
||||
|
||||
pub async fn available_utxos(&self) -> Result<Vec<ResolvedInput>> {
|
||||
pub async fn available_utxos(&self) -> Result<Vec<Utxo>> {
|
||||
self.cardano
|
||||
.utxos_at(&self.wallet.payment_credential())
|
||||
.utxos_at(&self.wallet.credential(), &None)
|
||||
.await
|
||||
}
|
||||
|
||||
pub fn wallet_address(&self) -> ShelleyAddress {
|
||||
ShelleyAddress::new(
|
||||
self.cardano.network_id(),
|
||||
self.wallet.payment_credential(),
|
||||
ShelleyDelegationPart::Null,
|
||||
pub fn wallet_address(&self) -> Address {
|
||||
Address::new(
|
||||
self.cardano.network(),
|
||||
self.wallet.credential(),
|
||||
None,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use minicbor::encode;
|
||||
use pallas_addresses::{Address, ShelleyAddress, ShelleyDelegationPart};
|
||||
use pallas_primitives::{
|
||||
conway::{
|
||||
PostAlonzoTransactionOutput, TransactionBody, TransactionInput, TransactionOutput, Tx,
|
||||
Value, WitnessSet,
|
||||
},
|
||||
Coin, Nullable, Set,
|
||||
};
|
||||
|
||||
use crate::{cardano::cardano::Cardano, wallet::Wallet};
|
||||
use crate::{
|
||||
, wallet::Wallet
|
||||
};
|
||||
|
||||
use super::{
|
||||
context::TxContext,
|
||||
plutus::{
|
||||
build_transaction, default_transaction_body, default_witness_set, expect_post_alonzo,
|
||||
from_network, into_outputs, value_subtract_lovelace, BuildParams,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
pub fn v2a<T, const N: usize>(v: Vec<T>) -> Result<[T; N]> {
|
||||
<[T;N]>::try_from(v).map_err(|v: Vec<T>| anyhow!("Expected a Vec of length {}, but got {}", N, v.len()))
|
||||
<[T; N]>::try_from(v)
|
||||
.map_err(|v: Vec<T>| anyhow!("Expected a Vec of length {}, but got {}", N, v.len()))
|
||||
}
|
||||
|
||||
pub fn concat<T: Clone>(l: &[T], r: &[T]) -> Vec<T> {
|
||||
|
|
|
@ -2,16 +2,19 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::utils::v2a;
|
||||
|
||||
use cardano_tx_builder::Skey;
|
||||
use rand::{rngs::OsRng, TryRngCore};
|
||||
use cardano_tx_builder::{Credential, Skey};
|
||||
use rand::{TryRngCore, rngs::OsRng};
|
||||
|
||||
const PREFIX: &str = "wallet_";
|
||||
|
||||
pub struct Wallet {
|
||||
pub skey: Skey
|
||||
pub skey: Skey,
|
||||
}
|
||||
|
||||
impl Wallet {
|
||||
pub fn credential(&self) -> Credential {
|
||||
self.skey.vkey().credential()
|
||||
}
|
||||
// pub fn sign(&self, tx: &mut Tx) {
|
||||
// let mut msg = Vec::new();
|
||||
// encode(&tx.transaction_body, &mut msg).unwrap();
|
||||
|
@ -29,8 +32,8 @@ pub fn from_env(env: &HashMap<String, String>) -> Wallet {
|
|||
.iter()
|
||||
.filter_map(|(k, v)| k.strip_prefix(PREFIX).map(|k| (k.to_string(), v.clone())))
|
||||
.collect();
|
||||
let raw = wallet_env.get("key").expect("wallet key not found");
|
||||
let skey = parse_raw_skey(raw);
|
||||
let raw = wallet_env.get("skey").expect("wallet `skey` not found");
|
||||
let skey = Skey(parse_raw_skey(raw));
|
||||
Wallet { skey }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue