|
@@ -58,25 +58,26 @@ impl Transaction {
|
|
|
}
|
|
|
|
|
|
let id = TransactionId::new(hasher.finalize().into());
|
|
|
+ let create = pay_to
|
|
|
+ .into_iter()
|
|
|
+ .enumerate()
|
|
|
+ .map(|(position, (to, amount))| Payment {
|
|
|
+ id: crate::PaymentId {
|
|
|
+ transaction: id.clone(),
|
|
|
+ position,
|
|
|
+ },
|
|
|
+ to,
|
|
|
+ amount,
|
|
|
+ spent_by: None,
|
|
|
+ status: status.clone(),
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
|
|
|
Ok(Self {
|
|
|
id,
|
|
|
spend: vec![],
|
|
|
+ create,
|
|
|
reference,
|
|
|
- create: pay_to
|
|
|
- .into_iter()
|
|
|
- .enumerate()
|
|
|
- .map(|(position, (to, amount))| Payment {
|
|
|
- id: crate::PaymentId {
|
|
|
- transaction: id,
|
|
|
- position,
|
|
|
- },
|
|
|
- to,
|
|
|
- amount,
|
|
|
- spent_by: None,
|
|
|
- status: status.clone(),
|
|
|
- })
|
|
|
- .collect(),
|
|
|
is_external_deposit: true,
|
|
|
status,
|
|
|
})
|
|
@@ -100,38 +101,41 @@ impl Transaction {
|
|
|
let id = TransactionId::new(hasher.finalize().into());
|
|
|
|
|
|
for (i, input) in spend.iter().enumerate() {
|
|
|
- if input.spent_by.is_some() && input.spent_by != Some(id) {
|
|
|
+ if input.spent_by.is_some() && input.spent_by.as_ref() != Some(&id) {
|
|
|
return Err(Error::SpentPayment(i));
|
|
|
}
|
|
|
if input.spent_by.is_none() && input.status != Status::Settled {
|
|
|
return Err(Error::InvalidPaymentStatus(i, input.status.clone()));
|
|
|
}
|
|
|
}
|
|
|
+ let spend = spend
|
|
|
+ .into_iter()
|
|
|
+ .map(|mut input| {
|
|
|
+ input.spent_by = Some(id.clone());
|
|
|
+ input
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
+
|
|
|
+ let create = pay_to
|
|
|
+ .into_iter()
|
|
|
+ .enumerate()
|
|
|
+ .map(|(position, (to, amount))| Payment {
|
|
|
+ id: crate::PaymentId {
|
|
|
+ transaction: id.clone(),
|
|
|
+ position,
|
|
|
+ },
|
|
|
+ to,
|
|
|
+ amount,
|
|
|
+ spent_by: None,
|
|
|
+ status: status.clone(),
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
|
|
|
Ok(Self {
|
|
|
id,
|
|
|
reference,
|
|
|
- spend: spend
|
|
|
- .into_iter()
|
|
|
- .map(|mut input| {
|
|
|
- input.spent_by = Some(id);
|
|
|
- input
|
|
|
- })
|
|
|
- .collect(),
|
|
|
- create: pay_to
|
|
|
- .into_iter()
|
|
|
- .enumerate()
|
|
|
- .map(|(position, (to, amount))| Payment {
|
|
|
- id: crate::PaymentId {
|
|
|
- transaction: id,
|
|
|
- position,
|
|
|
- },
|
|
|
- to,
|
|
|
- amount,
|
|
|
- spent_by: None,
|
|
|
- status: status.clone(),
|
|
|
- })
|
|
|
- .collect(),
|
|
|
+ spend,
|
|
|
+ create,
|
|
|
is_external_deposit: false,
|
|
|
status,
|
|
|
})
|
|
@@ -177,7 +181,7 @@ impl Transaction {
|
|
|
let mut credit = HashMap::<Asset, AmountCents>::new();
|
|
|
|
|
|
for (i, input) in self.spend.iter().enumerate() {
|
|
|
- if input.spent_by.is_some() && input.spent_by != Some(self.id) {
|
|
|
+ if input.spent_by.is_some() && input.spent_by.as_ref() != Some(&self.id) {
|
|
|
return Err(Error::SpentPayment(i));
|
|
|
}
|
|
|
if let Some(value) = debit.get_mut(input.amount.asset()) {
|
|
@@ -247,7 +251,7 @@ impl Transaction {
|
|
|
batch.store_new_payments(&self.create).await?;
|
|
|
for input in self.spend.iter_mut() {
|
|
|
batch
|
|
|
- .spend_payment(input.id, self.status.clone(), self.id)
|
|
|
+ .spend_payment(&input.id, self.status.clone(), &self.id)
|
|
|
.await?;
|
|
|
}
|
|
|
batch.commit().await?;
|