forked from swar16/TradeDex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollateralVault.cpp
More file actions
24 lines (21 loc) · 864 Bytes
/
CollateralVault.cpp
File metadata and controls
24 lines (21 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "CollateralVault.hpp"
void CollateralVault::depositCollateral(const std::string &user, double amount) {
if (amount <= 0) {
throw std::invalid_argument("Deposit amount must be positive");
}
balances_[user].totalCollateral += amount;
}
void CollateralVault::withdrawCollateral(const std::string &user, double amount) {
auto it = balances_.find(user);
if (it == balances_.end() || it->second.totalCollateral < amount) {
throw std::runtime_error("Insufficient collateral for withdrawal");
}
if (amount <= 0) {
throw std::invalid_argument("Withdrawal amount must be positive");
}
it->second.totalCollateral -= amount;
}
double CollateralVault::getBalance(const std::string &user) const {
auto it = balances_.find(user);
return (it == balances_.end()) ? 0.0 : it->second.totalCollateral;
}