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

970 merge #1029

Merged
merged 44 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
36bf07e
Rewriting RPC with error codes
SergiySW Jul 13, 2018
db1b0f6
Clang formatting
SergiySW Jul 13, 2018
12e33e5
Clang formatting
SergiySW Jul 13, 2018
9ed0641
Merge RPC chain & RPC successors
SergiySW Jul 13, 2018
5169767
Merge mrai_to_raw+krai_to_raw+rai_to_raw & mrai_from_raw+krai_from_ra…
SergiySW Jul 13, 2018
b836667
Small changes
SergiySW Jul 13, 2018
1530722
Reduce code with wallet_impl
SergiySW Jul 13, 2018
da82b1c
Reduce code with account_impl
SergiySW Jul 13, 2018
ed91aee
Formatting
SergiySW Jul 13, 2018
d9b1205
Several errors
SergiySW Jul 13, 2018
1909498
Reduce code size with count_impl
SergiySW Jul 13, 2018
2a29139
count_optional_impl
SergiySW Jul 13, 2018
45a2e1b
Formatting
SergiySW Jul 13, 2018
b9451c1
Merge branch 'master' into rpc_ec
SergiySW Jul 15, 2018
05447ef
Formatting
SergiySW Jul 15, 2018
e90112c
hash_impl
SergiySW Jul 16, 2018
5b9c4ed
Edit hash_impl to accept "block"
SergiySW Jul 16, 2018
68756bc
rpc_control_impl
SergiySW Jul 16, 2018
2c746f4
amount_impl
SergiySW Jul 16, 2018
9776e0a
Doule write issue
SergiySW Jul 16, 2018
06ca592
Typo
SergiySW Jul 16, 2018
cfdb9eb
Typo
SergiySW Jul 16, 2018
371b5fe
threshold_optional_impl
SergiySW Jul 17, 2018
73ec185
Simplification
SergiySW Jul 17, 2018
935f98c
Simplification
SergiySW Jul 17, 2018
b44a1bb
Fix
SergiySW Jul 17, 2018
79a0a12
work_optional_impl
SergiySW Jul 17, 2018
553a32a
Remove double check
SergiySW Jul 17, 2018
fa5e6a6
Simplification
SergiySW Jul 17, 2018
35bc006
Return "account" in history
SergiySW Jul 17, 2018
3c851cc
Optional data for amount_impl
SergiySW Jul 20, 2018
6d6c387
Less lines
SergiySW Jul 20, 2018
e314567
Simplify wallet_balances
SergiySW Jul 20, 2018
523dbd6
Merge remote-tracking branch 'upstream/master' into rpc_ec
SergiySW Jul 20, 2018
85f9b6a
Fix
SergiySW Jul 20, 2018
668a29d
Merge remote-tracking branch 'upstream/master' into rpc_ec
SergiySW Jul 20, 2018
f56fc3f
Fix
SergiySW Jul 20, 2018
b24a7d5
Merge branch 'master' into rpc_ec
SergiySW Aug 3, 2018
02cc9e8
Fix
SergiySW Aug 3, 2018
0d524b8
Use library for deterministic_key
SergiySW Aug 3, 2018
16bb25a
rai::pub_key function from library
SergiySW Aug 3, 2018
cf24370
Prevent possible empty responses
SergiySW Aug 3, 2018
69064c0
Rewriting RPC with error codes
clemahieu Aug 5, 2018
ef33465
Merge branch 'pulls/970' into 970_merge
clemahieu Aug 6, 2018
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
2 changes: 1 addition & 1 deletion rai/core_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,7 @@ TEST (rpc, wallet_create_fail)
{
system.poll ();
}
ASSERT_EQ ("Failed to create wallet. Increase lmdb_max_dbs in node config.", response.json.get<std::string> ("error"));
ASSERT_EQ ("Failed to create wallet. Increase lmdb_max_dbs in node config", response.json.get<std::string> ("error"));
}

TEST (rpc, wallet_ledger)
Expand Down
122 changes: 120 additions & 2 deletions rai/lib/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,42 @@ std::string nano::error_common_messages::message (int ev) const
return "Account already exists";
case nano::error_common::account_not_found:
return "Account not found";
case nano::error_common::account_not_found_wallet:
return "Account not found in wallet";
case nano::error_common::bad_account_number:
return "Bad account number";
case nano::error_common::bad_private_key:
return "Bad private key";
case nano::error_common::bad_public_key:
return "Bad public key";
case nano::error_common::bad_seed:
return "Bad seed";
case nano::error_common::bad_threshold:
return "Bad threshold number";
case nano::error_common::bad_wallet_number:
return "Bad wallet number";
case nano::error_common::bad_work_format:
return "Bad work";
case nano::error_common::invalid_work:
return "Invalid work";
case nano::error_common::insufficient_balance:
return "Insufficient balance";
case nano::error_common::invalid_amount:
return "Invalid amount number";
case nano::error_common::invalid_amount_big:
return "Amount too big";
case nano::error_common::invalid_count:
return "Invalid count";
case nano::error_common::invalid_ip_address:
return "Invalid IP address";
case nano::error_common::invalid_port:
return "Invalid port";
case nano::error_common::invalid_index:
return "Invalid index";
case nano::error_common::invalid_work:
return "Invalid work";
case nano::error_common::numeric_conversion:
return "Numeric conversion error";
case nano::error_common::wallet_lmdb_max_dbs:
return "Failed to create wallet. Increase lmdb_max_dbs in node config";
case nano::error_common::wallet_locked:
return "Wallet is locked";
case nano::error_common::wallet_not_found:
Expand All @@ -43,10 +63,108 @@ std::string nano::error_blocks_messages::message (int ev) const
return "Unknown error";
case nano::error_blocks::bad_hash_number:
return "Bad hash number";
case nano::error_blocks::invalid_block:
return "Block is invalid";
case nano::error_blocks::invalid_block_hash:
return "Invalid block hash";
case nano::error_blocks::invalid_type:
return "Invalid block type";
case nano::error_blocks::not_found:
return "Block not found";
case nano::error_blocks::work_low:
return "Block work is less than threshold";
}

return "Invalid error code";
}

std::string nano::error_rpc_messages::message (int ev) const
{
switch (static_cast<nano::error_rpc> (ev))
{
case nano::error_rpc::generic:
return "Unknown error";
case nano::error_rpc::bad_destination:
return "Bad destination account";
case nano::error_rpc::bad_key:
return "Bad key";
case nano::error_rpc::bad_link:
return "Bad link number";
case nano::error_rpc::bad_previous:
return "Bad previous";
case nano::error_rpc::bad_representative_number:
return "Bad representative number";
case nano::error_rpc::bad_source:
return "Bad source";
case nano::error_rpc::bad_timeout:
return "Bad timeout number";
case nano::error_rpc::block_create_balance_mismatch:
return "Balance mismatch for previous block";
case nano::error_rpc::block_create_key_required:
return "Private key or local wallet and account required";
case nano::error_rpc::block_create_public_key_mismatch:
return "Incorrect key for given account";
case nano::error_rpc::block_create_requirements_state:
return "Previous, representative, final balance and link (source or destination) are required";
case nano::error_rpc::block_create_requirements_open:
return "Representative account and source hash required";
case nano::error_rpc::block_create_requirements_receive:
return "Previous hash and source hash required";
case nano::error_rpc::block_create_requirements_change:
return "Representative account and previous hash required";
case nano::error_rpc::block_create_requirements_send:
return "Destination account, previous hash, current balance and amount required";
case nano::error_rpc::invalid_balance:
return "Invalid balance number";
case nano::error_rpc::invalid_destinations:
return "Invalid destinations number";
case nano::error_rpc::invalid_offset:
return "Invalid offset";
case nano::error_rpc::invalid_missing_type:
return "Invalid or missing type argument";
case nano::error_rpc::invalid_sources:
return "Invalid sources number";
case nano::error_rpc::payment_account_balance:
return "Account has non-zero balance";
case nano::error_rpc::payment_unable_create_account:
return "Unable to create transaction account";
case nano::error_rpc::rpc_control_disabled:
return "RPC control is disabled";
case nano::error_rpc::source_not_found:
return "Source not found";
}

return "Invalid error code";
}

std::string nano::error_process_messages::message (int ev) const
{
switch (static_cast<nano::error_process> (ev))
{
case nano::error_process::generic:
return "Unknown error";
case nano::error_process::bad_signature:
return "Bad signature";
case nano::error_process::old:
return "Old block";
case nano::error_process::negative_spend:
return "Negative spend";
case nano::error_process::fork:
return "Fork";
case nano::error_process::unreceivable:
return "Unreceivable";
case nano::error_process::gap_previous:
return "Gap previous block";
case nano::error_process::gap_source:
return "Gap source block";
case nano::error_process::opened_burn_account:
return "Burning account";
case nano::error_process::balance_mismatch:
return "Balance and amount delta do not match";
case nano::error_process::block_position:
return "This block cannot follow the previous block";
case nano::error_process::other:
"Error processing block";
}

return "Invalid error code";
Expand Down
66 changes: 64 additions & 2 deletions rai/lib/errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ enum class error_common
{
generic = 1,
account_not_found,
account_not_found_wallet,
account_exists,
bad_account_number,
bad_private_key,
bad_public_key,
bad_seed,
bad_threshold,
bad_wallet_number,
bad_work_format,
invalid_work,
invalid_amount,
invalid_amount_big,
invalid_count,
invalid_index,
invalid_ip_address,
invalid_port,
invalid_work,
insufficient_balance,
numeric_conversion,
wallet_lmdb_max_dbs,
wallet_locked,
wallet_not_found
};
Expand All @@ -47,8 +57,58 @@ enum class error_blocks
{
generic = 1,
bad_hash_number,
invalid_block,
invalid_block_hash,
not_found
invalid_type,
not_found,
work_low
};

/** RPC related errors */
enum class error_rpc
{
generic = 1,
bad_destination,
bad_key,
bad_link,
bad_previous,
bad_representative_number,
bad_source,
bad_timeout,
block_create_balance_mismatch,
block_create_key_required,
block_create_public_key_mismatch,
block_create_requirements_state,
block_create_requirements_open,
block_create_requirements_receive,
block_create_requirements_change,
block_create_requirements_send,
invalid_balance,
invalid_destinations,
invalid_offset,
invalid_missing_type,
invalid_sources,
payment_account_balance,
payment_unable_create_account,
rpc_control_disabled,
source_not_found
};

/** process_result related errors */
enum class error_process
{
generic = 1,
bad_signature, // Signature was bad, forged or transmission error
old, // Already seen and was valid
negative_spend, // Malicious attempt to spend a negative amount
fork, // Malicious fork based on previous
unreceivable, // Source block doesn't exist or has already been received
gap_previous, // Block marked as previous is unknown
gap_source, // Block marked as source is unknown
opened_burn_account, // The impossible happened, someone found the private key associated with the public key '0'.
balance_mismatch, // Balance and amount delta don't match
block_position, // This block cannot follow the previous block
other
};
}

Expand Down Expand Up @@ -95,3 +155,5 @@ enum class error_blocks

REGISTER_ERROR_CODES (nano, error_common);
REGISTER_ERROR_CODES (nano, error_blocks);
REGISTER_ERROR_CODES (nano, error_rpc);
REGISTER_ERROR_CODES (nano, error_process);
7 changes: 7 additions & 0 deletions rai/lib/numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ void rai::deterministic_key (rai::uint256_union const & seed_a, uint32_t index_a
blake2b_final (&hash, prv_a.bytes.data (), prv_a.bytes.size ());
}

rai::public_key rai::pub_key (rai::private_key const & privatekey_a)
{
rai::uint256_union result;
ed25519_publickey (privatekey_a.bytes.data (), result.bytes.data ());
return result;
}

bool rai::validate_message (rai::public_key const & public_key, rai::uint256_union const & message, rai::uint512_union const & signature)
{
auto result (0 != ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), public_key.bytes.data (), signature.bytes.data ()));
Expand Down
1 change: 1 addition & 0 deletions rai/lib/numbers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ using signature = uint512_union;
rai::uint512_union sign_message (rai::raw_key const &, rai::public_key const &, rai::uint256_union const &);
bool validate_message (rai::public_key const &, rai::uint256_union const &, rai::uint512_union const &);
void deterministic_key (rai::uint256_union const &, uint32_t, rai::uint256_union &);
rai::public_key pub_key (rai::private_key const &);
}

namespace std
Expand Down
Loading