-
Notifications
You must be signed in to change notification settings - Fork 148
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
Changes to handle invalid coin(s) in privacy-wallet-service. #3002
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the regular convention here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll update in the next commit. |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not throw the exception here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to prevent prematurely exiting from the function. The recipient should be able to claim coins received after the invalid coin, so I am letting it process all coins before raising the exception. |
||
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 | ||
} // namespace utt::client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, shouldn't we return false in the succ?
Also, I would suggest returning the invalid nullifiers and the reply.
Finally, we need to expose a way for the user to remove these invalid coins, otherwise it won't be able to proceed (the invalid coins will be chose over and over again)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, the recipent was able to claim coins received. Reporting back false after claiming all valid coins seems incorrect to me. The more correct approach seems to be to return true with a warning.
I didn't want the dapp to handle the invalid coins, but this is something that can be implemented. I'll discuss with you in more detail.