-
Notifications
You must be signed in to change notification settings - Fork 1.2k
adds rpc calls for setprivatesendrounds
and setprivatesendamount
#2230
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
Conversation
src/wallet/rpcwallet.cpp
Outdated
+ HelpExampleRpc("setprivatesendrounds", "16") | ||
); | ||
|
||
LOCK2(cs_main, pwalletMain->cs_wallet); |
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.
not sure if needed, the LOCK2
that is
This methods parameters should be added to the https://github.com/dashpay/dash/blob/develop/src/rpc/client.cpp#L30, as far as I can see. |
Hmm, @gladcow would that just be |
It should be smth like |
src/wallet/rpcwallet.cpp
Outdated
if (!EnsureWalletIsAvailable(request.fHelp)) | ||
return NullUniValue; | ||
|
||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) |
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.
request.params.size() != 1
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.
yup, that was just a copy / pasta
src/wallet/rpcwallet.cpp
Outdated
"1. rounds (numeric, required) The default number of rounds is " + std::to_string(DEFAULT_PRIVATESEND_ROUNDS) + | ||
" Cannot be more than " + std::to_string(MAX_PRIVATESEND_ROUNDS) + " nor less than " + std::to_string(MIN_PRIVATESEND_ROUNDS) + | ||
"\nResult:\n" | ||
"true|false (boolean) Returns true if successful\n" |
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.
There is no way for this to fail, should have no Results
at all imo.
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.
I agree, was just following the setup of the rpc command above it setfee
I think
src/wallet/rpcwallet.cpp
Outdated
+ HelpExampleRpc("setprivatesendrounds", "16") | ||
); | ||
|
||
LOCK2(cs_main, pwalletMain->cs_wallet); |
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.
Not needed. We should probably have some PS client specific lock but this is out of the scope of this PR.
src/wallet/rpcwallet.cpp
Outdated
LOCK2(cs_main, pwalletMain->cs_wallet); | ||
|
||
// Amount | ||
CAmount nRounds = AmountFromValue(request.params[0]); |
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.
Mixing rounds are int
s.
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.
how would I grab that from a Value
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.
request.params[0].get_int()
?
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.
since it compiled, I thought there must just be a conversion form CAmount to int as CAmount is an int of some size if I remember right
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.
Yeah, CAmount is just a int64, so if I just define it as
int nRounds = AmountFromValue(request.params[0]);
I would think that would work... Although I'm not even sure that's necessary
Thoughts?
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.
I think you are overcomplicating things a bit here :)
privateSendClient.nPrivateSendRounds = request.params[0].get_int();
This ^^^ should do the job just fine without the need for 1) temporary variable and 2) conversions back and forth.
src/wallet/rpcwallet.cpp
Outdated
|
||
privateSendClient.nPrivateSendRounds = nRounds; | ||
|
||
return true; |
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.
Should have no result (see above) and simply call return NullUniValue;
here.
src/wallet/rpcwallet.cpp
Outdated
if (request.fHelp || request.params.size() < 1 || request.params.size() > 1) | ||
throw std::runtime_error( | ||
"setprivatesendamount amount\n" | ||
"\nSet the goal amount for PrivateSend mixing.\n" |
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.
Pls insert in " + CURRENCY_UNIT + "
after amount
.
src/wallet/rpcwallet.cpp
Outdated
"\nArguments:\n" | ||
"1. amount (numeric, required) The default amount is " + std::to_string(DEFAULT_PRIVATESEND_AMOUNT) + | ||
" Cannot be more than " + std::to_string(MAX_PRIVATESEND_AMOUNT) + " nor less than " + std::to_string(MIN_PRIVATESEND_AMOUNT) + | ||
"\nResult:\n" |
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.
Same as for setprivatesendrounds
.
src/wallet/rpcwallet.cpp
Outdated
+ HelpExampleRpc("setprivatesendamount", "208") | ||
); | ||
|
||
LOCK2(cs_main, pwalletMain->cs_wallet); |
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.
Same as for setprivatesendrounds
.
src/wallet/rpcwallet.cpp
Outdated
LOCK2(cs_main, pwalletMain->cs_wallet); | ||
|
||
// Amount | ||
CAmount nAmount = AmountFromValue(request.params[0]); |
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.
Same as for setprivatesendrounds
.
src/wallet/rpcwallet.cpp
Outdated
|
||
privateSendClient.nPrivateSendAmount = nAmount; | ||
|
||
return true; |
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.
Same as for setprivatesendrounds
.
@UdjinM6 All changes applied 😄 |
src/wallet/rpcwallet.cpp
Outdated
|
||
int nRounds = request.params[0].get_int(); | ||
|
||
privateSendClient.nPrivateSendRounds = nRounds; |
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.
Why not squashing 2 lines into 1 i.e. privateSendClient.nPrivateSendRounds = request.params[0].get_int()
? (same for amount
)
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.
Ah, wait a minute... you must also make sure that values actually fin into min/max.
EDIT: e.g
privateSendClient.nPrivateSendRounds = std::min(std::max(request.params[0].get_int(), MIN_PRIVATESEND_ROUNDS), MAX_PRIVATESEND_ROUNDS);
EDIT2: fixed copy/paste mistake in the code example above 🙈
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.
Would that be best, or would it be better to return an error / return false
if it doesn't fit in the range?
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.
Hmm.. good idea 👍 But instead of returning false
should probably throw an error i.e. smth like
if (nRounds < MIN_PRIVATESEND_ROUNDS || nRounds > MAX_PRIVATESEND_ROUNDS)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid number of rounds");
Implemented that check + error throw @UdjinM6 |
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.
utACK
…ashpay#2230) * adds rpc calls for `setprivatesendrounds` and `setprivatesendamount` * tabs -> spaces * @gladcow change request * Whops tab -> spaces * @Udjin changes, not the CAmount -> int * int stuff * Throw error when rounds / amount isn't within range
Not tested yet. Not positive about help text, but it's probably fine.