Create dummy spend in empty builder by default (#36)

This commit is contained in:
Alexey Koren 2022-12-18 13:53:27 +01:00 committed by GitHub
parent d8f3563c1c
commit 5a50fb8d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -387,7 +387,7 @@ impl Builder {
// Pair up the spends and recipients, extending with dummy values as necessary.
for (asset, (mut spends, mut recipients)) in
partition_by_asset(&self.spends, &self.recipients)
partition_by_asset(&self.spends, &self.recipients, &mut rng)
{
let num_spends = spends.len();
let num_recipients = recipients.len();
@ -475,10 +475,12 @@ impl Builder {
}
}
/// partition a list of spends and recipients by note types.
/// Partition a list of spends and recipients by note types.
/// Method creates single dummy ZEC note if spends and recipients are both empty.
fn partition_by_asset(
spends: &[SpendInfo],
recipients: &[RecipientInfo],
rng: &mut impl RngCore,
) -> HashMap<AssetId, (Vec<SpendInfo>, Vec<RecipientInfo>)> {
let mut hm = HashMap::new();
@ -496,6 +498,11 @@ fn partition_by_asset(
.push(r.clone())
}
if hm.is_empty() {
let dummy_spend = SpendInfo::dummy(AssetId::native(), rng);
hm.insert(dummy_spend.note.asset(), (vec![dummy_spend], vec![]));
}
hm
}