Skip to content
Open
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
98 changes: 64 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,34 @@ autoexamples = false
uninlined_format_args = "allow"

[dependencies]
ledger = { git = "ssh://git@github.com/DLC-link/canton-lib", tag = "v0.2.0" }
keycloak = { git = "ssh://git@github.com/DLC-link/canton-lib", tag = "v0.2.0" }
registry = { git = "ssh://git@github.com/DLC-link/canton-lib", tag = "v0.2.0" }
common = { git = "ssh://git@github.com/DLC-link/canton-lib", tag = "v0.2.0" }
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }
# Canton-lib dependencies (WASM-compatible after refactoring)
ledger = { git = "ssh://git@github.com/DLC-link/canton-lib", branch = "refact/wasm" }
keycloak = { git = "ssh://git@github.com/DLC-link/canton-lib", branch = "refact/wasm" }
registry = { git = "ssh://git@github.com/DLC-link/canton-lib", branch = "refact/wasm" }
common = { git = "ssh://git@github.com/DLC-link/canton-lib", branch = "refact/wasm" }

# Core dependencies (WASM-compatible)
serde_json = "1"
chrono = "0.4.42"
uuid = { version = "1.18", features = ["v4"] }
csv = "1.3"
serde = { version = "1.0", features = ["derive"] }
futures = "0.3"
dotenvy = "0.15"
base64 = "0.22"
log = "0.4"
canton-api-client = "3.3.0-0.1.0"
reqwest = { version = "0.12.24", features = ["json"] }
uuid = { version = "1.18", features = ["v4", "js"] }
csv = "1.3"

# Platform-specific dependencies
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1.48.0", features = ["macros", "rt"] }

[dev-dependencies]
env_logger = "0.11"
dotenvy = "0.15"

[[example]]
name = "accept_transfers"
Expand Down
5 changes: 4 additions & 1 deletion examples/batch_distribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ async fn main() -> Result<(), String> {
));
}

let csv_content = std::fs::read_to_string(&csv_path)
.map_err(|e| format!("Failed to read CSV file '{}': {}", csv_path, e))?;

println!("📦 Batch Distribution");
println!("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
println!("CSV File: {}", csv_path);
Expand All @@ -35,7 +38,7 @@ async fn main() -> Result<(), String> {
env::var("DECENTRALIZED_PARTY_ID").expect("DECENTRALIZED_PARTY_ID must be set");

let batch_params = cbtc::batch::Params {
csv_path: csv_path.clone(),
csv_content,
sender: sender_party.clone(),
instrument_id: common::transfer::InstrumentId {
admin: decentralized_party.clone(),
Expand Down
22 changes: 6 additions & 16 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct CsvRecord {
}

pub struct Params {
pub csv_path: String,
pub csv_content: String,
pub sender: String,
pub instrument_id: common::transfer::InstrumentId,
pub ledger_host: String,
Expand All @@ -34,10 +34,9 @@ pub struct Params {
/// Each transfer uses the change from the previous transfer, eliminating the
/// need for pre-splitting UTXOs.
pub async fn submit_from_csv(params: Params) -> Result<(), String> {
// Read CSV file
log::debug!("Reading CSV from: {}", params.csv_path);
let mut reader = csv::Reader::from_path(&params.csv_path)
.map_err(|e| format!("Failed to read CSV file: {}", e))?;
// Parse CSV content
log::debug!("Parsing CSV content ({} bytes)", params.csv_content.len());
let mut reader = csv::Reader::from_reader(params.csv_content.as_bytes());

let mut recipients = Vec::new();
let mut total_amount = 0.0;
Expand Down Expand Up @@ -112,7 +111,7 @@ mod tests {
use super::*;
use keycloak::login::password_url;
use std::env;
use std::io::Write;


#[tokio::test]
async fn test_batch_from_csv() {
Expand All @@ -121,7 +120,6 @@ mod tests {
let receiver =
env::var("LIB_TEST_RECEIVER_PARTY_ID").expect("LIB_TEST_RECEIVER_PARTY_ID must be set");

// Create a temporary CSV file
let csv_content = format!(
"receiver,amount\n\
{receiver},0.0001\n\
Expand All @@ -130,14 +128,9 @@ mod tests {
{receiver},0.001\n"
);

let temp_path = "/tmp/test_batch_distribution.csv";
let mut file = std::fs::File::create(temp_path).expect("Failed to create temp CSV file");
file.write_all(csv_content.as_bytes())
.expect("Failed to write CSV content");

// Run batch distribution (authentication handled internally)
let batch_params = Params {
csv_path: temp_path.to_string(),
csv_content,
sender: env::var("PARTY_ID").expect("PARTY_ID must be set"),
instrument_id: common::transfer::InstrumentId {
admin: common::consts::DEVNET_DECENTRALIZED_PARTY_ID.to_string(),
Expand All @@ -161,8 +154,5 @@ mod tests {
};

submit_from_csv(batch_params).await.unwrap();

// Clean up
std::fs::remove_file(temp_path).ok();
}
}
Loading