From f64e502fcfd1cd9ebd1747d36278ce1d947a88df Mon Sep 17 00:00:00 2001 From: wiesche Date: Sat, 12 Sep 2026 11:19:57 +0200 Subject: [PATCH] clean up contracts --- api/src/owner.rs | 11 ----------- controller/tests/contract_accounts.rs | 1 - controller/tests/contract_early_proofs_rsr.rs | 5 ----- controller/tests/contract_early_proofs_srs.rs | 2 -- controller/tests/contract_rsr.rs | 5 ----- controller/tests/contract_self_spend_custom.rs | 1 - controller/tests/contract_srs_mwmixnet.rs | 4 +--- libwallet/src/api_impl/owner.rs | 15 --------------- libwallet/src/contract/utils.rs | 14 +++++++++++++- libwallet/src/slate_versions/v4_bin.rs | 4 ++-- 10 files changed, 16 insertions(+), 46 deletions(-) diff --git a/api/src/owner.rs b/api/src/owner.rs index 6fb546e..24c3478 100644 --- a/api/src/owner.rs +++ b/api/src/owner.rs @@ -958,17 +958,6 @@ where owner::contract_sign(w, keychain_mask, args, slate) } - /// Return the participant index in the slate that matches this wallet's context. - pub fn get_slate_index_matching_my_context( - &self, - keychain_mask: Option<&SecretKey>, - slate: &Slate, - ) -> Result { - let mut w_lock = self.wallet_inst.lock(); - let w = w_lock.lc_provider()?.wallet_inst()?; - owner::get_slate_index_matching_my_context(w, keychain_mask, slate) - } - /// Revoke a contract by double-spending one of its locked inputs. /// The transaction id must identify an existing contract. /// diff --git a/controller/tests/contract_accounts.rs b/controller/tests/contract_accounts.rs index 0010459..e028f97 100644 --- a/controller/tests/contract_accounts.rs +++ b/controller/tests/contract_accounts.rs @@ -274,7 +274,6 @@ fn contract_accounts_impl(test_dir: &'static str) -> Result<(), libwallet::Error let (_, wallet1_info) = api.retrieve_summary_info(m, true, 1)?; assert_eq!(wallet1_info.last_confirmed_height, 13); let (_, txs) = api.retrieve_txs(m, true, None, None, None)?; - println!("{:?}", txs); assert_eq!(txs.len(), 5); Ok(()) }, diff --git a/controller/tests/contract_early_proofs_rsr.rs b/controller/tests/contract_early_proofs_rsr.rs index 2862b67..ba5dfe2 100644 --- a/controller/tests/contract_early_proofs_rsr.rs +++ b/controller/tests/contract_early_proofs_rsr.rs @@ -105,7 +105,6 @@ fn contract_early_proofs_rsr_test_impl( )?; assert_eq!(slate.state, SlateState::Invoice1); - println!("I1 State slate: {}", slate); slate = roundtrip_slate(&slate, 5)?; wallet::controller::owner_single_use( @@ -123,7 +122,6 @@ fn contract_early_proofs_rsr_test_impl( Ok(()) }, )?; - println!("I2 State slate: {}", slate); assert_eq!(slate.state, SlateState::Invoice2); slate = roundtrip_slate(&slate, 5)?; @@ -241,9 +239,6 @@ fn contract_early_proofs_rsr_test_impl( ); let early_proof_json = serde_json::to_string(&early_proof).unwrap(); - // Should have all proof fields filled out - println!("EARLY PAYMENT PROOF: {}", early_proof_json); - wallet::controller::foreign_single_use( recv_wallet.clone(), PathBuf::from(test_dir), diff --git a/controller/tests/contract_early_proofs_srs.rs b/controller/tests/contract_early_proofs_srs.rs index 1d358b2..56d567f 100644 --- a/controller/tests/contract_early_proofs_srs.rs +++ b/controller/tests/contract_early_proofs_srs.rs @@ -231,8 +231,6 @@ fn contract_early_proofs_srs_test_impl(test_dir: &'static str) -> Result<(), lib ); let early_proof_json = serde_json::to_string(&early_proof).unwrap(); - // Should have all proof fields filled out - println!("EARLY PAYMENT PROOF: {}", early_proof_json); { let api = grin_wallet_api::Foreign::new( recv_wallet.clone(), diff --git a/controller/tests/contract_rsr.rs b/controller/tests/contract_rsr.rs index cf61ee0..b396645 100644 --- a/controller/tests/contract_rsr.rs +++ b/controller/tests/contract_rsr.rs @@ -234,11 +234,6 @@ fn contract_rsr_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> wallet_info.amount_currently_spendable, 4 * 60_000_000_000 + 5_000_000_000 - expected_fees_paid.unwrap().fee() // we expect the balance of 4 mined blocks + 5 Grin - fees paid ); - // println!("txlogentry: {:#?}", tx_log); - // println!("wallet info: {:#?}", wallet_info); - // let (validated, commits) = api.retrieve_outputs(m, true, false, Some(tx_log.id))?; - // println!("commits: {:#?}", commits); - // panic!("lala"); Ok(()) }, )?; diff --git a/controller/tests/contract_self_spend_custom.rs b/controller/tests/contract_self_spend_custom.rs index ac703a3..ccc5ceb 100644 --- a/controller/tests/contract_self_spend_custom.rs +++ b/controller/tests/contract_self_spend_custom.rs @@ -51,7 +51,6 @@ fn contract_self_spend_custom_tx_impl(test_dir: &'static str) -> Result<(), libw PathBuf::from(test_dir), |api, m| { let (_, commits) = api.retrieve_outputs(m, true, false, None)?; - println!("OOOT: {:?}", commits[0].output); use_inputs = format!( "{},{}", commits[0].output.commit.as_ref().unwrap(), diff --git a/controller/tests/contract_srs_mwmixnet.rs b/controller/tests/contract_srs_mwmixnet.rs index 8de3ec6..75d6692 100644 --- a/controller/tests/contract_srs_mwmixnet.rs +++ b/controller/tests/contract_srs_mwmixnet.rs @@ -144,9 +144,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet: // get last output let last_output = outputs.1[outputs.1.len() - 1].clone(); - let mwixnet_req = api.create_mwixnet_req(m, ¶ms, &last_output.commit, true)?; - - println!("MWIXNET REQ: {:?}", mwixnet_req); + api.create_mwixnet_req(m, ¶ms, &last_output.commit, true)?; // check output we created comsig for is indeed locked let outputs = api.retrieve_outputs(recv_mask, false, false, None)?; diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index e5a7b87..62e131d 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -1657,21 +1657,6 @@ where contract::revoke(&mut *w, keychain_mask, &args) } -/// Return the slate participant index matching this wallet's context -pub fn get_slate_index_matching_my_context( - w: &mut WalletBackend, - keychain_mask: Option<&SecretKey>, - slate: &Slate, -) -> Result -where - C: NodeClient, - K: Keychain, -{ - let keychain = w.keychain(keychain_mask)?; - let context = w.get_private_context(keychain_mask, slate.id.as_bytes())?; - slate.find_index_matching_context(&keychain, &context) -} - /// Create MXMixnet request pub fn create_mwixnet_req( w: &mut WalletBackend, diff --git a/libwallet/src/contract/utils.rs b/libwallet/src/contract/utils.rs index a17165e..de98522 100644 --- a/libwallet/src/contract/utils.rs +++ b/libwallet/src/contract/utils.rs @@ -50,7 +50,7 @@ pub fn create_tx_log_entry( if net_change > 0 { t.amount_credited = net_change as u64; } else { - t.amount_debited = -net_change as u64; + t.amount_debited = net_change.unsigned_abs(); } t.ttl_cutoff_height = match slate.ttl_cutoff_height { 0 => None, @@ -520,6 +520,18 @@ where mod tests { use super::*; + #[test] + fn tx_log_amounts() { + let slate = Slate::blank(2, false); + for (net_change, credited, debited) in + [(1, 1, 0), (0, 0, 0), (-1, 0, 1), (i64::MIN, 0, 1u64 << 63)] + { + let entry = create_tx_log_entry(&slate, net_change, Identifier::zero(), 0).unwrap(); + assert_eq!(entry.amount_credited, credited); + assert_eq!(entry.amount_debited, debited); + } + } + #[test] fn fee_contribution_kernel_split() { let (n_inputs, n_outputs, n_kernels) = (1, 1, 1); diff --git a/libwallet/src/slate_versions/v4_bin.rs b/libwallet/src/slate_versions/v4_bin.rs index 9f22346..c660bbe 100644 --- a/libwallet/src/slate_versions/v4_bin.rs +++ b/libwallet/src/slate_versions/v4_bin.rs @@ -64,7 +64,7 @@ impl Readable for SlateStateV4 { } /// Allow serializing of Uuids not defined in crate -pub struct UuidWrap(pub Uuid); +pub(crate) struct UuidWrap(pub Uuid); impl Writeable for UuidWrap { fn write(&self, writer: &mut W) -> Result<(), grin_ser::Error> { @@ -82,7 +82,7 @@ impl Readable for UuidWrap { } /// Helper struct to serialize optional fields efficiently -pub struct SlateOptFields { +pub(crate) struct SlateOptFields { /// num parts, default 2 pub num_parts: u8, /// amt, default 0