Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend_task/core/create_asset_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ impl AppContext {
let mut wallet_guard = wallet.write().map_err(|e| e.to_string())?;

wallet_guard.registration_asset_lock_transaction(
self,
self.network,
amount_duffs,
allow_take_fee_from_amount,
identity_index,
Some(self),
)?
};

Expand Down Expand Up @@ -64,12 +64,12 @@ impl AppContext {
let mut wallet_guard = wallet.write().map_err(|e| e.to_string())?;

wallet_guard.top_up_asset_lock_transaction(
self,
self.network,
amount_duffs,
allow_take_fee_from_amount,
identity_index,
top_up_index,
Some(self),
)?
};

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ impl AppContext {
return Err("Wallet must be unlocked".to_string());
}
wallet_guard.build_multi_recipient_payment_transaction(
self,
self.network,
&parsed_recipients,
DEFAULT_TX_FEE,
request.subtract_fee_from_amount,
Some(self),
)?
};

Expand Down
9 changes: 6 additions & 3 deletions src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,11 @@ impl AppContext {
{
let (public_key_map, public_key_hash_map) = wallet
.identity_authentication_ecdsa_public_keys_data_map(
self,
true,
self.network,
identity_index,
0..top_bound,
Some(self),
)?;
let wallet_private_keys = self.build_wallet_private_key_map(
identity,
Expand All @@ -434,10 +435,11 @@ impl AppContext {
for candidate_index in 0..MAX_IDENTITY_INDEX {
let (public_key_map, public_key_hash_map) = wallet
.identity_authentication_ecdsa_public_keys_data_map(
self,
false,
self.network,
candidate_index,
0..top_bound,
None,
)?;

if !Self::identity_matches_wallet_key_material(
Expand All @@ -450,10 +452,11 @@ impl AppContext {

let (public_key_map, public_key_hash_map) = wallet
.identity_authentication_ecdsa_public_keys_data_map(
self,
true,
self.network,
candidate_index,
0..top_bound,
Some(self),
)?;

let wallet_private_keys = self.build_wallet_private_key_map(
Expand Down
3 changes: 2 additions & 1 deletion src/backend_task/identity/load_identity_from_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ impl AppContext {
let mut wallet = wallet_arc_ref.wallet.write().unwrap();
wallet_seed_hash = wallet.seed_hash();
wallet.identity_authentication_ecdsa_public_keys_data_map(
self,
true,
self.network,
identity_index,
0..top_bound,
Some(self),
)?
};

Expand Down
6 changes: 3 additions & 3 deletions src/backend_task/identity/register_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ impl AppContext {
let mut wallet = wallet.write().map_err(|e| e.to_string())?;
wallet_id = wallet.seed_hash();
match wallet.registration_asset_lock_transaction(
self,
sdk.network,
amount,
true,
identity_index,
Some(self),
) {
Ok(transaction) => transaction,
Err(e) => {
Expand All @@ -109,11 +109,11 @@ impl AppContext {
return Err(e);
}
wallet.registration_asset_lock_transaction(
self,
sdk.network,
amount,
true,
identity_index,
Some(self),
)?
}
}
Expand Down Expand Up @@ -201,12 +201,12 @@ impl AppContext {
let mut wallet = wallet.write().unwrap();
wallet_id = wallet.seed_hash();
wallet.registration_asset_lock_transaction_for_utxo(
self,
sdk.network,
utxo,
tx_out.clone(),
input_address.clone(),
identity_index,
Some(self),
)?
};

Expand Down
6 changes: 3 additions & 3 deletions src/backend_task/identity/top_up_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ impl AppContext {
let mut wallet = wallet.write().map_err(|e| e.to_string())?;
let seed_hash = wallet.seed_hash();
let tx_result = match wallet.top_up_asset_lock_transaction(
self,
sdk.network,
amount,
true,
identity_index,
top_up_index,
Some(self),
) {
Ok(transaction) => transaction,
Err(e) => {
Expand All @@ -117,12 +117,12 @@ impl AppContext {
return Err(e);
}
wallet.top_up_asset_lock_transaction(
self,
sdk.network,
amount,
true,
identity_index,
top_up_index,
Some(self),
)?
}
};
Expand Down Expand Up @@ -179,13 +179,13 @@ impl AppContext {
let mut wallet = wallet.write().unwrap();
let seed_hash = wallet.seed_hash();
let tx_result = wallet.top_up_asset_lock_transaction_for_utxo(
self,
sdk.network,
utxo,
tx_out.clone(),
input_address.clone(),
identity_index,
top_up_index,
Some(self),
)?;
(tx_result.0, tx_result.1, seed_hash)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ impl AppContext {

// Try to create the asset lock transaction, reload UTXOs if needed
match wallet.generic_asset_lock_transaction(
self,
self.network,
asset_lock_amount,
allow_take_fee_from_amount,
Some(self),
) {
Ok((tx, private_key, address, _change, utxos)) => (tx, private_key, address, utxos),
Err(e) => {
Expand All @@ -67,10 +67,10 @@ impl AppContext {
}
let (tx, private_key, address, _change, utxos) = wallet
.generic_asset_lock_transaction(
self,
self.network,
asset_lock_amount,
allow_take_fee_from_amount,
Some(self),
)?;
(tx, private_key, address, utxos)
}
Expand Down
42 changes: 17 additions & 25 deletions src/model/wallet/asset_lock_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ impl Wallet {
#[allow(clippy::type_complexity)]
pub fn registration_asset_lock_transaction(
&mut self,
app_context: &AppContext,
network: Network,
amount: u64,
allow_take_fee_from_amount: bool,
identity_index: u32,
register_addresses: Option<&AppContext>,
) -> Result<
(
Transaction,
Expand All @@ -177,29 +177,26 @@ impl Wallet {
),
String,
> {
let private_key = self.identity_registration_ecdsa_private_key(
network,
identity_index,
register_addresses,
)?;
let private_key =
self.identity_registration_ecdsa_private_key(app_context, network, identity_index)?;
self.asset_lock_transaction_from_private_key(
app_context,
network,
amount,
allow_take_fee_from_amount,
private_key,
register_addresses,
)
}

#[allow(clippy::type_complexity)]
pub fn top_up_asset_lock_transaction(
&mut self,
app_context: &AppContext,
network: Network,
amount: u64,
allow_take_fee_from_amount: bool,
identity_index: u32,
top_up_index: u32,
register_addresses: Option<&AppContext>,
) -> Result<
(
Transaction,
Expand All @@ -210,17 +207,17 @@ impl Wallet {
String,
> {
let private_key = self.identity_top_up_ecdsa_private_key(
app_context,
network,
identity_index,
top_up_index,
register_addresses,
)?;
self.asset_lock_transaction_from_private_key(
app_context,
network,
amount,
allow_take_fee_from_amount,
private_key,
register_addresses,
)
}

Expand All @@ -229,10 +226,10 @@ impl Wallet {
#[allow(clippy::type_complexity)]
pub fn generic_asset_lock_transaction(
&mut self,
app_context: &AppContext,
network: Network,
amount: u64,
allow_take_fee_from_amount: bool,
register_addresses: Option<&AppContext>,
) -> Result<
(
Transaction,
Expand All @@ -256,11 +253,11 @@ impl Wallet {

let (tx, returned_private_key, change_address, used_utxos) = self
.asset_lock_transaction_from_private_key(
app_context,
network,
amount,
allow_take_fee_from_amount,
private_key,
register_addresses,
)?;

Ok((
Expand All @@ -275,11 +272,11 @@ impl Wallet {
#[allow(clippy::type_complexity)]
fn asset_lock_transaction_from_private_key(
&mut self,
app_context: &AppContext,
network: Network,
amount: u64,
allow_take_fee_from_amount: bool,
private_key: PrivateKey,
register_addresses: Option<&AppContext>,
) -> Result<
(
Transaction,
Expand Down Expand Up @@ -323,7 +320,7 @@ impl Wallet {
};

let (change_output, change_address) = if let Some(change) = change_option {
let change_address = self.change_address(network, register_addresses)?;
let change_address = self.change_address(network, Some(app_context))?;
(
Some(TxOut {
value: change,
Expand Down Expand Up @@ -431,27 +428,22 @@ impl Wallet {
})?;

// Transaction is fully built and signed; commit the UTXO removals now.
if let Some(context) = register_addresses {
self.remove_selected_utxos(&utxos, &context.db, network)?;
}
self.remove_selected_utxos(&utxos, &app_context.db, network)?;

Ok((tx, private_key, change_address, utxos))
}

pub fn registration_asset_lock_transaction_for_utxo(
&mut self,
app_context: &AppContext,
network: Network,
utxo: OutPoint,
previous_tx_output: TxOut,
input_address: Address,
identity_index: u32,
register_addresses: Option<&AppContext>,
) -> Result<(Transaction, PrivateKey), String> {
let private_key = self.identity_registration_ecdsa_private_key(
network,
identity_index,
register_addresses,
)?;
let private_key =
self.identity_registration_ecdsa_private_key(app_context, network, identity_index)?;
self.asset_lock_transaction_for_utxo_from_private_key(
network,
utxo,
Expand All @@ -464,19 +456,19 @@ impl Wallet {
#[allow(clippy::too_many_arguments)]
pub fn top_up_asset_lock_transaction_for_utxo(
&mut self,
app_context: &AppContext,
network: Network,
utxo: OutPoint,
previous_tx_output: TxOut,
input_address: Address,
identity_index: u32,
top_up_index: u32,
register_addresses: Option<&AppContext>,
) -> Result<(Transaction, PrivateKey), String> {
let private_key = self.identity_top_up_ecdsa_private_key(
app_context,
network,
identity_index,
top_up_index,
register_addresses,
)?;
self.asset_lock_transaction_for_utxo_from_private_key(
network,
Expand Down
Loading
Loading