Skip to content
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

checkifmncollateral rpc added #1427

Merged
merged 2 commits into from
May 11, 2024
Merged

checkifmncollateral rpc added #1427

merged 2 commits into from
May 11, 2024

Conversation

levonpetrosyan93
Copy link
Contributor

No description provided.

Copy link

coderabbitai bot commented Apr 7, 2024

Walkthrough

A delightful addition has been made to the system, allowing for masternode collateral existence checks. This enhancement includes the implementation of a new function in misc.cpp and the introduction of the "checkifmncollateral" RPC command in server.cpp. The public interface in server.h now includes the declaration for this new functionality, catering to users seeking masternode collateral verification via RPC commands.

Changes

Files Change Summary
src/rpc/misc.cpp Added checkifmncollateral function for masternode collateral existence check.
src/rpc/server.cpp
src/rpc/server.h
Added new RPC command "checkifmncollateral" and declared it in the public interface.

🐰✨
In the realm of code, where changes are bold,
A rabbit hopped in, its story untold.
"Check masternode's heart, is it there?" it asked,
With a command so new, in the sunlight it basked.
Through misc, server, both .cpp and .h,
A magical line, in the blockchain's mesh.
🥕🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 17aab98 and 6c2c868.
Files selected for processing (3)
  • src/rpc/misc.cpp (3 hunks)
  • src/rpc/server.cpp (1 hunks)
  • src/rpc/server.h (1 hunks)
Additional comments not posted (3)
src/rpc/server.h (1)

221-222: LGTM! The declaration of checkifmncollateral correctly follows the conventions for RPC command functions.

src/rpc/server.cpp (1)

347-348: LGTM! The addition of checkifmncollateral to the RPC commands under the "mobile" category is correctly implemented.

src/rpc/misc.cpp (1)

1772-1772: Ensure the RPC command category aligns with its functionality.

The checkifmncollateral function is added under the "mobile" category. If this functionality is specifically designed for mobile applications or has broader use, consider placing it in a more appropriate category or providing additional context in the help documentation.

src/rpc/misc.cpp Outdated
Comment on lines 1434 to 1473
UniValue checkifmncollateral(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() != 2)
throw std::runtime_error(
"checkifmncollateral\n"
"\nReturns bool value.\n"
"\nArguments:\n"
" \"txHash\"\n"
" \"index\"\n"
+ HelpExampleCli("checkifmncollateral", "\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"" "\"0\" ")
+ HelpExampleRpc("checkifmncollateral", "\"b476ed2b374bb081ea51d111f68f0136252521214e213d119b8dc67b92f5a390\"" "\"0\" ")
);

std::string strTxId;
int index;

try {
strTxId = request.params[0].get_str();
index = std::stol(request.params[1].get_str());
} catch (std::logic_error const & e) {
throw std::runtime_error(std::string("An exception occurred while parsing parameters: ") + e.what());
}

uint256 txid = uint256S(strTxId);

CTransactionRef tx;
uint256 hashBlock;
if(!GetTransaction(txid, tx, Params().GetConsensus(), hashBlock, true))
throw std::runtime_error("Unable to get the transction");

auto mnList = deterministicMNManager->GetListAtChainTip();
COutPoint o(txid, index);

bool mnexists = false;
if (deterministicMNManager->IsProTxWithCollateral(tx, index) || mnList.HasMNByCollateral(o)) {
mnexists = true;
}

return UniValue(mnexists);
}
Copy link

Choose a reason for hiding this comment

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

Add error handling for invalid parameters.

The function checkifmncollateral lacks error handling for cases where the transaction hash is invalid or the index is out of bounds. Consider adding checks to ensure the transaction exists and the index is within the valid range.

src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 6c2c868 and c1d2b5c.
Files selected for processing (1)
  • src/rpc/misc.cpp (3 hunks)
Additional comments not posted (1)
src/rpc/misc.cpp (1)

1434-1468: Review of the new RPC command checkifmncollateral.

  • Error Handling: The function correctly throws an exception if the number of parameters is incorrect or if the parameters cannot be parsed. This is good practice for robust error handling.
  • Transaction Retrieval: The function uses GetTransaction to retrieve the transaction from the transaction ID provided. It correctly checks if the transaction exists.
  • Masternode Collateral Check: It checks if the transaction output is used as collateral either directly or in the masternode list at the chain tip. This is done using IsProTxWithCollateral and HasMNByCollateral, which are appropriate for this check.
  • Return Value: The function returns a boolean indicating if the output is used as collateral, which aligns with the function's purpose.

Overall, the implementation of the checkifmncollateral function appears correct and adheres to the expected functionality as described in the PR. It properly integrates with the existing masternode management systems and provides a clear, boolean output for RPC clients.

@reubenyap reubenyap merged commit 065a60a into master May 11, 2024
6 checks passed
@reubenyap reubenyap deleted the checkifmncollateral branch May 11, 2024 17:45
firstcryptoman pushed a commit that referenced this pull request May 15, 2024
* checkifmncollateral rpc added

* review comments applied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants