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

Fix duplicate send ID insufficient balance again #1106

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rai/core_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ TEST (rpc, send_idempotent)
system.poll ();
}
ASSERT_EQ (200, response2.status);
ASSERT_EQ (response2.json.get<std::string> ("block"), block_text);
ASSERT_EQ ("", response2.json.get<std::string> ("error", ""));
ASSERT_EQ (block_text, response2.json.get<std::string> ("block"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes the error message clearer when it errors.

ASSERT_EQ (system.nodes[0]->balance (rai::test_genesis_key.pub), rai::genesis_amount / 4);
request.erase ("id");
request.put ("id", "456def");
Expand Down
37 changes: 19 additions & 18 deletions rai/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2611,29 +2611,30 @@ void rai::rpc_handler::send ()
if (!ec)
{
boost::optional<std::string> send_id (request.get_optional<std::string> ("id"));
if (balance >= amount.number ())
{
auto rpc_l (shared_from_this ());
auto response_a (response);
wallet->send_async (source, destination, amount.number (), [response_a](std::shared_ptr<rai::block> block_a) {
if (block_a != nullptr)
auto rpc_l (shared_from_this ());
auto response_a (response);
wallet->send_async (source, destination, amount.number (), [balance, amount, response_a](std::shared_ptr<rai::block> block_a) {
if (block_a != nullptr)
{
rai::uint256_union hash (block_a->hash ());
boost::property_tree::ptree response_l;
response_l.put ("block", hash.to_string ());
response_a (response_l);
}
else
{
if (balance >= amount.number ())
{
rai::uint256_union hash (block_a->hash ());
boost::property_tree::ptree response_l;
response_l.put ("block", hash.to_string ());
response_a (response_l);
error_response (response_a, "Error generating block");
}
else
{
error_response (response_a, "Error generating block");
std::error_code ec (nano::error_common::insufficient_balance);
error_response (response_a, ec.message ());
}
},
work == 0, send_id);
}
else
{
ec = nano::error_common::insufficient_balance;
}
}
},
work == 0, send_id);
}
}
else
Expand Down