Skip to content

Commit

Permalink
remove invoice state from context (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume authored Aug 6, 2020
1 parent e00c61f commit 9146c17
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 36 deletions.
3 changes: 1 addition & 2 deletions libwallet/src/api_impl/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ where
{
let mut sl = slate.clone();
let context = w.get_private_context(keychain_mask, sl.id.as_bytes())?;
let is_invoice = context.is_invoice;
if is_invoice {
if sl.state == SlateState::Invoice2 {
check_ttl(w, &sl)?;

let mut temp_ctx = context.clone();
Expand Down
20 changes: 0 additions & 20 deletions libwallet/src/api_impl/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ where
if let Ok(c) = context_res {
context.initial_sec_key = c.initial_sec_key;
context.initial_sec_nonce = c.initial_sec_nonce;
context.is_invoice = c.is_invoice;
context.fee = c.fee;
context.amount = c.amount;
for o in c.output_ids.iter() {
Expand Down Expand Up @@ -955,25 +954,6 @@ where
}
}

/// return whether slate was an invoice tx
pub fn context_is_invoice<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
keychain_mask: Option<&SecretKey>,
slate: &Slate,
) -> Result<bool, Error>
where
L: WalletLCProvider<'a, C, K>,
C: NodeClient + 'a,
K: Keychain + 'a,
{
let context = {
wallet_lock!(wallet_inst, w);
let context = w.get_private_context(keychain_mask, slate.id.as_bytes())?;
context
};
Ok(context.is_invoice)
}

/// Experimental, wrap the entire definition of how a wallet's state is updated
pub fn update_wallet_state<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
Expand Down
4 changes: 0 additions & 4 deletions libwallet/src/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub fn build_send_tx<'a, T: ?Sized, C, K>(
change_outputs: usize,
selection_strategy_is_use_all: bool,
parent_key_id: Identifier,
is_invoice: bool,
use_test_nonce: bool,
) -> Result<Context, Error>
where
Expand Down Expand Up @@ -79,7 +78,6 @@ where
blinding.secret_key(&keychain.secp()).unwrap(),
&parent_key_id,
use_test_nonce,
is_invoice,
);

context.fee = fee;
Expand Down Expand Up @@ -238,7 +236,6 @@ pub fn build_recipient_output<'a, T: ?Sized, C, K>(
slate: &mut Slate,
current_height: u64,
parent_key_id: Identifier,
is_invoice: bool,
use_test_rng: bool,
) -> Result<(Identifier, Context, TxLogEntry), Error>
where
Expand Down Expand Up @@ -268,7 +265,6 @@ where
.unwrap(),
&parent_key_id,
use_test_rng,
is_invoice,
);

context.add_output(&key_id, &None, amount);
Expand Down
2 changes: 0 additions & 2 deletions libwallet/src/internal/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ where
num_change_outputs,
selection_strategy_is_use_all,
parent_key_id.clone(),
!is_initiator,
use_test_rng,
)?;

Expand Down Expand Up @@ -226,7 +225,6 @@ where
slate,
current_height,
parent_key_id.clone(),
is_initiator,
use_test_rng,
)?;

Expand Down
4 changes: 0 additions & 4 deletions libwallet/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,6 @@ pub struct Context {
pub fee: u64,
/// Payment proof sender address derivation path, if needed
pub payment_proof_derivation_index: Option<u32>,
/// whether this was an invoice transaction
pub is_invoice: bool,
/// for invoice I2 Only, store the tx excess so we can
/// remove it from the slate on return
pub calculated_excess: Option<pedersen::Commitment>,
Expand All @@ -568,7 +566,6 @@ impl Context {
sec_key: SecretKey,
parent_key_id: &Identifier,
use_test_rng: bool,
is_invoice: bool,
) -> Context {
let sec_nonce = match use_test_rng {
false => aggsig::create_secnonce(secp).unwrap(),
Expand All @@ -585,7 +582,6 @@ impl Context {
amount: 0,
fee: 0,
payment_proof_derivation_index: None,
is_invoice,
calculated_excess: None,
}
}
Expand Down
8 changes: 4 additions & 4 deletions libwallet/tests/libwallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn aggsig_sender_receiver_interaction() {

let blind = blinding_factor.secret_key(&keychain.secp()).unwrap();

s_cx = Context::new(&keychain.secp(), blind, &parent, false, false);
s_cx = Context::new(&keychain.secp(), blind, &parent, false);
s_cx.get_public_keys(&keychain.secp())
};

Expand All @@ -88,7 +88,7 @@ fn aggsig_sender_receiver_interaction() {
// let blind = blind_sum.secret_key(&keychain.secp())?;
let blind = keychain.derive_key(0, &key_id, switch).unwrap();

rx_cx = Context::new(&keychain.secp(), blind, &parent, false, false);
rx_cx = Context::new(&keychain.secp(), blind, &parent, false);
let (pub_excess, pub_nonce) = rx_cx.get_public_keys(&keychain.secp());
rx_cx.add_output(&key_id, &None, 0);

Expand Down Expand Up @@ -293,7 +293,7 @@ fn aggsig_sender_receiver_interaction_offset() {

let blind = blinding_factor.secret_key(&keychain.secp()).unwrap();

s_cx = Context::new(&keychain.secp(), blind, &parent, false, false);
s_cx = Context::new(&keychain.secp(), blind, &parent, false);
s_cx.get_public_keys(&keychain.secp())
};

Expand All @@ -306,7 +306,7 @@ fn aggsig_sender_receiver_interaction_offset() {

let blind = keychain.derive_key(0, &key_id, switch).unwrap();

rx_cx = Context::new(&keychain.secp(), blind, &parent, false, false);
rx_cx = Context::new(&keychain.secp(), blind, &parent, false);
let (pub_excess, pub_nonce) = rx_cx.get_public_keys(&keychain.secp());
rx_cx.add_output(&key_id, &None, 0);

Expand Down

0 comments on commit 9146c17

Please sign in to comment.