From 0d8480b49d8cedda860c1211c195886afef9a9b1 Mon Sep 17 00:00:00 2001 From: William Wills Date: Mon, 20 Oct 2025 15:55:57 -0400 Subject: [PATCH 1/5] feat: dig collateralization (or vaporization?) --- .gitignore | 1 + Cargo.lock | 244 ++++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 2 +- src/wallet.rs | 175 ++++++------------------------------ 4 files changed, 245 insertions(+), 177 deletions(-) diff --git a/.gitignore b/.gitignore index b3621c0..1661cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /target/ **/*.rs.bk *.pdb +config.toml # IDE .vscode/ diff --git a/Cargo.lock b/Cargo.lock index 29c7110..3bdbf88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -63,9 +63,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.99" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "arraydeque" @@ -440,7 +440,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46f44eebc9bb4a596f0c770822facc117416a02db9c78d10b451956597011a3e" dependencies = [ "chia-protocol", - "chia-sdk-types", + "chia-sdk-types 0.29.0", "chia-ssl", "chia-traits 0.26.0", "futures-util", @@ -452,6 +452,24 @@ dependencies = [ "tungstenite", ] +[[package]] +name = "chia-sdk-client" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a9ab7609f5c98ff34fc5ba33ad50bfdecca771165640eb88e8054ccef18916" +dependencies = [ + "chia-protocol", + "chia-sdk-types 0.30.0", + "chia-ssl", + "chia-traits 0.26.0", + "futures-util", + "thiserror 2.0.16", + "tokio", + "tokio-tungstenite", + "tracing", + "tungstenite", +] + [[package]] name = "chia-sdk-coinset" version = "0.29.0" @@ -466,6 +484,20 @@ dependencies = [ "serde_json", ] +[[package]] +name = "chia-sdk-coinset" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb55e723e4b847fdbb9e729fef1a0f21c624b618bda8a17c9c205ff9db64a1e1" +dependencies = [ + "chia-protocol", + "hex", + "hex-literal", + "reqwest", + "serde", + "serde_json", +] + [[package]] name = "chia-sdk-derive" version = "0.29.0" @@ -477,6 +509,17 @@ dependencies = [ "syn", ] +[[package]] +name = "chia-sdk-derive" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add9e60902df26dfe987d87f1b19ab7e359c6269fa4f222a9d79c02a9dba969d" +dependencies = [ + "convert_case", + "quote", + "syn", +] + [[package]] name = "chia-sdk-driver" version = "0.29.0" @@ -490,8 +533,40 @@ dependencies = [ "chia-protocol", "chia-puzzle-types", "chia-puzzles", - "chia-sdk-signer", - "chia-sdk-types", + "chia-sdk-signer 0.29.0", + "chia-sdk-types 0.29.0", + "chia-secp", + "chia-sha2 0.26.0", + "chia-traits 0.26.0", + "chia_streamable_macro 0.26.0", + "clvm-traits", + "clvm-utils", + "clvmr", + "getrandom 0.2.16", + "hex", + "hex-literal", + "indexmap", + "num-bigint", + "rand", + "rand_chacha", + "thiserror 2.0.16", +] + +[[package]] +name = "chia-sdk-driver" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "260c97751f8986e7f82091e3bee504044efb79857f26bfcd2b5d37cba674f79e" +dependencies = [ + "bigdecimal", + "bip39", + "chia-bls 0.26.0", + "chia-consensus", + "chia-protocol", + "chia-puzzle-types", + "chia-puzzles", + "chia-sdk-signer 0.30.0", + "chia-sdk-types 0.30.0", "chia-secp", "chia-sha2 0.26.0", "chia-traits 0.26.0", @@ -518,7 +593,25 @@ dependencies = [ "chia-bls 0.26.0", "chia-consensus", "chia-protocol", - "chia-sdk-types", + "chia-sdk-types 0.29.0", + "chia-secp", + "chia-sha2 0.26.0", + "clvm-traits", + "clvmr", + "k256", + "thiserror 2.0.16", +] + +[[package]] +name = "chia-sdk-signer" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71037389cc3bdebc47c9c6cfebc898244393e4e7246b486d64922a9c23bbac6" +dependencies = [ + "chia-bls 0.26.0", + "chia-consensus", + "chia-protocol", + "chia-sdk-types 0.30.0", "chia-secp", "chia-sha2 0.26.0", "clvm-traits", @@ -539,9 +632,9 @@ dependencies = [ "chia-consensus", "chia-protocol", "chia-puzzle-types", - "chia-sdk-client", - "chia-sdk-signer", - "chia-sdk-types", + "chia-sdk-client 0.29.0", + "chia-sdk-signer 0.29.0", + "chia-sdk-types 0.29.0", "chia-secp", "chia-sha2 0.26.0", "chia-traits 0.26.0", @@ -565,6 +658,36 @@ dependencies = [ "tracing", ] +[[package]] +name = "chia-sdk-test" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "365b95611176b670cd61455ce6578cccf740a66b7d27cd3b31395c12f4073bc2" +dependencies = [ + "anyhow", + "bip39", + "chia-bls 0.26.0", + "chia-consensus", + "chia-protocol", + "chia-puzzle-types", + "chia-sdk-signer 0.30.0", + "chia-sdk-types 0.30.0", + "chia-secp", + "chia-sha2 0.26.0", + "chia-traits 0.26.0", + "clvm-traits", + "clvm-utils", + "clvmr", + "hex", + "indexmap", + "prettytable-rs", + "rand", + "rand_chacha", + "serde", + "serde_json", + "thiserror 2.0.16", +] + [[package]] name = "chia-sdk-types" version = "0.29.0" @@ -576,7 +699,29 @@ dependencies = [ "chia-protocol", "chia-puzzle-types", "chia-puzzles", - "chia-sdk-derive", + "chia-sdk-derive 0.29.0", + "chia-secp", + "chia-sha2 0.26.0", + "clvm-traits", + "clvm-utils", + "clvm_tools_rs", + "clvmr", + "hex-literal", + "thiserror 2.0.16", +] + +[[package]] +name = "chia-sdk-types" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "298b92f005cd884861678808813cb49dca3545231b6b442d691e01535ed86825" +dependencies = [ + "chia-bls 0.26.0", + "chia-consensus", + "chia-protocol", + "chia-puzzle-types", + "chia-puzzles", + "chia-sdk-derive 0.30.0", "chia-secp", "chia-sha2 0.26.0", "clvm-traits", @@ -601,6 +746,20 @@ dependencies = [ "thiserror 2.0.16", ] +[[package]] +name = "chia-sdk-utils" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "738bc2a53dcece78184aca4de617df666e984af0c86560131213039889d927fc" +dependencies = [ + "bech32", + "chia-protocol", + "indexmap", + "rand", + "rand_chacha", + "thiserror 2.0.16", +] + [[package]] name = "chia-secp" version = "0.26.0" @@ -684,13 +843,33 @@ checksum = "0ae886c1c212efcbd43564e8039920d3bd94a8db35e8fbd649e6b01ebe8c167e" dependencies = [ "chia-bls 0.26.0", "chia-protocol", - "chia-sdk-client", - "chia-sdk-coinset", - "chia-sdk-driver", - "chia-sdk-signer", - "chia-sdk-test", - "chia-sdk-types", - "chia-sdk-utils", + "chia-sdk-client 0.29.0", + "chia-sdk-coinset 0.29.0", + "chia-sdk-driver 0.29.0", + "chia-sdk-signer 0.29.0", + "chia-sdk-test 0.29.0", + "chia-sdk-types 0.29.0", + "chia-sdk-utils 0.29.0", + "clvm-traits", + "clvm-utils", + "clvmr", +] + +[[package]] +name = "chia-wallet-sdk" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94547c50b141ad9ae84f9bcc26c0bf467b7570f0354c906fb203eeea69886a4c" +dependencies = [ + "chia-bls 0.26.0", + "chia-protocol", + "chia-sdk-client 0.30.0", + "chia-sdk-coinset 0.30.0", + "chia-sdk-driver 0.30.0", + "chia-sdk-signer 0.30.0", + "chia-sdk-test 0.30.0", + "chia-sdk-types 0.30.0", + "chia-sdk-utils 0.30.0", "clvm-traits", "clvm-utils", "clvmr", @@ -927,7 +1106,7 @@ checksum = "d0e7ee25be16a809900191178eb535f16d4543a9a7c504f94516ae10d20909f0" dependencies = [ "chia", "chia-puzzles", - "chia-wallet-sdk", + "chia-wallet-sdk 0.29.0", "clvm-traits", "clvmr", "futures-util", @@ -983,7 +1162,7 @@ dependencies = [ "base64 0.21.7", "bip39", "chia", - "chia-wallet-sdk", + "chia-wallet-sdk 0.30.0", "datalayer-driver", "dirs", "hex", @@ -1605,9 +1784,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.11.0" +version = "2.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +checksum = "4b0f83760fb341a774ed326568e19f5a863af4a952def8c39f9ab92fd95b88e5" dependencies = [ "equivalent", "hashbrown", @@ -2520,18 +2699,28 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", @@ -2540,14 +2729,15 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.143" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" dependencies = [ "itoa", "memchr", "ryu", "serde", + "serde_core", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 733f2a8..5cab5e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.70" [dependencies] datalayer-driver = "1.0.1" -chia-wallet-sdk = "0.29.0" +chia-wallet-sdk = "0.30.0" chia = "0.26.0" bip39 = "2.0" thiserror = "1.0" diff --git a/src/wallet.rs b/src/wallet.rs index 2d35b51..ac41bfc 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -19,12 +19,11 @@ use datalayer_driver::{ use hex_literal::hex; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::env; use std::fs; use std::path::PathBuf; -pub static DIG_MIN_HEIGHT: u32 = 5777842; pub static DIG_COIN_ASSET_ID: Lazy = Lazy::new(|| { Bytes32::new(hex!( "a406d3a9de984d03c9591c10d917593b434d5263cabe2b42f6b367df16832f81" @@ -48,6 +47,7 @@ struct KeyringData { wallets: HashMap, } +#[derive(Debug, Clone)] pub struct Wallet { mnemonic: Option, wallet_name: String, @@ -276,13 +276,12 @@ impl Wallet { } /// Get all unspent DIG Token coins - // todo: this should be moved to the driver - pub async fn get_all_unspent_dig_coins( + pub async fn get_all_unspent_dig_cats( &self, peer: &Peer, omit_coins: Vec, verbose: bool, - ) -> Result, WalletError> { + ) -> Result, WalletError> { let p2 = self.get_owner_puzzle_hash().await?; let dig_cat_ph = CatArgs::curry_tree_hash(*DIG_COIN_ASSET_ID, TreeHash::from(p2)); let dig_cat_ph_bytes = Bytes32::from(dig_cat_ph.to_bytes()); @@ -294,19 +293,18 @@ impl Wallet { None, // previous_height - start from genesis datalayer_driver::constants::get_mainnet_genesis_challenge(), // Use mainnet for now ) - .await - .map_err(|e| WalletError::NetworkError(format!("Failed to get unspent coins: {}", e)))?; + .await + .map_err(|e| WalletError::NetworkError(format!("Failed to get unspent coins: {}", e)))?; // Convert coin states to coins and filter out omitted coins let omit_coin_ids: Vec = omit_coins.iter().map(get_coin_id).collect(); - let available_coin_states: Vec = unspent_coin_states .coin_states .into_iter() .filter(|coin_state| !omit_coin_ids.contains(&get_coin_id(&coin_state.coin))) .collect(); - let mut proved_dig_token_coins: Vec = vec![]; + let mut proved_dig_cats: Vec = vec![]; let mut allocator = Allocator::new(); @@ -329,136 +327,12 @@ impl Wallet { } }; - // 1) Request parent coin state - let parent_state_result = peer - .request_coin_state( - vec![coin.parent_coin_info], - None, - MAINNET_CONSTANTS.genesis_challenge, - false, - ) - .await; - - let parent_state_response = match parent_state_result { - Ok(response) => response, - Err(error) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::NetworkError(format!( - "Failed to get coin state: {}", - error - )) - ); - } - continue; - } - }; - - let parent_state = match parent_state_response { - Ok(state) => state, - Err(_) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::CoinSetError("Coin state rejected".to_string()) - ); - } - continue; - } - }; - - // 2) Request parent puzzle and solution - let parent_puzzle_and_solution_result = peer - .request_puzzle_and_solution(parent_state.coin_ids[0], coin_created_height) - .await; - - let parent_puzzle_and_solution_response = match parent_puzzle_and_solution_result { - Ok(response) => response, - Err(error) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::NetworkError(format!( - "Failed to get puzzle and solution: {}", - error - )) - ); - } - continue; - } - }; - - let parent_puzzle_and_solution = match parent_puzzle_and_solution_response { - Ok(v) => v, - Err(_) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::CoinSetError( - "Parent puzzle solution rejected".to_string() - ) - ); - } - continue; - } - }; - - // 3) Convert puzzle to CLVM - let parent_puzzle_ptr = match parent_puzzle_and_solution.puzzle.to_clvm(&mut allocator) - { - Ok(ptr) => ptr, - Err(error) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::CoinSetError(format!( - "Failed to parse puzzle and solution: {}", - error - )) - ); - } - continue; - } - }; - - let parent_puzzle = Puzzle::parse(&allocator, parent_puzzle_ptr); - - // 4) Convert solution to CLVM - let parent_solution = match parent_puzzle_and_solution.solution.to_clvm(&mut allocator) - { - Ok(solution) => solution, - Err(error) => { - if verbose { - eprintln!( - "ERROR: coin_id {} | {}", - coin_id, - WalletError::CoinSetError(format!( - "Failed to parse puzzle and solution: {}", - error - )) - ); - } - continue; - } - }; - - // 5) Parse CAT to prove lineage - let cat_parse_result = Cat::parse_children( - &mut allocator, - parent_state.coin_states[0].coin, - parent_puzzle, - parent_solution, - ); + //Parse CAT to prove lineage + let cat_parse_result = datalayer_driver::async_api::prove_dig_cat_coin(peer, coin, coin_created_height).await; match cat_parse_result { - Ok(_) => { + Ok(parsed_cat) => { // lineage proved. append coin in question - proved_dig_token_coins.push(*coin); + proved_dig_cats.push(parsed_cat); } Err(error) => { if verbose { @@ -476,38 +350,41 @@ impl Wallet { } } - Ok(proved_dig_token_coins) + Ok(proved_dig_cats) } - pub async fn select_unspent_dig_token_coins( + pub async fn select_unspent_dig_cats( &self, peer: &Peer, coin_amount: u64, - fee: u64, omit_coins: Vec, verbose: bool, - ) -> Result, WalletError> { - let total_needed = coin_amount + fee; - let available_dig_coins = self - .get_all_unspent_dig_coins(peer, omit_coins, verbose) + ) -> Result, WalletError> { + let available_dig_cats = self + .get_all_unspent_dig_cats(peer, omit_coins, verbose) .await?; + + let dig_coins = available_dig_cats.iter().map(|cat| cat.coin).collect::>(); // Use the DataLayer-Driver's select_coins function - let selected_coins = datalayer_driver::select_coins(&available_dig_coins, total_needed) + let selected_coins = datalayer_driver::select_coins(&dig_coins, coin_amount) .map_err(|e| WalletError::DataLayerError(format!("Coin selection failed: {}", e)))?; if selected_coins.is_empty() { return Err(WalletError::NoUnspentCoins); } - Ok(selected_coins) + let selected_coins_ids: HashSet = selected_coins.iter().map(get_coin_id).collect(); + let selected_cats = available_dig_cats.into_iter().filter(|cat| selected_coins_ids.contains(&cat.coin.coin_id())).collect::>(); + + Ok(selected_cats) } pub async fn get_dig_balance(&self, peer: &Peer, verbose: bool) -> Result { - let dig_coins = self - .get_all_unspent_dig_coins(peer, vec![], verbose) + let dig_cats = self + .get_all_unspent_dig_cats(peer, vec![], verbose) .await?; - let dig_balance = dig_coins.iter().map(|c| c.amount).sum::(); + let dig_balance = dig_cats.iter().map(|c| c.coin.amount).sum::(); Ok(dig_balance) } From 680c270448e2ab68a3579c72ffc0467eb429b503 Mon Sep 17 00:00:00 2001 From: William Wills Date: Mon, 27 Oct 2025 20:18:14 -0400 Subject: [PATCH 2/5] chore: align versions --- Cargo.lock | 226 ++++++-------------------------------------------- src/wallet.rs | 12 +-- 2 files changed, 29 insertions(+), 209 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3bdbf88..ce4a1cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -433,25 +433,6 @@ dependencies = [ "hex-literal", ] -[[package]] -name = "chia-sdk-client" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f44eebc9bb4a596f0c770822facc117416a02db9c78d10b451956597011a3e" -dependencies = [ - "chia-protocol", - "chia-sdk-types 0.29.0", - "chia-ssl", - "chia-traits 0.26.0", - "futures-util", - "native-tls", - "thiserror 2.0.16", - "tokio", - "tokio-tungstenite", - "tracing", - "tungstenite", -] - [[package]] name = "chia-sdk-client" version = "0.30.0" @@ -459,10 +440,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09a9ab7609f5c98ff34fc5ba33ad50bfdecca771165640eb88e8054ccef18916" dependencies = [ "chia-protocol", - "chia-sdk-types 0.30.0", + "chia-sdk-types", "chia-ssl", "chia-traits 0.26.0", "futures-util", + "native-tls", "thiserror 2.0.16", "tokio", "tokio-tungstenite", @@ -470,20 +452,6 @@ dependencies = [ "tungstenite", ] -[[package]] -name = "chia-sdk-coinset" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8cac592b1eece9eb9e46db9027d58f4c3ec9b549c5419e249998c53ed7795bd" -dependencies = [ - "chia-protocol", - "hex", - "hex-literal", - "reqwest", - "serde", - "serde_json", -] - [[package]] name = "chia-sdk-coinset" version = "0.30.0" @@ -498,17 +466,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "chia-sdk-derive" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7ac9360740b8af343eadcb60f3155d6f9f56bef2f56d79b71e3e6be2a5d529" -dependencies = [ - "convert_case", - "quote", - "syn", -] - [[package]] name = "chia-sdk-derive" version = "0.30.0" @@ -520,38 +477,6 @@ dependencies = [ "syn", ] -[[package]] -name = "chia-sdk-driver" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca91b1e0ec55edbe736cf9f7a33b492ca05c635ccb022fe9511be83b6ba3e235" -dependencies = [ - "bigdecimal", - "bip39", - "chia-bls 0.26.0", - "chia-consensus", - "chia-protocol", - "chia-puzzle-types", - "chia-puzzles", - "chia-sdk-signer 0.29.0", - "chia-sdk-types 0.29.0", - "chia-secp", - "chia-sha2 0.26.0", - "chia-traits 0.26.0", - "chia_streamable_macro 0.26.0", - "clvm-traits", - "clvm-utils", - "clvmr", - "getrandom 0.2.16", - "hex", - "hex-literal", - "indexmap", - "num-bigint", - "rand", - "rand_chacha", - "thiserror 2.0.16", -] - [[package]] name = "chia-sdk-driver" version = "0.30.0" @@ -565,8 +490,8 @@ dependencies = [ "chia-protocol", "chia-puzzle-types", "chia-puzzles", - "chia-sdk-signer 0.30.0", - "chia-sdk-types 0.30.0", + "chia-sdk-signer", + "chia-sdk-types", "chia-secp", "chia-sha2 0.26.0", "chia-traits 0.26.0", @@ -584,24 +509,6 @@ dependencies = [ "thiserror 2.0.16", ] -[[package]] -name = "chia-sdk-signer" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd70865cfd9881f5282d4a9c5e42905f96f88b2ec35efda8cf23c944e258d20" -dependencies = [ - "chia-bls 0.26.0", - "chia-consensus", - "chia-protocol", - "chia-sdk-types 0.29.0", - "chia-secp", - "chia-sha2 0.26.0", - "clvm-traits", - "clvmr", - "k256", - "thiserror 2.0.16", -] - [[package]] name = "chia-sdk-signer" version = "0.30.0" @@ -611,7 +518,7 @@ dependencies = [ "chia-bls 0.26.0", "chia-consensus", "chia-protocol", - "chia-sdk-types 0.30.0", + "chia-sdk-types", "chia-secp", "chia-sha2 0.26.0", "clvm-traits", @@ -622,9 +529,9 @@ dependencies = [ [[package]] name = "chia-sdk-test" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c459f50deea22e03ab715868d9ed0c11922d7325a0dd8d328d07b3ad5df63e5c" +checksum = "365b95611176b670cd61455ce6578cccf740a66b7d27cd3b31395c12f4073bc2" dependencies = [ "anyhow", "bip39", @@ -632,9 +539,9 @@ dependencies = [ "chia-consensus", "chia-protocol", "chia-puzzle-types", - "chia-sdk-client 0.29.0", - "chia-sdk-signer 0.29.0", - "chia-sdk-types 0.29.0", + "chia-sdk-client", + "chia-sdk-signer", + "chia-sdk-types", "chia-secp", "chia-sha2 0.26.0", "chia-traits 0.26.0", @@ -658,58 +565,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "chia-sdk-test" -version = "0.30.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "365b95611176b670cd61455ce6578cccf740a66b7d27cd3b31395c12f4073bc2" -dependencies = [ - "anyhow", - "bip39", - "chia-bls 0.26.0", - "chia-consensus", - "chia-protocol", - "chia-puzzle-types", - "chia-sdk-signer 0.30.0", - "chia-sdk-types 0.30.0", - "chia-secp", - "chia-sha2 0.26.0", - "chia-traits 0.26.0", - "clvm-traits", - "clvm-utils", - "clvmr", - "hex", - "indexmap", - "prettytable-rs", - "rand", - "rand_chacha", - "serde", - "serde_json", - "thiserror 2.0.16", -] - -[[package]] -name = "chia-sdk-types" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b14123f03a5ccb66c245b216481436749d11c8f394c0fe7a2bf1e35f2a582f6f" -dependencies = [ - "chia-bls 0.26.0", - "chia-consensus", - "chia-protocol", - "chia-puzzle-types", - "chia-puzzles", - "chia-sdk-derive 0.29.0", - "chia-secp", - "chia-sha2 0.26.0", - "clvm-traits", - "clvm-utils", - "clvm_tools_rs", - "clvmr", - "hex-literal", - "thiserror 2.0.16", -] - [[package]] name = "chia-sdk-types" version = "0.30.0" @@ -721,7 +576,7 @@ dependencies = [ "chia-protocol", "chia-puzzle-types", "chia-puzzles", - "chia-sdk-derive 0.30.0", + "chia-sdk-derive", "chia-secp", "chia-sha2 0.26.0", "clvm-traits", @@ -732,20 +587,6 @@ dependencies = [ "thiserror 2.0.16", ] -[[package]] -name = "chia-sdk-utils" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca897c36475cbc6832271cacdc4c5d13f5963ef61f99cebec246fd91e981306f" -dependencies = [ - "bech32", - "chia-protocol", - "indexmap", - "rand", - "rand_chacha", - "thiserror 2.0.16", -] - [[package]] name = "chia-sdk-utils" version = "0.30.0" @@ -835,26 +676,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "chia-wallet-sdk" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ae886c1c212efcbd43564e8039920d3bd94a8db35e8fbd649e6b01ebe8c167e" -dependencies = [ - "chia-bls 0.26.0", - "chia-protocol", - "chia-sdk-client 0.29.0", - "chia-sdk-coinset 0.29.0", - "chia-sdk-driver 0.29.0", - "chia-sdk-signer 0.29.0", - "chia-sdk-test 0.29.0", - "chia-sdk-types 0.29.0", - "chia-sdk-utils 0.29.0", - "clvm-traits", - "clvm-utils", - "clvmr", -] - [[package]] name = "chia-wallet-sdk" version = "0.30.0" @@ -863,13 +684,13 @@ checksum = "94547c50b141ad9ae84f9bcc26c0bf467b7570f0354c906fb203eeea69886a4c" dependencies = [ "chia-bls 0.26.0", "chia-protocol", - "chia-sdk-client 0.30.0", - "chia-sdk-coinset 0.30.0", - "chia-sdk-driver 0.30.0", - "chia-sdk-signer 0.30.0", - "chia-sdk-test 0.30.0", - "chia-sdk-types 0.30.0", - "chia-sdk-utils 0.30.0", + "chia-sdk-client", + "chia-sdk-coinset", + "chia-sdk-driver", + "chia-sdk-signer", + "chia-sdk-test", + "chia-sdk-types", + "chia-sdk-utils", "clvm-traits", "clvm-utils", "clvmr", @@ -1101,17 +922,16 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "datalayer-driver" version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0e7ee25be16a809900191178eb535f16d4543a9a7c504f94516ae10d20909f0" dependencies = [ "chia", "chia-puzzles", - "chia-wallet-sdk 0.29.0", + "chia-wallet-sdk", "clvm-traits", "clvmr", "futures-util", "hex", "hex-literal", + "indexmap", "num-bigint", "openssl", "openssl-sys", @@ -1162,7 +982,7 @@ dependencies = [ "base64 0.21.7", "bip39", "chia", - "chia-wallet-sdk 0.30.0", + "chia-wallet-sdk", "datalayer-driver", "dirs", "hex", @@ -3844,3 +3664,7 @@ dependencies = [ "quote", "syn", ] + +[[patch.unused]] +name = "dig-store-coin" +version = "0.1.0" diff --git a/src/wallet.rs b/src/wallet.rs index ac41bfc..cf89d2d 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -24,11 +24,9 @@ use std::env; use std::fs; use std::path::PathBuf; -pub static DIG_COIN_ASSET_ID: Lazy = Lazy::new(|| { - Bytes32::new(hex!( +pub const DIG_COIN_ASSET_ID: Bytes32 = Bytes32::new(hex!( "a406d3a9de984d03c9591c10d917593b434d5263cabe2b42f6b367df16832f81" - )) -}); + )); const KEYRING_FILE: &str = "keyring.json"; // Cache duration constant - keeping for potential future use #[allow(dead_code)] @@ -272,7 +270,7 @@ impl Wallet { public_key, signature, ) - .map_err(|e| WalletError::CryptoError(e.to_string())) + .map_err(|e| WalletError::CryptoError(e.to_string())) } /// Get all unspent DIG Token coins @@ -283,7 +281,7 @@ impl Wallet { verbose: bool, ) -> Result, WalletError> { let p2 = self.get_owner_puzzle_hash().await?; - let dig_cat_ph = CatArgs::curry_tree_hash(*DIG_COIN_ASSET_ID, TreeHash::from(p2)); + let dig_cat_ph = CatArgs::curry_tree_hash(DIG_COIN_ASSET_ID, TreeHash::from(p2)); let dig_cat_ph_bytes = Bytes32::from(dig_cat_ph.to_bytes()); // Get unspent coin states from the DataLayer-Driver async API @@ -306,8 +304,6 @@ impl Wallet { let mut proved_dig_cats: Vec = vec![]; - let mut allocator = Allocator::new(); - for coin_state in &available_coin_states { let coin = &coin_state.coin; let coin_id = coin.coin_id(); From b68daec7b72acfb440fa9120af6d1de3664f6c32 Mon Sep 17 00:00:00 2001 From: William Wills Date: Thu, 30 Oct 2025 14:48:41 -0400 Subject: [PATCH 3/5] chore: minor tweaks --- .gitignore | 2 +- Cargo.lock | 4 ---- src/wallet.rs | 14 +++++--------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 1661cfc..d8c3f88 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /target/ **/*.rs.bk *.pdb -config.toml +.cargo/config.toml # IDE .vscode/ diff --git a/Cargo.lock b/Cargo.lock index ce4a1cc..4fc5b4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3664,7 +3664,3 @@ dependencies = [ "quote", "syn", ] - -[[patch.unused]] -name = "dig-store-coin" -version = "0.1.0" diff --git a/src/wallet.rs b/src/wallet.rs index cf89d2d..fa4063d 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -7,9 +7,8 @@ use base64::{engine::general_purpose, Engine as _}; use bip39::{Language, Mnemonic}; use chia::protocol::CoinState; use chia::puzzles::cat::CatArgs; -use chia_wallet_sdk::driver::{Cat, Puzzle}; -use chia_wallet_sdk::prelude::{Allocator, ToClvm, TreeHash}; -use chia_wallet_sdk::types::MAINNET_CONSTANTS; +use chia_wallet_sdk::driver::{Cat}; +use chia_wallet_sdk::prelude::{ ToClvm, TreeHash}; use datalayer_driver::{ address_to_puzzle_hash, connect_random, get_coin_id, master_public_key_to_first_puzzle_hash, master_public_key_to_wallet_synthetic_key, master_secret_key_to_wallet_synthetic_secret_key, @@ -17,16 +16,13 @@ use datalayer_driver::{ Bytes32, Coin, CoinSpend, NetworkType, Peer, PublicKey, SecretKey, Signature, }; use hex_literal::hex; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::env; use std::fs; use std::path::PathBuf; +use datalayer_driver::wallet::DIG_ASSET_ID; -pub const DIG_COIN_ASSET_ID: Bytes32 = Bytes32::new(hex!( - "a406d3a9de984d03c9591c10d917593b434d5263cabe2b42f6b367df16832f81" - )); const KEYRING_FILE: &str = "keyring.json"; // Cache duration constant - keeping for potential future use #[allow(dead_code)] @@ -280,8 +276,8 @@ impl Wallet { omit_coins: Vec, verbose: bool, ) -> Result, WalletError> { - let p2 = self.get_owner_puzzle_hash().await?; - let dig_cat_ph = CatArgs::curry_tree_hash(DIG_COIN_ASSET_ID, TreeHash::from(p2)); + let owner_puzzle_hash = self.get_owner_puzzle_hash().await?; + let dig_cat_ph = CatArgs::curry_tree_hash(DIG_ASSET_ID, TreeHash::from(owner_puzzle_hash)); let dig_cat_ph_bytes = Bytes32::from(dig_cat_ph.to_bytes()); // Get unspent coin states from the DataLayer-Driver async API From 346c442c346002c8b70baaca68e57c9747dbeef0 Mon Sep 17 00:00:00 2001 From: William Wills Date: Sun, 2 Nov 2025 14:12:48 -0500 Subject: [PATCH 4/5] chore: update datalayer driver version --- Cargo.lock | 6 +++++- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4fc5b4d..4995e2f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -921,7 +921,7 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "datalayer-driver" -version = "1.0.1" +version = "2.0.0" dependencies = [ "chia", "chia-puzzles", @@ -3664,3 +3664,7 @@ dependencies = [ "quote", "syn", ] + +[[patch.unused]] +name = "dig-store-coin" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 5cab5e3..62122ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" rust-version = "1.70" [dependencies] -datalayer-driver = "1.0.1" +datalayer-driver = "2.0.0" chia-wallet-sdk = "0.30.0" chia = "0.26.0" bip39 = "2.0" From ab844ccb56090a5ba97dd5978752088e15accfe3 Mon Sep 17 00:00:00 2001 From: William Wills Date: Sun, 2 Nov 2025 14:46:04 -0500 Subject: [PATCH 5/5] chore: fmt and clippy --- Cargo.lock | 6 ++---- src/wallet.rs | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4995e2f..3de64d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -922,6 +922,8 @@ checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" [[package]] name = "datalayer-driver" version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abd50de97bd63bae84bc92766f3c5570689fba4e6c45b0e4855471351f8749c" dependencies = [ "chia", "chia-puzzles", @@ -3664,7 +3666,3 @@ dependencies = [ "quote", "syn", ] - -[[patch.unused]] -name = "dig-store-coin" -version = "0.1.0" diff --git a/src/wallet.rs b/src/wallet.rs index fa4063d..a444682 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -7,21 +7,20 @@ use base64::{engine::general_purpose, Engine as _}; use bip39::{Language, Mnemonic}; use chia::protocol::CoinState; use chia::puzzles::cat::CatArgs; -use chia_wallet_sdk::driver::{Cat}; -use chia_wallet_sdk::prelude::{ ToClvm, TreeHash}; +use chia_wallet_sdk::driver::Cat; +use chia_wallet_sdk::prelude::TreeHash; +use datalayer_driver::wallet::DIG_ASSET_ID; use datalayer_driver::{ address_to_puzzle_hash, connect_random, get_coin_id, master_public_key_to_first_puzzle_hash, master_public_key_to_wallet_synthetic_key, master_secret_key_to_wallet_synthetic_secret_key, puzzle_hash_to_address, secret_key_to_public_key, sign_message, verify_signature, Bytes, Bytes32, Coin, CoinSpend, NetworkType, Peer, PublicKey, SecretKey, Signature, }; -use hex_literal::hex; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::env; use std::fs; use std::path::PathBuf; -use datalayer_driver::wallet::DIG_ASSET_ID; const KEYRING_FILE: &str = "keyring.json"; // Cache duration constant - keeping for potential future use @@ -266,7 +265,7 @@ impl Wallet { public_key, signature, ) - .map_err(|e| WalletError::CryptoError(e.to_string())) + .map_err(|e| WalletError::CryptoError(e.to_string())) } /// Get all unspent DIG Token coins @@ -287,8 +286,8 @@ impl Wallet { None, // previous_height - start from genesis datalayer_driver::constants::get_mainnet_genesis_challenge(), // Use mainnet for now ) - .await - .map_err(|e| WalletError::NetworkError(format!("Failed to get unspent coins: {}", e)))?; + .await + .map_err(|e| WalletError::NetworkError(format!("Failed to get unspent coins: {}", e)))?; // Convert coin states to coins and filter out omitted coins let omit_coin_ids: Vec = omit_coins.iter().map(get_coin_id).collect(); @@ -320,7 +319,9 @@ impl Wallet { }; //Parse CAT to prove lineage - let cat_parse_result = datalayer_driver::async_api::prove_dig_cat_coin(peer, coin, coin_created_height).await; + let cat_parse_result = + datalayer_driver::async_api::prove_dig_cat_coin(peer, coin, coin_created_height) + .await; match cat_parse_result { Ok(parsed_cat) => { // lineage proved. append coin in question @@ -355,8 +356,11 @@ impl Wallet { let available_dig_cats = self .get_all_unspent_dig_cats(peer, omit_coins, verbose) .await?; - - let dig_coins = available_dig_cats.iter().map(|cat| cat.coin).collect::>(); + + let dig_coins = available_dig_cats + .iter() + .map(|cat| cat.coin) + .collect::>(); // Use the DataLayer-Driver's select_coins function let selected_coins = datalayer_driver::select_coins(&dig_coins, coin_amount) @@ -367,15 +371,16 @@ impl Wallet { } let selected_coins_ids: HashSet = selected_coins.iter().map(get_coin_id).collect(); - let selected_cats = available_dig_cats.into_iter().filter(|cat| selected_coins_ids.contains(&cat.coin.coin_id())).collect::>(); + let selected_cats = available_dig_cats + .into_iter() + .filter(|cat| selected_coins_ids.contains(&cat.coin.coin_id())) + .collect::>(); Ok(selected_cats) } pub async fn get_dig_balance(&self, peer: &Peer, verbose: bool) -> Result { - let dig_cats = self - .get_all_unspent_dig_cats(peer, vec![], verbose) - .await?; + let dig_cats = self.get_all_unspent_dig_cats(peer, vec![], verbose).await?; let dig_balance = dig_cats.iter().map(|c| c.coin.amount).sum::(); Ok(dig_balance) }