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

Add wallet_history with timestamps #994

Merged
merged 39 commits into from Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1f508d1
process_local
SergiySW Jul 25, 2018
ac5e366
process_local for wallet actions
SergiySW Jul 25, 2018
6443e5b
Fix
SergiySW Jul 25, 2018
15341dc
Add timestamps table
SergiySW Jul 25, 2018
73173fa
Add timestamp in process_local
SergiySW Jul 25, 2018
4182302
Timestamp in RPC history & blocks_info
SergiySW Jul 25, 2018
240811c
Timestamps core_test
SergiySW Jul 25, 2018
b8d3ee1
Add timestamps to RPC history core_test
SergiySW Jul 25, 2018
1be9f5a
RPC wallet_history
SergiySW Jul 25, 2018
7224c1e
Wallet_history sorting
SergiySW Jul 25, 2018
78bfa0f
wallet_history test
SergiySW Jul 25, 2018
1e0e9af
Typo
SergiySW Jul 25, 2018
c88571d
Formatting
SergiySW Jul 25, 2018
1075184
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Aug 13, 2018
6b13a92
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Sep 6, 2018
e1c0e84
Updates
SergiySW Sep 6, 2018
a0b585c
Typo
SergiySW Sep 6, 2018
73dc14f
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Sep 9, 2018
920f67a
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Sep 10, 2018
b5a933c
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Sep 12, 2018
8977bca
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Sep 14, 2018
a866fd3
Fix
SergiySW Sep 14, 2018
5c7f8cc
Add sideband information to database.
clemahieu Jan 2, 2019
31b37bf
Sideband RPC & open blocks adjustment (#1555)
SergiySW Jan 5, 2019
99eca06
Improving log message for sideband upgrade process.
clemahieu Jan 9, 2019
e648b41
merge upstream/block_sideband_squash
SergiySW Jan 13, 2019
41b2953
fix merge artifacts
SergiySW Jan 13, 2019
536b90c
Adding test to show that blocks are put in the correct epoch.
clemahieu Jan 13, 2019
870bab4
Merge remote-tracking branch 'upstream/block_sideband_squash' into ti…
SergiySW Jan 13, 2019
920f61f
Fix test_response
SergiySW Jan 13, 2019
a5e1128
Update test
SergiySW Jan 13, 2019
0a183fd
Use decode_unsigned & correct error code for timestamps
SergiySW Jan 15, 2019
116d8f6
Bump the version number on start of sideband upgrade in addition to a…
clemahieu Jan 27, 2019
df39356
Merge branch 'master' into block_sideband_squash
clemahieu Jan 27, 2019
655b669
Merge branch 'master' into block_sideband_squash
clemahieu Jan 27, 2019
8e2bd29
Merge remote-tracking branch 'upstream/block_sideband_squash' into ti…
SergiySW Jan 27, 2019
2b73c05
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Jan 27, 2019
98a16e8
Proper transactions
SergiySW Jan 27, 2019
fdd3709
Merge remote-tracking branch 'upstream/master' into timestamps
SergiySW Jan 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
418 changes: 358 additions & 60 deletions nano/core_test/block_store.cpp

Large diffs are not rendered by default.

71 changes: 66 additions & 5 deletions nano/core_test/rpc.cpp
Expand Up @@ -3147,13 +3147,12 @@ TEST (rpc, blocks_info)
ASSERT_FALSE (pending.is_initialized ());
boost::optional<std::string> source (blocks.second.get_optional<std::string> ("source_account"));
ASSERT_FALSE (source.is_initialized ());
boost::optional<std::string> balance (blocks.second.get_optional<std::string> ("balance"));
ASSERT_FALSE (balance.is_initialized ());
std::string balance_text (blocks.second.get<std::string> ("balance"));
ASSERT_EQ (nano::genesis_amount.convert_to<std::string> (), balance_text);
}
// Test for optional values
request.put ("source", "true");
request.put ("pending", "1");
request.put ("balance", "true");
test_response response2 (request, rpc, system.io_ctx);
system.deadline_set (5s);
while (response2.status == 0)
Expand All @@ -3167,8 +3166,6 @@ TEST (rpc, blocks_info)
ASSERT_EQ ("0", source);
std::string pending (blocks.second.get<std::string> ("pending"));
ASSERT_EQ ("0", pending);
std::string balance_text (blocks.second.get<std::string> ("balance"));
ASSERT_EQ (nano::genesis_amount.convert_to<std::string> (), balance_text);
}
}

Expand Down Expand Up @@ -3998,3 +3995,67 @@ TEST (rpc, node_id_delete)
nano::keypair node_id (system.nodes[0]->store.get_node_id (transaction));
ASSERT_NE (node_id.pub.to_string (), system.nodes[0]->node_id.pub.to_string ());
}

TEST (rpc, wallet_history)
{
nano::system system (24000, 1);
auto node0 (system.nodes[0]);
nano::genesis genesis;
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
auto timestamp1 (nano::seconds_since_epoch ());
auto send (system.wallet (0)->send_action (nano::test_genesis_key.pub, nano::test_genesis_key.pub, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send);
std::this_thread::sleep_for (std::chrono::milliseconds (1000));
auto timestamp2 (nano::seconds_since_epoch ());
auto receive (system.wallet (0)->receive_action (static_cast<nano::send_block &> (*send), nano::test_genesis_key.pub, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, receive);
nano::keypair key;
std::this_thread::sleep_for (std::chrono::milliseconds (1000));
auto timestamp3 (nano::seconds_since_epoch ());
auto send2 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key.pub, node0->config.receive_minimum.number ()));
ASSERT_NE (nullptr, send2);
system.deadline_set (10s);
nano::rpc rpc (system.io_ctx, *node0, nano::rpc_config (true));
rpc.start ();
boost::property_tree::ptree request;
request.put ("action", "wallet_history");
request.put ("wallet", node0->wallets.items.begin ()->first.to_string ());
test_response response (request, rpc, system.io_ctx);
system.deadline_set (5s);
while (response.status == 0)
{
system.poll ();
}
ASSERT_EQ (200, response.status);
std::vector<std::tuple<std::string, std::string, std::string, std::string, std::string, std::string>> history_l;
auto & history_node (response.json.get_child ("history"));
for (auto i (history_node.begin ()), n (history_node.end ()); i != n; ++i)
{
history_l.push_back (std::make_tuple (i->second.get<std::string> ("type"), i->second.get<std::string> ("account"), i->second.get<std::string> ("amount"), i->second.get<std::string> ("hash"), i->second.get<std::string> ("wallet_account"), i->second.get<std::string> ("local_timestamp")));
}
ASSERT_EQ (4, history_l.size ());
ASSERT_EQ ("send", std::get<0> (history_l[0]));
ASSERT_EQ (key.pub.to_account (), std::get<1> (history_l[0]));
ASSERT_EQ (node0->config.receive_minimum.to_string_dec (), std::get<2> (history_l[0]));
ASSERT_EQ (send2->hash ().to_string (), std::get<3> (history_l[0]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<4> (history_l[0]));
ASSERT_EQ (std::to_string (timestamp3), std::get<5> (history_l[0]));
ASSERT_EQ ("receive", std::get<0> (history_l[1]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<1> (history_l[1]));
ASSERT_EQ (node0->config.receive_minimum.to_string_dec (), std::get<2> (history_l[1]));
ASSERT_EQ (receive->hash ().to_string (), std::get<3> (history_l[1]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<4> (history_l[1]));
ASSERT_EQ (std::to_string (timestamp2), std::get<5> (history_l[1]));
ASSERT_EQ ("send", std::get<0> (history_l[2]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<1> (history_l[2]));
ASSERT_EQ (node0->config.receive_minimum.to_string_dec (), std::get<2> (history_l[2]));
ASSERT_EQ (send->hash ().to_string (), std::get<3> (history_l[2]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<4> (history_l[2]));
ASSERT_EQ (std::to_string (timestamp1), std::get<5> (history_l[2]));
// Genesis block
ASSERT_EQ ("receive", std::get<0> (history_l[3]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<1> (history_l[3]));
ASSERT_EQ (nano::genesis_amount.convert_to<std::string> (), std::get<2> (history_l[3]));
ASSERT_EQ (genesis.hash ().to_string (), std::get<3> (history_l[3]));
ASSERT_EQ (nano::test_genesis_key.pub.to_account (), std::get<4> (history_l[3]));
}
4 changes: 3 additions & 1 deletion nano/core_test/versioning.cpp
Expand Up @@ -14,8 +14,10 @@ TEST (versioning, account_info_v1)
auto error (false);
nano::mdb_store store (error, logging, file);
ASSERT_FALSE (error);
store.stop ();
auto transaction (store.tx_begin (true));
store.block_put (transaction, open.hash (), open);
nano::block_sideband sideband (nano::block_type::open, 0, 0, 0, 0, 0);
store.block_put (transaction, open.hash (), open, sideband);
auto status (mdb_put (store.env.tx (transaction), store.accounts_v0, nano::mdb_val (account), v1.val (), 0));
ASSERT_EQ (0, status);
store.version_put (transaction, 1);
Expand Down
58 changes: 29 additions & 29 deletions nano/lib/blocks.cpp
Expand Up @@ -53,13 +53,41 @@ bool nano::from_string_hex (std::string const & value_a, uint64_t & target_a)
return error;
}

std::string nano::block::to_json ()
std::string nano::block::to_json () const
{
std::string result;
serialize_json (result);
return result;
}

size_t nano::block::size (nano::block_type type_a)
{
size_t result (0);
switch (type_a)
{
case nano::block_type::invalid:
case nano::block_type::not_a_block:
assert (false);
break;
case nano::block_type::send:
result = nano::send_block::size;
break;
case nano::block_type::receive:
result = nano::receive_block::size;
break;
case nano::block_type::change:
result = nano::change_block::size;
break;
case nano::block_type::open:
result = nano::open_block::size;
break;
case nano::block_type::state:
result = nano::state_block::size;
break;
}
return result;
}

nano::block_hash nano::block::hash () const
{
nano::uint256_union result;
Expand Down Expand Up @@ -1427,34 +1455,6 @@ hashables (error_a, tree_a)
}
}

size_t nano::block::size (nano::block_type type_a)
{
size_t result (0);
switch (type_a)
{
case nano::block_type::invalid:
case nano::block_type::not_a_block:
assert (false);
break;
case nano::block_type::send:
result = nano::send_block::size;
break;
case nano::block_type::receive:
result = nano::receive_block::size;
break;
case nano::block_type::change:
result = nano::change_block::size;
break;
case nano::block_type::open:
result = nano::open_block::size;
break;
case nano::block_type::state:
result = nano::state_block::size;
break;
}
return result;
}

void nano::receive_block::hash (blake2b_state & hash_a) const
{
hashables.hash (hash_a);
Expand Down
2 changes: 1 addition & 1 deletion nano/lib/blocks.hpp
Expand Up @@ -47,7 +47,7 @@ class block
nano::block_hash hash () const;
// Return a digest of hashables and non-hashables in this block.
nano::block_hash full_hash () const;
std::string to_json ();
std::string to_json () const;
virtual void hash (blake2b_state &) const = 0;
virtual uint64_t block_work () const = 0;
virtual void block_work_set (uint64_t) = 0;
Expand Down
2 changes: 2 additions & 0 deletions nano/lib/errors.cpp
Expand Up @@ -154,6 +154,8 @@ std::string nano::error_rpc_messages::message (int ev) const
return "Invalid root hash";
case nano::error_rpc::invalid_sources:
return "Invalid sources number";
case nano::error_rpc::invalid_timestamp:
return "Invalid timestamp";
case nano::error_rpc::payment_account_balance:
return "Account has non-zero balance";
case nano::error_rpc::payment_unable_create_account:
Expand Down
1 change: 1 addition & 0 deletions nano/lib/errors.hpp
Expand Up @@ -103,6 +103,7 @@ enum class error_rpc
invalid_missing_type,
invalid_root,
invalid_sources,
invalid_timestamp,
payment_account_balance,
payment_unable_create_account,
rpc_control_disabled,
Expand Down
39 changes: 13 additions & 26 deletions nano/lib/interface.h
Expand Up @@ -11,52 +11,39 @@ typedef unsigned char * xrb_uint512; // 64byte array for signatures
typedef void * xrb_transaction;

// Convert amount bytes 'source' to a 40 byte null-terminated decimal string 'destination'
[[deprecated]]
void xrb_uint128_to_dec (const xrb_uint128 source, char * destination);
[[deprecated]] void xrb_uint128_to_dec (const xrb_uint128 source, char * destination);
// Convert public/private key bytes 'source' to a 65 byte null-terminated hex string 'destination'
[[deprecated]]
void xrb_uint256_to_string (const xrb_uint256 source, char * destination);
[[deprecated]] void xrb_uint256_to_string (const xrb_uint256 source, char * destination);
// Convert public key bytes 'source' to a 66 byte non-null-terminated account string 'destination'
[[deprecated]]
void xrb_uint256_to_address (xrb_uint256 source, char * destination);
[[deprecated]] void xrb_uint256_to_address (xrb_uint256 source, char * destination);
// Convert public/private key bytes 'source' to a 129 byte null-terminated hex string 'destination'
[[deprecated]]
void xrb_uint512_to_string (const xrb_uint512 source, char * destination);
[[deprecated]] void xrb_uint512_to_string (const xrb_uint512 source, char * destination);

// Convert 39 byte decimal string 'source' to a byte array 'destination'
// Return 0 on success, nonzero on error
[[deprecated]]
int xrb_uint128_from_dec (const char * source, xrb_uint128 destination);
[[deprecated]] int xrb_uint128_from_dec (const char * source, xrb_uint128 destination);
// Convert 64 byte hex string 'source' to a byte array 'destination'
// Return 0 on success, nonzero on error
[[deprecated]]
int xrb_uint256_from_string (const char * source, xrb_uint256 destination);
[[deprecated]] int xrb_uint256_from_string (const char * source, xrb_uint256 destination);
// Convert 128 byte hex string 'source' to a byte array 'destination'
// Return 0 on success, nonzero on error
[[deprecated]]
int xrb_uint512_from_string (const char * source, xrb_uint512 destination);
[[deprecated]] int xrb_uint512_from_string (const char * source, xrb_uint512 destination);

// Check if the null-terminated string 'account' is a valid xrb account number
// Return 0 on correct, nonzero on invalid
[[deprecated]]
int xrb_valid_address (const char * account);
[[deprecated]] int xrb_valid_address (const char * account);

// Create a new random number in to 'destination'
[[deprecated]]
void xrb_generate_random (xrb_uint256 destination);
[[deprecated]] void xrb_generate_random (xrb_uint256 destination);
// Retrieve the deterministic private key for 'seed' at 'index'
[[deprecated]]
void xrb_seed_key (const xrb_uint256 seed, int index, xrb_uint256);
[[deprecated]] void xrb_seed_key (const xrb_uint256 seed, int index, xrb_uint256);
// Derive the public key 'pub' from 'key'
[[deprecated]]
void xrb_key_account (xrb_uint256 key, xrb_uint256 pub);
[[deprecated]] void xrb_key_account (xrb_uint256 key, xrb_uint256 pub);

// Sign 'transaction' using 'private_key' and write to 'signature'
[[deprecated]]
char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private_key);
[[deprecated]] char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private_key);
// Generate work for 'transaction'
[[deprecated]]
char * xrb_work_transaction (const char * transaction);
[[deprecated]] char * xrb_work_transaction (const char * transaction);

#if __cplusplus
} // extern "C"
Expand Down
3 changes: 3 additions & 0 deletions nano/lib/utility.cpp
Expand Up @@ -58,6 +58,9 @@ namespace thread_role
case nano::thread_role::name::signature_checking:
thread_role_name_string = "Signature check";
break;
case nano::thread_role::name::slow_db_upgrade:
thread_role_name_string = "Slow db upgrade";
break;
}

/*
Expand Down
1 change: 1 addition & 0 deletions nano/lib/utility.hpp
Expand Up @@ -42,6 +42,7 @@ namespace thread_role
bootstrap_initiator,
voting,
signature_checking,
slow_db_upgrade,
};
nano::thread_role::name get (void);
void set (nano::thread_role::name);
Expand Down