Skip to content

Commit

Permalink
Merge pull request #3194 from golemfactory/kek/informative-allocation…
Browse files Browse the repository at this point in the history
…-errors

payment: differentiate insufficient account / deposit funds
  • Loading branch information
kamirr authored Apr 24, 2024
2 parents 0d353ab + 5e433f3 commit e456684
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 @@ -407,7 +407,7 @@ impl Erc20Driver {
);

Ok(if msg.amount > account_balance - total_allocated_amount {
ValidateAllocationResult::InsufficientFunds
ValidateAllocationResult::InsufficientAccountFunds
} else {
ValidateAllocationResult::Valid
})
Expand Down Expand Up @@ -504,7 +504,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 e456684

Please sign in to comment.