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