Skip to content

Commit

Permalink
updating comsig creation, attempt to get working
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Aug 29, 2024
1 parent 872bc05 commit d5c64d5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ impl ContractNewArgs {
net_change: Some(net_change),
num_participants: self.num_participants,
add_outputs: self.add_outputs,
delete_context_on_final_sign: true,
selection_args: OutputSelectionArgs {
use_inputs: match self.use_inputs.as_ref() {
Some(v) => Some(v.to_string()),
Expand Down
1 change: 1 addition & 0 deletions controller/tests/contract_srs_mwmixnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
// Send wallet finalizes and posts
wallet::controller::owner_single_use(Some(send_wallet.clone()), send_mask, None, |api, m| {
let args = &mut ContractSetupArgsAPI {
delete_context_on_final_sign: false,
..Default::default()
};
args.proof_args.suppress_proof = true;
Expand Down
1 change: 1 addition & 0 deletions libwallet/src/contract/actions/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where
&mut context,
setup_args.add_outputs,
false,
setup_args.delete_context_on_final_sign,
)?;

Ok(slate)
Expand Down
2 changes: 2 additions & 0 deletions libwallet/src/contract/actions/revoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ where
net_change: Some(0), // self-spend
num_participants: 1,
add_outputs: false,
delete_context_on_final_sign: true,
selection_args: OutputSelectionArgs {
use_inputs: Some(String::from(input_commit)),
..Default::default()
Expand All @@ -90,6 +91,7 @@ where
net_change: None, // we already have it in the context as 0 now
num_participants: 1,
add_outputs: false,
delete_context_on_final_sign: true,
selection_args: OutputSelectionArgs {
use_inputs: Some(String::from(input_commit)),
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions libwallet/src/contract/actions/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ where
&mut context,
setup_args.add_outputs,
false,
setup_args.delete_context_on_final_sign,
)?;

Ok(slate)
Expand Down
10 changes: 9 additions & 1 deletion libwallet/src/contract/actions/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ where
let (sl, mut context) = compute(w, keychain_mask, slate, setup_args)?;

// Atomically commit state
contract::utils::save_step(w, keychain_mask, &sl, &mut context, will_add_outputs, true)?;
contract::utils::save_step(
w,
keychain_mask,
&sl,
&mut context,
will_add_outputs,
true,
setup_args.delete_context_on_final_sign,
)?;

Ok(sl)
}
Expand Down
4 changes: 4 additions & 0 deletions libwallet/src/contract/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub struct ContractSetupArgsAPI {
pub add_outputs: bool,
/// Output selection arguments
pub selection_args: OutputSelectionArgs,
/// If false, don't delete context when finalizing (to facilitate mwixnet transactions)
pub delete_context_on_final_sign: bool,
/// Proof arguments
pub proof_args: ProofArgs,
}
Expand All @@ -148,6 +150,7 @@ impl Default for ContractSetupArgsAPI {
net_change: None,
num_participants: 2,
add_outputs: false,
delete_context_on_final_sign: true,
selection_args: OutputSelectionArgs {
..Default::default()
},
Expand Down Expand Up @@ -177,6 +180,7 @@ impl Default for ContractNewArgsAPI {
net_change: None,
num_participants: 2,
add_outputs: false,
delete_context_on_final_sign: true,
selection_args: OutputSelectionArgs {
..Default::default()
},
Expand Down
4 changes: 3 additions & 1 deletion libwallet/src/contract/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::types::{Context, NodeClient, StoredProofInfo, TxLogEntryType, WalletB
use crate::util::OnionV3Address;
use crate::{address, Error, OutputData, OutputStatus, TxLogEntry};
use grin_core::core::FeeFields;
use grin_util::file::delete;
use uuid::Uuid;

/// Creates an initial TxLogEntry without input/output or kernel information
Expand Down Expand Up @@ -188,6 +189,7 @@ pub fn save_step<'a, T: ?Sized, C, K>(
context: &mut Context,
step_added_outputs: bool,
is_signed: bool,
delete_on_final: bool,
) -> Result<(), Error>
where
T: WalletBackend<'a, C, K>,
Expand Down Expand Up @@ -276,7 +278,7 @@ where
}

// Update context
if is_signed && !is_step2 {
if is_signed && !is_step2 && delete_on_final {
// NOTE: We MUST forget the context when we sign. Ideally, these two would be atomic or perhaps
// when we call slate::sigadd_partial_signaturen we could swap the secret key with a temporary one just to be safe.
// The reason we don't delete if we are at step2 is because in case we want to do safe cancel,
Expand Down

0 comments on commit d5c64d5

Please sign in to comment.