Skip to content

adds rpc calls for setprivatesendrounds and setprivatesendamount - #2230

Merged
UdjinM6 merged 7 commits into
dashpay:developfrom
PastaPastaPasta:rpcAdds
Aug 21, 2018
Merged

adds rpc calls for setprivatesendrounds and setprivatesendamount#2230
UdjinM6 merged 7 commits into
dashpay:developfrom
PastaPastaPasta:rpcAdds

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Not tested yet. Not positive about help text, but it's probably fine.

Comment thread src/wallet/rpcwallet.cpp Outdated
+ HelpExampleRpc("setprivatesendrounds", "16")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

@PastaPastaPasta PastaPastaPasta Aug 17, 2018

Copy link
Copy Markdown
Member Author

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

@gladcow

gladcow commented Aug 17, 2018

Copy link
Copy Markdown

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.

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

Hmm, @gladcow would that just be { "setprivatesendrounds", 1, "rounds" }, and { "setprivatesendamount", 1, "amount" }, ? I don't quite understand that list so...

@gladcow

gladcow commented Aug 17, 2018

Copy link
Copy Markdown

It should be smth like { "setprivatesendrounds", 0, "rounds" }, parameter index is zero-based. This list is used to convert non-string rpc parameters to their real type, both your methods use number parameters, so this parameters should be added here.

Comment thread src/wallet/rpcwallet.cpp Outdated
if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;

if (request.fHelp || request.params.size() < 1 || request.params.size() > 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request.params.size() != 1

Copy link
Copy Markdown
Member Author

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

Comment thread 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"

Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Member Author

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

Comment thread src/wallet/rpcwallet.cpp Outdated
+ HelpExampleRpc("setprivatesendrounds", "16")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

Copy link
Copy Markdown

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.

Comment thread src/wallet/rpcwallet.cpp Outdated
LOCK2(cs_main, pwalletMain->cs_wallet);

// Amount
CAmount nRounds = AmountFromValue(request.params[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing rounds are ints.

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown

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() ?

Copy link
Copy Markdown
Member Author

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

Copy link
Copy Markdown
Member Author

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?

Copy link
Copy Markdown

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.

Comment thread src/wallet/rpcwallet.cpp Outdated

privateSendClient.nPrivateSendRounds = nRounds;

return true;

Copy link
Copy Markdown

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.

Comment thread 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"

Copy link
Copy Markdown

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.

Comment thread 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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for setprivatesendrounds.

Comment thread src/wallet/rpcwallet.cpp Outdated
+ HelpExampleRpc("setprivatesendamount", "208")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for setprivatesendrounds.

Comment thread src/wallet/rpcwallet.cpp Outdated
LOCK2(cs_main, pwalletMain->cs_wallet);

// Amount
CAmount nAmount = AmountFromValue(request.params[0]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for setprivatesendrounds.

Comment thread src/wallet/rpcwallet.cpp Outdated

privateSendClient.nPrivateSendAmount = nAmount;

return true;

Copy link
Copy Markdown

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 UdjinM6 added this to the 12.4 milestone Aug 17, 2018
@PastaPastaPasta

Copy link
Copy Markdown
Member Author

@UdjinM6 All changes applied 😄

Comment thread src/wallet/rpcwallet.cpp

int nRounds = request.params[0].get_int();

privateSendClient.nPrivateSendRounds = nRounds;

Copy link
Copy Markdown

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)

@UdjinM6 UdjinM6 Aug 17, 2018

Copy link
Copy Markdown

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 🙈

Copy link
Copy Markdown
Member Author

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?

@UdjinM6 UdjinM6 Aug 17, 2018

Copy link
Copy Markdown

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");

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

Implemented that check + error throw @UdjinM6

@UdjinM6 UdjinM6 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@UdjinM6
UdjinM6 merged commit 98ed90c into dashpay:develop Aug 21, 2018
@PastaPastaPasta
PastaPastaPasta deleted the rpcAdds branch September 15, 2018 02:08
thephez added a commit to thephez/dash-docs that referenced this pull request Oct 23, 2018
thephez added a commit to dash-docs/dash-docs that referenced this pull request Nov 19, 2018
CryptoCentric pushed a commit to absolute-community/absolute that referenced this pull request Apr 25, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants