diff --git a/utt/include/transaction.hpp b/utt/include/transaction.hpp index 7e7d317250..d0283b5916 100644 --- a/utt/include/transaction.hpp +++ b/utt/include/transaction.hpp @@ -89,4 +89,13 @@ class Transaction { struct Impl; Impl* pImpl_; }; -} // namespace libutt::api::operations \ No newline at end of file + +class InvalidCoinsInTransfer : public std::exception { + public: + explicit InvalidCoinsInTransfer(const std::string& what) : msg(what){}; + virtual const char* what() const noexcept override { return msg.c_str(); } + + private: + std::string msg; +}; +} // namespace libutt::api::operations diff --git a/utt/privacy-wallet-service/include/PrivacyService.hpp b/utt/privacy-wallet-service/include/PrivacyService.hpp index 50f026c1dc..e7edec2677 100644 --- a/utt/privacy-wallet-service/include/PrivacyService.hpp +++ b/utt/privacy-wallet-service/include/PrivacyService.hpp @@ -22,6 +22,7 @@ #include "Wallet.hpp" #include #include +#include namespace utt::walletservice { //@TODO hide on its own file.. @@ -106,4 +107,4 @@ class PrivacyWalletService { std::unique_ptr grpc_server_; std::unique_ptr privacy_wallet_service_; }; -} // namespace utt::walletservice \ No newline at end of file +} // namespace utt::walletservice diff --git a/utt/privacy-wallet-service/proto/api/v1/wallet-api.proto b/utt/privacy-wallet-service/proto/api/v1/wallet-api.proto index 1624a1698a..1dd1eaf9f3 100644 --- a/utt/privacy-wallet-service/proto/api/v1/wallet-api.proto +++ b/utt/privacy-wallet-service/proto/api/v1/wallet-api.proto @@ -69,6 +69,7 @@ message ClaimCoinsRequest { message ClaimCoinsReponse { bool succ = 1; + string warning = 2; } message GenerateMintTx { @@ -154,4 +155,4 @@ message PrivacyWalletResponse { SetAppDataResponse set_app_data_response = 9; GetAppDataResponse get_app_data_response = 10; } -} \ No newline at end of file +} diff --git a/utt/privacy-wallet-service/src/PrivacyService.cpp b/utt/privacy-wallet-service/src/PrivacyService.cpp index 2abe63539f..3fd9fa6806 100644 --- a/utt/privacy-wallet-service/src/PrivacyService.cpp +++ b/utt/privacy-wallet-service/src/PrivacyService.cpp @@ -275,14 +275,16 @@ ::grpc::Status PrivacyWalletServiceImpl::handleUserClaimCoinsRequest(::grpc::Ser response->set_err(err_msg); return grpc::Status(grpc::StatusCode::ABORTED, err_msg); } + } catch (const libutt::api::operations::InvalidCoinsInTransfer& e) { + std::cout << e.what() << std::endl; + response->mutable_claim_coins_response()->set_warning(e.what()); } catch (const std::exception& e) { std::cout << e.what() << std::endl; response->set_err(e.what()); return grpc::Status(grpc::StatusCode::ABORTED, e.what()); } if (response) { - auto resp = response->mutable_claim_coins_response(); - resp->set_succ(true); + response->mutable_claim_coins_response()->set_succ(true); } return grpc::Status::OK; } @@ -428,4 +430,4 @@ ::grpc::Status PrivacyWalletServiceImpl::handleGetAppDataRequest( return grpc::Status::OK; } -} // namespace utt::walletservice \ No newline at end of file +} // namespace utt::walletservice diff --git a/utt/utt-client-api/src/User.cpp b/utt/utt-client-api/src/User.cpp index 4093e920e1..d2bb992a7e 100644 --- a/utt/utt-client-api/src/User.cpp +++ b/utt/utt-client-api/src/User.cpp @@ -447,9 +447,13 @@ void User::updateTransferTx(const Transaction& tx, const TxOutputSigs& sigs) { // Claim coins auto claimedCoins = pImpl_->client_->claimCoins(uttTx, pImpl_->params_, sigs); - + bool invalidCoinsInTransfer(false); for (auto& coin : claimedCoins) { - if (!pImpl_->client_->validate(coin)) throw std::runtime_error("Invalid normal coin in transfer!"); + if (!pImpl_->client_->validate(coin)) { + logdbg_user << "Invalid coin found; coin details: " << dbgPrintCoins({coin}) << endl; + invalidCoinsInTransfer = true; + continue; + } pImpl_->storage_->setCoin(coin); if (coin.getType() == libutt::api::Coin::Type::Normal) { logdbg_user << "claimed normal coin: " << dbgPrintCoins({coin}) << endl; @@ -464,6 +468,9 @@ void User::updateTransferTx(const Transaction& tx, const TxOutputSigs& sigs) { } } } + if (invalidCoinsInTransfer) { + throw libutt::api::operations::InvalidCoinsInTransfer("Invalid normal coin(s) in transfer!"); + } } } @@ -617,4 +624,4 @@ void User::debugOutput() const { std::cout << "------ USER DEBUG OUTPUT END -------------\n"; } -} // namespace utt::client \ No newline at end of file +} // namespace utt::client