pub fn init_send_tx<'a, T: ?Sized, C, K>(
	w: &mut T,
	keychain_mask: Option<&SecretKey>,
	args: InitTxArgs,
	use_test_rng: bool,
	outputs: Option<Vec<&str>>, // outputs to include into the transaction
	routputs: usize,            // Number of resulting outputs. Normally it is 1
) -> Result<Slate, Error>
where
	T: WalletBackend<'a, C, K>,
	C: NodeClient + 'a,
	K: Keychain + 'a,
{
	let parent_key_id = match args.src_acct_name {
		Some(d) => {
			let pm = w.get_acct_path(d)?;
			match pm {
				Some(p) => p.path,
				None => w.parent_key_id(),
			}
		}
		None => w.parent_key_id(),
	};

	let message = match args.message {
		Some(mut m) => {
			m.truncate(USER_MESSAGE_MAX_LEN);
			Some(m)
		}
		None => None,
	};

	let mut slate = tx::new_tx_slate(&mut *w, args.amount, 2, use_test_rng, args.ttl_blocks)?;

	// if we just want to estimate, don't save a context, just send the results
	// back
	if let Some(true) = args.estimate_only {
		let (total, fee) = tx::estimate_send_tx(
			&mut *w,
			args.amount,
			args.minimum_confirmations,
			args.max_outputs as usize,
			args.num_change_outputs as usize,
			args.selection_strategy_is_use_all,
			&parent_key_id,
			&outputs,
			routputs,
			args.exclude_change_outputs.unwrap_or(false),
			args.minimum_confirmations_change_outputs,
		)?;
		slate.amount = total;
		slate.fee = fee;
		return Ok(slate);
	}

	let mut context = tx::add_inputs_to_slate(
		&mut *w,
		keychain_mask,
		&mut slate,
		args.minimum_confirmations,
		args.max_outputs as usize,
		args.num_change_outputs as usize,
		args.selection_strategy_is_use_all,
		&parent_key_id,
		0,
		message,
		true,
		use_test_rng,
		outputs,
		routputs,
		args.exclude_change_outputs.unwrap_or(false),
		args.minimum_confirmations_change_outputs,
	)?;

	// Payment Proof, add addresses to slate and save address
	// TODO: Note we only use single derivation path for now,
	// probably want to allow sender to specify which one
	let deriv_path = 0u32;
	let k = w.keychain(keychain_mask)?;
	let sender_a = proofaddress::payment_proof_address(&k, &parent_key_id, deriv_path)?;

	if let Some(a) = args.address {
		if a.eq("file_proof") {
			debug!("doing file proof");
			//in file proof, we are putting the same address both both sender_address and receiver_address
			slate.payment_proof = Some(PaymentInfo {
				sender_address: sender_a.clone(),
				receiver_address: sender_a.clone(),
				receiver_signature: None,
			});

			context.payment_proof_derivation_index = Some(deriv_path);
		}
	}

	if let Some(a) = args.payment_proof_recipient_address {
		slate.payment_proof = Some(PaymentInfo {
			sender_address: sender_a,
			receiver_address: a,
			receiver_signature: None,
		});

		context.payment_proof_derivation_index = Some(deriv_path);
	} else {
		debug!("There is no payment proof recipient address");
	}

	// mwc713 payment proof support.
	for input in slate.tx.inputs() {
		context.input_commits.push(input.commit.clone());
	}

	for output in slate.tx.outputs() {
		context.output_commits.push(output.commit.clone());
	}

	// Save the aggsig context in our DB for when we
	// recieve the transaction back
	{
		let mut batch = w.batch(keychain_mask)?;
		batch.save_private_context(slate.id.as_bytes(), 0, &context)?;
		batch.commit()?;
	}
	if let Some(v) = args.target_slate_version {
		slate.version_info.orig_version = v;
	}

	Ok(slate)
}
/// Initiate tx as sender
/// Caller is responsible for wallet refresh
Initiate tx as sender
Caller is responsible for wallet refresh
Initiate tx as sender Caller is responsible for wallet refresh
pub fn init_send_tx<'a, T: ?Sized, C, K>(
	w: &mut T,
	keychain_mask: Option<&SecretKey>,
	args: InitTxArgs,
	use_test_rng: bool,
	outputs: Option<Vec<&str>>, // outputs to include into the transaction
	routputs: usize,            // Number of resulting outputs. Normally it is 1
) -> Result<Slate, Error>
where
	T: WalletBackend<'a, C, K>,
	C: NodeClient + 'a,
	K: Keychain + 'a,
{
	let parent_key_id = match args.src_acct_name {
		Some(d) => {
			let pm = w.get_acct_path(d)?;
			match pm {
				Some(p) => p.path,
				None => w.parent_key_id(),
			}
		}
		None => w.parent_key_id(),
	};
	let message = match args.message {
		Some(mut m) => {
			m.truncate(USER_MESSAGE_MAX_LEN);
			Some(m)
		}
		None => None,
	};
	let mut slate = tx::new_tx_slate(&mut *w, args.amount, 2, use_test_rng, args.ttl_blocks)?;
	// if we just want to estimate, don't save a context, just send the results
	// back
	if let Some(true) = args.estimate_only {
		let (total, fee) = tx::estimate_send_tx(
			&mut *w,
			args.amount,
			args.minimum_confirmations,
			args.max_outputs as usize,
			args.num_change_outputs as usize,
			args.selection_strategy_is_use_all,
			&parent_key_id,
			&outputs,
			routputs,
			args.exclude_change_outputs.unwrap_or(false),
			args.minimum_confirmations_change_outputs,
		)?;
		slate.amount = total;
		slate.fee = fee;
		return Ok(slate);
	}
	let mut context = tx::add_inputs_to_slate(
		&mut *w,
		keychain_mask,
		&mut slate,
		args.minimum_confirmations,
		args.max_outputs as usize,
		args.num_change_outputs as usize,
		args.selection_strategy_is_use_all,
		&parent_key_id,
		0,
		message,
		true,
		use_test_rng,
		outputs,
		routputs,
		args.exclude_change_outputs.unwrap_or(false),
		args.minimum_confirmations_change_outputs,
	)?;
	// Payment Proof, add addresses to slate and save address
	// TODO: Note we only use single derivation path for now,
	// probably want to allow sender to specify which one
	let deriv_path = 0u32;
	let k = w.keychain(keychain_mask)?;
	let sender_a = proofaddress::payment_proof_address(&k, &parent_key_id, deriv_path)?;
	if let Some(a) = args.address {
		if a.eq("file_proof") {
			debug!("doing file proof");
			//in file proof, we are putting the same address both both sender_address and receiver_address
			slate.payment_proof = Some(PaymentInfo {
				sender_address: sender_a.clone(),
				receiver_address: sender_a.clone(),
				receiver_signature: None,
			});
			context.payment_proof_derivation_index = Some(deriv_path);
		}
	}
	if let Some(a) = args.payment_proof_recipient_address {
		slate.payment_proof = Some(PaymentInfo {
			sender_address: sender_a,
			receiver_address: a,
			receiver_signature: None,
		});
		context.payment_proof_derivation_index = Some(deriv_path);
	} else {
		debug!("There is no payment proof recipient address");
	}
	// mwc713 payment proof support.
	for input in slate.tx.inputs() {
		context.input_commits.push(input.commit.clone());
	}
	for output in slate.tx.outputs() {
		context.output_commits.push(output.commit.clone());
	}
	// Save the aggsig context in our DB for when we
	// recieve the transaction back
	{
		let mut batch = w.batch(keychain_mask)?;
		batch.save_private_context(slate.id.as_bytes(), 0, &context)?;
		batch.commit()?;
	}
	if let Some(v) = args.target_slate_version {
		slate.version_info.orig_version = v;
	}
	Ok(slate)
}
pub fn init_send_tx < ' a , T : ? Sized , C , K > ( w : & mut T , keychain_mask : Option < & SecretKey > , args : InitTxArgs , use_test_rng : bool , outputs : Option < Vec < & str > > , // outputs to include into the transaction routputs : usize , // Number of resulting outputs. Normally it is 1 ) -> Result < Slate , Error > where T : WalletBackend < ' a , C , K > , C : NodeClient + ' a , K : Keychain + ' a , { let parent_key_id = match args . src_acct_name { Some ( d ) => { let pm = w . get_acct_path ( d ) ? ; match pm { Some ( p ) => p . path , None => w . parent_key_id ( ) , } } None => w . parent_key_id ( ) , } ; let message = match args . message { Some ( mut m ) => { m . truncate ( USER_MESSAGE_MAX_LEN ) ; Some ( m ) } None => None , } ; let mut slate = tx :: new_tx_slate ( & mut * w , args . amount , 2 , use_test_rng , args . ttl_blocks ) ? ; // if we just want to estimate, don't save a context, just send the results // back if let Some ( true ) = args . estimate_only { let ( total , fee ) = tx :: estimate_send_tx ( & mut * w , args . amount , args . minimum_confirmations , args . max_outputs as usize , args . num_change_outputs as usize , args . selection_strategy_is_use_all , & parent_key_id , & outputs , routputs , args . exclude_change_outputs . unwrap_or ( false ) , args . minimum_confirmations_change_outputs , ) ? ; slate . amount = total ; slate . fee = fee ; return Ok ( slate ) ; } let mut context = tx :: add_inputs_to_slate ( & mut * w , keychain_mask , & mut slate , args . minimum_confirmations , args . max_outputs as usize , args . num_change_outputs as usize , args . selection_strategy_is_use_all , & parent_key_id , 0 , message , true , use_test_rng , outputs , routputs , args . exclude_change_outputs . unwrap_or ( false ) , args . minimum_confirmations_change_outputs , ) ? ; // Payment Proof, add addresses to slate and save address // TODO: Note we only use single derivation path for now, // probably want to allow sender to specify which one let deriv_path = 0u32 ; let k = w . keychain ( keychain_mask ) ? ; let sender_a = proofaddress :: payment_proof_address ( & k , & parent_key_id , deriv_path ) ? ; if let Some ( a ) = args . address { if a . eq ( " " ) { debug ! ( " " ) ; //in file proof, we are putting the same address both both sender_address and receiver_address slate . payment_proof = Some ( PaymentInfo { sender_address : sender_a . clone ( ) , receiver_address : sender_a . clone ( ) , receiver_signature : None , } ) ; context . payment_proof_derivation_index = Some ( deriv_path ) ; } } if let Some ( a ) = args . payment_proof_recipient_address { slate . payment_proof = Some ( PaymentInfo { sender_address : sender_a , receiver_address : a , receiver_signature : None , } ) ; context . payment_proof_derivation_index = Some ( deriv_path ) ; } else { debug ! ( " " ) ; } // mwc713 payment proof support. for input in slate . tx . inputs ( ) { context . input_commits . push ( input . commit . clone ( ) ) ; } for output in slate . tx . outputs ( ) { context . output_commits . push ( output . commit . clone ( ) ) ; } // Save the aggsig context in our DB for when we // recieve the transaction back { let mut batch = w . batch ( keychain_mask ) ? ; batch . save_private_context ( slate . id . as_bytes ( ) , 0 , & context ) ? ; batch . commit ( ) ? ; } if let Some ( v ) = args . target_slate_version { slate . version_info . orig_version = v ; } Ok ( slate ) }
Initiate tx as sender
Caller is responsible for wallet refresh
Initiate tx as sender Caller is responsible for wallet refresh
w
&mut T
keychain_mask
Option<&SecretKey>
args
InitTxArgs
use_test_rng
bool
outputs
Option<Vec<&str>>
routputs
usize
w
&mut T
keychain_mask
Option<&SecretKey>
args
InitTxArgs
use_test_rng
bool
outputs
Option<Vec<&str>>
routputs
usize