Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
366 changes: 60 additions & 306 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,15 @@ keywords = ["cardano", "blockchain", "wallet"]
categories = ["command-line-utilities", "blockchain", "cardano", "wallet"]

[dependencies]
tx3-lang = "0.13.0"
tx3-cardano = "0.13.0"
tx3-sdk = "^0"

# tx3-lang = { git = "https://github.com/tx3-lang/tx3.git" }
# tx3-cardano = { git = "https://github.com/tx3-lang/tx3.git" }
# tx3-sdk = "^0"
# tx3-sdk = { git = "https://github.com/tx3-lang/rust-sdk.git" }

# tx3-lang = { path = "../../tx3-lang/tx3/crates/tx3-lang" }
# tx3-cardano = { path = "../../tx3-lang/tx3/crates/tx3-cardano" }
# tx3-sdk = { path = "../../tx3-lang/rust-sdk/sdk" }
tx3-sdk = { path = "../../tx3-lang/rust-sdk/sdk" }

# utxorpc = { git = "https://github.com/utxorpc/rust-sdk" }
utxorpc = "0.12.0"
# utxorpc = { path = "../../utxorpc/rust-sdk" }

bech32 = "0.9.1"
bech32 = "0.11.1"
bip39 = { version = "2.0.0", features = ["rand_core"] }
chrono = { version = "0.4.39", features = ["serde"] }
clap = { version = "4.5.29", features = ["derive", "env"] }
Expand Down
82 changes: 40 additions & 42 deletions src/tx/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ use std::{
collections::{BTreeMap, HashMap},
path::Path,
};
use tx3_lang::{ArgValue, ProtoTx, Protocol, UtxoRef};
use tx3_sdk::trp::{self, TxEnvelope};

use tx3_sdk::{
tii::Invocation,
trp::{self, TxEnvelope},
WellKnownType,
};
use tx3_sdk::{ArgValue, UtxoRef};

use crate::provider::types::Provider;

pub fn load_args(
inline_args: Option<&str>,
file_args: Option<&Path>,
params: &BTreeMap<String, tx3_lang::ir::Type>,
params: &BTreeMap<String, WellKnownType>,
) -> Result<HashMap<String, ArgValue>> {
let json_string = match (inline_args, file_args) {
(Some(inline_args), None) => inline_args.to_string(),
Expand All @@ -33,38 +38,40 @@ pub fn load_args(

for (key, ty) in params {
if let Some(value) = value.remove(key) {
let arg_value = tx3_sdk::trp::args::from_json(value, ty)?;
let arg_value = tx3_sdk::interop::json::from_json(value, ty)?;
args.insert(key.clone(), arg_value);
}
}

Ok(args)
}

pub fn load_prototx(tx3_file: &Path, tx3_template: Option<String>) -> Result<ProtoTx> {
let protocol = Protocol::from_file(tx3_file)
.load()
.context("parsing tx3 file")?;
pub fn prepare_invocation(tii_file: &Path, tx: Option<String>) -> Result<Invocation> {
let protocol = tx3_sdk::tii::Protocol::from_file(tii_file).context("parsing tii file")?;

let txs: Vec<String> = protocol.txs().map(|x| x.name.value.to_string()).collect();

let template = match tx3_template {
let template = match tx {
Some(template) => template,
None => {
let template = if txs.len() == 1 {
txs.first().unwrap().clone()
let template = if protocol.txs().len() == 1 {
protocol.txs().keys().next().unwrap().clone()
} else {
inquire::Select::new("What transaction do you want to build?", txs).prompt()?
let keys = protocol
.txs()
.keys()
.map(|x| x.to_string())
.collect::<Vec<String>>();

inquire::Select::new("What transaction do you want to build?", keys).prompt()?
};
template
}
};

Ok(protocol.new_tx(&template)?)
Ok(protocol.invoke(&template, None)?)
}

pub fn inquire_args(
params: &BTreeMap<String, tx3_lang::ir::Type>,
params: &BTreeMap<String, WellKnownType>,
ctx: &crate::Context,
provider: &Provider,
) -> Result<HashMap<String, ArgValue>> {
Expand All @@ -74,7 +81,7 @@ pub fn inquire_args(
let text_key = format!("{key}:");

match value {
tx3_lang::ir::Type::Address => {
WellKnownType::Address => {
let custom_address = String::from("custom address");
let mut options = ctx
.store
Expand Down Expand Up @@ -104,7 +111,7 @@ pub fn inquire_args(

argvalues.insert(key.clone(), trp::ArgValue::Address(address.to_vec()));
}
tx3_lang::ir::Type::Int => {
WellKnownType::Int => {
let value = inquire::Text::new(&text_key)
.with_help_message("Enter an integer value")
.prompt()?
Expand All @@ -113,7 +120,7 @@ pub fn inquire_args(

argvalues.insert(key.clone(), trp::ArgValue::Int(value.into()));
}
tx3_lang::ir::Type::UtxoRef => {
WellKnownType::UtxoRef => {
let value = inquire::Text::new(&text_key)
.with_help_message("Enter the utxo reference as hash#idx")
.prompt()
Expand All @@ -130,12 +137,12 @@ pub fn inquire_args(
let utxo_ref = UtxoRef::new(hash.as_slice(), idx);
argvalues.insert(key.clone(), trp::ArgValue::UtxoRef(utxo_ref));
}
tx3_lang::ir::Type::Bool => {
WellKnownType::Bool => {
let value = inquire::Confirm::new(&text_key).prompt()?;

argvalues.insert(key.clone(), trp::ArgValue::Bool(value));
}
tx3_lang::ir::Type::Bytes => {
WellKnownType::Bytes => {
let value = inquire::Text::new(&text_key)
.with_help_message("Enter the bytes as hex string")
.prompt()?;
Expand All @@ -145,37 +152,37 @@ pub fn inquire_args(
argvalues.insert(key.clone(), trp::ArgValue::Bytes(value));
}

tx3_lang::ir::Type::Undefined => {
WellKnownType::Undefined => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type Undefined, not supported yet"
));
}
tx3_lang::ir::Type::Unit => {
WellKnownType::Unit => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type Unit, not supported yet",
));
}
tx3_lang::ir::Type::Utxo => {
WellKnownType::Utxo => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type Utxo, not supported yet"
));
}
tx3_lang::ir::Type::AnyAsset => {
WellKnownType::AnyAsset => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type AnyAsset, not supported yet"
));
}
tx3_lang::ir::Type::List => {
WellKnownType::List => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type List, not supported yet",
));
}
tx3_lang::ir::Type::Custom(x) => {
WellKnownType::Custom(x) => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is a custom type {x}, not supported yet"
));
}
tx3_lang::ir::Type::Map => {
WellKnownType::Map => {
return Err(anyhow::anyhow!(
"tx3 arg {key} is of type Map, not supported yet",
));
Expand All @@ -187,12 +194,14 @@ pub fn inquire_args(
}

pub fn define_args(
params: &BTreeMap<String, tx3_lang::ir::Type>,
invocation: &mut Invocation,
inline_args: Option<&str>,
file_args: Option<&Path>,
ctx: &crate::Context,
provider: &Provider,
) -> Result<HashMap<String, ArgValue>> {
let params = invocation.define_params()?;

let mut remaining_params = params.clone();

let mut loaded_args = super::common::load_args(inline_args, file_args, &remaining_params)?;
Expand All @@ -211,19 +220,8 @@ pub fn define_args(
Ok(loaded_args)
}

pub async fn resolve_tx(
prototx: &ProtoTx,
args: HashMap<String, ArgValue>,
provider: &Provider,
) -> Result<TxEnvelope> {
let request = tx3_sdk::trp::ProtoTxRequest {
tir: tx3_sdk::trp::TirInfo {
version: tx3_lang::ir::IR_VERSION.to_string(),
encoding: "hex".to_string(),
bytecode: hex::encode(prototx.ir_bytes()),
},
args,
};
pub async fn resolve_tx(invocation: Invocation, provider: &Provider) -> Result<TxEnvelope> {
let request = invocation.into_trp_request()?;

provider.trp_resolve(request).await
}
Expand Down
33 changes: 0 additions & 33 deletions src/tx/construct/add_input.rs

This file was deleted.

33 changes: 0 additions & 33 deletions src/tx/construct/add_output.rs

This file was deleted.

31 changes: 0 additions & 31 deletions src/tx/construct/build.rs

This file was deleted.

Loading
Loading