Skip to content

Conversation

PastaPastaPasta
Copy link
Member

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

+ HelpExampleRpc("setprivatesendrounds", "16")
);

LOCK2(cs_main, pwalletMain->cs_wallet);
Copy link
Member Author

@PastaPastaPasta PastaPastaPasta Aug 17, 2018

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
Copy link

gladcow commented Aug 17, 2018

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
Member Author

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

@gladcow
Copy link

gladcow commented Aug 17, 2018

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.

if (!EnsureWalletIsAvailable(request.fHelp))
return NullUniValue;

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

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
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

"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

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
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

+ HelpExampleRpc("setprivatesendrounds", "16")
);

LOCK2(cs_main, pwalletMain->cs_wallet);
Copy link

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.

LOCK2(cs_main, pwalletMain->cs_wallet);

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

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
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

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
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
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

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.


privateSendClient.nPrivateSendRounds = nRounds;

return true;
Copy link

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.

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

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.

"\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

Choose a reason for hiding this comment

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

Same as for setprivatesendrounds.

+ HelpExampleRpc("setprivatesendamount", "208")
);

LOCK2(cs_main, pwalletMain->cs_wallet);
Copy link

Choose a reason for hiding this comment

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

Same as for setprivatesendrounds.

LOCK2(cs_main, pwalletMain->cs_wallet);

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

Choose a reason for hiding this comment

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

Same as for setprivatesendrounds.


privateSendClient.nPrivateSendAmount = nAmount;

return true;
Copy link

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
Member Author

@UdjinM6 All changes applied 😄


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

privateSendClient.nPrivateSendRounds = nRounds;
Copy link

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)

Copy link

@UdjinM6 UdjinM6 Aug 17, 2018

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

Copy link

@UdjinM6 UdjinM6 Aug 17, 2018

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
Member Author

Implemented that check + error throw @UdjinM6

Copy link

@UdjinM6 UdjinM6 left a comment

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