Refactor `create_proposed_transaction` to return the information needed
to construct a `SentTransaction`, and then call `wallet_db.store_sent_tx` outside the `create_proposed_transaction` call. This should have no semantic effect by itself, but is preparation to move where we call `store_sent_tx`. Signed-off-by: Daira-Emma Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
7c5ac7b151
commit
40358f4b69
|
@ -607,14 +607,23 @@ where
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
let mut unused_transparent_outputs = HashMap::new();
|
let mut unused_transparent_outputs = HashMap::new();
|
||||||
|
|
||||||
|
let created = time::OffsetDateTime::now_utc();
|
||||||
|
let account_id = wallet_db
|
||||||
|
.get_account_for_ufvk(&usk.to_unified_full_viewing_key())
|
||||||
|
.map_err(Error::DataSource)?
|
||||||
|
.ok_or(Error::KeyNotRecognized)?
|
||||||
|
.id();
|
||||||
|
|
||||||
let mut step_results = Vec::with_capacity(proposal.steps().len());
|
let mut step_results = Vec::with_capacity(proposal.steps().len());
|
||||||
for step in proposal.steps() {
|
for step in proposal.steps() {
|
||||||
let step_result = create_proposed_transaction(
|
#[allow(unused_variables)]
|
||||||
|
let (step_result, outputs, fee_amount, utxos_spent) = create_proposed_transaction(
|
||||||
wallet_db,
|
wallet_db,
|
||||||
params,
|
params,
|
||||||
spend_prover,
|
spend_prover,
|
||||||
output_prover,
|
output_prover,
|
||||||
usk,
|
usk,
|
||||||
|
account_id,
|
||||||
ovk_policy.clone(),
|
ovk_policy.clone(),
|
||||||
proposal.fee_rule(),
|
proposal.fee_rule(),
|
||||||
proposal.min_target_height(),
|
proposal.min_target_height(),
|
||||||
|
@ -623,6 +632,16 @@ where
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
&mut unused_transparent_outputs,
|
&mut unused_transparent_outputs,
|
||||||
)?;
|
)?;
|
||||||
|
let tx = SentTransaction {
|
||||||
|
tx: step_result.transaction(),
|
||||||
|
created,
|
||||||
|
account: account_id,
|
||||||
|
outputs,
|
||||||
|
fee_amount,
|
||||||
|
#[cfg(feature = "transparent-inputs")]
|
||||||
|
utxos_spent,
|
||||||
|
};
|
||||||
|
wallet_db.store_sent_tx(&tx).map_err(Error::DataSource)?;
|
||||||
step_results.push((step, step_result));
|
step_results.push((step, step_result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -657,6 +676,7 @@ fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
|
||||||
spend_prover: &impl SpendProver,
|
spend_prover: &impl SpendProver,
|
||||||
output_prover: &impl OutputProver,
|
output_prover: &impl OutputProver,
|
||||||
usk: &UnifiedSpendingKey,
|
usk: &UnifiedSpendingKey,
|
||||||
|
account_id: <DbT as WalletRead>::AccountId,
|
||||||
ovk_policy: OvkPolicy,
|
ovk_policy: OvkPolicy,
|
||||||
fee_rule: &FeeRuleT,
|
fee_rule: &FeeRuleT,
|
||||||
min_target_height: BlockHeight,
|
min_target_height: BlockHeight,
|
||||||
|
@ -666,7 +686,15 @@ fn create_proposed_transaction<DbT, ParamsT, InputsErrT, FeeRuleT, N>(
|
||||||
StepOutput,
|
StepOutput,
|
||||||
(TransparentAddress, OutPoint),
|
(TransparentAddress, OutPoint),
|
||||||
>,
|
>,
|
||||||
) -> Result<BuildResult, ErrorT<DbT, InputsErrT, FeeRuleT>>
|
) -> Result<
|
||||||
|
(
|
||||||
|
BuildResult,
|
||||||
|
Vec<SentTransactionOutput<<DbT as WalletRead>::AccountId>>,
|
||||||
|
NonNegativeAmount,
|
||||||
|
Vec<OutPoint>,
|
||||||
|
),
|
||||||
|
ErrorT<DbT, InputsErrT, FeeRuleT>,
|
||||||
|
>
|
||||||
where
|
where
|
||||||
DbT: WalletWrite + WalletCommitmentTrees,
|
DbT: WalletWrite + WalletCommitmentTrees,
|
||||||
ParamsT: consensus::Parameters + Clone,
|
ParamsT: consensus::Parameters + Clone,
|
||||||
|
@ -708,12 +736,6 @@ where
|
||||||
return Err(Error::ProposalNotSupported);
|
return Err(Error::ProposalNotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
let account_id = wallet_db
|
|
||||||
.get_account_for_ufvk(&usk.to_unified_full_viewing_key())
|
|
||||||
.map_err(Error::DataSource)?
|
|
||||||
.ok_or(Error::KeyNotRecognized)?
|
|
||||||
.id();
|
|
||||||
|
|
||||||
let (sapling_anchor, sapling_inputs) =
|
let (sapling_anchor, sapling_inputs) =
|
||||||
if proposal_step.involves(PoolType::Shielded(ShieldedProtocol::Sapling)) {
|
if proposal_step.involves(PoolType::Shielded(ShieldedProtocol::Sapling)) {
|
||||||
proposal_step.shielded_inputs().map_or_else(
|
proposal_step.shielded_inputs().map_or_else(
|
||||||
|
@ -903,6 +925,8 @@ where
|
||||||
}
|
}
|
||||||
utxos_spent
|
utxos_spent
|
||||||
};
|
};
|
||||||
|
#[cfg(not(feature = "transparent-inputs"))]
|
||||||
|
let utxos_spent = vec![];
|
||||||
|
|
||||||
#[cfg(feature = "orchard")]
|
#[cfg(feature = "orchard")]
|
||||||
let orchard_fvk: orchard::keys::FullViewingKey = usk.orchard().into();
|
let orchard_fvk: orchard::keys::FullViewingKey = usk.orchard().into();
|
||||||
|
@ -1278,19 +1302,9 @@ where
|
||||||
outputs.extend(sapling_outputs);
|
outputs.extend(sapling_outputs);
|
||||||
outputs.extend(transparent_outputs);
|
outputs.extend(transparent_outputs);
|
||||||
|
|
||||||
wallet_db
|
let fee_amount = proposal_step.balance().fee_required();
|
||||||
.store_sent_tx(&SentTransaction {
|
|
||||||
tx: build_result.transaction(),
|
|
||||||
created: time::OffsetDateTime::now_utc(),
|
|
||||||
account: account_id,
|
|
||||||
outputs,
|
|
||||||
fee_amount: proposal_step.balance().fee_required(),
|
|
||||||
#[cfg(feature = "transparent-inputs")]
|
|
||||||
utxos_spent,
|
|
||||||
})
|
|
||||||
.map_err(Error::DataSource)?;
|
|
||||||
|
|
||||||
Ok(build_result)
|
Ok((build_result, outputs, fee_amount, utxos_spent))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a transaction that consumes available transparent UTXOs belonging to the specified
|
/// Constructs a transaction that consumes available transparent UTXOs belonging to the specified
|
||||||
|
|
Loading…
Reference in New Issue