Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payment: differentiate insufficient account / deposit funds #3194

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading