@@ -6,15 +6,11 @@ use aes_gcm::{
66use base64:: { engine:: general_purpose, Engine as _} ;
77use bip39:: { Language , Mnemonic } ;
88use chia:: protocol:: CoinState ;
9- use chia:: puzzles:: cat:: CatArgs ;
10- use chia_wallet_sdk:: driver:: Cat ;
11- use chia_wallet_sdk:: prelude:: TreeHash ;
12- use datalayer_driver:: wallet:: DIG_ASSET_ID ;
139use datalayer_driver:: {
1410 address_to_puzzle_hash, connect_random, get_coin_id, master_public_key_to_first_puzzle_hash,
1511 master_public_key_to_wallet_synthetic_key, master_secret_key_to_wallet_synthetic_secret_key,
1612 puzzle_hash_to_address, secret_key_to_public_key, sign_message, verify_signature, Bytes ,
17- Bytes32 , Coin , CoinSpend , NetworkType , Peer , PublicKey , SecretKey , Signature ,
13+ Bytes32 , Coin , CoinSpend , DigCoin , NetworkType , Peer , PublicKey , SecretKey , Signature ,
1814} ;
1915use serde:: { Deserialize , Serialize } ;
2016use std:: collections:: { HashMap , HashSet } ;
@@ -269,20 +265,19 @@ impl Wallet {
269265 }
270266
271267 /// Get all unspent DIG Token coins
272- pub async fn get_all_unspent_dig_cats (
268+ pub async fn get_all_unspent_dig_coins (
273269 & self ,
274270 peer : & Peer ,
275271 omit_coins : Vec < Coin > ,
276272 verbose : bool ,
277- ) -> Result < Vec < Cat > , WalletError > {
273+ ) -> Result < Vec < DigCoin > , WalletError > {
278274 let owner_puzzle_hash = self . get_owner_puzzle_hash ( ) . await ?;
279- let dig_cat_ph = CatArgs :: curry_tree_hash ( DIG_ASSET_ID , TreeHash :: from ( owner_puzzle_hash) ) ;
280- let dig_cat_ph_bytes = Bytes32 :: from ( dig_cat_ph. to_bytes ( ) ) ;
275+ let dig_ph = DigCoin :: puzzle_hash ( owner_puzzle_hash) ;
281276
282277 // Get unspent coin states from the DataLayer-Driver async API
283278 let unspent_coin_states = datalayer_driver:: async_api:: get_all_unspent_coins (
284279 peer,
285- dig_cat_ph_bytes ,
280+ dig_ph ,
286281 None , // previous_height - start from genesis
287282 datalayer_driver:: constants:: get_mainnet_genesis_challenge ( ) , // Use mainnet for now
288283 )
@@ -297,31 +292,11 @@ impl Wallet {
297292 . filter ( |coin_state| !omit_coin_ids. contains ( & get_coin_id ( & coin_state. coin ) ) )
298293 . collect ( ) ;
299294
300- let mut proved_dig_cats: Vec < Cat > = vec ! [ ] ;
295+ let mut proved_dig_cats: Vec < DigCoin > = vec ! [ ] ;
301296
302297 for coin_state in & available_coin_states {
303- let coin = & coin_state. coin ;
304- let coin_id = coin. coin_id ( ) ;
305- let coin_created_height = match coin_state. created_height {
306- Some ( height) => height,
307- None => {
308- if verbose {
309- eprintln ! (
310- "ERROR: coin_id {} | {}" ,
311- coin_id,
312- WalletError :: CoinSetError (
313- "Cannot determine coin creation height" . to_string( )
314- )
315- ) ;
316- }
317- continue ;
318- }
319- } ;
320-
321298 //Parse CAT to prove lineage
322- let cat_parse_result =
323- datalayer_driver:: async_api:: prove_dig_cat_coin ( peer, coin, coin_created_height)
324- . await ;
299+ let cat_parse_result = DigCoin :: from_coin_state ( peer, coin_state) . await ;
325300 match cat_parse_result {
326301 Ok ( parsed_cat) => {
327302 // lineage proved. append coin in question
@@ -331,7 +306,7 @@ impl Wallet {
331306 if verbose {
332307 eprintln ! (
333308 "ERROR: coin_id {} | {}" ,
334- coin_id,
309+ coin_state . coin . coin_id( ) ,
335310 WalletError :: CoinSetError ( format!(
336311 "Failed to parse CAT and prove lineage: {}" ,
337312 error
@@ -346,20 +321,20 @@ impl Wallet {
346321 Ok ( proved_dig_cats)
347322 }
348323
349- pub async fn select_unspent_dig_cats (
324+ pub async fn select_unspent_dig_coins (
350325 & self ,
351326 peer : & Peer ,
352327 coin_amount : u64 ,
353328 omit_coins : Vec < Coin > ,
354329 verbose : bool ,
355- ) -> Result < Vec < Cat > , WalletError > {
330+ ) -> Result < Vec < DigCoin > , WalletError > {
356331 let available_dig_cats = self
357- . get_all_unspent_dig_cats ( peer, omit_coins, verbose)
332+ . get_all_unspent_dig_coins ( peer, omit_coins, verbose)
358333 . await ?;
359334
360335 let dig_coins = available_dig_cats
361336 . iter ( )
362- . map ( |cat| cat. coin )
337+ . map ( |dig_coin| dig_coin . cat ( ) . coin )
363338 . collect :: < Vec < _ > > ( ) ;
364339
365340 // Use the DataLayer-Driver's select_coins function
@@ -371,17 +346,22 @@ impl Wallet {
371346 }
372347
373348 let selected_coins_ids: HashSet < Bytes32 > = selected_coins. iter ( ) . map ( get_coin_id) . collect ( ) ;
374- let selected_cats = available_dig_cats
349+ let dig_coin = available_dig_cats
375350 . into_iter ( )
376- . filter ( |cat | selected_coins_ids. contains ( & cat. coin . coin_id ( ) ) )
351+ . filter ( |dig_coin | selected_coins_ids. contains ( & dig_coin . cat ( ) . coin . coin_id ( ) ) )
377352 . collect :: < Vec < _ > > ( ) ;
378353
379- Ok ( selected_cats )
354+ Ok ( dig_coin )
380355 }
381356
382357 pub async fn get_dig_balance ( & self , peer : & Peer , verbose : bool ) -> Result < u64 , WalletError > {
383- let dig_cats = self . get_all_unspent_dig_cats ( peer, vec ! [ ] , verbose) . await ?;
384- let dig_balance = dig_cats. iter ( ) . map ( |c| c. coin . amount ) . sum :: < u64 > ( ) ;
358+ let dig_cats = self
359+ . get_all_unspent_dig_coins ( peer, vec ! [ ] , verbose)
360+ . await ?;
361+ let dig_balance = dig_cats
362+ . iter ( )
363+ . map ( |dig_coin| dig_coin. cat ( ) . coin . amount )
364+ . sum :: < u64 > ( ) ;
385365 Ok ( dig_balance)
386366 }
387367
0 commit comments