Skip to content

Commit

Permalink
payment: differentiate insufficient account / deposit funds
Browse files Browse the repository at this point in the history
  • Loading branch information
kamirr committed Jul 9, 2024
1 parent ce88369 commit 754cd58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/model/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ impl ValidateAllocation {

#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum ValidateAllocationResult {
InsufficientFunds,
InsufficientAccountFunds,
InsufficientDepositFunds,
TimeoutExceedsDeposit,
MalformedDepositContract,
MalformedDepositId,
Expand Down
4 changes: 2 additions & 2 deletions core/payment-driver/erc20/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl Erc20Driver {
);

Ok(if msg.amount > account_balance - total_allocated_amount {
ValidateAllocationResult::InsufficientFunds
ValidateAllocationResult::InsufficientAccountFunds
} else {
ValidateAllocationResult::Valid
})
Expand Down Expand Up @@ -483,7 +483,7 @@ impl Erc20Driver {
deposit_balance
);

return Ok(ValidateAllocationResult::InsufficientFunds);
return Ok(ValidateAllocationResult::InsufficientDepositFunds);
}

if let Some(timeout) = msg.timeout {
Expand Down
14 changes: 12 additions & 2 deletions core/payment/src/api/allocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,15 @@ async fn create_allocation(

match async move { Ok(bus::service(LOCAL_SERVICE).send(validate_msg).await??) }.await {
Ok(ValidateAllocationResult::Valid) => {}
Ok(ValidateAllocationResult::InsufficientFunds) => {
Ok(ValidateAllocationResult::InsufficientAccountFunds) => {
return bad_req_and_log(format!("Insufficient funds to make allocation for payment platform {payment_triple}. \
Top up your account or release all existing allocations to unlock the funds via `yagna payment release-allocations`"));
}
Ok(ValidateAllocationResult::InsufficientDepositFunds) => {
return bad_req_and_log(
"Insufficient funds on the deposit for this allocation".to_string(),
);
}
Ok(ValidateAllocationResult::TimeoutExceedsDeposit) => {
return bad_req_and_log(
"Requested allocation timeout either not set or exceeds deposit timeout"
Expand Down Expand Up @@ -522,10 +527,15 @@ async fn amend_allocation(
};
match async move { Ok(bus::service(LOCAL_SERVICE).send(validate_msg).await??) }.await {
Ok(ValidateAllocationResult::Valid) => {}
Ok(ValidateAllocationResult::InsufficientFunds) => {
Ok(ValidateAllocationResult::InsufficientAccountFunds) => {
return bad_req_and_log(format!("Insufficient funds to make allocation for payment platform {payment_triple}. \
Top up your account or release all existing allocations to unlock the funds via `yagna payment release-allocations`"));
}
Ok(ValidateAllocationResult::InsufficientDepositFunds) => {
return bad_req_and_log(
"Insufficient funds on the deposit for this allocation".to_string(),
);
}
Ok(ValidateAllocationResult::TimeoutExceedsDeposit) => {
return bad_req_and_log(
"Requested allocation timeout either not set or exceeds deposit timeout"
Expand Down

0 comments on commit 754cd58

Please sign in to comment.