adds rpc calls for setprivatesendrounds and setprivatesendamount#2230
adds rpc calls for setprivatesendrounds and setprivatesendamount#2230UdjinM6 merged 7 commits intodashpay:developfrom
setprivatesendrounds and setprivatesendamount#2230Conversation
src/wallet/rpcwallet.cpp
Outdated
| + HelpExampleRpc("setprivatesendrounds", "16") | ||
| ); | ||
|
|
||
| LOCK2(cs_main, pwalletMain->cs_wallet); |
There was a problem hiding this comment.
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.
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.
There is no way for this to fail, should have no Results at all imo.
There was a problem hiding this comment.
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.
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.
how would I grab that from a Value
There was a problem hiding this comment.
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.
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.
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.
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.
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" |
src/wallet/rpcwallet.cpp
Outdated
| + HelpExampleRpc("setprivatesendamount", "208") | ||
| ); | ||
|
|
||
| LOCK2(cs_main, pwalletMain->cs_wallet); |
src/wallet/rpcwallet.cpp
Outdated
| LOCK2(cs_main, pwalletMain->cs_wallet); | ||
|
|
||
| // Amount | ||
| CAmount nAmount = AmountFromValue(request.params[0]); |
src/wallet/rpcwallet.cpp
Outdated
|
|
||
| privateSendClient.nPrivateSendAmount = nAmount; | ||
|
|
||
| return true; |
|
@UdjinM6 All changes applied 😄 |
|
|
||
| int nRounds = request.params[0].get_int(); | ||
|
|
||
| privateSendClient.nPrivateSendRounds = nRounds; |
There was a problem hiding this comment.
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.
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.
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.
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 |
…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.