Skip to content

Conversation

personthingman2
Copy link
Contributor

This is my first contribution to an open source project so please tell me if I'm doing anything wrong.
This is a fix for #1168. I moved the logic into GetGlobalStatus because MemorizeMessage is only run when a message is received, meaning users would have to restart their client for an expired poll to disappear. As a result msPoll now contains the entire message XML so it can be processed in GetGlobalStatus.
The "Poll: " and "Foundation Poll: " concats were removed because it looked silly to me.

Copy link
Member

@tomasbrod tomasbrod left a comment

Choose a reason for hiding this comment

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

Please put your logic in a function and wrap it in a try-catch so it does not crash wallet on invalid data.
Otherwise good. Thank you for contributing.

src/main.cpp Outdated
// Alerts are displayed as polls but do not have an expiration
if(sPollExpiration.empty())
{
sPollExpiration = std::to_string(pindexBest->nTime);
Copy link
Member

Choose a reason for hiding this comment

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

Avoid converting things to string if possible.

src/main.cpp Outdated
{
sPollExpiration = std::to_string(pindexBest->nTime);
}
if (stoll(sPollExpiration) >= pindexBest->nTime)
Copy link
Member

Choose a reason for hiding this comment

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

Unsafe strtoll. Please add error and exception handling or use another function (ToString maybe?).

src/main.cpp Outdated
}
else
{
GlobalStatusStruct.poll = "No current polls";
Copy link
Member

Choose a reason for hiding this comment

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

I do not like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you elaborate? I don't see what's wrong with this.

@personthingman2
Copy link
Contributor Author

I've moved the logic into the new functionGetPoll(), added uint_64_t uPollExpiration which removes the need to convert to string, and put a try/catch around the remaining stoll(). I don't believe an additional try/catch is required around the function call in GetGlobalStatus() because that entire function is already in a try/catch.

@iFoggz
Copy link
Member

iFoggz commented Aug 10, 2018

I agree with @tomasbrod asking of the try catch there as well. better to pass back no current poll for malformed time then having msMiningErrors saying Error obtaining status and in turn not providing the other valid data/or incomplete data to the wallet -- this saves confusion as well as to where the problem is/was

src/main.h Outdated
@@ -260,6 +260,8 @@ bool WriteKey(std::string sKey, std::string sValue);
double GetBlockDifficulty(unsigned int nBits);
std::string ExtractXML(std::string XMLdata, std::string key, std::string key_end);

std::string GetPoll();
Copy link
Member

Choose a reason for hiding this comment

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

Please use more descriptive name, with overview or statusbar words. There are getters for rpcs and voting tab, we do not want name clashes.

Copy link
Member

@tomasbrod tomasbrod left a comment

Choose a reason for hiding this comment

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

I accidentally set status to approve.
About that no polls message: if it is a separate line, sure, show that message so it does not appear empty. But if it is under status field, no polls message would just takes up space.

@personthingman2
Copy link
Contributor Author

I've changed GetPoll() to GetCurrentOverviewTabPoll() and added a try/catch around the function call with a log error.

The "No current polls" message is only shown in the "Current Poll: " field of the overview tab so it does not clutter any other field.

Here is a screenshot of what it looks like:
screenshot from 2018-08-11 15-57-32

@iFoggz
Copy link
Member

iFoggz commented Aug 11, 2018

label poll is not used for anything but poll

Copy link
Member

@iFoggz iFoggz left a comment

Choose a reason for hiding this comment

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

tACK 569bc8d; apon another approval I think due to this being a cosmetic fix more then anything it'll be a small include for the upcoming release milestone if @denravonska and @tomasbrod concur.

src/main.cpp Outdated
}
catch (std::exception &e)
{
GlobalStatusStruct.poll = "Error obtaining last poll";
Copy link
Member

Choose a reason for hiding this comment

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

Translations should be considered here.
GlobalStatusStruct.poll = _("Error obtaining last poll");

Copy link
Member

Choose a reason for hiding this comment

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

Why the user needs to see this error?

Copy link
Member

Choose a reason for hiding this comment

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

I agree if anything a log entry about the exception should be put. Remove translation and log the e.what() under debug

src/main.cpp Outdated
}
else
{
poll = "No current polls";
Copy link
Member

Choose a reason for hiding this comment

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

Translations:
poll = _("No current polls");

Copy link
Member

Choose a reason for hiding this comment

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

What about "Current Poll: none"?

Copy link
Member

Choose a reason for hiding this comment

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

Short but sweet.

Copy link
Member

@iFoggz iFoggz left a comment

Choose a reason for hiding this comment

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

Actually thinking about this. We should consider use the _() and do translations where we can to increase the readability across languages where we can.

@personthingman2
Copy link
Contributor Author

I will wait on adding translations until #1262 is merged.

Do we want it to say "No current polls" or "None"? I think the former sounds better in the context of the overview page.

@iFoggz
Copy link
Member

iFoggz commented Aug 14, 2018

i would say don't worry about the translations part and it can be done at a later point when we do another translation update before release :) having the _() wont break your code. no worries there -- so just add the requested _() in a commit and make sure all reviews are satisfied and we can move to approval and merge. i'll update the translation strings at next release

you wouldn't be manually adding to the bitcoinstrings.cpp file. there's a script for that and would be in a separate pr for updated information

@personthingman2
Copy link
Contributor Author

Is this PR appropriate in its current state or would you guys like any additional changes?

@denravonska denravonska merged commit d638c81 into gridcoin-community:development Sep 3, 2018
@denravonska denravonska added this to the Camilla milestone Oct 8, 2018
@denravonska denravonska added the bug label Oct 8, 2018
@cyrossignol
Copy link
Member

Any reason to worry about the full contract message appearing in the output of getmininginfo now for command-line users?

"MiningInfo 2": "<MT>poll</MT><MK>What_do_you_call_a_positively_charged_seal?\n</MK><MV><TITLE>What_do_you_call_a_positively_charged_seal?\n</TITLE><DAYS>14</DAYS><QUESTION>What_do_you_call_a_positively_charged_seal?\n</QUESTION><ANSWERS>A_Sealion;God_dammit_Foxifi!</ANSW ERS><SHARETYPE>3</SHARETYPE><URL>https://i.imgur.com/1D4iQZl.jpg</URL><EXPIRATION>1544712997</EXPIRATION></MV><MA>A</MA><MPK></MPK><MS>MEQCIHwhNJRKus9MwSYWo6epSyfaNytv2/IFFp5fCVUDNZwUAiBUS2U68h4y+ptkQ7tnUr/YGO8bL1Gz4EbIrE1207g2zA==</MS>",

@philipswift
Copy link

With jokes like that...yes! ;)

denravonska added a commit that referenced this pull request Apr 3, 2019
Added:
 - Add `rainbymagnitude` RPC command #1235 (@Foggyx420).
 - Add stake splitting and side staking #1265 (@jamescowens).
 - Detect and block Windows shutdown so wallet can exit cleanly #1309
   (@jamescowens).
 - Add message support to sendfrom and sendtoaddress #1400 (@denravonska).

Changed:
 - Configuration options are now case insensitive #294 (@Foggyx420).
 - Update command in beaconstatus help message #1312 (@chrstphrchvz).
 - Improve synchronization speeds:
   - Refactor superblock pack/unpack #1194 (@denravonska).
   - Optimize neuralsecurity calculations #1255 (@denravonska).
   - Reduce hash calculations when checking blocks #1206 (@denravonska).
 - Make display of private key in beaconstatus OPT-IN only #1275 (@Foggyx420).
 - Store Beacon keys in Wallet #1088 (@tomasbrod).
 - Use default colors for pie chart #1333 (@chrstphrchvz).
 - Show hand cursor when hovering clickable labels #1332 (@chrstphrchvz).
 - Update README.md #1337 (@Peppernrino).
 - Fix integer overflow with displayed nonce #1297 (@personthingman2).
 - Improve application cache performance #1317 (@denravonska).
 - Improve reorg speeds #1263 (@denravonska).
 - Update Polish translation #1375 (@michalkania).

Fixed:
 - Remove expired polls from overview page #1250 (@personthingman2).
 - Fix plural text on block age #1304 (@scribblemaniac).
 - Fix researcher staking issue if your chain head was staked by you,
   #1299 (@denravonska).
 - Fix incorrect address to grcpool node #1314 (@wilkart).
 - Do not replace underscores by spaces in Qt Poll URLs #1327 (@tomasbrod).
 - Fix scraper SSL issues #1330 (@Foggyx420).

Removed:
 - Remove or merged several RPC commands #1228 (@Foggyx420):
    - `newburnaddress`, removed.
    - `burn2`: Removed.
    - `cpid`: Merged into `projects`.
    - `mymagnitude`: Merged into `magnitude`.
    - `rsa`: Removed, use `magnitude`.
    - `rsaweight`: Removed, use `magnitude`.
    - `proveownership`: Removed.
    - `encrypt`: Removed.
 - Remove obsolete POW fields from RPC responses #1358 (@jamescowens).
 - Remove obsolete netsoft fields for slight RAM requirement reduction
   #1336 (@denravonska).
 - Remove unused attachment functionality #1345 (@denravonska).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants