Strong types for the various bit unions (#2300)
* Add strong types for the various bit unions * Merge with master * Fix formatting * Add some accidentally missed unstaged files from merge
This commit is contained in:
parent
d1e462956a
commit
5ffe345b6d
68 changed files with 1184 additions and 755 deletions
|
@ -12,10 +12,10 @@
|
|||
|
||||
TEST (ed25519, signing)
|
||||
{
|
||||
nano::uint256_union prv (0);
|
||||
nano::uint256_union pub (nano::pub_key (prv));
|
||||
nano::private_key prv (0);
|
||||
auto pub (nano::pub_key (prv));
|
||||
nano::uint256_union message (0);
|
||||
nano::uint512_union signature;
|
||||
nano::signature signature;
|
||||
ed25519_sign (message.bytes.data (), sizeof (message.bytes), prv.bytes.data (), pub.bytes.data (), signature.bytes.data ());
|
||||
auto valid1 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ()));
|
||||
ASSERT_EQ (0, valid1);
|
||||
|
@ -28,7 +28,7 @@ TEST (transaction_block, empty)
|
|||
{
|
||||
nano::keypair key1;
|
||||
nano::send_block block (0, 1, 13, key1.prv, key1.pub, 2);
|
||||
nano::uint256_union hash (block.hash ());
|
||||
auto hash (block.hash ());
|
||||
ASSERT_FALSE (nano::validate_message (key1.pub, hash, block.signature));
|
||||
block.signature.bytes[32] ^= 0x1;
|
||||
ASSERT_TRUE (nano::validate_message (key1.pub, hash, block.signature));
|
||||
|
|
|
@ -60,7 +60,7 @@ TEST (block_store, add_item)
|
|||
auto store = nano::make_store (logger, nano::unique_path ());
|
||||
ASSERT_TRUE (!store->init_error ());
|
||||
nano::open_block block (0, 1, 0, nano::keypair ().prv, 0, 0);
|
||||
nano::uint256_union hash1 (block.hash ());
|
||||
auto hash1 (block.hash ());
|
||||
auto transaction (store->tx_begin_write ());
|
||||
auto latest1 (store->block_get (transaction, hash1));
|
||||
ASSERT_EQ (nullptr, latest1);
|
||||
|
@ -106,7 +106,7 @@ TEST (block_store, add_nonempty_block)
|
|||
ASSERT_TRUE (!store->init_error ());
|
||||
nano::keypair key1;
|
||||
nano::open_block block (0, 1, 0, nano::keypair ().prv, 0, 0);
|
||||
nano::uint256_union hash1 (block.hash ());
|
||||
auto hash1 (block.hash ());
|
||||
block.signature = nano::sign_message (key1.prv, key1.pub, hash1);
|
||||
auto transaction (store->tx_begin_write ());
|
||||
auto latest1 (store->block_get (transaction, hash1));
|
||||
|
@ -125,14 +125,14 @@ TEST (block_store, add_two_items)
|
|||
ASSERT_TRUE (!store->init_error ());
|
||||
nano::keypair key1;
|
||||
nano::open_block block (0, 1, 1, nano::keypair ().prv, 0, 0);
|
||||
nano::uint256_union hash1 (block.hash ());
|
||||
auto hash1 (block.hash ());
|
||||
block.signature = nano::sign_message (key1.prv, key1.pub, hash1);
|
||||
auto transaction (store->tx_begin_write ());
|
||||
auto latest1 (store->block_get (transaction, hash1));
|
||||
ASSERT_EQ (nullptr, latest1);
|
||||
nano::open_block block2 (0, 1, 3, nano::keypair ().prv, 0, 0);
|
||||
block2.hashables.account = 3;
|
||||
nano::uint256_union hash2 (block2.hash ());
|
||||
auto hash2 (block2.hash ());
|
||||
block2.signature = nano::sign_message (key1.prv, key1.pub, hash2);
|
||||
auto latest2 (store->block_get (transaction, hash2));
|
||||
ASSERT_EQ (nullptr, latest2);
|
||||
|
@ -435,7 +435,7 @@ TEST (block_store, one_bootstrap)
|
|||
auto begin (store->unchecked_begin (transaction));
|
||||
auto end (store->unchecked_end ());
|
||||
ASSERT_NE (end, begin);
|
||||
nano::uint256_union hash1 (begin->first.key ());
|
||||
auto hash1 (begin->first.key ());
|
||||
ASSERT_EQ (block1->hash (), hash1);
|
||||
auto blocks (store->unchecked_get (transaction, hash1));
|
||||
ASSERT_EQ (1, blocks.size ());
|
||||
|
@ -639,12 +639,12 @@ TEST (block_store, latest_exists)
|
|||
nano::logger_mt logger;
|
||||
auto store = nano::make_store (logger, nano::unique_path ());
|
||||
ASSERT_TRUE (!store->init_error ());
|
||||
nano::block_hash two (2);
|
||||
nano::account two (2);
|
||||
nano::account_info info;
|
||||
auto transaction (store->tx_begin_write ());
|
||||
store->confirmation_height_put (transaction, two, 0);
|
||||
store->account_put (transaction, two, info);
|
||||
nano::block_hash one (1);
|
||||
nano::account one (1);
|
||||
ASSERT_FALSE (store->account_exists (transaction, one));
|
||||
}
|
||||
|
||||
|
@ -717,7 +717,7 @@ TEST (block_store, block_count)
|
|||
auto transaction (store->tx_begin_write ());
|
||||
ASSERT_EQ (0, store->block_count (transaction).sum ());
|
||||
nano::open_block block (0, 1, 0, nano::keypair ().prv, 0, 0);
|
||||
nano::uint256_union hash1 (block.hash ());
|
||||
auto hash1 (block.hash ());
|
||||
nano::block_sideband sideband (nano::block_type::open, 0, 0, 0, 0, 0);
|
||||
store->block_put (transaction, hash1, block, sideband);
|
||||
}
|
||||
|
@ -857,7 +857,7 @@ TEST (mdb_block_store, upgrade_v3_v4)
|
|||
auto transaction (store.tx_begin_write ());
|
||||
ASSERT_FALSE (store.init_error ());
|
||||
ASSERT_LT (3, store.version_get (transaction));
|
||||
nano::pending_key key (key2.pub, key3.pub);
|
||||
nano::pending_key key (key2.pub, reinterpret_cast<nano::block_hash const &> (key3.pub));
|
||||
nano::pending_info info;
|
||||
auto error (store.pending_get (transaction, key, info));
|
||||
ASSERT_FALSE (error);
|
||||
|
@ -1828,7 +1828,7 @@ TEST (block_store, reset_renew_existing_transaction)
|
|||
|
||||
nano::keypair key1;
|
||||
nano::open_block block (0, 1, 1, nano::keypair ().prv, 0, 0);
|
||||
nano::uint256_union hash1 (block.hash ());
|
||||
auto hash1 (block.hash ());
|
||||
auto read_transaction = store->tx_begin_read ();
|
||||
|
||||
// Block shouldn't exist yet
|
||||
|
|
|
@ -570,15 +570,15 @@ TEST (system, generate_send_new)
|
|||
{
|
||||
auto transaction (system.nodes[0]->wallets.tx_begin_read ());
|
||||
auto iterator2 (system.wallet (0)->store.begin (transaction));
|
||||
if (nano::uint256_union (iterator2->first) != nano::test_genesis_key.pub)
|
||||
if (iterator2->first != nano::test_genesis_key.pub)
|
||||
{
|
||||
new_account = nano::uint256_union (iterator2->first);
|
||||
new_account = iterator2->first;
|
||||
}
|
||||
++iterator2;
|
||||
ASSERT_NE (system.wallet (0)->store.end (), iterator2);
|
||||
if (nano::uint256_union (iterator2->first) != nano::test_genesis_key.pub)
|
||||
if (iterator2->first != nano::test_genesis_key.pub)
|
||||
{
|
||||
new_account = nano::uint256_union (iterator2->first);
|
||||
new_account = iterator2->first;
|
||||
}
|
||||
++iterator2;
|
||||
ASSERT_EQ (system.wallet (0)->store.end (), iterator2);
|
||||
|
@ -967,7 +967,7 @@ TEST (ledger, successor)
|
|||
system.nodes[0]->work_generate_blocking (send1);
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (send1, *system.nodes[0]->ledger.successor (transaction, nano::qualified_root (genesis.hash (), 0)));
|
||||
ASSERT_EQ (send1, *system.nodes[0]->ledger.successor (transaction, nano::qualified_root (genesis.hash (), nano::root (0))));
|
||||
ASSERT_EQ (*genesis.open, *system.nodes[0]->ledger.successor (transaction, genesis.open->qualified_root ()));
|
||||
ASSERT_EQ (nullptr, system.nodes[0]->ledger.successor (transaction, nano::qualified_root (0)));
|
||||
}
|
||||
|
@ -1003,7 +1003,7 @@ TEST (ledger, fail_change_gap_previous)
|
|||
store->initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
|
||||
nano::keypair key1;
|
||||
nano::change_block block (1, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (1));
|
||||
nano::change_block block (1, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (nano::root (1)));
|
||||
auto result1 (ledger.process (transaction, block));
|
||||
ASSERT_EQ (nano::process_result::gap_previous, result1.code);
|
||||
}
|
||||
|
@ -1077,7 +1077,7 @@ TEST (ledger, fail_send_gap_previous)
|
|||
store->initialize (transaction, genesis, ledger.rep_weights, ledger.cemented_count, ledger.block_count_cache);
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
|
||||
nano::keypair key1;
|
||||
nano::send_block block (1, key1.pub, 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (1));
|
||||
nano::send_block block (1, key1.pub, 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (nano::root (1)));
|
||||
auto result1 (ledger.process (transaction, block));
|
||||
ASSERT_EQ (nano::process_result::gap_previous, result1.code);
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ TEST (ledger, fail_receive_gap_previous_opened)
|
|||
nano::open_block block3 (block1.hash (), 1, key1.pub, key1.prv, key1.pub, pool.generate (key1.pub));
|
||||
auto result3 (ledger.process (transaction, block3));
|
||||
ASSERT_EQ (nano::process_result::progress, result3.code);
|
||||
nano::receive_block block4 (1, block2.hash (), key1.prv, key1.pub, pool.generate (1));
|
||||
nano::receive_block block4 (1, block2.hash (), key1.prv, key1.pub, pool.generate (nano::root (1)));
|
||||
auto result4 (ledger.process (transaction, block4));
|
||||
ASSERT_EQ (nano::process_result::gap_previous, result4.code);
|
||||
}
|
||||
|
@ -1375,7 +1375,7 @@ TEST (ledger, fail_receive_gap_previous_unopened)
|
|||
nano::send_block block2 (block1.hash (), key1.pub, 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (block1.hash ()));
|
||||
auto result2 (ledger.process (transaction, block2));
|
||||
ASSERT_EQ (nano::process_result::progress, result2.code);
|
||||
nano::receive_block block3 (1, block2.hash (), key1.prv, key1.pub, pool.generate (1));
|
||||
nano::receive_block block3 (1, block2.hash (), key1.prv, key1.pub, pool.generate (nano::root (1)));
|
||||
auto result3 (ledger.process (transaction, block3));
|
||||
ASSERT_EQ (nano::process_result::gap_previous, result3.code);
|
||||
}
|
||||
|
@ -1986,7 +1986,7 @@ TEST (ledger, state_open_previous_fail)
|
|||
nano::keypair destination;
|
||||
nano::state_block send1 (nano::genesis_account, genesis.hash (), nano::genesis_account, nano::genesis_amount - nano::Gxrb_ratio, destination.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
|
||||
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send1).code);
|
||||
nano::state_block open1 (destination.pub, destination.pub, nano::genesis_account, nano::Gxrb_ratio, send1.hash (), destination.prv, destination.pub, pool.generate (destination.pub));
|
||||
nano::state_block open1 (destination.pub, 1, nano::genesis_account, nano::Gxrb_ratio, send1.hash (), destination.prv, destination.pub, pool.generate (1));
|
||||
ASSERT_EQ (nano::process_result::gap_previous, ledger.process (transaction, open1).code);
|
||||
}
|
||||
|
||||
|
@ -2399,7 +2399,8 @@ TEST (ledger, successor_epoch)
|
|||
nano::send_block send1 (genesis.hash (), key1.pub, nano::genesis_amount - 1, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
|
||||
nano::state_block open (key1.pub, 0, key1.pub, 1, send1.hash (), key1.prv, key1.pub, pool.generate (key1.pub));
|
||||
nano::state_block change (key1.pub, open.hash (), key1.pub, 1, 0, key1.prv, key1.pub, pool.generate (open.hash ()));
|
||||
nano::state_block epoch_open (open.hash (), 0, 0, 0, system.nodes[0]->ledger.link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (open.hash ()));
|
||||
auto open_hash = open.hash ();
|
||||
nano::state_block epoch_open (reinterpret_cast<nano::account const &> (open_hash), 0, 0, 0, system.nodes[0]->ledger.link (nano::epoch::epoch_1), nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (open.hash ()));
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, send1).code);
|
||||
ASSERT_EQ (nano::process_result::progress, system.nodes[0]->ledger.process (transaction, open).code);
|
||||
|
@ -2462,8 +2463,9 @@ TEST (ledger, block_hash_account_conflict)
|
|||
/*
|
||||
* Generate an epoch open for the account with the same value as the block hash
|
||||
*/
|
||||
auto receive1_hash = receive1->hash ();
|
||||
std::shared_ptr<nano::state_block> open_epoch1 = builder.state ()
|
||||
.account (receive1->hash ())
|
||||
.account (reinterpret_cast<nano::account const &> (receive1_hash))
|
||||
.previous (0)
|
||||
.representative (0)
|
||||
.balance (0)
|
||||
|
|
|
@ -92,8 +92,9 @@ TEST (message, confirm_ack_hash_serialization)
|
|||
for (auto i (hashes.size ()); i < 12; i++)
|
||||
{
|
||||
nano::keypair key1;
|
||||
nano::keypair previous;
|
||||
nano::state_block block (key1.pub, previous.pub, key1.pub, 2, 4, key1.prv, key1.pub, 5);
|
||||
nano::block_hash previous;
|
||||
nano::random_pool::generate_block (previous.bytes.data (), previous.bytes.size ());
|
||||
nano::state_block block (key1.pub, previous, key1.pub, 2, 4, key1.prv, key1.pub, 5);
|
||||
hashes.push_back (block.hash ());
|
||||
}
|
||||
nano::keypair representative1;
|
||||
|
@ -167,14 +168,15 @@ TEST (message, confirm_req_hash_batch_serialization)
|
|||
{
|
||||
nano::keypair key;
|
||||
nano::keypair representative;
|
||||
std::vector<std::pair<nano::block_hash, nano::block_hash>> roots_hashes;
|
||||
std::vector<std::pair<nano::block_hash, nano::root>> roots_hashes;
|
||||
nano::state_block open (key.pub, 0, representative.pub, 2, 4, key.prv, key.pub, 5);
|
||||
roots_hashes.push_back (std::make_pair (open.hash (), open.root ()));
|
||||
for (auto i (roots_hashes.size ()); i < 7; i++)
|
||||
{
|
||||
nano::keypair key1;
|
||||
nano::keypair previous;
|
||||
nano::state_block block (key1.pub, previous.pub, representative.pub, 2, 4, key1.prv, key1.pub, 5);
|
||||
nano::block_hash previous;
|
||||
nano::random_pool::generate_block (previous.bytes.data (), previous.bytes.size ());
|
||||
nano::state_block block (key1.pub, previous, representative.pub, 2, 4, key1.prv, key1.pub, 5);
|
||||
roots_hashes.push_back (std::make_pair (block.hash (), block.root ()));
|
||||
}
|
||||
roots_hashes.push_back (std::make_pair (open.hash (), open.root ()));
|
||||
|
|
|
@ -62,7 +62,7 @@ TEST (message_parser, exact_confirm_ack_size)
|
|||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer (block_uniquer);
|
||||
nano::message_parser parser (block_uniquer, vote_uniquer, visitor, system.work);
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (1)));
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (nano::root (1))));
|
||||
auto vote (std::make_shared<nano::vote> (0, nano::keypair ().prv, 0, std::move (block)));
|
||||
nano::confirm_ack message (vote);
|
||||
std::vector<uint8_t> bytes;
|
||||
|
@ -95,7 +95,7 @@ TEST (message_parser, exact_confirm_req_size)
|
|||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer (block_uniquer);
|
||||
nano::message_parser parser (block_uniquer, vote_uniquer, visitor, system.work);
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (1)));
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (nano::root (1))));
|
||||
nano::confirm_req message (std::move (block));
|
||||
std::vector<uint8_t> bytes;
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ TEST (message_parser, exact_confirm_req_hash_size)
|
|||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer (block_uniquer);
|
||||
nano::message_parser parser (block_uniquer, vote_uniquer, visitor, system.work);
|
||||
nano::send_block block (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (1));
|
||||
nano::send_block block (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (nano::root (1)));
|
||||
nano::confirm_req message (block.hash (), block.root ());
|
||||
std::vector<uint8_t> bytes;
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ TEST (message_parser, exact_publish_size)
|
|||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer (block_uniquer);
|
||||
nano::message_parser parser (block_uniquer, vote_uniquer, visitor, system.work);
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (1)));
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (nano::root (1))));
|
||||
nano::publish message (std::move (block));
|
||||
std::vector<uint8_t> bytes;
|
||||
{
|
||||
|
|
|
@ -220,7 +220,7 @@ TEST (network, multi_keepalive)
|
|||
TEST (network, send_discarded_publish)
|
||||
{
|
||||
nano::system system (24000, 2);
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (1)));
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 2, nano::keypair ().prv, 4, system.work.generate (nano::root (1))));
|
||||
nano::genesis genesis;
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
|
@ -242,7 +242,7 @@ TEST (network, send_invalid_publish)
|
|||
{
|
||||
nano::system system (24000, 2);
|
||||
nano::genesis genesis;
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 20, nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (1)));
|
||||
auto block (std::make_shared<nano::send_block> (1, 1, 20, nano::test_genesis_key.prv, nano::test_genesis_key.pub, system.work.generate (nano::root (1))));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_read ());
|
||||
system.nodes[0]->network.flood_block (block);
|
||||
|
@ -466,7 +466,7 @@ TEST (bulk_pull, no_address)
|
|||
nano::system system (24000, 1);
|
||||
auto connection (std::make_shared<nano::bootstrap_server> (nullptr, system.nodes[0]));
|
||||
std::unique_ptr<nano::bulk_pull> req (new nano::bulk_pull);
|
||||
req->start = 1;
|
||||
req->start = nano::root (1);
|
||||
req->end = 2;
|
||||
connection->requests.push (std::unique_ptr<nano::message>{});
|
||||
auto request (std::make_shared<nano::bulk_pull_server> (connection, std::move (req)));
|
||||
|
@ -790,7 +790,7 @@ TEST (bootstrap_processor, push_one)
|
|||
nano::system system (24000, 1);
|
||||
nano::keypair key1;
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
auto wallet (node1->wallets.create (nano::uint256_union ()));
|
||||
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
wallet->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::uint128_t balance1 (node1->balance (nano::test_genesis_key.pub));
|
||||
|
@ -891,7 +891,7 @@ TEST (bootstrap_processor, wallet_lazy_frontier)
|
|||
// Start wallet lazy bootstrap
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->network.udp_channels.insert (system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version);
|
||||
auto wallet (node1->wallets.create (nano::uint256_union ()));
|
||||
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
wallet->insert_adhoc (key2.prv);
|
||||
node1->bootstrap_wallet ();
|
||||
|
@ -922,7 +922,7 @@ TEST (bootstrap_processor, wallet_lazy_pending)
|
|||
// Start wallet lazy bootstrap
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, nano::unique_path (), system.alarm, system.logging, system.work));
|
||||
node1->network.udp_channels.insert (system.nodes[0]->network.endpoint (), node1->network_params.protocol.protocol_version);
|
||||
auto wallet (node1->wallets.create (nano::uint256_union ()));
|
||||
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
wallet->insert_adhoc (key2.prv);
|
||||
node1->bootstrap_wallet ();
|
||||
|
@ -1085,7 +1085,7 @@ TEST (bulk, offline_send)
|
|||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
nano::keypair key2;
|
||||
auto wallet (node1->wallets.create (nano::uint256_union ()));
|
||||
auto wallet (node1->wallets.create (nano::random_wallet_id ()));
|
||||
wallet->insert_adhoc (key2.prv);
|
||||
ASSERT_NE (nullptr, system.wallet (0)->send_action (nano::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ()));
|
||||
ASSERT_NE (std::numeric_limits<nano::uint256_t>::max (), system.nodes[0]->balance (nano::test_genesis_key.pub));
|
||||
|
@ -1383,7 +1383,7 @@ TEST (message_buffer_manager, stats)
|
|||
TEST (bulk_pull_account, basics)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
system.nodes[0]->config.receive_minimum = nano::uint128_union (20);
|
||||
system.nodes[0]->config.receive_minimum = 20;
|
||||
nano::keypair key1;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
system.wallet (0)->insert_adhoc (key1.prv);
|
||||
|
|
|
@ -2292,7 +2292,7 @@ TEST (node, confirm_quorum)
|
|||
nano::genesis genesis;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
// Put greater than online_weight_minimum in pending so quorum can't be reached
|
||||
nano::uint128_union new_balance (system.nodes[0]->config.online_weight_minimum.number () - nano::Gxrb_ratio);
|
||||
nano::amount new_balance (system.nodes[0]->config.online_weight_minimum.number () - nano::Gxrb_ratio);
|
||||
auto send1 (std::make_shared<nano::state_block> (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, new_balance, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, *system.nodes[0]->work_generate_blocking (genesis.hash ())));
|
||||
{
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
|
@ -2407,7 +2407,7 @@ TEST (node, local_votes_cache_generate_new_vote)
|
|||
ASSERT_EQ (nano::process_result::progress, node.ledger.process (transaction, *send2).code);
|
||||
}
|
||||
// Generate new vote for request with 2 hashes (one of hashes is cached)
|
||||
std::vector<std::pair<nano::block_hash, nano::block_hash>> roots_hashes{ std::make_pair (send1->hash (), send1->root ()), std::make_pair (send2->hash (), send2->root ()) };
|
||||
std::vector<std::pair<nano::block_hash, nano::root>> roots_hashes{ std::make_pair (send1->hash (), send1->root ()), std::make_pair (send2->hash (), send2->root ()) };
|
||||
nano::confirm_req message2 (roots_hashes);
|
||||
for (auto i (0); i < 100; ++i)
|
||||
{
|
||||
|
|
|
@ -37,14 +37,14 @@ namespace nano
|
|||
{
|
||||
using uint128_t = boost::multiprecision::uint128_t;
|
||||
class keypair;
|
||||
union uint256_union;
|
||||
class public_key;
|
||||
extern nano::keypair const & zero_key;
|
||||
extern nano::keypair const & test_genesis_key;
|
||||
extern std::string const & nano_test_genesis;
|
||||
extern std::string const & genesis_block;
|
||||
extern nano::uint256_union const & nano_test_account;
|
||||
extern nano::uint256_union const & genesis_account;
|
||||
extern nano::uint256_union const & burn_account;
|
||||
extern nano::public_key const & nano_test_account;
|
||||
extern nano::public_key const & genesis_account;
|
||||
extern nano::public_key const & burn_account;
|
||||
extern nano::uint128_t const & genesis_amount;
|
||||
|
||||
class stringstream_mt_sink : public boost::iostreams::sink
|
||||
|
|
|
@ -174,7 +174,7 @@ TEST (uint256_union, key_encryption)
|
|||
nano::raw_key key4;
|
||||
key4.decrypt (encrypted, secret_key, key1.pub.owords[0]);
|
||||
ASSERT_EQ (key1.prv, key4);
|
||||
nano::public_key pub (nano::pub_key (key4.data));
|
||||
auto pub (nano::pub_key (key4.as_private_key ()));
|
||||
ASSERT_EQ (key1.pub, pub);
|
||||
}
|
||||
|
||||
|
@ -367,14 +367,14 @@ TEST (uint256_union, big_endian_union_function)
|
|||
|
||||
TEST (uint256_union, decode_nano_variant)
|
||||
{
|
||||
nano::uint256_union key;
|
||||
nano::account key;
|
||||
ASSERT_FALSE (key.decode_account ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp"));
|
||||
ASSERT_FALSE (key.decode_account ("nano_1111111111111111111111111111111111111111111111111111hifc8npp"));
|
||||
}
|
||||
|
||||
TEST (uint256_union, account_transcode)
|
||||
{
|
||||
nano::uint256_union value;
|
||||
nano::account value;
|
||||
auto text (nano::test_genesis_key.pub.to_account ());
|
||||
ASSERT_FALSE (value.decode_account (text));
|
||||
ASSERT_EQ (nano::test_genesis_key.pub, value);
|
||||
|
@ -386,15 +386,15 @@ TEST (uint256_union, account_transcode)
|
|||
unsigned offset = (text.front () == 'x') ? 3 : 4;
|
||||
ASSERT_EQ ('_', text[offset]);
|
||||
text[offset] = '-';
|
||||
nano::uint256_union value2;
|
||||
nano::account value2;
|
||||
ASSERT_FALSE (value2.decode_account (text));
|
||||
ASSERT_EQ (value, value2);
|
||||
}
|
||||
|
||||
TEST (uint256_union, account_encode_lex)
|
||||
{
|
||||
nano::uint256_union min ("0000000000000000000000000000000000000000000000000000000000000000");
|
||||
nano::uint256_union max ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
nano::account min ("0000000000000000000000000000000000000000000000000000000000000000");
|
||||
nano::account max ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
auto min_text (min.to_account ());
|
||||
auto max_text (max.to_account ());
|
||||
|
||||
|
@ -408,9 +408,9 @@ TEST (uint256_union, account_encode_lex)
|
|||
auto previous (min_text);
|
||||
for (auto i (1); i != 1000; ++i)
|
||||
{
|
||||
nano::uint256_union number (min.number () + i);
|
||||
nano::account number (min.number () + i);
|
||||
auto text (number.to_account ());
|
||||
nano::uint256_union output;
|
||||
nano::account output;
|
||||
output.decode_account (text);
|
||||
ASSERT_EQ (number, output);
|
||||
ASSERT_GT (text, previous);
|
||||
|
@ -420,7 +420,7 @@ TEST (uint256_union, account_encode_lex)
|
|||
{
|
||||
nano::keypair key;
|
||||
auto text (key.pub.to_account ());
|
||||
nano::uint256_union output;
|
||||
nano::account output;
|
||||
output.decode_account (text);
|
||||
ASSERT_EQ (key.pub, output);
|
||||
}
|
||||
|
@ -428,7 +428,7 @@ TEST (uint256_union, account_encode_lex)
|
|||
|
||||
TEST (uint256_union, bounds)
|
||||
{
|
||||
nano::uint256_union key;
|
||||
nano::account key;
|
||||
std::string bad1 (64, '\x000');
|
||||
bad1[0] = 'x';
|
||||
bad1[1] = 'r';
|
||||
|
|
|
@ -26,7 +26,7 @@ TEST (wallet, no_special_keys_accounts)
|
|||
|
||||
for (uint64_t account = 0; account < nano::wallet_store::special_count; account++)
|
||||
{
|
||||
nano::uint256_union account_l (account);
|
||||
nano::account account_l (account);
|
||||
ASSERT_FALSE (wallet.exists (transaction, account_l));
|
||||
}
|
||||
}
|
||||
|
@ -145,20 +145,20 @@ TEST (wallet, two_item_iteration)
|
|||
wallet.insert_adhoc (transaction, key2.prv);
|
||||
for (auto i (wallet.begin (transaction)), j (wallet.end ()); i != j; ++i)
|
||||
{
|
||||
pubs.insert (nano::uint256_union (i->first));
|
||||
pubs.insert (i->first);
|
||||
nano::raw_key password;
|
||||
wallet.wallet_key (password, transaction);
|
||||
nano::raw_key key;
|
||||
key.decrypt (nano::wallet_value (i->second).key, password, (nano::uint256_union (i->first)).owords[0].number ());
|
||||
prvs.insert (key.data);
|
||||
key.decrypt (nano::wallet_value (i->second).key, password, (i->first).owords[0].number ());
|
||||
prvs.insert (key.as_private_key ());
|
||||
}
|
||||
}
|
||||
ASSERT_EQ (2, pubs.size ());
|
||||
ASSERT_EQ (2, prvs.size ());
|
||||
ASSERT_NE (pubs.end (), pubs.find (key1.pub));
|
||||
ASSERT_NE (prvs.end (), prvs.find (key1.prv.data));
|
||||
ASSERT_NE (prvs.end (), prvs.find (key1.prv.as_private_key ()));
|
||||
ASSERT_NE (pubs.end (), pubs.find (key2.pub));
|
||||
ASSERT_NE (prvs.end (), prvs.find (key2.prv.data));
|
||||
ASSERT_NE (prvs.end (), prvs.find (key2.prv.as_private_key ()));
|
||||
}
|
||||
|
||||
TEST (wallet, insufficient_spend_one)
|
||||
|
@ -281,7 +281,7 @@ TEST (wallet, find_none)
|
|||
nano::kdf kdf;
|
||||
nano::wallet_store wallet (init, kdf, transaction, nano::genesis_account, 1, "0");
|
||||
ASSERT_FALSE (init);
|
||||
nano::uint256_union account (1000);
|
||||
nano::account account (1000);
|
||||
ASSERT_EQ (wallet.end (), wallet.find (transaction, account));
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ TEST (wallet, rekey)
|
|||
|
||||
TEST (account, encode_zero)
|
||||
{
|
||||
nano::uint256_union number0 (0);
|
||||
nano::account number0 (0);
|
||||
std::string str0;
|
||||
number0.encode_account (str0);
|
||||
|
||||
|
@ -345,14 +345,14 @@ TEST (account, encode_zero)
|
|||
*/
|
||||
ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ());
|
||||
ASSERT_EQ (65, str0.size ());
|
||||
nano::uint256_union number1;
|
||||
nano::account number1;
|
||||
ASSERT_FALSE (number1.decode_account (str0));
|
||||
ASSERT_EQ (number0, number1);
|
||||
}
|
||||
|
||||
TEST (account, encode_all)
|
||||
{
|
||||
nano::uint256_union number0;
|
||||
nano::account number0;
|
||||
number0.decode_hex ("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
||||
std::string str0;
|
||||
number0.encode_account (str0);
|
||||
|
@ -361,18 +361,18 @@ TEST (account, encode_all)
|
|||
* Handle different lengths for "xrb_" prefixed and "nano_" prefixed accounts
|
||||
*/
|
||||
ASSERT_EQ ((str0.front () == 'x') ? 64 : 65, str0.size ());
|
||||
nano::uint256_union number1;
|
||||
nano::account number1;
|
||||
ASSERT_FALSE (number1.decode_account (str0));
|
||||
ASSERT_EQ (number0, number1);
|
||||
}
|
||||
|
||||
TEST (account, encode_fail)
|
||||
{
|
||||
nano::uint256_union number0 (0);
|
||||
nano::account number0 (0);
|
||||
std::string str0;
|
||||
number0.encode_account (str0);
|
||||
str0[16] ^= 1;
|
||||
nano::uint256_union number1;
|
||||
nano::account number1;
|
||||
ASSERT_TRUE (number1.decode_account (str0));
|
||||
}
|
||||
|
||||
|
@ -639,7 +639,7 @@ TEST (wallet, work)
|
|||
wallet->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::genesis genesis;
|
||||
auto done (false);
|
||||
system.deadline_set (10s);
|
||||
system.deadline_set (20s);
|
||||
while (!done)
|
||||
{
|
||||
auto transaction (system.wallet (0)->wallets.tx_begin_read ());
|
||||
|
@ -746,13 +746,10 @@ TEST (wallet, deterministic_keys)
|
|||
auto transaction (env.tx_begin_write ());
|
||||
nano::kdf kdf;
|
||||
nano::wallet_store wallet (init, kdf, transaction, nano::genesis_account, 1, "0");
|
||||
nano::raw_key key1;
|
||||
wallet.deterministic_key (key1, transaction, 0);
|
||||
nano::raw_key key2;
|
||||
wallet.deterministic_key (key2, transaction, 0);
|
||||
auto key1 = wallet.deterministic_key (transaction, 0);
|
||||
auto key2 = wallet.deterministic_key (transaction, 0);
|
||||
ASSERT_EQ (key1, key2);
|
||||
nano::raw_key key3;
|
||||
wallet.deterministic_key (key3, transaction, 1);
|
||||
auto key3 = wallet.deterministic_key (transaction, 1);
|
||||
ASSERT_NE (key1, key3);
|
||||
ASSERT_EQ (0, wallet.deterministic_index_get (transaction));
|
||||
wallet.deterministic_index_set (transaction, 1);
|
||||
|
@ -760,7 +757,7 @@ TEST (wallet, deterministic_keys)
|
|||
auto key4 (wallet.deterministic_insert (transaction));
|
||||
nano::raw_key key5;
|
||||
ASSERT_FALSE (wallet.fetch (transaction, key4, key5));
|
||||
ASSERT_EQ (key3, key5);
|
||||
ASSERT_EQ (key3, key5.as_private_key ());
|
||||
ASSERT_EQ (2, wallet.deterministic_index_get (transaction));
|
||||
wallet.deterministic_index_set (transaction, 1);
|
||||
ASSERT_EQ (1, wallet.deterministic_index_get (transaction));
|
||||
|
@ -905,11 +902,11 @@ TEST (wallet, upgrade_backup)
|
|||
};
|
||||
// clang-format on
|
||||
|
||||
nano::keypair id;
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
{
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, dir, system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
auto wallet (node1->wallets.create (id.pub));
|
||||
auto wallet (node1->wallets.create (wallet_id));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
auto transaction (node1->wallets.tx_begin_write ());
|
||||
wallet->store.version_put (transaction, 3);
|
||||
|
@ -920,7 +917,7 @@ TEST (wallet, upgrade_backup)
|
|||
{
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, dir, system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
auto wallet (node1->wallets.open (id.pub));
|
||||
auto wallet (node1->wallets.open (wallet_id));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
auto transaction (node1->wallets.tx_begin_write ());
|
||||
ASSERT_LT (3u, wallet->store.version (transaction));
|
||||
|
@ -934,7 +931,7 @@ TEST (wallet, upgrade_backup)
|
|||
node_config.backup_before_upgrade = true;
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, dir, system.alarm, node_config, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
auto wallet (node1->wallets.open (id.pub));
|
||||
auto wallet (node1->wallets.open (wallet_id));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
auto transaction (node1->wallets.tx_begin_read ());
|
||||
ASSERT_LT (3u, wallet->store.version (transaction));
|
||||
|
@ -1076,9 +1073,8 @@ TEST (wallet, change_seed)
|
|||
seed1.data = 1;
|
||||
nano::public_key pub;
|
||||
uint32_t index (4);
|
||||
nano::raw_key prv;
|
||||
nano::deterministic_key (seed1.data, index, prv.data);
|
||||
pub = nano::pub_key (prv.data);
|
||||
auto prv = nano::deterministic_key (seed1, index);
|
||||
pub = nano::pub_key (prv);
|
||||
wallet->insert_adhoc (nano::test_genesis_key.prv, false);
|
||||
auto block (wallet->send_action (nano::test_genesis_key.pub, pub, 100));
|
||||
ASSERT_NE (nullptr, block);
|
||||
|
@ -1110,9 +1106,8 @@ TEST (wallet, deterministic_restore)
|
|||
wallet->store.seed (seed2, transaction);
|
||||
ASSERT_EQ (seed1, seed2);
|
||||
ASSERT_EQ (1, wallet->store.deterministic_index_get (transaction));
|
||||
nano::raw_key prv;
|
||||
nano::deterministic_key (seed1.data, index, prv.data);
|
||||
pub = nano::pub_key (prv.data);
|
||||
auto prv = nano::deterministic_key (seed1, index);
|
||||
pub = nano::pub_key (prv);
|
||||
}
|
||||
wallet->insert_adhoc (nano::test_genesis_key.prv, false);
|
||||
auto block (wallet->send_action (nano::test_genesis_key.pub, pub, 100));
|
||||
|
|
|
@ -16,8 +16,7 @@ TEST (wallets, open_create)
|
|||
nano::wallets wallets (error, *system.nodes[0]);
|
||||
ASSERT_FALSE (error);
|
||||
ASSERT_EQ (1, wallets.items.size ()); // it starts out with a default wallet
|
||||
nano::keypair random_key;
|
||||
nano::uint256_union id (random_key.pub);
|
||||
auto id = nano::random_wallet_id ();
|
||||
ASSERT_EQ (nullptr, wallets.open (id));
|
||||
auto wallet (wallets.create (id));
|
||||
ASSERT_NE (nullptr, wallet);
|
||||
|
@ -27,8 +26,7 @@ TEST (wallets, open_create)
|
|||
TEST (wallets, open_existing)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
nano::keypair random_key;
|
||||
nano::uint256_union id (random_key.pub);
|
||||
auto id (nano::random_wallet_id ());
|
||||
{
|
||||
bool error (false);
|
||||
nano::wallets wallets (error, *system.nodes[0]);
|
||||
|
@ -58,7 +56,7 @@ TEST (wallets, open_existing)
|
|||
TEST (wallets, remove)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
nano::uint256_union one (1);
|
||||
nano::wallet_id one (1);
|
||||
{
|
||||
bool error (false);
|
||||
nano::wallets wallets (error, *system.nodes[0]);
|
||||
|
@ -83,19 +81,19 @@ TEST (wallets, upgrade)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
auto path (nano::unique_path ());
|
||||
nano::keypair id;
|
||||
auto id = nano::random_wallet_id ();
|
||||
{
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, path, system.alarm, system.logging, system.work));
|
||||
ASSERT_FALSE (node1->init_error ());
|
||||
bool error (false);
|
||||
nano::wallets wallets (error, *node1);
|
||||
wallets.create (id.pub);
|
||||
wallets.create (id);
|
||||
auto transaction_source (node1->wallets.env.tx_begin_write ());
|
||||
auto tx_source = static_cast<MDB_txn *> (transaction_source.get_handle ());
|
||||
auto & mdb_store (dynamic_cast<nano::mdb_store &> (node1->store));
|
||||
auto transaction_destination (mdb_store.tx_begin_write ());
|
||||
auto tx_destination = static_cast<MDB_txn *> (transaction_destination.get_handle ());
|
||||
wallets.move_table (id.pub.to_string (), tx_source, tx_destination);
|
||||
wallets.move_table (id.to_string (), tx_source, tx_destination);
|
||||
node1->store.version_put (transaction_destination, 11);
|
||||
|
||||
nano::account_info info;
|
||||
|
@ -108,15 +106,15 @@ TEST (wallets, upgrade)
|
|||
}
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, 24001, path, system.alarm, system.logging, system.work));
|
||||
ASSERT_EQ (1, node1->wallets.items.size ());
|
||||
ASSERT_EQ (id.pub, node1->wallets.items.begin ()->first);
|
||||
ASSERT_EQ (id, node1->wallets.items.begin ()->first);
|
||||
auto transaction_new (node1->wallets.env.tx_begin_write ());
|
||||
auto tx_new = static_cast<MDB_txn *> (transaction_new.get_handle ());
|
||||
auto transaction_old (node1->store.tx_begin_write ());
|
||||
auto tx_old = static_cast<MDB_txn *> (transaction_old.get_handle ());
|
||||
MDB_dbi old_handle;
|
||||
ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (tx_old, id.pub.to_string ().c_str (), 0, &old_handle));
|
||||
ASSERT_EQ (MDB_NOTFOUND, mdb_dbi_open (tx_old, id.to_string ().c_str (), 0, &old_handle));
|
||||
MDB_dbi new_handle;
|
||||
ASSERT_EQ (0, mdb_dbi_open (tx_new, id.pub.to_string ().c_str (), 0, &new_handle));
|
||||
ASSERT_EQ (0, mdb_dbi_open (tx_new, id.to_string ().c_str (), 0, &new_handle));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -129,25 +127,25 @@ TEST (wallets, DISABLED_wallet_create_max)
|
|||
const int nonWalletDbs = 19;
|
||||
for (int i = 0; i < system.nodes[0]->config.lmdb_max_dbs - nonWalletDbs; i++)
|
||||
{
|
||||
nano::keypair key;
|
||||
auto wallet = wallets.create (key.pub);
|
||||
auto existing = wallets.items.find (key.pub);
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
auto wallet = wallets.create (wallet_id);
|
||||
auto existing = wallets.items.find (wallet_id);
|
||||
ASSERT_TRUE (existing != wallets.items.end ());
|
||||
nano::raw_key seed;
|
||||
seed.data = 0;
|
||||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
existing->second->store.seed_set (transaction, seed);
|
||||
}
|
||||
nano::keypair key;
|
||||
wallets.create (key.pub);
|
||||
auto existing = wallets.items.find (key.pub);
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
wallets.create (wallet_id);
|
||||
auto existing = wallets.items.find (wallet_id);
|
||||
ASSERT_TRUE (existing == wallets.items.end ());
|
||||
}
|
||||
|
||||
TEST (wallets, reload)
|
||||
{
|
||||
nano::system system (24000, 1);
|
||||
nano::uint256_union one (1);
|
||||
nano::wallet_id one (1);
|
||||
bool error (false);
|
||||
ASSERT_FALSE (error);
|
||||
ASSERT_EQ (1, system.nodes[0]->wallets.items.size ());
|
||||
|
|
|
@ -234,9 +234,7 @@ TEST (websocket, confirmation)
|
|||
config.websocket_config.port = 24078;
|
||||
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), system.alarm, config, system.work, node_flags));
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node1->wallets.create (wallet);
|
||||
node1->wallets.create (nano::random_wallet_id ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
||||
|
@ -344,9 +342,7 @@ TEST (websocket, stopped_election)
|
|||
config.websocket_config.port = 24078;
|
||||
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), system.alarm, config, system.work, node_flags));
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node1->wallets.create (wallet);
|
||||
node1->wallets.create (nano::random_wallet_id ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
||||
|
@ -406,9 +402,7 @@ TEST (websocket, confirmation_options)
|
|||
config.websocket_config.port = 24078;
|
||||
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), system.alarm, config, system.work, node_flags));
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node1->wallets.create (wallet);
|
||||
node1->wallets.create (nano::random_wallet_id ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
||||
|
@ -555,9 +549,7 @@ TEST (websocket, vote)
|
|||
config.websocket_config.port = 24078;
|
||||
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), system.alarm, config, system.work, node_flags));
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node1->wallets.create (wallet);
|
||||
node1->wallets.create (nano::random_wallet_id ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
||||
|
@ -618,9 +610,7 @@ TEST (websocket, vote_options)
|
|||
config.websocket_config.port = 24078;
|
||||
|
||||
auto node1 (std::make_shared<nano::node> (system.io_ctx, nano::unique_path (), system.alarm, config, system.work, node_flags));
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node1->wallets.create (wallet);
|
||||
node1->wallets.create (nano::random_wallet_id ());
|
||||
node1->start ();
|
||||
system.nodes.push_back (node1);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ TEST (work, cancel)
|
|||
auto done (false);
|
||||
while (!done)
|
||||
{
|
||||
nano::uint256_union key (1);
|
||||
nano::root key (1);
|
||||
pool.generate (key, [&done](boost::optional<uint64_t> work_a) {
|
||||
done = !work_a;
|
||||
});
|
||||
|
@ -50,12 +50,12 @@ TEST (work, cancel)
|
|||
TEST (work, cancel_many)
|
||||
{
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
|
||||
nano::uint256_union key1 (1);
|
||||
nano::uint256_union key2 (2);
|
||||
nano::uint256_union key3 (1);
|
||||
nano::uint256_union key4 (1);
|
||||
nano::uint256_union key5 (3);
|
||||
nano::uint256_union key6 (1);
|
||||
nano::root key1 (1);
|
||||
nano::root key2 (2);
|
||||
nano::root key3 (1);
|
||||
nano::root key4 (1);
|
||||
nano::root key5 (3);
|
||||
nano::root key6 (1);
|
||||
pool.generate (key1, [](boost::optional<uint64_t>) {});
|
||||
pool.generate (key2, [](boost::optional<uint64_t>) {});
|
||||
pool.generate (key3, [](boost::optional<uint64_t>) {});
|
||||
|
@ -78,12 +78,12 @@ TEST (work, opencl)
|
|||
auto opencl (nano::opencl_work::create (true, { 0, 0, 16 * 1024 }, logger));
|
||||
if (opencl != nullptr)
|
||||
{
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max (), std::chrono::nanoseconds (0), opencl ? [&opencl](nano::uint256_union const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max (), std::chrono::nanoseconds (0), opencl ? [&opencl](nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
return opencl->generate_work (root_a, difficulty_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> & ticket_a)> (nullptr));
|
||||
: std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> & ticket_a)> (nullptr));
|
||||
ASSERT_NE (nullptr, pool.opencl);
|
||||
nano::uint256_union root;
|
||||
nano::root root;
|
||||
uint64_t difficulty (0xff00000000000000);
|
||||
uint64_t difficulty_add (0x000f000000000000);
|
||||
for (auto i (0); i < 16; ++i)
|
||||
|
@ -125,7 +125,7 @@ TEST (work, opencl_config)
|
|||
TEST (work, difficulty)
|
||||
{
|
||||
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
|
||||
nano::uint256_union root (1);
|
||||
nano::root root (1);
|
||||
uint64_t difficulty1 (0xff00000000000000);
|
||||
uint64_t difficulty2 (0xfff0000000000000);
|
||||
uint64_t difficulty3 (0xffff000000000000);
|
||||
|
@ -155,7 +155,7 @@ TEST (work, eco_pow)
|
|||
timer.start ();
|
||||
for (int i = 0; i < num_iterations; ++i)
|
||||
{
|
||||
nano::uint256_union root (1);
|
||||
nano::root root (1);
|
||||
uint64_t difficulty1 (0xff00000000000000);
|
||||
uint64_t difficulty2 (0xfff0000000000000);
|
||||
uint64_t nonce (0);
|
||||
|
|
|
@ -244,93 +244,93 @@ nano::state_block_builder & nano::state_block_builder::zero ()
|
|||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::account (nano::account account)
|
||||
nano::state_block_builder & nano::state_block_builder::account (nano::account const & account)
|
||||
{
|
||||
block->hashables.account = account;
|
||||
build_state |= build_flags::account_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::account_hex (std::string account_hex)
|
||||
nano::state_block_builder & nano::state_block_builder::account_hex (std::string const & account_hex)
|
||||
{
|
||||
account_hex_impl (account_hex, ec, block);
|
||||
build_state |= build_flags::account_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::account_address (std::string address)
|
||||
nano::state_block_builder & nano::state_block_builder::account_address (std::string const & address)
|
||||
{
|
||||
account_address_impl (address, ec, block);
|
||||
build_state |= build_flags::account_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::representative (nano::account account)
|
||||
nano::state_block_builder & nano::state_block_builder::representative (nano::account const & account)
|
||||
{
|
||||
block->hashables.representative = account;
|
||||
build_state |= build_flags::representative_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::representative_hex (std::string account_hex)
|
||||
nano::state_block_builder & nano::state_block_builder::representative_hex (std::string const & account_hex)
|
||||
{
|
||||
representative_hex_impl (account_hex, ec, block);
|
||||
build_state |= build_flags::representative_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::representative_address (std::string address)
|
||||
nano::state_block_builder & nano::state_block_builder::representative_address (std::string const & address)
|
||||
{
|
||||
representative_address_impl (address, ec, block);
|
||||
build_state |= build_flags::representative_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::previous (nano::block_hash previous)
|
||||
nano::state_block_builder & nano::state_block_builder::previous (nano::block_hash const & previous)
|
||||
{
|
||||
block->hashables.previous = previous;
|
||||
build_state |= build_flags::previous_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::previous_hex (std::string previous_hex)
|
||||
nano::state_block_builder & nano::state_block_builder::previous_hex (std::string const & previous_hex)
|
||||
{
|
||||
previous_hex_impl (previous_hex, ec, block);
|
||||
build_state |= build_flags::previous_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::balance (nano::amount balance)
|
||||
nano::state_block_builder & nano::state_block_builder::balance (nano::amount const & balance)
|
||||
{
|
||||
block->hashables.balance = balance;
|
||||
build_state |= build_flags::balance_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::balance_dec (std::string balance_decimal)
|
||||
nano::state_block_builder & nano::state_block_builder::balance_dec (std::string const & balance_decimal)
|
||||
{
|
||||
balance_dec_impl (balance_decimal, ec, block);
|
||||
build_state |= build_flags::balance_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::balance_hex (std::string balance_hex)
|
||||
nano::state_block_builder & nano::state_block_builder::balance_hex (std::string const & balance_hex)
|
||||
{
|
||||
balance_hex_impl (balance_hex, ec, block);
|
||||
build_state |= build_flags::balance_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::link (nano::uint256_union link)
|
||||
nano::state_block_builder & nano::state_block_builder::link (nano::link const & link)
|
||||
{
|
||||
block->hashables.link = link;
|
||||
build_state |= build_flags::link_present;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::link_hex (std::string link_hex)
|
||||
nano::state_block_builder & nano::state_block_builder::link_hex (std::string const & link_hex)
|
||||
{
|
||||
nano::uint256_union link;
|
||||
nano::link link;
|
||||
if (!link.decode_hex (link_hex))
|
||||
{
|
||||
block->hashables.link = link;
|
||||
|
@ -343,9 +343,9 @@ nano::state_block_builder & nano::state_block_builder::link_hex (std::string lin
|
|||
return *this;
|
||||
}
|
||||
|
||||
nano::state_block_builder & nano::state_block_builder::link_address (std::string link_address)
|
||||
nano::state_block_builder & nano::state_block_builder::link_address (std::string const & link_address)
|
||||
{
|
||||
nano::account link;
|
||||
nano::link link;
|
||||
if (!link.decode_account (link_address))
|
||||
{
|
||||
block->hashables.link = link;
|
||||
|
|
|
@ -133,33 +133,33 @@ public:
|
|||
/** Sets all hashables, signature and work to zero. */
|
||||
state_block_builder & zero ();
|
||||
/** Set account */
|
||||
state_block_builder & account (nano::account account);
|
||||
state_block_builder & account (nano::account const & account);
|
||||
/** Set account from hex representation of public key */
|
||||
state_block_builder & account_hex (std::string account_hex);
|
||||
state_block_builder & account_hex (std::string const & account_hex);
|
||||
/** Set account from an xrb_ or nano_ address */
|
||||
state_block_builder & account_address (std::string account_address);
|
||||
state_block_builder & account_address (std::string const & account_address);
|
||||
/** Set representative */
|
||||
state_block_builder & representative (nano::account account);
|
||||
state_block_builder & representative (nano::account const & account);
|
||||
/** Set representative from hex representation of public key */
|
||||
state_block_builder & representative_hex (std::string account_hex);
|
||||
state_block_builder & representative_hex (std::string const & account_hex);
|
||||
/** Set representative from an xrb_ or nano_ address */
|
||||
state_block_builder & representative_address (std::string account_address);
|
||||
state_block_builder & representative_address (std::string const & account_address);
|
||||
/** Set previous block hash */
|
||||
state_block_builder & previous (nano::block_hash previous);
|
||||
state_block_builder & previous (nano::block_hash const & previous);
|
||||
/** Set previous block hash from hex representation */
|
||||
state_block_builder & previous_hex (std::string previous_hex);
|
||||
state_block_builder & previous_hex (std::string const & previous_hex);
|
||||
/** Set balance */
|
||||
state_block_builder & balance (nano::amount balance);
|
||||
state_block_builder & balance (nano::amount const & balance);
|
||||
/** Set balance from decimal string */
|
||||
state_block_builder & balance_dec (std::string balance_decimal);
|
||||
state_block_builder & balance_dec (std::string const & balance_decimal);
|
||||
/** Set balance from hex string */
|
||||
state_block_builder & balance_hex (std::string balance_hex);
|
||||
state_block_builder & balance_hex (std::string const & balance_hex);
|
||||
/** Set link */
|
||||
state_block_builder & link (nano::uint256_union link);
|
||||
state_block_builder & link (nano::link const & link);
|
||||
/** Set link from hex representation */
|
||||
state_block_builder & link_hex (std::string link_hex);
|
||||
state_block_builder & link_hex (std::string const & link_hex);
|
||||
/** Set link from an xrb_ or nano_ address */
|
||||
state_block_builder & link_address (std::string link_address);
|
||||
state_block_builder & link_address (std::string const & link_address);
|
||||
/** Provides validation for build() */
|
||||
void validate ();
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ size_t nano::block::size (nano::block_type type_a)
|
|||
|
||||
nano::block_hash nano::block::hash () const
|
||||
{
|
||||
nano::uint256_union result;
|
||||
nano::block_hash result;
|
||||
blake2b_state hash_l;
|
||||
auto status (blake2b_init (&hash_l, sizeof (result.bytes)));
|
||||
assert (status == 0);
|
||||
|
@ -100,24 +100,28 @@ nano::block_hash nano::block::full_hash () const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::account nano::block::representative () const
|
||||
nano::account const & nano::block::representative () const
|
||||
{
|
||||
return 0;
|
||||
static nano::account rep{ 0 };
|
||||
return rep;
|
||||
}
|
||||
|
||||
nano::block_hash nano::block::source () const
|
||||
nano::block_hash const & nano::block::source () const
|
||||
{
|
||||
return 0;
|
||||
static nano::block_hash source{ 0 };
|
||||
return source;
|
||||
}
|
||||
|
||||
nano::block_hash nano::block::link () const
|
||||
nano::link const & nano::block::link () const
|
||||
{
|
||||
return 0;
|
||||
static nano::link link{ 0 };
|
||||
return link;
|
||||
}
|
||||
|
||||
nano::account nano::block::account () const
|
||||
nano::account const & nano::block::account () const
|
||||
{
|
||||
return 0;
|
||||
static nano::account account{ 0 };
|
||||
return account;
|
||||
}
|
||||
|
||||
nano::qualified_root nano::block::qualified_root () const
|
||||
|
@ -125,9 +129,10 @@ nano::qualified_root nano::block::qualified_root () const
|
|||
return nano::qualified_root (previous (), root ());
|
||||
}
|
||||
|
||||
nano::amount nano::block::balance () const
|
||||
nano::amount const & nano::block::balance () const
|
||||
{
|
||||
return 0;
|
||||
static nano::amount amount{ 0 };
|
||||
return amount;
|
||||
}
|
||||
|
||||
void nano::send_block::visit (nano::block_visitor & visitor_a) const
|
||||
|
@ -373,27 +378,27 @@ bool nano::send_block::operator== (nano::send_block const & other_a) const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::block_hash nano::send_block::previous () const
|
||||
nano::block_hash const & nano::send_block::previous () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::block_hash nano::send_block::root () const
|
||||
nano::root const & nano::send_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::amount nano::send_block::balance () const
|
||||
nano::amount const & nano::send_block::balance () const
|
||||
{
|
||||
return hashables.balance;
|
||||
}
|
||||
|
||||
nano::signature nano::send_block::block_signature () const
|
||||
nano::signature const & nano::send_block::block_signature () const
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
void nano::send_block::signature_set (nano::uint512_union const & signature_a)
|
||||
void nano::send_block::signature_set (nano::signature const & signature_a)
|
||||
{
|
||||
signature = signature_a;
|
||||
}
|
||||
|
@ -518,13 +523,13 @@ void nano::open_block::block_work_set (uint64_t work_a)
|
|||
work = work_a;
|
||||
}
|
||||
|
||||
nano::block_hash nano::open_block::previous () const
|
||||
nano::block_hash const & nano::open_block::previous () const
|
||||
{
|
||||
nano::block_hash result (0);
|
||||
static nano::block_hash result{ 0 };
|
||||
return result;
|
||||
}
|
||||
|
||||
nano::account nano::open_block::account () const
|
||||
nano::account const & nano::open_block::account () const
|
||||
{
|
||||
return hashables.account;
|
||||
}
|
||||
|
@ -639,27 +644,27 @@ bool nano::open_block::valid_predecessor (nano::block const & block_a) const
|
|||
return false;
|
||||
}
|
||||
|
||||
nano::block_hash nano::open_block::source () const
|
||||
nano::block_hash const & nano::open_block::source () const
|
||||
{
|
||||
return hashables.source;
|
||||
}
|
||||
|
||||
nano::block_hash nano::open_block::root () const
|
||||
nano::root const & nano::open_block::root () const
|
||||
{
|
||||
return hashables.account;
|
||||
}
|
||||
|
||||
nano::account nano::open_block::representative () const
|
||||
nano::account const & nano::open_block::representative () const
|
||||
{
|
||||
return hashables.representative;
|
||||
}
|
||||
|
||||
nano::signature nano::open_block::block_signature () const
|
||||
nano::signature const & nano::open_block::block_signature () const
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
void nano::open_block::signature_set (nano::uint512_union const & signature_a)
|
||||
void nano::open_block::signature_set (nano::signature const & signature_a)
|
||||
{
|
||||
signature = signature_a;
|
||||
}
|
||||
|
@ -768,7 +773,7 @@ void nano::change_block::block_work_set (uint64_t work_a)
|
|||
work = work_a;
|
||||
}
|
||||
|
||||
nano::block_hash nano::change_block::previous () const
|
||||
nano::block_hash const & nano::change_block::previous () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
@ -888,27 +893,27 @@ bool nano::change_block::valid_predecessor (nano::block const & block_a) const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::block_hash nano::change_block::root () const
|
||||
nano::root const & nano::change_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::account nano::change_block::representative () const
|
||||
nano::account const & nano::change_block::representative () const
|
||||
{
|
||||
return hashables.representative;
|
||||
}
|
||||
|
||||
nano::signature nano::change_block::block_signature () const
|
||||
nano::signature const & nano::change_block::block_signature () const
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
void nano::change_block::signature_set (nano::uint512_union const & signature_a)
|
||||
void nano::change_block::signature_set (nano::signature const & signature_a)
|
||||
{
|
||||
signature = signature_a;
|
||||
}
|
||||
|
||||
nano::state_hashables::state_hashables (nano::account const & account_a, nano::block_hash const & previous_a, nano::account const & representative_a, nano::amount const & balance_a, nano::uint256_union const & link_a) :
|
||||
nano::state_hashables::state_hashables (nano::account const & account_a, nano::block_hash const & previous_a, nano::account const & representative_a, nano::amount const & balance_a, nano::link const & link_a) :
|
||||
account (account_a),
|
||||
previous (previous_a),
|
||||
representative (representative_a),
|
||||
|
@ -975,7 +980,7 @@ void nano::state_hashables::hash (blake2b_state & hash_a) const
|
|||
blake2b_update (&hash_a, link.bytes.data (), sizeof (link.bytes));
|
||||
}
|
||||
|
||||
nano::state_block::state_block (nano::account const & account_a, nano::block_hash const & previous_a, nano::account const & representative_a, nano::amount const & balance_a, nano::uint256_union const & link_a, nano::raw_key const & prv_a, nano::public_key const & pub_a, uint64_t work_a) :
|
||||
nano::state_block::state_block (nano::account const & account_a, nano::block_hash const & previous_a, nano::account const & representative_a, nano::amount const & balance_a, nano::link const & link_a, nano::raw_key const & prv_a, nano::public_key const & pub_a, uint64_t work_a) :
|
||||
hashables (account_a, previous_a, representative_a, balance_a, link_a),
|
||||
signature (nano::sign_message (prv_a, pub_a, hash ())),
|
||||
work (work_a)
|
||||
|
@ -1044,12 +1049,12 @@ void nano::state_block::block_work_set (uint64_t work_a)
|
|||
work = work_a;
|
||||
}
|
||||
|
||||
nano::block_hash nano::state_block::previous () const
|
||||
nano::block_hash const & nano::state_block::previous () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::account nano::state_block::account () const
|
||||
nano::account const & nano::state_block::account () const
|
||||
{
|
||||
return hashables.account;
|
||||
}
|
||||
|
@ -1182,32 +1187,39 @@ bool nano::state_block::valid_predecessor (nano::block const & block_a) const
|
|||
return true;
|
||||
}
|
||||
|
||||
nano::block_hash nano::state_block::root () const
|
||||
nano::root const & nano::state_block::root () const
|
||||
{
|
||||
return !hashables.previous.is_zero () ? hashables.previous : hashables.account;
|
||||
if (!hashables.previous.is_zero ())
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hashables.account;
|
||||
}
|
||||
}
|
||||
|
||||
nano::block_hash nano::state_block::link () const
|
||||
nano::link const & nano::state_block::link () const
|
||||
{
|
||||
return hashables.link;
|
||||
}
|
||||
|
||||
nano::account nano::state_block::representative () const
|
||||
nano::account const & nano::state_block::representative () const
|
||||
{
|
||||
return hashables.representative;
|
||||
}
|
||||
|
||||
nano::amount nano::state_block::balance () const
|
||||
nano::amount const & nano::state_block::balance () const
|
||||
{
|
||||
return hashables.balance;
|
||||
}
|
||||
|
||||
nano::signature nano::state_block::block_signature () const
|
||||
nano::signature const & nano::state_block::block_signature () const
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
void nano::state_block::signature_set (nano::uint512_union const & signature_a)
|
||||
void nano::state_block::signature_set (nano::signature const & signature_a)
|
||||
{
|
||||
signature = signature_a;
|
||||
}
|
||||
|
@ -1503,27 +1515,27 @@ bool nano::receive_block::valid_predecessor (nano::block const & block_a) const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::block_hash nano::receive_block::previous () const
|
||||
nano::block_hash const & nano::receive_block::previous () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::block_hash nano::receive_block::source () const
|
||||
nano::block_hash const & nano::receive_block::source () const
|
||||
{
|
||||
return hashables.source;
|
||||
}
|
||||
|
||||
nano::block_hash nano::receive_block::root () const
|
||||
nano::root const & nano::receive_block::root () const
|
||||
{
|
||||
return hashables.previous;
|
||||
}
|
||||
|
||||
nano::signature nano::receive_block::block_signature () const
|
||||
nano::signature const & nano::receive_block::block_signature () const
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
void nano::receive_block::signature_set (nano::uint512_union const & signature_a)
|
||||
void nano::receive_block::signature_set (nano::signature const & signature_a)
|
||||
{
|
||||
signature = signature_a;
|
||||
}
|
||||
|
|
|
@ -64,27 +64,27 @@ public:
|
|||
virtual void hash (blake2b_state &) const = 0;
|
||||
virtual uint64_t block_work () const = 0;
|
||||
virtual void block_work_set (uint64_t) = 0;
|
||||
virtual nano::account account () const;
|
||||
virtual nano::account const & account () const;
|
||||
// Previous block in account's chain, zero for open block
|
||||
virtual nano::block_hash previous () const = 0;
|
||||
virtual nano::block_hash const & previous () const = 0;
|
||||
// Source block for open/receive blocks, zero otherwise.
|
||||
virtual nano::block_hash source () const;
|
||||
virtual nano::block_hash const & source () const;
|
||||
// Previous block or account number for open blocks
|
||||
virtual nano::block_hash root () const = 0;
|
||||
virtual nano::root const & root () const = 0;
|
||||
// Qualified root value based on previous() and root()
|
||||
virtual nano::qualified_root qualified_root () const;
|
||||
// Link field for state blocks, zero otherwise.
|
||||
virtual nano::block_hash link () const;
|
||||
virtual nano::account representative () const;
|
||||
virtual nano::amount balance () const;
|
||||
virtual nano::link const & link () const;
|
||||
virtual nano::account const & representative () const;
|
||||
virtual nano::amount const & balance () const;
|
||||
virtual void serialize (nano::stream &) const = 0;
|
||||
virtual void serialize_json (std::string &, bool = false) const = 0;
|
||||
virtual void serialize_json (boost::property_tree::ptree &) const = 0;
|
||||
virtual void visit (nano::block_visitor &) const = 0;
|
||||
virtual bool operator== (nano::block const &) const = 0;
|
||||
virtual nano::block_type type () const = 0;
|
||||
virtual nano::signature block_signature () const = 0;
|
||||
virtual void signature_set (nano::uint512_union const &) = 0;
|
||||
virtual nano::signature const & block_signature () const = 0;
|
||||
virtual void signature_set (nano::signature const &) = 0;
|
||||
virtual ~block () = default;
|
||||
virtual bool valid_predecessor (nano::block const &) const = 0;
|
||||
static size_t size (nano::block_type);
|
||||
|
@ -93,7 +93,7 @@ class send_hashables
|
|||
{
|
||||
public:
|
||||
send_hashables () = default;
|
||||
send_hashables (nano::account const &, nano::block_hash const &, nano::amount const &);
|
||||
send_hashables (nano::block_hash const &, nano::account const &, nano::amount const &);
|
||||
send_hashables (bool &, nano::stream &);
|
||||
send_hashables (bool &, boost::property_tree::ptree const &);
|
||||
void hash (blake2b_state &) const;
|
||||
|
@ -114,9 +114,9 @@ public:
|
|||
void hash (blake2b_state &) const override;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::block_hash previous () const override;
|
||||
nano::block_hash root () const override;
|
||||
nano::amount balance () const override;
|
||||
nano::block_hash const & previous () const override;
|
||||
nano::root const & root () const override;
|
||||
nano::amount const & balance () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
@ -124,8 +124,8 @@ public:
|
|||
bool deserialize_json (boost::property_tree::ptree const &);
|
||||
void visit (nano::block_visitor &) const override;
|
||||
nano::block_type type () const override;
|
||||
nano::signature block_signature () const override;
|
||||
void signature_set (nano::uint512_union const &) override;
|
||||
nano::signature const & block_signature () const override;
|
||||
void signature_set (nano::signature const &) override;
|
||||
bool operator== (nano::block const &) const override;
|
||||
bool operator== (nano::send_block const &) const;
|
||||
bool valid_predecessor (nano::block const &) const override;
|
||||
|
@ -158,9 +158,9 @@ public:
|
|||
void hash (blake2b_state &) const override;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::block_hash previous () const override;
|
||||
nano::block_hash source () const override;
|
||||
nano::block_hash root () const override;
|
||||
nano::block_hash const & previous () const override;
|
||||
nano::block_hash const & source () const override;
|
||||
nano::root const & root () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
@ -168,8 +168,8 @@ public:
|
|||
bool deserialize_json (boost::property_tree::ptree const &);
|
||||
void visit (nano::block_visitor &) const override;
|
||||
nano::block_type type () const override;
|
||||
nano::signature block_signature () const override;
|
||||
void signature_set (nano::uint512_union const &) override;
|
||||
nano::signature const & block_signature () const override;
|
||||
void signature_set (nano::signature const &) override;
|
||||
bool operator== (nano::block const &) const override;
|
||||
bool operator== (nano::receive_block const &) const;
|
||||
bool valid_predecessor (nano::block const &) const override;
|
||||
|
@ -204,11 +204,11 @@ public:
|
|||
void hash (blake2b_state &) const override;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::block_hash previous () const override;
|
||||
nano::account account () const override;
|
||||
nano::block_hash source () const override;
|
||||
nano::block_hash root () const override;
|
||||
nano::account representative () const override;
|
||||
nano::block_hash const & previous () const override;
|
||||
nano::account const & account () const override;
|
||||
nano::block_hash const & source () const override;
|
||||
nano::root const & root () const override;
|
||||
nano::account const & representative () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
@ -216,8 +216,8 @@ public:
|
|||
bool deserialize_json (boost::property_tree::ptree const &);
|
||||
void visit (nano::block_visitor &) const override;
|
||||
nano::block_type type () const override;
|
||||
nano::signature block_signature () const override;
|
||||
void signature_set (nano::uint512_union const &) override;
|
||||
nano::signature const & block_signature () const override;
|
||||
void signature_set (nano::signature const &) override;
|
||||
bool operator== (nano::block const &) const override;
|
||||
bool operator== (nano::open_block const &) const;
|
||||
bool valid_predecessor (nano::block const &) const override;
|
||||
|
@ -250,9 +250,9 @@ public:
|
|||
void hash (blake2b_state &) const override;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::block_hash previous () const override;
|
||||
nano::block_hash root () const override;
|
||||
nano::account representative () const override;
|
||||
nano::block_hash const & previous () const override;
|
||||
nano::root const & root () const override;
|
||||
nano::account const & representative () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
@ -260,8 +260,8 @@ public:
|
|||
bool deserialize_json (boost::property_tree::ptree const &);
|
||||
void visit (nano::block_visitor &) const override;
|
||||
nano::block_type type () const override;
|
||||
nano::signature block_signature () const override;
|
||||
void signature_set (nano::uint512_union const &) override;
|
||||
nano::signature const & block_signature () const override;
|
||||
void signature_set (nano::signature const &) override;
|
||||
bool operator== (nano::block const &) const override;
|
||||
bool operator== (nano::change_block const &) const;
|
||||
bool valid_predecessor (nano::block const &) const override;
|
||||
|
@ -274,7 +274,7 @@ class state_hashables
|
|||
{
|
||||
public:
|
||||
state_hashables () = default;
|
||||
state_hashables (nano::account const &, nano::block_hash const &, nano::account const &, nano::amount const &, nano::uint256_union const &);
|
||||
state_hashables (nano::account const &, nano::block_hash const &, nano::account const &, nano::amount const &, nano::link const &);
|
||||
state_hashables (bool &, nano::stream &);
|
||||
state_hashables (bool &, boost::property_tree::ptree const &);
|
||||
void hash (blake2b_state &) const;
|
||||
|
@ -291,7 +291,7 @@ public:
|
|||
// Allows lookup of account balance simply by looking at the head block
|
||||
nano::amount balance;
|
||||
// Link field contains source block_hash if receiving, destination account if sending
|
||||
nano::uint256_union link;
|
||||
nano::link link;
|
||||
// Serialized size
|
||||
static size_t constexpr size = sizeof (account) + sizeof (previous) + sizeof (representative) + sizeof (balance) + sizeof (link);
|
||||
};
|
||||
|
@ -299,7 +299,7 @@ class state_block : public nano::block
|
|||
{
|
||||
public:
|
||||
state_block () = default;
|
||||
state_block (nano::account const &, nano::block_hash const &, nano::account const &, nano::amount const &, nano::uint256_union const &, nano::raw_key const &, nano::public_key const &, uint64_t);
|
||||
state_block (nano::account const &, nano::block_hash const &, nano::account const &, nano::amount const &, nano::link const &, nano::raw_key const &, nano::public_key const &, uint64_t);
|
||||
state_block (bool &, nano::stream &);
|
||||
state_block (bool &, boost::property_tree::ptree const &);
|
||||
virtual ~state_block () = default;
|
||||
|
@ -307,12 +307,12 @@ public:
|
|||
void hash (blake2b_state &) const override;
|
||||
uint64_t block_work () const override;
|
||||
void block_work_set (uint64_t) override;
|
||||
nano::block_hash previous () const override;
|
||||
nano::account account () const override;
|
||||
nano::block_hash root () const override;
|
||||
nano::block_hash link () const override;
|
||||
nano::account representative () const override;
|
||||
nano::amount balance () const override;
|
||||
nano::block_hash const & previous () const override;
|
||||
nano::account const & account () const override;
|
||||
nano::root const & root () const override;
|
||||
nano::link const & link () const override;
|
||||
nano::account const & representative () const override;
|
||||
nano::amount const & balance () const override;
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void serialize_json (std::string &, bool = false) const override;
|
||||
|
@ -320,8 +320,8 @@ public:
|
|||
bool deserialize_json (boost::property_tree::ptree const &);
|
||||
void visit (nano::block_visitor &) const override;
|
||||
nano::block_type type () const override;
|
||||
nano::signature block_signature () const override;
|
||||
void signature_set (nano::uint512_union const &) override;
|
||||
nano::signature const & block_signature () const override;
|
||||
void signature_set (nano::signature const &) override;
|
||||
bool operator== (nano::block const &) const override;
|
||||
bool operator== (nano::state_block const &) const;
|
||||
bool valid_predecessor (nano::block const &) const override;
|
||||
|
|
|
@ -31,7 +31,7 @@ uint8_t account_decode (char value)
|
|||
}
|
||||
}
|
||||
|
||||
void nano::uint256_union::encode_account (std::string & destination_a) const
|
||||
void nano::public_key::encode_account (std::string & destination_a) const
|
||||
{
|
||||
assert (destination_a.empty ());
|
||||
destination_a.reserve (65);
|
||||
|
@ -53,19 +53,19 @@ void nano::uint256_union::encode_account (std::string & destination_a) const
|
|||
std::reverse (destination_a.begin (), destination_a.end ());
|
||||
}
|
||||
|
||||
std::string nano::uint256_union::to_account () const
|
||||
std::string nano::public_key::to_account () const
|
||||
{
|
||||
std::string result;
|
||||
encode_account (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string nano::uint256_union::to_node_id () const
|
||||
std::string nano::public_key::to_node_id () const
|
||||
{
|
||||
return to_account ().replace (0, 4, "node");
|
||||
}
|
||||
|
||||
bool nano::uint256_union::decode_account (std::string const & source_a)
|
||||
bool nano::public_key::decode_account (std::string const & source_a)
|
||||
{
|
||||
auto error (source_a.size () < 5);
|
||||
if (!error)
|
||||
|
@ -391,31 +391,38 @@ void nano::raw_key::decrypt (nano::uint256_union const & ciphertext, nano::raw_k
|
|||
dec.ProcessData (data.bytes.data (), ciphertext.bytes.data (), sizeof (ciphertext.bytes));
|
||||
}
|
||||
|
||||
nano::uint512_union nano::sign_message (nano::raw_key const & private_key, nano::public_key const & public_key, nano::uint256_union const & message)
|
||||
nano::private_key const & nano::raw_key::as_private_key () const
|
||||
{
|
||||
nano::uint512_union result;
|
||||
return reinterpret_cast<nano::private_key const &> (data);
|
||||
}
|
||||
|
||||
nano::signature nano::sign_message (nano::raw_key const & private_key, nano::public_key const & public_key, nano::uint256_union const & message)
|
||||
{
|
||||
nano::signature result;
|
||||
ed25519_sign (message.bytes.data (), sizeof (message.bytes), private_key.data.bytes.data (), public_key.bytes.data (), result.bytes.data ());
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::deterministic_key (nano::uint256_union const & seed_a, uint32_t index_a, nano::uint256_union & prv_a)
|
||||
nano::private_key nano::deterministic_key (nano::raw_key const & seed_a, uint32_t index_a)
|
||||
{
|
||||
nano::private_key prv_key;
|
||||
blake2b_state hash;
|
||||
blake2b_init (&hash, prv_a.bytes.size ());
|
||||
blake2b_update (&hash, seed_a.bytes.data (), seed_a.bytes.size ());
|
||||
blake2b_init (&hash, prv_key.bytes.size ());
|
||||
blake2b_update (&hash, seed_a.data.bytes.data (), seed_a.data.bytes.size ());
|
||||
nano::uint256_union index (index_a);
|
||||
blake2b_update (&hash, reinterpret_cast<uint8_t *> (&index.dwords[7]), sizeof (uint32_t));
|
||||
blake2b_final (&hash, prv_a.bytes.data (), prv_a.bytes.size ());
|
||||
blake2b_final (&hash, prv_key.bytes.data (), prv_key.bytes.size ());
|
||||
return prv_key;
|
||||
}
|
||||
|
||||
nano::public_key nano::pub_key (nano::private_key const & privatekey_a)
|
||||
{
|
||||
nano::uint256_union result;
|
||||
nano::public_key result;
|
||||
ed25519_publickey (privatekey_a.bytes.data (), result.bytes.data ());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool nano::validate_message (nano::public_key const & public_key, nano::uint256_union const & message, nano::uint512_union const & signature)
|
||||
bool nano::validate_message (nano::public_key const & public_key, nano::uint256_union const & message, nano::signature const & signature)
|
||||
{
|
||||
auto result (0 != ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), public_key.bytes.data (), signature.bytes.data ()));
|
||||
return result;
|
||||
|
@ -770,6 +777,91 @@ std::string nano::uint128_union::to_string_dec () const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::hash_or_account::hash_or_account (uint64_t value_a) :
|
||||
raw (value_a)
|
||||
{
|
||||
}
|
||||
|
||||
bool nano::hash_or_account::is_zero () const
|
||||
{
|
||||
return raw.is_zero ();
|
||||
}
|
||||
|
||||
void nano::hash_or_account::clear ()
|
||||
{
|
||||
raw.clear ();
|
||||
}
|
||||
|
||||
bool nano::hash_or_account::decode_hex (std::string const & text_a)
|
||||
{
|
||||
return raw.decode_hex (text_a);
|
||||
}
|
||||
|
||||
bool nano::hash_or_account::decode_account (std::string const & source_a)
|
||||
{
|
||||
return account.decode_account (source_a);
|
||||
}
|
||||
|
||||
std::string nano::hash_or_account::to_string () const
|
||||
{
|
||||
return raw.to_string ();
|
||||
}
|
||||
|
||||
std::string nano::hash_or_account::to_account () const
|
||||
{
|
||||
return account.to_account ();
|
||||
}
|
||||
|
||||
nano::hash_or_account::operator nano::block_hash const & () const
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
nano::hash_or_account::operator nano::account const & () const
|
||||
{
|
||||
return account;
|
||||
}
|
||||
|
||||
nano::hash_or_account::operator nano::uint256_union const & () const
|
||||
{
|
||||
return raw;
|
||||
}
|
||||
|
||||
nano::link::link (uint64_t value_a) :
|
||||
hash_or_account (value_a)
|
||||
{
|
||||
}
|
||||
|
||||
nano::root::root (uint64_t value_a) :
|
||||
hash_or_account (value_a)
|
||||
{
|
||||
}
|
||||
|
||||
nano::block_hash const & nano::root::previous () const
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool nano::root::operator== (nano::root const & root_a) const
|
||||
{
|
||||
return bytes == root_a.bytes;
|
||||
}
|
||||
|
||||
bool nano::root::operator!= (nano::root const & root_a) const
|
||||
{
|
||||
return !(*this == root_a);
|
||||
}
|
||||
|
||||
bool nano::link::operator== (nano::link const & link_a) const
|
||||
{
|
||||
return bytes == link_a.bytes;
|
||||
}
|
||||
|
||||
bool nano::link::operator!= (nano::link const & link_a) const
|
||||
{
|
||||
return !(*this == link_a);
|
||||
}
|
||||
|
||||
std::string nano::to_string_hex (uint64_t const value_a)
|
||||
{
|
||||
std::stringstream stream;
|
||||
|
@ -836,3 +928,23 @@ double nano::difficulty::to_multiplier (uint64_t const difficulty_a, uint64_t co
|
|||
#ifdef _WIN32
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
nano::public_key::operator nano::link const & () const
|
||||
{
|
||||
return nano::to_link (*this);
|
||||
}
|
||||
|
||||
nano::public_key::operator nano::root const & () const
|
||||
{
|
||||
return nano::to_root (*this);
|
||||
}
|
||||
|
||||
nano::block_hash::operator nano::link const & () const
|
||||
{
|
||||
return nano::to_link (*this);
|
||||
}
|
||||
|
||||
nano::block_hash::operator nano::root const & () const
|
||||
{
|
||||
return nano::to_root (*this);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ nano::uint128_t const kxrb_ratio = nano::uint128_t ("100000000000000000000000000
|
|||
nano::uint128_t const xrb_ratio = nano::uint128_t ("1000000000000000000000000"); // 10^24
|
||||
nano::uint128_t const raw_ratio = nano::uint128_t ("1"); // 10^0
|
||||
|
||||
union uint128_union final
|
||||
class uint128_union
|
||||
{
|
||||
public:
|
||||
uint128_union () = default;
|
||||
|
@ -43,16 +43,26 @@ public:
|
|||
bool is_zero () const;
|
||||
std::string to_string () const;
|
||||
std::string to_string_dec () const;
|
||||
std::array<uint8_t, 16> bytes;
|
||||
std::array<char, 16> chars;
|
||||
std::array<uint32_t, 4> dwords;
|
||||
std::array<uint64_t, 2> qwords;
|
||||
union
|
||||
{
|
||||
std::array<uint8_t, 16> bytes;
|
||||
std::array<char, 16> chars;
|
||||
std::array<uint32_t, 4> dwords;
|
||||
std::array<uint64_t, 2> qwords;
|
||||
};
|
||||
};
|
||||
static_assert (std::is_nothrow_move_constructible<uint128_union>::value, "uint128_union should be noexcept MoveConstructible");
|
||||
|
||||
// Balances are 128 bit.
|
||||
using amount = uint128_union;
|
||||
class raw_key;
|
||||
union uint256_union final
|
||||
class amount : public uint128_union
|
||||
{
|
||||
public:
|
||||
using uint128_union::uint128_union;
|
||||
};
|
||||
class raw_key;
|
||||
class uint256_union
|
||||
{
|
||||
public:
|
||||
uint256_union () = default;
|
||||
/**
|
||||
* Decode from hex string
|
||||
|
@ -71,26 +81,116 @@ union uint256_union final
|
|||
bool decode_hex (std::string const &);
|
||||
void encode_dec (std::string &) const;
|
||||
bool decode_dec (std::string const &);
|
||||
void encode_account (std::string &) const;
|
||||
std::string to_account () const;
|
||||
std::string to_node_id () const;
|
||||
bool decode_account (std::string const &);
|
||||
std::array<uint8_t, 32> bytes;
|
||||
std::array<char, 32> chars;
|
||||
std::array<uint32_t, 8> dwords;
|
||||
std::array<uint64_t, 4> qwords;
|
||||
std::array<uint128_union, 2> owords;
|
||||
|
||||
void clear ();
|
||||
bool is_zero () const;
|
||||
std::string to_string () const;
|
||||
nano::uint256_t number () const;
|
||||
|
||||
union
|
||||
{
|
||||
std::array<uint8_t, 32> bytes;
|
||||
std::array<char, 32> chars;
|
||||
std::array<uint32_t, 8> dwords;
|
||||
std::array<uint64_t, 4> qwords;
|
||||
std::array<uint128_union, 2> owords;
|
||||
};
|
||||
};
|
||||
static_assert (std::is_nothrow_move_constructible<uint256_union>::value, "uint256_union should be noexcept MoveConstructible");
|
||||
|
||||
class link;
|
||||
class root;
|
||||
|
||||
// All keys and hashes are 256 bit.
|
||||
using block_hash = uint256_union;
|
||||
using account = uint256_union;
|
||||
using public_key = uint256_union;
|
||||
using private_key = uint256_union;
|
||||
using secret_key = uint256_union;
|
||||
class block_hash final : public uint256_union
|
||||
{
|
||||
public:
|
||||
using uint256_union::uint256_union;
|
||||
operator nano::link const & () const;
|
||||
operator nano::root const & () const;
|
||||
};
|
||||
|
||||
class public_key final : public uint256_union
|
||||
{
|
||||
public:
|
||||
using uint256_union::uint256_union;
|
||||
|
||||
std::string to_node_id () const;
|
||||
void encode_account (std::string &) const;
|
||||
std::string to_account () const;
|
||||
bool decode_account (std::string const &);
|
||||
|
||||
operator nano::link const & () const;
|
||||
operator nano::root const & () const;
|
||||
};
|
||||
|
||||
class wallet_id : public uint256_union
|
||||
{
|
||||
using uint256_union::uint256_union;
|
||||
};
|
||||
|
||||
// These are synonymous
|
||||
using account = public_key;
|
||||
|
||||
class hash_or_account
|
||||
{
|
||||
public:
|
||||
bool is_zero () const;
|
||||
void clear ();
|
||||
std::string to_string () const;
|
||||
bool decode_hex (std::string const &);
|
||||
bool decode_account (std::string const &);
|
||||
std::string to_account () const;
|
||||
|
||||
operator nano::block_hash const & () const;
|
||||
operator nano::account const & () const;
|
||||
operator nano::uint256_union const & () const;
|
||||
|
||||
union
|
||||
{
|
||||
std::array<uint8_t, 32> bytes;
|
||||
nano::uint256_union raw; // This can be used when you don't want to explicitly mention either of the types
|
||||
nano::account account;
|
||||
nano::block_hash hash;
|
||||
};
|
||||
|
||||
protected:
|
||||
// Cannot instantiate a concrete version of this class
|
||||
hash_or_account () = default;
|
||||
hash_or_account (uint64_t value_a);
|
||||
};
|
||||
|
||||
// A link can either be a destination account or source hash
|
||||
class link final : public hash_or_account
|
||||
{
|
||||
public:
|
||||
link () = default;
|
||||
link (uint64_t value_a);
|
||||
|
||||
bool operator== (nano::link const &) const;
|
||||
bool operator!= (nano::link const &) const;
|
||||
};
|
||||
|
||||
// A root can either be an open block hash or a previous hash
|
||||
class root final : public hash_or_account
|
||||
{
|
||||
public:
|
||||
root () = default;
|
||||
root (uint64_t value_a);
|
||||
|
||||
bool operator== (nano::root const &) const;
|
||||
bool operator!= (nano::root const &) const;
|
||||
|
||||
nano::block_hash const & previous () const;
|
||||
};
|
||||
|
||||
class private_key : public uint256_union
|
||||
{
|
||||
public:
|
||||
using uint256_union::uint256_union;
|
||||
};
|
||||
|
||||
// The seed or private key
|
||||
class raw_key final
|
||||
{
|
||||
public:
|
||||
|
@ -98,10 +198,12 @@ public:
|
|||
void decrypt (nano::uint256_union const &, nano::raw_key const &, uint128_union const &);
|
||||
bool operator== (nano::raw_key const &) const;
|
||||
bool operator!= (nano::raw_key const &) const;
|
||||
nano::private_key const & as_private_key () const;
|
||||
nano::uint256_union data;
|
||||
};
|
||||
union uint512_union final
|
||||
class uint512_union
|
||||
{
|
||||
public:
|
||||
uint512_union () = default;
|
||||
uint512_union (nano::uint256_union const &, nano::uint256_union const &);
|
||||
uint512_union (nano::uint512_t const &);
|
||||
|
@ -110,22 +212,73 @@ union uint512_union final
|
|||
nano::uint512_union & operator^= (nano::uint512_union const &);
|
||||
void encode_hex (std::string &) const;
|
||||
bool decode_hex (std::string const &);
|
||||
std::array<uint8_t, 64> bytes;
|
||||
std::array<uint32_t, 16> dwords;
|
||||
std::array<uint64_t, 8> qwords;
|
||||
std::array<uint256_union, 2> uint256s;
|
||||
void clear ();
|
||||
bool is_zero () const;
|
||||
nano::uint512_t number () const;
|
||||
std::string to_string () const;
|
||||
};
|
||||
using signature = uint512_union;
|
||||
using qualified_root = uint512_union;
|
||||
|
||||
nano::uint512_union sign_message (nano::raw_key const &, nano::public_key const &, nano::uint256_union const &);
|
||||
bool validate_message (nano::public_key const &, nano::uint256_union const &, nano::uint512_union const &);
|
||||
union
|
||||
{
|
||||
std::array<uint8_t, 64> bytes;
|
||||
std::array<uint32_t, 16> dwords;
|
||||
std::array<uint64_t, 8> qwords;
|
||||
std::array<uint256_union, 2> uint256s;
|
||||
};
|
||||
};
|
||||
static_assert (std::is_nothrow_move_constructible<uint512_union>::value, "uint512_union should be noexcept MoveConstructible");
|
||||
|
||||
inline nano::link const & to_link (nano::block_hash const & hash_a)
|
||||
{
|
||||
return reinterpret_cast<nano::link const &> (hash_a);
|
||||
}
|
||||
|
||||
inline nano::link const & to_link (nano::account const & account_a)
|
||||
{
|
||||
return reinterpret_cast<nano::link const &> (account_a);
|
||||
}
|
||||
|
||||
inline nano::root const & to_root (nano::block_hash const & hash_a)
|
||||
{
|
||||
return reinterpret_cast<nano::root const &> (hash_a);
|
||||
}
|
||||
|
||||
inline nano::root const & to_root (nano::account const & account_a)
|
||||
{
|
||||
return reinterpret_cast<nano::root const &> (account_a);
|
||||
}
|
||||
|
||||
inline nano::account const & root_as_account (nano::root const & root_a)
|
||||
{
|
||||
static_assert (sizeof (nano::root) == sizeof (nano::account), "Sizes do not match");
|
||||
static_assert (std::is_standard_layout<nano::root>::value && std::is_standard_layout<nano::account>::value, "Both types must have standard layout");
|
||||
return reinterpret_cast<nano::account const &> (root_a);
|
||||
}
|
||||
|
||||
class signature : public uint512_union
|
||||
{
|
||||
public:
|
||||
using uint512_union::uint512_union;
|
||||
};
|
||||
|
||||
class qualified_root : public uint512_union
|
||||
{
|
||||
public:
|
||||
using uint512_union::uint512_union;
|
||||
|
||||
nano::block_hash const & previous () const
|
||||
{
|
||||
return reinterpret_cast<nano::block_hash const &> (uint256s[0]);
|
||||
}
|
||||
nano::root const & root () const
|
||||
{
|
||||
return reinterpret_cast<nano::root const &> (uint256s[1]);
|
||||
}
|
||||
};
|
||||
|
||||
nano::signature sign_message (nano::raw_key const &, nano::public_key const &, nano::uint256_union const &);
|
||||
bool validate_message (nano::public_key const &, nano::uint256_union const &, nano::signature const &);
|
||||
bool validate_message_batch (const unsigned char **, size_t *, const unsigned char **, const unsigned char **, size_t, int *);
|
||||
void deterministic_key (nano::uint256_union const &, uint32_t, nano::uint256_union &);
|
||||
nano::private_key deterministic_key (nano::raw_key const &, uint32_t);
|
||||
nano::public_key pub_key (nano::private_key const &);
|
||||
|
||||
/* Conversion methods */
|
||||
|
@ -156,6 +309,46 @@ struct hash<::nano::uint256_union>
|
|||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::account>
|
||||
{
|
||||
size_t operator() (::nano::account const & data_a) const
|
||||
{
|
||||
return hash<::nano::uint256_union> () (data_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::block_hash>
|
||||
{
|
||||
size_t operator() (::nano::block_hash const & data_a) const
|
||||
{
|
||||
return hash<::nano::uint256_union> () (data_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::private_key>
|
||||
{
|
||||
size_t operator() (::nano::private_key const & data_a) const
|
||||
{
|
||||
return hash<::nano::uint256_union> () (data_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::root>
|
||||
{
|
||||
size_t operator() (::nano::root const & data_a) const
|
||||
{
|
||||
return hash<::nano::uint256_union> () (data_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::wallet_id>
|
||||
{
|
||||
size_t operator() (::nano::wallet_id const & data_a) const
|
||||
{
|
||||
return hash<::nano::uint256_union> () (data_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::uint256_t>
|
||||
{
|
||||
size_t operator() (::nano::uint256_t const & number_a) const
|
||||
|
@ -171,4 +364,12 @@ struct hash<::nano::uint512_union>
|
|||
return *reinterpret_cast<size_t const *> (data_a.bytes.data ());
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::qualified_root>
|
||||
{
|
||||
size_t operator() (::nano::qualified_root const & data_a) const
|
||||
{
|
||||
return *reinterpret_cast<size_t const *> (data_a.bytes.data ());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -56,10 +56,12 @@ seq_con_info_leaf::seq_con_info_leaf (const seq_con_info & info) :
|
|||
info (info)
|
||||
{
|
||||
}
|
||||
|
||||
bool seq_con_info_leaf::is_composite () const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const seq_con_info & seq_con_info_leaf::get_info () const
|
||||
{
|
||||
return info;
|
||||
|
@ -249,9 +251,9 @@ thread ([this]() {
|
|||
|
||||
void nano::worker::run ()
|
||||
{
|
||||
nano::unique_lock<std::mutex> lk (mutex);
|
||||
while (!stopped)
|
||||
{
|
||||
nano::unique_lock<std::mutex> lk (mutex);
|
||||
if (!queue.empty ())
|
||||
{
|
||||
auto func = queue.front ();
|
||||
|
@ -261,6 +263,7 @@ void nano::worker::run ()
|
|||
// So that we reduce locking for anything being pushed as that will
|
||||
// most likely be on an io-thread
|
||||
std::this_thread::yield ();
|
||||
lk.lock ();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -286,7 +289,10 @@ void nano::worker::push_task (std::function<void()> func_a)
|
|||
|
||||
void nano::worker::stop ()
|
||||
{
|
||||
stopped = true;
|
||||
{
|
||||
nano::unique_lock<std::mutex> lk (mutex);
|
||||
stopped = true;
|
||||
}
|
||||
cv.notify_one ();
|
||||
if (thread.joinable ())
|
||||
{
|
||||
|
|
|
@ -172,7 +172,7 @@ private:
|
|||
nano::condition_variable cv;
|
||||
std::deque<std::function<void()>> queue;
|
||||
std::mutex mutex;
|
||||
std::atomic<bool> stopped{ false };
|
||||
bool stopped{ false };
|
||||
std::thread thread;
|
||||
|
||||
friend std::unique_ptr<seq_con_info_component> collect_seq_con_info (worker &, const std::string &);
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
nano::error parse (std::string const & wallet_a, std::string const & account_a);
|
||||
nano::error serialize_toml (nano::tomlconfig & toml_a) const;
|
||||
nano::error deserialize_toml (nano::tomlconfig & toml_a);
|
||||
nano::uint256_union wallet;
|
||||
nano::wallet_id wallet;
|
||||
nano::account account{ 0 };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <future>
|
||||
|
||||
bool nano::work_validate (nano::block_hash const & root_a, uint64_t work_a, uint64_t * difficulty_a)
|
||||
bool nano::work_validate (nano::root const & root_a, uint64_t work_a, uint64_t * difficulty_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
auto value (nano::work_value (root_a, work_a));
|
||||
|
@ -21,7 +21,7 @@ bool nano::work_validate (nano::block const & block_a, uint64_t * difficulty_a)
|
|||
return work_validate (block_a.root (), block_a.block_work (), difficulty_a);
|
||||
}
|
||||
|
||||
uint64_t nano::work_value (nano::block_hash const & root_a, uint64_t work_a)
|
||||
uint64_t nano::work_value (nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
uint64_t result;
|
||||
blake2b_state hash;
|
||||
|
@ -32,7 +32,7 @@ uint64_t nano::work_value (nano::block_hash const & root_a, uint64_t work_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::work_pool::work_pool (unsigned max_threads_a, std::chrono::nanoseconds pow_rate_limiter_a, std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> opencl_a) :
|
||||
nano::work_pool::work_pool (unsigned max_threads_a, std::chrono::nanoseconds pow_rate_limiter_a, std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> opencl_a) :
|
||||
ticket (0),
|
||||
done (false),
|
||||
pow_rate_limiter (pow_rate_limiter_a),
|
||||
|
@ -154,7 +154,7 @@ void nano::work_pool::loop (uint64_t thread)
|
|||
}
|
||||
}
|
||||
|
||||
void nano::work_pool::cancel (nano::uint256_union const & root_a)
|
||||
void nano::work_pool::cancel (nano::root const & root_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
if (!done)
|
||||
|
@ -195,33 +195,33 @@ void nano::work_pool::stop ()
|
|||
producer_condition.notify_all ();
|
||||
}
|
||||
|
||||
void nano::work_pool::generate (nano::uint256_union const & hash_a, std::function<void(boost::optional<uint64_t> const &)> callback_a)
|
||||
void nano::work_pool::generate (nano::root const & root_a, std::function<void(boost::optional<uint64_t> const &)> callback_a)
|
||||
{
|
||||
generate (hash_a, callback_a, network_constants.publish_threshold);
|
||||
generate (root_a, callback_a, network_constants.publish_threshold);
|
||||
}
|
||||
|
||||
void nano::work_pool::generate (nano::uint256_union const & hash_a, std::function<void(boost::optional<uint64_t> const &)> callback_a, uint64_t difficulty_a)
|
||||
void nano::work_pool::generate (nano::root const & root_a, std::function<void(boost::optional<uint64_t> const &)> callback_a, uint64_t difficulty_a)
|
||||
{
|
||||
assert (!hash_a.is_zero ());
|
||||
assert (!root_a.is_zero ());
|
||||
boost::optional<uint64_t> result;
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
pending.push_back ({ hash_a, callback_a, difficulty_a });
|
||||
pending.emplace_back (root_a, callback_a, difficulty_a);
|
||||
}
|
||||
producer_condition.notify_all ();
|
||||
}
|
||||
|
||||
uint64_t nano::work_pool::generate (nano::uint256_union const & hash_a)
|
||||
uint64_t nano::work_pool::generate (nano::root const & root_a)
|
||||
{
|
||||
return generate (hash_a, network_constants.publish_threshold);
|
||||
return generate (root_a, network_constants.publish_threshold);
|
||||
}
|
||||
|
||||
uint64_t nano::work_pool::generate (nano::uint256_union const & hash_a, uint64_t difficulty_a)
|
||||
uint64_t nano::work_pool::generate (nano::root const & root_a, uint64_t difficulty_a)
|
||||
{
|
||||
std::promise<boost::optional<uint64_t>> work;
|
||||
std::future<boost::optional<uint64_t>> future = work.get_future ();
|
||||
// clang-format off
|
||||
generate (hash_a, [&work](boost::optional<uint64_t> work_a) {
|
||||
generate (root_a, [&work](boost::optional<uint64_t> work_a) {
|
||||
work.set_value (work_a);
|
||||
},
|
||||
difficulty_a);
|
||||
|
|
|
@ -15,29 +15,34 @@
|
|||
namespace nano
|
||||
{
|
||||
class block;
|
||||
bool work_validate (nano::block_hash const &, uint64_t, uint64_t * = nullptr);
|
||||
bool work_validate (nano::root const &, uint64_t, uint64_t * = nullptr);
|
||||
bool work_validate (nano::block const &, uint64_t * = nullptr);
|
||||
uint64_t work_value (nano::block_hash const &, uint64_t);
|
||||
uint64_t work_value (nano::root const &, uint64_t);
|
||||
class opencl_work;
|
||||
class work_item final
|
||||
{
|
||||
public:
|
||||
nano::uint256_union item;
|
||||
work_item (nano::root const & item_a, std::function<void(boost::optional<uint64_t> const &)> const & callback_a, uint64_t difficulty_a) :
|
||||
item (item_a), callback (callback_a), difficulty (difficulty_a)
|
||||
{
|
||||
}
|
||||
|
||||
nano::root item;
|
||||
std::function<void(boost::optional<uint64_t> const &)> callback;
|
||||
uint64_t difficulty;
|
||||
};
|
||||
class work_pool final
|
||||
{
|
||||
public:
|
||||
work_pool (unsigned, std::chrono::nanoseconds = std::chrono::nanoseconds (0), std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> = nullptr);
|
||||
work_pool (unsigned, std::chrono::nanoseconds = std::chrono::nanoseconds (0), std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> = nullptr);
|
||||
~work_pool ();
|
||||
void loop (uint64_t);
|
||||
void stop ();
|
||||
void cancel (nano::uint256_union const &);
|
||||
void generate (nano::uint256_union const &, std::function<void(boost::optional<uint64_t> const &)>);
|
||||
void generate (nano::uint256_union const &, std::function<void(boost::optional<uint64_t> const &)>, uint64_t);
|
||||
uint64_t generate (nano::uint256_union const &);
|
||||
uint64_t generate (nano::uint256_union const &, uint64_t);
|
||||
void cancel (nano::root const &);
|
||||
void generate (nano::root const &, std::function<void(boost::optional<uint64_t> const &)>);
|
||||
void generate (nano::root const &, std::function<void(boost::optional<uint64_t> const &)>, uint64_t);
|
||||
uint64_t generate (nano::root const &);
|
||||
uint64_t generate (nano::root const &, uint64_t);
|
||||
size_t size ();
|
||||
nano::network_constants network_constants;
|
||||
std::atomic<int> ticket;
|
||||
|
@ -47,7 +52,7 @@ public:
|
|||
std::mutex mutex;
|
||||
nano::condition_variable producer_condition;
|
||||
std::chrono::nanoseconds pow_rate_limiter;
|
||||
std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> opencl;
|
||||
std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> opencl;
|
||||
nano::observer_set<bool> work_observers;
|
||||
};
|
||||
|
||||
|
|
|
@ -49,10 +49,10 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
|
|||
nano::logger_mt logger{ config.node.logging.min_time_between_log_output };
|
||||
boost::asio::io_context io_ctx;
|
||||
auto opencl (nano::opencl_work::create (config.opencl_enable, config.opencl, logger));
|
||||
nano::work_pool opencl_work (config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl](nano::uint256_union const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
nano::work_pool opencl_work (config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl](nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> & ticket_a) {
|
||||
return opencl->generate_work (root_a, difficulty_a, ticket_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
: std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
nano::alarm alarm (io_ctx);
|
||||
try
|
||||
{
|
||||
|
|
|
@ -225,7 +225,7 @@ int main (int argc, char * const * argv)
|
|||
<< "Account: " << rep.pub.to_account () << "\n";
|
||||
}
|
||||
nano::uint128_t balance (std::numeric_limits<nano::uint128_t>::max ());
|
||||
nano::open_block genesis_block (genesis.pub, genesis.pub, genesis.pub, genesis.prv, genesis.pub, work.generate (genesis.pub));
|
||||
nano::open_block genesis_block (reinterpret_cast<const nano::block_hash &> (genesis.pub), genesis.pub, genesis.pub, genesis.prv, genesis.pub, work.generate (genesis.pub));
|
||||
std::cout << genesis_block.to_json ();
|
||||
std::cout.flush ();
|
||||
nano::block_hash previous (genesis_block.hash ());
|
||||
|
@ -432,10 +432,10 @@ int main (int argc, char * const * argv)
|
|||
{
|
||||
nano::logger_mt logger;
|
||||
auto opencl (nano::opencl_work::create (true, { platform, device, threads }, logger));
|
||||
nano::work_pool work_pool (std::numeric_limits<unsigned>::max (), std::chrono::nanoseconds (0), opencl ? [&opencl](nano::uint256_union const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
nano::work_pool work_pool (std::numeric_limits<unsigned>::max (), std::chrono::nanoseconds (0), opencl ? [&opencl](nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (root_a, difficulty_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
: std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
nano::change_block block (0, 0, nano::keypair ().prv, 0, 0);
|
||||
std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%. Difficulty: %4$#x\n") % platform % device % threads % difficulty);
|
||||
for (uint64_t i (0); true; ++i)
|
||||
|
@ -503,8 +503,7 @@ int main (int argc, char * const * argv)
|
|||
{
|
||||
nano::keypair key;
|
||||
nano::uint256_union message;
|
||||
nano::uint512_union signature;
|
||||
signature = nano::sign_message (key.prv, key.pub, message);
|
||||
auto signature = nano::sign_message (key.prv, key.pub, message);
|
||||
auto begin (std::chrono::high_resolution_clock::now ());
|
||||
for (auto i (0u); i < 1000; ++i)
|
||||
{
|
||||
|
@ -566,7 +565,7 @@ int main (int argc, char * const * argv)
|
|||
nano::uint128_t genesis_balance (std::numeric_limits<nano::uint128_t>::max ());
|
||||
// Generating keys
|
||||
std::vector<nano::keypair> keys (num_accounts);
|
||||
std::vector<nano::block_hash> frontiers (num_accounts);
|
||||
std::vector<nano::root> frontiers (num_accounts);
|
||||
std::vector<nano::uint128_t> balances (num_accounts, 1000000000);
|
||||
// Generating blocks
|
||||
std::deque<std::shared_ptr<nano::block>> blocks;
|
||||
|
@ -628,7 +627,7 @@ int main (int argc, char * const * argv)
|
|||
.previous (frontiers[other])
|
||||
.representative (keys[other].pub)
|
||||
.balance (balances[other])
|
||||
.link (frontiers[j])
|
||||
.link (static_cast<nano::block_hash const &> (frontiers[j]))
|
||||
.sign (keys[other].prv, keys[other].pub)
|
||||
.work (work.generate (frontiers[other]))
|
||||
.build ();
|
||||
|
|
|
@ -80,10 +80,10 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
|
|||
std::shared_ptr<nano_qt::wallet> gui;
|
||||
nano::set_application_icon (application);
|
||||
auto opencl (nano::opencl_work::create (config.opencl_enable, config.opencl, logger));
|
||||
nano::work_pool work (config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl](nano::uint256_union const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
nano::work_pool work (config.node.work_threads, config.node.pow_sleep_interval, opencl ? [&opencl](nano::root const & root_a, uint64_t difficulty_a, std::atomic<int> &) {
|
||||
return opencl->generate_work (root_a, difficulty_a);
|
||||
}
|
||||
: std::function<boost::optional<uint64_t> (nano::uint256_union const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
: std::function<boost::optional<uint64_t> (nano::root const &, uint64_t, std::atomic<int> &)> (nullptr));
|
||||
nano::alarm alarm (io_ctx);
|
||||
nano::node_flags flags;
|
||||
|
||||
|
@ -110,8 +110,7 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost
|
|||
auto existing (wallet->store.begin (transaction));
|
||||
if (existing != wallet->store.end ())
|
||||
{
|
||||
nano::uint256_union account (existing->first);
|
||||
wallet_config.account = account;
|
||||
wallet_config.account = existing->first;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -109,7 +109,7 @@ void nano::active_transactions::request_confirm (nano::unique_lock<std::mutex> &
|
|||
unsigned unconfirmed_count (0);
|
||||
unsigned unconfirmed_request_count (0);
|
||||
unsigned could_fit_delay = node.network_params.network.is_test_network () ? high_confirmation_request_count - 1 : 1;
|
||||
std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::block_hash>>> requests_bundle;
|
||||
std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::root>>> requests_bundle;
|
||||
std::deque<std::shared_ptr<nano::block>> rebroadcast_bundle;
|
||||
std::deque<std::pair<std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>>> confirm_req_bundle;
|
||||
|
||||
|
@ -251,7 +251,7 @@ void nano::active_transactions::request_confirm (nano::unique_lock<std::mutex> &
|
|||
{
|
||||
if (requests_bundle.size () < max_broadcast_queue)
|
||||
{
|
||||
std::deque<std::pair<nano::block_hash, nano::block_hash>> insert_root_hash = { root_hash };
|
||||
std::deque<std::pair<nano::block_hash, nano::root>> insert_root_hash = { root_hash };
|
||||
requests_bundle.insert (std::make_pair (rep, insert_root_hash));
|
||||
}
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ void nano::active_transactions::prioritize_frontiers_for_confirmation (nano::tra
|
|||
for (auto item_it = items.cbegin (); item_it != items.cend (); ++item_it)
|
||||
{
|
||||
// Skip this wallet if it has been traversed already while there are others still awaiting
|
||||
if (wallet_accounts_already_iterated.find (item_it->first) != wallet_accounts_already_iterated.end ())
|
||||
if (wallet_ids_already_iterated.find (item_it->first) != wallet_ids_already_iterated.end ())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -419,14 +419,14 @@ void nano::active_transactions::prioritize_frontiers_for_confirmation (nano::tra
|
|||
auto & wallet (item_it->second);
|
||||
nano::lock_guard<std::recursive_mutex> wallet_lock (wallet->store.mutex);
|
||||
|
||||
auto & next_wallet_frontier_account = next_wallet_frontier_accounts.emplace (item_it->first, wallet_store::special_count).first->second;
|
||||
auto & next_wallet_frontier_account = next_wallet_id_accounts.emplace (item_it->first, wallet_store::special_count).first->second;
|
||||
|
||||
auto i (wallet->store.begin (wallet_transaction, next_wallet_frontier_account));
|
||||
auto n (wallet->store.end ());
|
||||
uint64_t confirmation_height = 0;
|
||||
for (; i != n; ++i)
|
||||
{
|
||||
auto & account (i->first);
|
||||
auto const & account (i->first);
|
||||
if (!node.store.account_get (transaction_a, account, info) && !node.store.confirmation_height_get (transaction_a, account, confirmation_height))
|
||||
{
|
||||
// If it exists in normal priority collection delete from there.
|
||||
|
@ -450,13 +450,13 @@ void nano::active_transactions::prioritize_frontiers_for_confirmation (nano::tra
|
|||
// Go back to the beginning when we have reached the end of the wallet accounts for this wallet
|
||||
if (i == n)
|
||||
{
|
||||
wallet_accounts_already_iterated.emplace (item_it->first);
|
||||
next_wallet_frontier_accounts.at (item_it->first) = wallet_store::special_count;
|
||||
wallet_ids_already_iterated.emplace (item_it->first);
|
||||
next_wallet_id_accounts.at (item_it->first) = wallet_store::special_count;
|
||||
|
||||
// Skip wallet accounts when they have all been traversed
|
||||
if (std::next (item_it) == items.cend ())
|
||||
{
|
||||
wallet_accounts_already_iterated.clear ();
|
||||
wallet_ids_already_iterated.clear ();
|
||||
skip_wallets = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class confirmed_set_info final
|
|||
{
|
||||
public:
|
||||
std::chrono::steady_clock::time_point time;
|
||||
nano::uint512_union root;
|
||||
nano::qualified_root root;
|
||||
};
|
||||
|
||||
// Core class for determining consensus
|
||||
|
@ -167,8 +167,8 @@ private:
|
|||
std::greater<uint64_t>>>>;
|
||||
prioritize_num_uncemented priority_wallet_cementable_frontiers;
|
||||
prioritize_num_uncemented priority_cementable_frontiers;
|
||||
std::unordered_set<nano::account> wallet_accounts_already_iterated;
|
||||
std::unordered_map<nano::uint256_union, nano::account> next_wallet_frontier_accounts;
|
||||
std::unordered_set<nano::wallet_id> wallet_ids_already_iterated;
|
||||
std::unordered_map<nano::wallet_id, nano::account> next_wallet_id_accounts;
|
||||
bool skip_wallets{ false };
|
||||
void prioritize_account_for_confirmation (prioritize_num_uncemented &, size_t &, nano::account const &, nano::account_info const &, uint64_t);
|
||||
static size_t constexpr max_priority_cementable_frontiers{ 100000 };
|
||||
|
|
|
@ -159,7 +159,7 @@ void nano::block_processor::verify_state_blocks (nano::unique_lock<std::mutex> &
|
|||
if (!items.empty ())
|
||||
{
|
||||
auto size (items.size ());
|
||||
std::vector<nano::uint256_union> hashes;
|
||||
std::vector<nano::block_hash> hashes;
|
||||
hashes.reserve (size);
|
||||
std::vector<unsigned char const *> messages;
|
||||
messages.reserve (size);
|
||||
|
@ -169,7 +169,7 @@ void nano::block_processor::verify_state_blocks (nano::unique_lock<std::mutex> &
|
|||
accounts.reserve (size);
|
||||
std::vector<unsigned char const *> pub_keys;
|
||||
pub_keys.reserve (size);
|
||||
std::vector<nano::uint512_union> blocks_signatures;
|
||||
std::vector<nano::signature> blocks_signatures;
|
||||
blocks_signatures.reserve (size);
|
||||
std::vector<unsigned char const *> signatures;
|
||||
signatures.reserve (size);
|
||||
|
|
|
@ -533,8 +533,8 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a)
|
|||
}
|
||||
else if (mode == nano::bootstrap_mode::lazy)
|
||||
{
|
||||
assert (pull.account == pull.head);
|
||||
if (!lazy_processed_or_exists (pull.account))
|
||||
assert (pull.root == pull.head);
|
||||
if (!lazy_processed_or_exists (pull.root))
|
||||
{
|
||||
// Retry for lazy pulls (not weak state block link assumptions)
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
|
@ -547,7 +547,7 @@ void nano::bootstrap_attempt::requeue_pull (nano::pull_info const & pull_a)
|
|||
{
|
||||
if (node->config.logging.bulk_pull_logging ())
|
||||
{
|
||||
node->logger.try_log (boost::str (boost::format ("Failed to pull account %1% down to %2% after %3% attempts and %4% blocks processed") % pull.account.to_account () % pull.end.to_string () % pull.attempts % pull.processed));
|
||||
node->logger.try_log (boost::str (boost::format ("Failed to pull account %1% down to %2% after %3% attempts and %4% blocks processed") % pull.root.to_account () % pull.end.to_string () % pull.attempts % pull.processed));
|
||||
}
|
||||
node->stats.inc (nano::stat::type::bootstrap, nano::stat::detail::bulk_pull_failed_account, nano::stat::dir::in);
|
||||
|
||||
|
@ -789,11 +789,11 @@ void nano::bootstrap_attempt::lazy_block_state (std::shared_ptr<nano::block> blo
|
|||
{
|
||||
auto transaction (node->store.tx_begin_read ());
|
||||
nano::uint128_t balance (block_l->hashables.balance.number ());
|
||||
nano::block_hash link (block_l->hashables.link);
|
||||
auto const & link (block_l->hashables.link);
|
||||
// If link is not epoch link or 0. And if block from link is unknown
|
||||
if (!link.is_zero () && !node->ledger.is_epoch_link (link) && lazy_blocks.find (link) == lazy_blocks.end () && !node->store.block_exists (transaction, link))
|
||||
{
|
||||
nano::block_hash previous (block_l->hashables.previous);
|
||||
auto const & previous (block_l->hashables.previous);
|
||||
// If state block previous is 0 then source block required
|
||||
if (previous.is_zero ())
|
||||
{
|
||||
|
@ -1170,7 +1170,7 @@ void nano::pulls_cache::add (nano::pull_info const & pull_a)
|
|||
cache.erase (cache.begin ());
|
||||
}
|
||||
assert (cache.size () <= cache_size_max);
|
||||
nano::uint512_union head_512 (pull_a.account, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.root, pull_a.head_original);
|
||||
auto existing (cache.get<account_head_tag> ().find (head_512));
|
||||
if (existing == cache.get<account_head_tag> ().end ())
|
||||
{
|
||||
|
@ -1193,7 +1193,7 @@ void nano::pulls_cache::add (nano::pull_info const & pull_a)
|
|||
void nano::pulls_cache::update_pull (nano::pull_info & pull_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> guard (pulls_cache_mutex);
|
||||
nano::uint512_union head_512 (pull_a.account, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.root, pull_a.head_original);
|
||||
auto existing (cache.get<account_head_tag> ().find (head_512));
|
||||
if (existing != cache.get<account_head_tag> ().end ())
|
||||
{
|
||||
|
@ -1204,7 +1204,7 @@ void nano::pulls_cache::update_pull (nano::pull_info & pull_a)
|
|||
void nano::pulls_cache::remove (nano::pull_info const & pull_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> guard (pulls_cache_mutex);
|
||||
nano::uint512_union head_512 (pull_a.account, pull_a.head_original);
|
||||
nano::uint512_union head_512 (pull_a.root, pull_a.head_original);
|
||||
cache.get<account_head_tag> ().erase (head_512);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/transport/tcp.hpp>
|
||||
|
||||
nano::pull_info::pull_info (nano::account const & account_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a) :
|
||||
account (account_a),
|
||||
nano::pull_info::pull_info (nano::root const & root_a, nano::block_hash const & head_a, nano::block_hash const & end_a, count_t count_a) :
|
||||
root (root_a),
|
||||
head (head_a),
|
||||
head_original (head_a),
|
||||
end (end_a),
|
||||
|
@ -30,13 +30,13 @@ nano::bulk_pull_client::~bulk_pull_client ()
|
|||
pull.head = expected;
|
||||
if (connection->attempt->mode != nano::bootstrap_mode::legacy)
|
||||
{
|
||||
pull.account = expected;
|
||||
pull.root = expected;
|
||||
}
|
||||
pull.processed += pull_blocks - unexpected_count;
|
||||
connection->attempt->requeue_pull (pull);
|
||||
if (connection->node->config.logging.bulk_pull_logging ())
|
||||
{
|
||||
connection->node->logger.try_log (boost::str (boost::format ("Bulk pull end block is not expected %1% for account %2%") % pull.end.to_string () % pull.account.to_account ()));
|
||||
connection->node->logger.try_log (boost::str (boost::format ("Bulk pull end block is not expected %1% for account %2%") % pull.end.to_string () % pull.root.to_account ()));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -54,7 +54,16 @@ void nano::bulk_pull_client::request ()
|
|||
{
|
||||
expected = pull.head;
|
||||
nano::bulk_pull req;
|
||||
req.start = (pull.head == pull.head_original) ? pull.account : pull.head; // Account for new pulls, head for cached pulls
|
||||
if (pull.head == pull.head_original)
|
||||
{
|
||||
// Account for new pulls
|
||||
req.start = pull.root;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Head for cached pulls
|
||||
req.start = pull.head;
|
||||
}
|
||||
req.end = pull.end;
|
||||
req.count = pull.count;
|
||||
req.set_count_present (pull.count != 0);
|
||||
|
@ -62,7 +71,7 @@ void nano::bulk_pull_client::request ()
|
|||
if (connection->node->config.logging.bulk_pull_logging ())
|
||||
{
|
||||
nano::unique_lock<std::mutex> lock (connection->attempt->mutex);
|
||||
connection->node->logger.try_log (boost::str (boost::format ("Requesting account %1% from %2%. %3% accounts in queue") % pull.account.to_account () % connection->channel->to_string () % connection->attempt->pulls.size ()));
|
||||
connection->node->logger.try_log (boost::str (boost::format ("Requesting account %1% from %2%. %3% accounts in queue") % pull.root.to_account () % connection->channel->to_string () % connection->attempt->pulls.size ()));
|
||||
}
|
||||
else if (connection->node->config.logging.network_logging () && connection->attempt->should_log ())
|
||||
{
|
||||
|
|
|
@ -12,8 +12,8 @@ class pull_info
|
|||
public:
|
||||
using count_t = nano::bulk_pull::count_t;
|
||||
pull_info () = default;
|
||||
pull_info (nano::account const &, nano::block_hash const &, nano::block_hash const &, count_t = 0);
|
||||
nano::account account{ 0 };
|
||||
pull_info (nano::root const &, nano::block_hash const &, nano::block_hash const &, count_t = 0);
|
||||
nano::root root{ 0 };
|
||||
nano::block_hash head{ 0 };
|
||||
nano::block_hash head_original{ 0 };
|
||||
nano::block_hash end{ 0 };
|
||||
|
@ -34,7 +34,7 @@ public:
|
|||
void received_block (boost::system::error_code const &, size_t, nano::block_type);
|
||||
nano::block_hash first ();
|
||||
std::shared_ptr<nano::bootstrap_client> connection;
|
||||
nano::block_hash expected;
|
||||
nano::root expected;
|
||||
nano::account known_account;
|
||||
nano::pull_info pull;
|
||||
uint64_t pull_blocks;
|
||||
|
@ -65,7 +65,7 @@ public:
|
|||
void no_block_sent (boost::system::error_code const &, size_t);
|
||||
std::shared_ptr<nano::bootstrap_server> connection;
|
||||
std::unique_ptr<nano::bulk_pull> request;
|
||||
nano::block_hash current;
|
||||
nano::root current;
|
||||
bool include_start;
|
||||
nano::bulk_pull::count_t max_count;
|
||||
nano::bulk_pull::count_t sent_count;
|
||||
|
|
|
@ -136,7 +136,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
std::string password;
|
||||
|
@ -182,7 +182,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
nano::uint256_union pub;
|
||||
nano::account pub;
|
||||
pub.decode_hex (vm["key"].as<std::string> ());
|
||||
std::cout << "Account: " << pub.to_account () << std::endl;
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
account.decode_account (vm["account"].as<std::string> ());
|
||||
std::cout << "Hex: " << account.to_string () << std::endl;
|
||||
}
|
||||
|
@ -519,9 +519,9 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("key") == 1)
|
||||
{
|
||||
nano::uint256_union prv;
|
||||
nano::private_key prv;
|
||||
prv.decode_hex (vm["key"].as<std::string> ());
|
||||
nano::uint256_union pub (nano::pub_key (prv));
|
||||
nano::public_key pub (nano::pub_key (prv));
|
||||
std::cout << "Private: " << prv.to_string () << std::endl
|
||||
<< "Public: " << pub.to_string () << std::endl
|
||||
<< "Account: " << pub.to_account () << std::endl;
|
||||
|
@ -536,7 +536,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("wallet") == 1 && vm.count ("key") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
std::string password;
|
||||
|
@ -590,7 +590,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("wallet") == 1 && (vm.count ("seed") == 1 || vm.count ("key") == 1))
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
std::string password;
|
||||
|
@ -681,8 +681,8 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
if (!ec)
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
nano::keypair wallet_key;
|
||||
auto wallet (node.node->wallets.create (wallet_key.pub));
|
||||
auto wallet_key = nano::random_wallet_id ();
|
||||
auto wallet (node.node->wallets.create (wallet_key));
|
||||
if (wallet != nullptr)
|
||||
{
|
||||
if (vm.count ("password") > 0)
|
||||
|
@ -701,7 +701,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
auto transaction (wallet->wallets.tx_begin_write ());
|
||||
wallet->change_seed (transaction, seed_key);
|
||||
}
|
||||
std::cout << wallet_key.pub.to_string () << std::endl;
|
||||
std::cout << wallet_key.to_string () << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -719,7 +719,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
password = vm["password"].as<std::string> ();
|
||||
}
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
|
@ -740,7 +740,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
(void)error;
|
||||
assert (!error);
|
||||
std::cout << boost::str (boost::format ("Pub: %1% Prv: %2%\n") % account.to_account () % key.data.to_string ());
|
||||
if (nano::pub_key (key.data) != account)
|
||||
if (nano::pub_key (key.as_private_key ()) != account)
|
||||
{
|
||||
std::cerr << boost::str (boost::format ("Invalid private key %1%\n") % key.data.to_string ());
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
|
@ -823,7 +823,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
}
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
|
@ -920,7 +920,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
auto transaction (i->second->wallets.tx_begin_read ());
|
||||
for (auto j (i->second->store.begin (transaction)), m (i->second->store.end ()); j != m; ++j)
|
||||
{
|
||||
std::cout << nano::uint256_union (j->first).to_account () << '\n';
|
||||
std::cout << nano::account (j->first).to_account () << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -929,7 +929,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
if (vm.count ("wallet") == 1 && vm.count ("account") == 1)
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
auto wallet (node.node->wallets.items.find (wallet_id));
|
||||
|
@ -978,7 +978,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("wallet") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
inactive_node node (data_path);
|
||||
|
@ -1013,7 +1013,7 @@ std::error_code nano::handle_node_options (boost::program_options::variables_map
|
|||
{
|
||||
if (vm.count ("account") == 1)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
if (!wallet_id.decode_hex (vm["wallet"].as<std::string> ()))
|
||||
{
|
||||
nano::account account;
|
||||
|
|
|
@ -557,7 +557,7 @@ block (block_a)
|
|||
header.block_type_set (block->type ());
|
||||
}
|
||||
|
||||
nano::confirm_req::confirm_req (std::vector<std::pair<nano::block_hash, nano::block_hash>> const & roots_hashes_a) :
|
||||
nano::confirm_req::confirm_req (std::vector<std::pair<nano::block_hash, nano::root>> const & roots_hashes_a) :
|
||||
message (nano::message_type::confirm_req),
|
||||
roots_hashes (roots_hashes_a)
|
||||
{
|
||||
|
@ -567,9 +567,9 @@ roots_hashes (roots_hashes_a)
|
|||
header.count_set (static_cast<uint8_t> (roots_hashes.size ()));
|
||||
}
|
||||
|
||||
nano::confirm_req::confirm_req (nano::block_hash const & hash_a, nano::block_hash const & root_a) :
|
||||
nano::confirm_req::confirm_req (nano::block_hash const & hash_a, nano::root const & root_a) :
|
||||
message (nano::message_type::confirm_req),
|
||||
roots_hashes (std::vector<std::pair<nano::block_hash, nano::block_hash>> (1, std::make_pair (hash_a, root_a)))
|
||||
roots_hashes (std::vector<std::pair<nano::block_hash, nano::root>> (1, std::make_pair (hash_a, root_a)))
|
||||
{
|
||||
assert (!roots_hashes.empty ());
|
||||
// not_a_block (1) block type for hashes + roots request
|
||||
|
|
|
@ -310,14 +310,14 @@ class confirm_req final : public message
|
|||
public:
|
||||
confirm_req (bool &, nano::stream &, nano::message_header const &, nano::block_uniquer * = nullptr);
|
||||
explicit confirm_req (std::shared_ptr<nano::block>);
|
||||
confirm_req (std::vector<std::pair<nano::block_hash, nano::block_hash>> const &);
|
||||
confirm_req (nano::block_hash const &, nano::block_hash const &);
|
||||
confirm_req (std::vector<std::pair<nano::block_hash, nano::root>> const &);
|
||||
confirm_req (nano::block_hash const &, nano::root const &);
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &, nano::block_uniquer * = nullptr);
|
||||
void visit (nano::message_visitor &) const override;
|
||||
bool operator== (nano::confirm_req const &) const;
|
||||
std::shared_ptr<nano::block> block;
|
||||
std::vector<std::pair<nano::block_hash, nano::block_hash>> roots_hashes;
|
||||
std::vector<std::pair<nano::block_hash, nano::root>> roots_hashes;
|
||||
std::string roots_string () const;
|
||||
static size_t size (nano::block_type, size_t = 0);
|
||||
};
|
||||
|
@ -355,7 +355,7 @@ public:
|
|||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void visit (nano::message_visitor &) const override;
|
||||
nano::uint256_union start;
|
||||
nano::root start;
|
||||
nano::block_hash end;
|
||||
count_t count;
|
||||
bool is_count_present () const;
|
||||
|
@ -372,8 +372,8 @@ public:
|
|||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void visit (nano::message_visitor &) const override;
|
||||
nano::uint256_union account;
|
||||
nano::uint128_union minimum_amount;
|
||||
nano::account account;
|
||||
nano::amount minimum_amount;
|
||||
bulk_pull_account_flags flags;
|
||||
static size_t constexpr size = sizeof (account) + sizeof (minimum_amount) + sizeof (bulk_pull_account_flags);
|
||||
};
|
||||
|
@ -390,7 +390,7 @@ class node_id_handshake final : public message
|
|||
{
|
||||
public:
|
||||
node_id_handshake (bool &, nano::stream &, nano::message_header const &);
|
||||
node_id_handshake (boost::optional<nano::block_hash>, boost::optional<std::pair<nano::account, nano::signature>>);
|
||||
node_id_handshake (boost::optional<nano::uint256_union>, boost::optional<std::pair<nano::account, nano::signature>>);
|
||||
void serialize (nano::stream &) const override;
|
||||
bool deserialize (nano::stream &);
|
||||
void visit (nano::message_visitor &) const override;
|
||||
|
|
|
@ -360,7 +360,7 @@ void nano::confirmation_height_processor::collect_unconfirmed_receive_and_source
|
|||
hash = block->previous ();
|
||||
}
|
||||
|
||||
// We could be traversing a very large account so we don't want to have open read transactions for too long.
|
||||
// We could be traversing a very large account so we don't want to open read transactions for too long.
|
||||
if (num_to_confirm % batch_read_size == 0)
|
||||
{
|
||||
transaction_a.refresh ();
|
||||
|
|
|
@ -14,7 +14,7 @@ std::shared_ptr<request_type> nano::work_peer_request::get_prepared_json_request
|
|||
return request;
|
||||
}
|
||||
|
||||
nano::distributed_work::distributed_work (unsigned int backoff_a, nano::node & node_a, nano::block_hash const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a) :
|
||||
nano::distributed_work::distributed_work (unsigned int backoff_a, nano::node & node_a, nano::root const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a) :
|
||||
callback (callback_a),
|
||||
backoff (backoff_a),
|
||||
node (node_a),
|
||||
|
@ -374,12 +374,12 @@ node (node_a)
|
|||
{
|
||||
}
|
||||
|
||||
void nano::distributed_work_factory::make (nano::block_hash const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
void nano::distributed_work_factory::make (nano::root const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
make (1, root_a, callback_a, difficulty_a, account_a);
|
||||
}
|
||||
|
||||
void nano::distributed_work_factory::make (unsigned int backoff_a, nano::block_hash const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
void nano::distributed_work_factory::make (unsigned int backoff_a, nano::root const & root_a, std::function<void(boost::optional<uint64_t>)> const & callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
cleanup_finished ();
|
||||
auto distributed (std::make_shared<nano::distributed_work> (backoff_a, node, root_a, callback_a, difficulty_a, account_a));
|
||||
|
@ -390,7 +390,7 @@ void nano::distributed_work_factory::make (unsigned int backoff_a, nano::block_h
|
|||
distributed->start ();
|
||||
}
|
||||
|
||||
void nano::distributed_work_factory::cancel (nano::block_hash const & root_a, bool const local_stop)
|
||||
void nano::distributed_work_factory::cancel (nano::root const & root_a, bool const local_stop)
|
||||
{
|
||||
{
|
||||
nano::lock_guard<std::mutex> guard (mutex);
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
class distributed_work final : public std::enable_shared_from_this<nano::distributed_work>
|
||||
{
|
||||
public:
|
||||
distributed_work (unsigned int, nano::node &, nano::block_hash const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
distributed_work (unsigned int, nano::node &, nano::root const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
~distributed_work ();
|
||||
void start ();
|
||||
void start_work ();
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
std::function<void(boost::optional<uint64_t>)> callback;
|
||||
unsigned int backoff; // in seconds
|
||||
nano::node & node;
|
||||
nano::block_hash root;
|
||||
nano::root root;
|
||||
boost::optional<nano::account> const & account;
|
||||
std::mutex mutex;
|
||||
std::map<boost::asio::ip::address, uint16_t> outstanding;
|
||||
|
@ -76,12 +76,12 @@ class distributed_work_factory final
|
|||
{
|
||||
public:
|
||||
distributed_work_factory (nano::node &);
|
||||
void make (nano::block_hash const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void make (unsigned int, nano::block_hash const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void cancel (nano::block_hash const &, bool const local_stop = false);
|
||||
void make (nano::root const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void make (unsigned int, nano::root const &, std::function<void(boost::optional<uint64_t>)> const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void cancel (nano::root const &, bool const local_stop = false);
|
||||
void cleanup_finished ();
|
||||
|
||||
std::unordered_map<nano::block_hash, std::vector<std::weak_ptr<nano::distributed_work>>> work;
|
||||
std::unordered_map<nano::root, std::vector<std::weak_ptr<nano::distributed_work>>> work;
|
||||
std::mutex mutex;
|
||||
nano::node & node;
|
||||
};
|
||||
|
|
|
@ -153,7 +153,7 @@ std::shared_ptr<nano::wallet> nano::json_handler::wallet_impl ()
|
|||
if (!ec)
|
||||
{
|
||||
std::string wallet_text (request.get<std::string> ("wallet"));
|
||||
nano::uint256_union wallet;
|
||||
nano::wallet_id wallet;
|
||||
if (!wallet.decode_hex (wallet_text))
|
||||
{
|
||||
auto existing (node.wallets.items.find (wallet));
|
||||
|
@ -500,7 +500,7 @@ void nano::json_handler::account_create ()
|
|||
void nano::json_handler::account_get ()
|
||||
{
|
||||
std::string key_text (request.get<std::string> ("key"));
|
||||
nano::uint256_union pub;
|
||||
nano::public_key pub;
|
||||
if (!pub.decode_hex (key_text))
|
||||
{
|
||||
response_l.put ("account", pub.to_account ());
|
||||
|
@ -596,7 +596,7 @@ void nano::json_handler::account_move ()
|
|||
{
|
||||
std::string source_text (rpc_l->request.get<std::string> ("source"));
|
||||
auto accounts_text (rpc_l->request.get_child ("accounts"));
|
||||
nano::uint256_union source;
|
||||
nano::wallet_id source;
|
||||
if (!source.decode_hex (source_text))
|
||||
{
|
||||
auto existing (rpc_l->node.wallets.items.find (source));
|
||||
|
@ -1040,7 +1040,7 @@ void nano::json_handler::blocks ()
|
|||
if (!ec)
|
||||
{
|
||||
std::string hash_text = hashes.second.data ();
|
||||
nano::uint256_union hash;
|
||||
nano::block_hash hash;
|
||||
if (!hash.decode_hex (hash_text))
|
||||
{
|
||||
auto block (node.store.block_get (transaction, hash));
|
||||
|
@ -1089,7 +1089,7 @@ void nano::json_handler::blocks_info ()
|
|||
if (!ec)
|
||||
{
|
||||
std::string hash_text = hashes.second.data ();
|
||||
nano::uint256_union hash;
|
||||
nano::block_hash hash;
|
||||
if (!hash.decode_hex (hash_text))
|
||||
{
|
||||
nano::block_sideband sideband;
|
||||
|
@ -1225,7 +1225,7 @@ void nano::json_handler::block_create ()
|
|||
if (!ec)
|
||||
{
|
||||
std::string type (request.get<std::string> ("type"));
|
||||
nano::uint256_union wallet (0);
|
||||
nano::wallet_id wallet (0);
|
||||
boost::optional<std::string> wallet_text (request.get_optional<std::string> ("wallet"));
|
||||
if (wallet_text.is_initialized ())
|
||||
{
|
||||
|
@ -1240,13 +1240,13 @@ void nano::json_handler::block_create ()
|
|||
{
|
||||
account = account_impl (account_text.get ());
|
||||
}
|
||||
nano::uint256_union representative (0);
|
||||
nano::account representative (0);
|
||||
boost::optional<std::string> representative_text (request.get_optional<std::string> ("representative"));
|
||||
if (!ec && representative_text.is_initialized ())
|
||||
{
|
||||
representative = account_impl (representative_text.get (), nano::error_rpc::bad_representative_number);
|
||||
}
|
||||
nano::uint256_union destination (0);
|
||||
nano::account destination (0);
|
||||
boost::optional<std::string> destination_text (request.get_optional<std::string> ("destination"));
|
||||
if (!ec && destination_text.is_initialized ())
|
||||
{
|
||||
|
@ -1261,7 +1261,7 @@ void nano::json_handler::block_create ()
|
|||
ec = nano::error_rpc::bad_source;
|
||||
}
|
||||
}
|
||||
nano::uint128_union amount (0);
|
||||
nano::amount amount (0);
|
||||
boost::optional<std::string> amount_text (request.get_optional<std::string> ("amount"));
|
||||
if (!ec && amount_text.is_initialized ())
|
||||
{
|
||||
|
@ -1273,8 +1273,8 @@ void nano::json_handler::block_create ()
|
|||
auto work (work_optional_impl ());
|
||||
nano::raw_key prv;
|
||||
prv.data.clear ();
|
||||
nano::uint256_union previous (0);
|
||||
nano::uint128_union balance (0);
|
||||
nano::block_hash previous (0);
|
||||
nano::amount balance (0);
|
||||
if (!ec && wallet != 0 && account != 0)
|
||||
{
|
||||
auto existing (node.wallets.items.find (wallet));
|
||||
|
@ -1320,7 +1320,7 @@ void nano::json_handler::block_create ()
|
|||
ec = nano::error_rpc::invalid_balance;
|
||||
}
|
||||
}
|
||||
nano::uint256_union link (0);
|
||||
nano::link link (0);
|
||||
boost::optional<std::string> link_text (request.get_optional<std::string> ("link"));
|
||||
if (!ec && link_text.is_initialized ())
|
||||
{
|
||||
|
@ -1335,13 +1335,20 @@ void nano::json_handler::block_create ()
|
|||
else
|
||||
{
|
||||
// Retrieve link from source or destination
|
||||
link = source.is_zero () ? destination : source;
|
||||
if (source.is_zero ())
|
||||
{
|
||||
link = destination;
|
||||
}
|
||||
else
|
||||
{
|
||||
link = source;
|
||||
}
|
||||
}
|
||||
if (!ec)
|
||||
{
|
||||
if (prv.data != 0)
|
||||
{
|
||||
nano::uint256_union pub (nano::pub_key (prv.data));
|
||||
nano::account pub (nano::pub_key (prv.as_private_key ()));
|
||||
// Fetching account balance & previous for send blocks (if aren't given directly)
|
||||
if (!previous_text.is_initialized () && !balance_text.is_initialized ())
|
||||
{
|
||||
|
@ -1372,7 +1379,17 @@ void nano::json_handler::block_create ()
|
|||
{
|
||||
if (work == 0)
|
||||
{
|
||||
auto opt_work_l (node.work_generate_blocking (previous.is_zero () ? pub : previous, nano::account (pub)));
|
||||
nano::root root;
|
||||
if (previous.is_zero ())
|
||||
{
|
||||
root = pub;
|
||||
}
|
||||
else
|
||||
{
|
||||
root = previous;
|
||||
}
|
||||
|
||||
auto opt_work_l (node.work_generate_blocking (root, nano::account (pub)));
|
||||
if (opt_work_l.is_initialized ())
|
||||
{
|
||||
work = *opt_work_l;
|
||||
|
@ -1992,9 +2009,8 @@ void nano::json_handler::deterministic_key ()
|
|||
try
|
||||
{
|
||||
uint32_t index (std::stoul (index_text));
|
||||
nano::uint256_union prv;
|
||||
nano::deterministic_key (seed.data, index, prv);
|
||||
nano::uint256_union pub (nano::pub_key (prv));
|
||||
nano::private_key prv = nano::deterministic_key (seed, index);
|
||||
nano::public_key pub (nano::pub_key (prv));
|
||||
response_l.put ("private", prv.to_string ());
|
||||
response_l.put ("public", pub.to_string ());
|
||||
response_l.put ("account", pub.to_account ());
|
||||
|
@ -2071,10 +2087,6 @@ public:
|
|||
}
|
||||
void receive_block (nano::receive_block const & block_a)
|
||||
{
|
||||
if (should_ignore_account (block_a.hashables.source))
|
||||
{
|
||||
return;
|
||||
}
|
||||
tree.put ("type", "receive");
|
||||
auto account (handler.node.ledger.account (transaction, block_a.hashables.source).to_account ());
|
||||
tree.put ("account", account);
|
||||
|
@ -2088,10 +2100,6 @@ public:
|
|||
}
|
||||
void open_block (nano::open_block const & block_a)
|
||||
{
|
||||
if (should_ignore_account (block_a.hashables.source))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (raw)
|
||||
{
|
||||
tree.put ("type", "open");
|
||||
|
@ -2357,10 +2365,10 @@ void nano::json_handler::key_create ()
|
|||
void nano::json_handler::key_expand ()
|
||||
{
|
||||
std::string key_text (request.get<std::string> ("key"));
|
||||
nano::uint256_union prv;
|
||||
nano::private_key prv;
|
||||
if (!prv.decode_hex (key_text))
|
||||
{
|
||||
nano::uint256_union pub (nano::pub_key (prv));
|
||||
nano::public_key pub (nano::pub_key (prv));
|
||||
response_l.put ("private", prv.to_string ());
|
||||
response_l.put ("public", pub.to_string ());
|
||||
response_l.put ("account", pub.to_account ());
|
||||
|
@ -2751,7 +2759,7 @@ void nano::json_handler::payment_begin ()
|
|||
auto rpc_l (shared_from_this ());
|
||||
node.worker.push_task ([rpc_l]() {
|
||||
std::string id_text (rpc_l->request.get<std::string> ("wallet"));
|
||||
nano::uint256_union id;
|
||||
nano::wallet_id id;
|
||||
if (!id.decode_hex (id_text))
|
||||
{
|
||||
auto existing (rpc_l->node.wallets.items.find (id));
|
||||
|
@ -3084,7 +3092,7 @@ void nano::json_handler::receive ()
|
|||
if (!ec && work)
|
||||
{
|
||||
nano::account_info info;
|
||||
nano::uint256_union head;
|
||||
nano::root head;
|
||||
if (!node.store.account_get (block_transaction, account, info))
|
||||
{
|
||||
head = info.head;
|
||||
|
@ -3560,7 +3568,7 @@ void nano::json_handler::sign ()
|
|||
// Signing
|
||||
if (prv.data != 0)
|
||||
{
|
||||
nano::public_key pub (nano::pub_key (prv.data));
|
||||
nano::public_key pub (nano::pub_key (prv.as_private_key ()));
|
||||
nano::signature signature (nano::sign_message (prv, pub, hash));
|
||||
response_l.put ("signature", signature.to_string ());
|
||||
if (block != nullptr)
|
||||
|
@ -3718,7 +3726,7 @@ void nano::json_handler::unchecked_keys ()
|
|||
{
|
||||
const bool json_block_l = request.get<bool> ("json_block", false);
|
||||
auto count (count_optional_impl ());
|
||||
nano::uint256_union key (0);
|
||||
nano::block_hash key (0);
|
||||
boost::optional<std::string> hash_text (request.get_optional<std::string> ("key"));
|
||||
if (!ec && hash_text.is_initialized ())
|
||||
{
|
||||
|
@ -3735,7 +3743,7 @@ void nano::json_handler::unchecked_keys ()
|
|||
{
|
||||
boost::property_tree::ptree entry;
|
||||
nano::unchecked_info const & info (i->second);
|
||||
entry.put ("key", nano::block_hash (i->first.key ()).to_string ());
|
||||
entry.put ("key", i->first.key ().to_string ());
|
||||
entry.put ("hash", info.block->hash ().to_string ());
|
||||
entry.put ("modified_timestamp", std::to_string (info.modified));
|
||||
if (json_block_l)
|
||||
|
@ -4037,12 +4045,12 @@ void nano::json_handler::wallet_create ()
|
|||
}
|
||||
if (!rpc_l->ec)
|
||||
{
|
||||
nano::keypair wallet_id;
|
||||
auto wallet (rpc_l->node.wallets.create (wallet_id.pub));
|
||||
auto existing (rpc_l->node.wallets.items.find (wallet_id.pub));
|
||||
auto wallet_id = random_wallet_id ();
|
||||
auto wallet (rpc_l->node.wallets.create (wallet_id));
|
||||
auto existing (rpc_l->node.wallets.items.find (wallet_id));
|
||||
if (existing != rpc_l->node.wallets.items.end ())
|
||||
{
|
||||
rpc_l->response_l.put ("wallet", wallet_id.pub.to_string ());
|
||||
rpc_l->response_l.put ("wallet", wallet_id.to_string ());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4067,7 +4075,7 @@ void nano::json_handler::wallet_destroy ()
|
|||
auto rpc_l (shared_from_this ());
|
||||
node.worker.push_task ([rpc_l]() {
|
||||
std::string wallet_text (rpc_l->request.get<std::string> ("wallet"));
|
||||
nano::uint256_union wallet;
|
||||
nano::wallet_id wallet;
|
||||
if (!wallet.decode_hex (wallet_text))
|
||||
{
|
||||
auto existing (rpc_l->node.wallets.items.find (wallet));
|
||||
|
|
|
@ -188,11 +188,11 @@ void nano::mdb_store::upgrade_v1_to_v2 (nano::write_transaction const & transact
|
|||
nano::account account (1);
|
||||
while (!account.is_zero ())
|
||||
{
|
||||
nano::mdb_iterator<nano::uint256_union, nano::account_info_v1> i (transaction_a, accounts_v0, nano::mdb_val (account));
|
||||
nano::mdb_iterator<nano::account, nano::account_info_v1> i (transaction_a, accounts_v0, nano::mdb_val (account));
|
||||
std::cerr << std::hex;
|
||||
if (i != nano::mdb_iterator<nano::uint256_union, nano::account_info_v1> (nullptr))
|
||||
if (i != nano::mdb_iterator<nano::account, nano::account_info_v1> (nullptr))
|
||||
{
|
||||
account = nano::uint256_union (i->first);
|
||||
account = nano::account (i->first);
|
||||
nano::account_info_v1 v1 (i->second);
|
||||
nano::account_info_v5 v2;
|
||||
v2.balance = v1.balance;
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
wallet_value (nano::db_val<MDB_val> const &);
|
||||
wallet_value (nano::uint256_union const &, uint64_t);
|
||||
nano::db_val<MDB_val> val () const;
|
||||
nano::private_key key;
|
||||
nano::uint256_union key;
|
||||
uint64_t work;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -319,7 +319,7 @@ void nano::network::broadcast_confirm_req_base (std::shared_ptr<nano::block> blo
|
|||
}
|
||||
}
|
||||
|
||||
void nano::network::broadcast_confirm_req_batch (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::block_hash>>> request_bundle_a, unsigned delay_a, bool resumption)
|
||||
void nano::network::broadcast_confirm_req_batch (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::root>>> request_bundle_a, unsigned delay_a, bool resumption)
|
||||
{
|
||||
const size_t max_reps = 50;
|
||||
if (!resumption && node.config.logging.network_logging ())
|
||||
|
@ -333,7 +333,7 @@ void nano::network::broadcast_confirm_req_batch (std::unordered_map<std::shared_
|
|||
while (j != request_bundle_a.end ())
|
||||
{
|
||||
count++;
|
||||
std::vector<std::pair<nano::block_hash, nano::block_hash>> roots_hashes;
|
||||
std::vector<std::pair<nano::block_hash, nano::root>> roots_hashes;
|
||||
// Limit max request size hash + root to 7 pairs
|
||||
while (roots_hashes.size () < confirm_req_hashes_max && !j->second.empty ())
|
||||
{
|
||||
|
@ -481,13 +481,14 @@ public:
|
|||
// Search for block root
|
||||
successor = node.store.block_successor (transaction, root_hash.second);
|
||||
// Search for account root
|
||||
if (successor.is_zero () && node.store.account_exists (transaction, root_hash.second))
|
||||
if (successor.is_zero ())
|
||||
{
|
||||
nano::account_info info;
|
||||
auto error (node.store.account_get (transaction, root_hash.second, info));
|
||||
(void)error;
|
||||
assert (!error);
|
||||
successor = info.open_block;
|
||||
if (!error)
|
||||
{
|
||||
successor = info.open_block;
|
||||
}
|
||||
}
|
||||
if (!successor.is_zero ())
|
||||
{
|
||||
|
|
|
@ -125,7 +125,7 @@ public:
|
|||
void send_confirm_req (std::shared_ptr<nano::transport::channel>, std::shared_ptr<nano::block>);
|
||||
void broadcast_confirm_req (std::shared_ptr<nano::block>);
|
||||
void broadcast_confirm_req_base (std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>, unsigned, bool = false);
|
||||
void broadcast_confirm_req_batch (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::block_hash>>>, unsigned = broadcast_interval_ms, bool = false);
|
||||
void broadcast_confirm_req_batch (std::unordered_map<std::shared_ptr<nano::transport::channel>, std::deque<std::pair<nano::block_hash, nano::root>>>, unsigned = broadcast_interval_ms, bool = false);
|
||||
void broadcast_confirm_req_batch (std::deque<std::pair<std::shared_ptr<nano::block>, std::shared_ptr<std::vector<std::shared_ptr<nano::transport::channel>>>>>, unsigned = broadcast_interval_ms);
|
||||
void confirm_hashes (nano::transaction const &, std::shared_ptr<nano::transport::channel>, std::vector<nano::block_hash>);
|
||||
bool send_votes_cache (std::shared_ptr<nano::transport::channel>, nano::block_hash const &);
|
||||
|
|
|
@ -359,7 +359,7 @@ startup_time (std::chrono::steady_clock::now ())
|
|||
});
|
||||
}
|
||||
// Cancelling local work generation
|
||||
observers.work_cancel.add ([this](nano::block_hash const & root_a) {
|
||||
observers.work_cancel.add ([this](nano::root const & root_a) {
|
||||
this->work.cancel (root_a);
|
||||
this->distributed_work.cancel (root_a);
|
||||
});
|
||||
|
@ -756,7 +756,7 @@ nano::block_hash nano::node::rep_block (nano::account const & account_a)
|
|||
{
|
||||
auto transaction (store.tx_begin_read ());
|
||||
nano::account_info info;
|
||||
nano::account result (0);
|
||||
nano::block_hash result (0);
|
||||
if (!store.account_get (transaction, account_a, info))
|
||||
{
|
||||
result = ledger.representative (transaction, info.head);
|
||||
|
@ -975,27 +975,27 @@ boost::optional<uint64_t> nano::node::work_generate_blocking (nano::block & bloc
|
|||
return opt_work_l;
|
||||
}
|
||||
|
||||
void nano::node::work_generate (nano::uint256_union const & hash_a, std::function<void(boost::optional<uint64_t>)> callback_a, boost::optional<nano::account> const & account_a)
|
||||
void nano::node::work_generate (nano::root const & root_a, std::function<void(boost::optional<uint64_t>)> callback_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
work_generate (hash_a, callback_a, network_params.network.publish_threshold, account_a);
|
||||
work_generate (root_a, callback_a, network_params.network.publish_threshold, account_a);
|
||||
}
|
||||
|
||||
void nano::node::work_generate (nano::uint256_union const & hash_a, std::function<void(boost::optional<uint64_t>)> callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
void nano::node::work_generate (nano::root const & root_a, std::function<void(boost::optional<uint64_t>)> callback_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
distributed_work.make (hash_a, callback_a, difficulty_a, account_a);
|
||||
distributed_work.make (root_a, callback_a, difficulty_a, account_a);
|
||||
}
|
||||
|
||||
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::uint256_union const & hash_a, boost::optional<nano::account> const & account_a)
|
||||
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
return work_generate_blocking (hash_a, network_params.network.publish_threshold, account_a);
|
||||
return work_generate_blocking (root_a, network_params.network.publish_threshold, account_a);
|
||||
}
|
||||
|
||||
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::uint256_union const & hash_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
boost::optional<uint64_t> nano::node::work_generate_blocking (nano::root const & root_a, uint64_t difficulty_a, boost::optional<nano::account> const & account_a)
|
||||
{
|
||||
std::promise<uint64_t> promise;
|
||||
std::future<uint64_t> future = promise.get_future ();
|
||||
// clang-format off
|
||||
work_generate (hash_a, [&promise](boost::optional<uint64_t> work_a) {
|
||||
work_generate (root_a, [&promise](boost::optional<uint64_t> work_a) {
|
||||
promise.set_value (work_a.value_or (0));
|
||||
},
|
||||
difficulty_a, account_a);
|
||||
|
@ -1264,7 +1264,7 @@ std::shared_ptr<nano::node> nano::node::shared ()
|
|||
bool nano::node::validate_block_by_previous (nano::transaction const & transaction, std::shared_ptr<nano::block> block_a)
|
||||
{
|
||||
bool result (false);
|
||||
nano::account account;
|
||||
nano::root account;
|
||||
if (!block_a->previous ().is_zero ())
|
||||
{
|
||||
if (store.block_exists (transaction, block_a->previous ()))
|
||||
|
|
|
@ -125,10 +125,10 @@ public:
|
|||
int price (nano::uint128_t const &, int);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::block &, uint64_t);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::block &);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::uint256_union const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::uint256_union const &, boost::optional<nano::account> const & = boost::none);
|
||||
void work_generate (nano::uint256_union const &, std::function<void(boost::optional<uint64_t>)>, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void work_generate (nano::uint256_union const &, std::function<void(boost::optional<uint64_t>)>, boost::optional<nano::account> const & = boost::none);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
boost::optional<uint64_t> work_generate_blocking (nano::root const &, boost::optional<nano::account> const & = boost::none);
|
||||
void work_generate (nano::root const &, std::function<void(boost::optional<uint64_t>)>, uint64_t, boost::optional<nano::account> const & = boost::none);
|
||||
void work_generate (nano::root const &, std::function<void(boost::optional<uint64_t>)>, boost::optional<nano::account> const & = boost::none);
|
||||
void add_initial_peers ();
|
||||
void block_confirm (std::shared_ptr<nano::block>);
|
||||
bool block_confirmed_or_being_confirmed (nano::transaction const &, nano::block_hash const &);
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
nano::observer_set<std::shared_ptr<nano::transport::channel>> endpoint;
|
||||
nano::observer_set<> disconnect;
|
||||
nano::observer_set<uint64_t> difficulty;
|
||||
nano::observer_set<nano::block_hash const &> work_cancel;
|
||||
nano::observer_set<nano::root const &> work_cancel;
|
||||
};
|
||||
|
||||
std::unique_ptr<seq_con_info_component> collect_seq_con_info (node_observers & node_observers, const std::string & name);
|
||||
|
|
|
@ -466,7 +466,7 @@ bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & jso
|
|||
auto reps_l (json.get_required_child ("preconfigured_representatives"));
|
||||
nano::jsonconfig reps;
|
||||
reps_l.array_entries<std::string> ([&reps](std::string entry) {
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
account.decode_account (entry);
|
||||
reps.push (account.to_account ());
|
||||
});
|
||||
|
|
|
@ -687,13 +687,13 @@ nano::opencl_work::~opencl_work ()
|
|||
}
|
||||
}
|
||||
|
||||
boost::optional<uint64_t> nano::opencl_work::generate_work (nano::uint256_union const & root_a, uint64_t const difficulty_a)
|
||||
boost::optional<uint64_t> nano::opencl_work::generate_work (nano::root const & root_a, uint64_t const difficulty_a)
|
||||
{
|
||||
std::atomic<int> ticket_l{ 0 };
|
||||
return generate_work (root_a, difficulty_a, ticket_l);
|
||||
}
|
||||
|
||||
boost::optional<uint64_t> nano::opencl_work::generate_work (nano::uint256_union const & root_a, uint64_t const difficulty_a, std::atomic<int> & ticket_a)
|
||||
boost::optional<uint64_t> nano::opencl_work::generate_work (nano::root const & root_a, uint64_t const difficulty_a, std::atomic<int> & ticket_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
bool error (false);
|
||||
|
@ -708,7 +708,7 @@ boost::optional<uint64_t> nano::opencl_work::generate_work (nano::uint256_union
|
|||
cl_int write_error1 = clEnqueueWriteBuffer (queue, attempt_buffer, false, 0, sizeof (uint64_t), &result, 0, nullptr, nullptr);
|
||||
if (write_error1 == CL_SUCCESS)
|
||||
{
|
||||
cl_int write_error2 = clEnqueueWriteBuffer (queue, item_buffer, false, 0, sizeof (nano::uint256_union), root_a.bytes.data (), 0, nullptr, nullptr);
|
||||
cl_int write_error2 = clEnqueueWriteBuffer (queue, item_buffer, false, 0, sizeof (nano::root), root_a.bytes.data (), 0, nullptr, nullptr);
|
||||
if (write_error2 == CL_SUCCESS)
|
||||
{
|
||||
cl_int write_error3 = clEnqueueWriteBuffer (queue, difficulty_buffer, false, 0, sizeof (uint64_t), &difficulty_a, 0, nullptr, nullptr);
|
||||
|
|
|
@ -36,15 +36,15 @@ public:
|
|||
void dump (std::ostream & stream);
|
||||
std::vector<nano::opencl_platform> platforms;
|
||||
};
|
||||
union uint256_union;
|
||||
class root;
|
||||
class work_pool;
|
||||
class opencl_work
|
||||
{
|
||||
public:
|
||||
opencl_work (bool &, nano::opencl_config const &, nano::opencl_environment &, nano::logger_mt &);
|
||||
~opencl_work ();
|
||||
boost::optional<uint64_t> generate_work (nano::uint256_union const &, uint64_t const);
|
||||
boost::optional<uint64_t> generate_work (nano::uint256_union const &, uint64_t const, std::atomic<int> &);
|
||||
boost::optional<uint64_t> generate_work (nano::root const &, uint64_t const);
|
||||
boost::optional<uint64_t> generate_work (nano::root const &, uint64_t const, std::atomic<int> &);
|
||||
static std::unique_ptr<opencl_work> create (bool, nano::opencl_config const &, nano::logger_mt &);
|
||||
nano::opencl_config const & config;
|
||||
std::mutex mutex;
|
||||
|
|
|
@ -28,9 +28,7 @@ std::shared_ptr<nano::node> nano::system::add_node (nano::node_config const & no
|
|||
auto node (std::make_shared<nano::node> (io_ctx, nano::unique_path (), alarm, node_config_a, work, node_flags_a));
|
||||
assert (!node->init_error ());
|
||||
node->start ();
|
||||
nano::uint256_union wallet;
|
||||
nano::random_pool::generate_block (wallet.bytes.data (), wallet.bytes.size ());
|
||||
node->wallets.create (wallet);
|
||||
node->wallets.create (nano::random_wallet_id ());
|
||||
nodes.reserve (nodes.size () + 1);
|
||||
nodes.push_back (node);
|
||||
if (nodes.size () > 1)
|
||||
|
@ -257,9 +255,9 @@ void nano::system::generate_receive (nano::node & node_a)
|
|||
std::shared_ptr<nano::block> send_block;
|
||||
{
|
||||
auto transaction (node_a.store.tx_begin_read ());
|
||||
nano::uint256_union random_block;
|
||||
random_pool::generate_block (random_block.bytes.data (), sizeof (random_block.bytes));
|
||||
auto i (node_a.store.pending_begin (transaction, nano::pending_key (random_block, 0)));
|
||||
nano::account random_account;
|
||||
random_pool::generate_block (random_account.bytes.data (), sizeof (random_account.bytes));
|
||||
auto i (node_a.store.pending_begin (transaction, nano::pending_key (random_account, 0)));
|
||||
if (i != node_a.store.pending_end ())
|
||||
{
|
||||
nano::pending_key const & send_hash (i->first);
|
||||
|
|
|
@ -141,9 +141,9 @@ void nano::vote_processor::verify_votes (std::deque<std::pair<std::shared_ptr<na
|
|||
auto size (votes_a.size ());
|
||||
std::vector<unsigned char const *> messages;
|
||||
messages.reserve (size);
|
||||
std::vector<nano::uint256_union> hashes;
|
||||
std::vector<nano::block_hash> hashes;
|
||||
hashes.reserve (size);
|
||||
std::vector<size_t> lengths (size, sizeof (nano::uint256_union));
|
||||
std::vector<size_t> lengths (size, sizeof (nano::block_hash));
|
||||
std::vector<unsigned char const *> pub_keys;
|
||||
pub_keys.reserve (size);
|
||||
std::vector<unsigned char const *> signatures;
|
||||
|
|
|
@ -55,14 +55,13 @@ void nano::wallet_store::seed_set (nano::transaction const & transaction_a, nano
|
|||
nano::public_key nano::wallet_store::deterministic_insert (nano::transaction const & transaction_a)
|
||||
{
|
||||
auto index (deterministic_index_get (transaction_a));
|
||||
nano::raw_key prv;
|
||||
deterministic_key (prv, transaction_a, index);
|
||||
nano::public_key result (nano::pub_key (prv.data));
|
||||
auto prv = deterministic_key (transaction_a, index);
|
||||
nano::public_key result (nano::pub_key (prv));
|
||||
while (exists (transaction_a, result))
|
||||
{
|
||||
++index;
|
||||
deterministic_key (prv, transaction_a, index);
|
||||
result = nano::pub_key (prv.data);
|
||||
prv = deterministic_key (transaction_a, index);
|
||||
result = nano::pub_key (prv);
|
||||
}
|
||||
uint64_t marker (1);
|
||||
marker <<= 32;
|
||||
|
@ -75,9 +74,8 @@ nano::public_key nano::wallet_store::deterministic_insert (nano::transaction con
|
|||
|
||||
nano::public_key nano::wallet_store::deterministic_insert (nano::transaction const & transaction_a, uint32_t const index)
|
||||
{
|
||||
nano::raw_key prv;
|
||||
deterministic_key (prv, transaction_a, index);
|
||||
nano::public_key result (nano::pub_key (prv.data));
|
||||
auto prv = deterministic_key (transaction_a, index);
|
||||
nano::public_key result (nano::pub_key (prv));
|
||||
uint64_t marker (1);
|
||||
marker <<= 32;
|
||||
marker |= index;
|
||||
|
@ -85,12 +83,12 @@ nano::public_key nano::wallet_store::deterministic_insert (nano::transaction con
|
|||
return result;
|
||||
}
|
||||
|
||||
void nano::wallet_store::deterministic_key (nano::raw_key & prv_a, nano::transaction const & transaction_a, uint32_t index_a)
|
||||
nano::private_key nano::wallet_store::deterministic_key (nano::transaction const & transaction_a, uint32_t index_a)
|
||||
{
|
||||
assert (valid_password (transaction_a));
|
||||
nano::raw_key seed_l;
|
||||
seed (seed_l, transaction_a);
|
||||
nano::deterministic_key (seed_l.data, index_a, prv_a.data);
|
||||
return nano::deterministic_key (seed_l, index_a);
|
||||
}
|
||||
|
||||
uint32_t nano::wallet_store::deterministic_index_get (nano::transaction const & transaction_a)
|
||||
|
@ -115,7 +113,7 @@ void nano::wallet_store::deterministic_clear (nano::transaction const & transact
|
|||
{
|
||||
case nano::key_type::deterministic:
|
||||
{
|
||||
nano::uint256_union const & key (i->first);
|
||||
auto const & key (i->first);
|
||||
erase (transaction_a, key);
|
||||
i = begin (transaction_a, key);
|
||||
break;
|
||||
|
@ -243,19 +241,19 @@ void nano::fan::value_set (nano::raw_key const & value_a)
|
|||
}
|
||||
|
||||
// Wallet version number
|
||||
nano::uint256_union const nano::wallet_store::version_special (0);
|
||||
nano::account const nano::wallet_store::version_special (0);
|
||||
// Random number used to salt private key encryption
|
||||
nano::uint256_union const nano::wallet_store::salt_special (1);
|
||||
nano::account const nano::wallet_store::salt_special (1);
|
||||
// Key used to encrypt wallet keys, encrypted itself by the user password
|
||||
nano::uint256_union const nano::wallet_store::wallet_key_special (2);
|
||||
nano::account const nano::wallet_store::wallet_key_special (2);
|
||||
// Check value used to see if password is valid
|
||||
nano::uint256_union const nano::wallet_store::check_special (3);
|
||||
nano::account const nano::wallet_store::check_special (3);
|
||||
// Representative account to be used if we open a new account
|
||||
nano::uint256_union const nano::wallet_store::representative_special (4);
|
||||
nano::account const nano::wallet_store::representative_special (4);
|
||||
// Wallet seed for deterministic key generation
|
||||
nano::uint256_union const nano::wallet_store::seed_special (5);
|
||||
nano::account const nano::wallet_store::seed_special (5);
|
||||
// Current key index for deterministic keys
|
||||
nano::uint256_union const nano::wallet_store::deterministic_index_special (6);
|
||||
nano::account const nano::wallet_store::deterministic_index_special (6);
|
||||
int const nano::wallet_store::special_count (7);
|
||||
size_t const nano::wallet_store::check_iv_index (0);
|
||||
size_t const nano::wallet_store::seed_iv_index (1);
|
||||
|
@ -283,7 +281,7 @@ kdf (kdf_a)
|
|||
}
|
||||
for (auto i (wallet_l.begin ()), n (wallet_l.end ()); i != n; ++i)
|
||||
{
|
||||
nano::uint256_union key;
|
||||
nano::account key;
|
||||
init_a = key.decode_hex (i->first);
|
||||
if (!init_a)
|
||||
{
|
||||
|
@ -396,39 +394,39 @@ void nano::wallet_store::representative_set (nano::transaction const & transacti
|
|||
nano::account nano::wallet_store::representative (nano::transaction const & transaction_a)
|
||||
{
|
||||
nano::wallet_value value (entry_get_raw (transaction_a, nano::wallet_store::representative_special));
|
||||
return value.key;
|
||||
return reinterpret_cast<nano::account const &> (value.key);
|
||||
}
|
||||
|
||||
nano::public_key nano::wallet_store::insert_adhoc (nano::transaction const & transaction_a, nano::raw_key const & prv)
|
||||
{
|
||||
assert (valid_password (transaction_a));
|
||||
nano::public_key pub (nano::pub_key (prv.data));
|
||||
nano::public_key pub (nano::pub_key (prv.as_private_key ()));
|
||||
nano::raw_key password_l;
|
||||
wallet_key (password_l, transaction_a);
|
||||
nano::uint256_union ciphertext;
|
||||
nano::private_key ciphertext;
|
||||
ciphertext.encrypt (prv, password_l, pub.owords[0].number ());
|
||||
entry_put_raw (transaction_a, pub, nano::wallet_value (ciphertext, 0));
|
||||
return pub;
|
||||
}
|
||||
|
||||
bool nano::wallet_store::insert_watch (nano::transaction const & transaction_a, nano::public_key const & pub_a)
|
||||
bool nano::wallet_store::insert_watch (nano::transaction const & transaction_a, nano::account const & pub_a)
|
||||
{
|
||||
bool error (!valid_public_key (pub_a));
|
||||
if (!error)
|
||||
{
|
||||
entry_put_raw (transaction_a, pub_a, nano::wallet_value (nano::uint256_union (0), 0));
|
||||
entry_put_raw (transaction_a, pub_a, nano::wallet_value (nano::private_key (0), 0));
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
void nano::wallet_store::erase (nano::transaction const & transaction_a, nano::public_key const & pub)
|
||||
void nano::wallet_store::erase (nano::transaction const & transaction_a, nano::account const & pub)
|
||||
{
|
||||
auto status (mdb_del (tx (transaction_a), handle, nano::mdb_val (pub), nullptr));
|
||||
(void)status;
|
||||
assert (status == 0);
|
||||
}
|
||||
|
||||
nano::wallet_value nano::wallet_store::entry_get_raw (nano::transaction const & transaction_a, nano::public_key const & pub_a)
|
||||
nano::wallet_value nano::wallet_store::entry_get_raw (nano::transaction const & transaction_a, nano::account const & pub_a)
|
||||
{
|
||||
nano::wallet_value result;
|
||||
nano::mdb_val value;
|
||||
|
@ -445,7 +443,7 @@ nano::wallet_value nano::wallet_store::entry_get_raw (nano::transaction const &
|
|||
return result;
|
||||
}
|
||||
|
||||
void nano::wallet_store::entry_put_raw (nano::transaction const & transaction_a, nano::public_key const & pub_a, nano::wallet_value const & entry_a)
|
||||
void nano::wallet_store::entry_put_raw (nano::transaction const & transaction_a, nano::account const & pub_a, nano::wallet_value const & entry_a)
|
||||
{
|
||||
auto status (mdb_put (tx (transaction_a), handle, nano::mdb_val (pub_a), nano::mdb_val (sizeof (entry_a), const_cast<nano::wallet_value *> (&entry_a)), 0));
|
||||
(void)status;
|
||||
|
@ -475,7 +473,7 @@ nano::key_type nano::wallet_store::key_type (nano::wallet_value const & value_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool nano::wallet_store::fetch (nano::transaction const & transaction_a, nano::public_key const & pub, nano::raw_key & prv)
|
||||
bool nano::wallet_store::fetch (nano::transaction const & transaction_a, nano::account const & pub, nano::raw_key & prv)
|
||||
{
|
||||
auto result (false);
|
||||
if (valid_password (transaction_a))
|
||||
|
@ -490,7 +488,7 @@ bool nano::wallet_store::fetch (nano::transaction const & transaction_a, nano::p
|
|||
nano::raw_key seed_l;
|
||||
seed (seed_l, transaction_a);
|
||||
uint32_t index (static_cast<uint32_t> (value.key.number () & static_cast<uint32_t> (-1)));
|
||||
deterministic_key (prv, transaction_a, index);
|
||||
prv.data = deterministic_key (transaction_a, index);
|
||||
break;
|
||||
}
|
||||
case nano::key_type::adhoc:
|
||||
|
@ -519,7 +517,7 @@ bool nano::wallet_store::fetch (nano::transaction const & transaction_a, nano::p
|
|||
}
|
||||
if (!result)
|
||||
{
|
||||
nano::public_key compare (nano::pub_key (prv.data));
|
||||
nano::public_key compare (nano::pub_key (prv.as_private_key ()));
|
||||
if (!(pub == compare))
|
||||
{
|
||||
result = true;
|
||||
|
@ -593,7 +591,7 @@ bool nano::wallet_store::import (nano::transaction const & transaction_a, nano::
|
|||
for (auto i (other_a.begin (transaction_a)), n (end ()); i != n; ++i)
|
||||
{
|
||||
nano::raw_key prv;
|
||||
auto error (other_a.fetch (transaction_a, nano::uint256_union (i->first), prv));
|
||||
auto error (other_a.fetch (transaction_a, i->first, prv));
|
||||
result = result | error;
|
||||
if (!result)
|
||||
{
|
||||
|
@ -603,9 +601,9 @@ bool nano::wallet_store::import (nano::transaction const & transaction_a, nano::
|
|||
}
|
||||
else
|
||||
{
|
||||
insert_watch (transaction_a, nano::uint256_union (i->first));
|
||||
insert_watch (transaction_a, i->first);
|
||||
}
|
||||
other_a.erase (transaction_a, nano::uint256_union (i->first));
|
||||
other_a.erase (transaction_a, i->first);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -668,7 +666,7 @@ void nano::wallet_store::upgrade_v1_v2 (nano::transaction const & transaction_a)
|
|||
// Key failed to decrypt despite valid password
|
||||
nano::wallet_value data (entry_get_raw (transaction_a, key));
|
||||
prv.decrypt (data.key, zero_password, salt (transaction_a).owords[0]);
|
||||
nano::public_key compare (nano::pub_key (prv.data));
|
||||
nano::public_key compare (nano::pub_key (prv.as_private_key ()));
|
||||
if (compare == key)
|
||||
{
|
||||
// If we successfully decrypted it, rewrite the key back with the correct wallet key
|
||||
|
@ -679,7 +677,7 @@ void nano::wallet_store::upgrade_v1_v2 (nano::transaction const & transaction_a)
|
|||
// Also try the empty password
|
||||
nano::wallet_value data (entry_get_raw (transaction_a, key));
|
||||
prv.decrypt (data.key, empty_password, salt (transaction_a).owords[0]);
|
||||
nano::public_key compare (nano::pub_key (prv.data));
|
||||
nano::public_key compare (nano::pub_key (prv.as_private_key ()));
|
||||
if (compare == key)
|
||||
{
|
||||
// If we successfully decrypted it, rewrite the key back with the correct wallet key
|
||||
|
@ -957,7 +955,7 @@ std::shared_ptr<nano::block> nano::wallet::receive_action (nano::block const & s
|
|||
}
|
||||
else
|
||||
{
|
||||
block.reset (new nano::state_block (account, 0, representative_a, pending_info.amount, hash, prv, account, work_a));
|
||||
block.reset (new nano::state_block (account, 0, representative_a, pending_info.amount, reinterpret_cast<nano::link const &> (hash), prv, account, work_a));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1049,7 +1047,7 @@ std::shared_ptr<nano::block> nano::wallet::send_action (nano::account const & so
|
|||
auto status (mdb_get (wallets.env.tx (transaction), wallets.node.wallets.send_action_ids, *id_mdb_val, result));
|
||||
if (status == 0)
|
||||
{
|
||||
nano::uint256_union hash (result);
|
||||
nano::block_hash hash (result);
|
||||
block = wallets.node.store.block_get (block_transaction, hash);
|
||||
if (block != nullptr)
|
||||
{
|
||||
|
@ -1220,7 +1218,7 @@ void nano::wallet::send_async (nano::account const & source_a, nano::account con
|
|||
}
|
||||
|
||||
// Update work for account if latest root is root_a
|
||||
void nano::wallet::work_update (nano::transaction const & transaction_a, nano::account const & account_a, nano::block_hash const & root_a, uint64_t work_a)
|
||||
void nano::wallet::work_update (nano::transaction const & transaction_a, nano::account const & account_a, nano::root const & root_a, uint64_t work_a)
|
||||
{
|
||||
assert (!nano::work_validate (root_a, work_a));
|
||||
assert (store.exists (transaction_a, account_a));
|
||||
|
@ -1236,10 +1234,10 @@ void nano::wallet::work_update (nano::transaction const & transaction_a, nano::a
|
|||
}
|
||||
}
|
||||
|
||||
void nano::wallet::work_ensure (nano::account const & account_a, nano::block_hash const & hash_a)
|
||||
void nano::wallet::work_ensure (nano::account const & account_a, nano::root const & root_a)
|
||||
{
|
||||
wallets.node.wallets.queue_wallet_action (nano::wallets::generate_priority, shared_from_this (), [account_a, hash_a](nano::wallet & wallet_a) {
|
||||
wallet_a.work_cache_blocking (account_a, hash_a);
|
||||
wallets.node.wallets.queue_wallet_action (nano::wallets::generate_priority, shared_from_this (), [account_a, root_a](nano::wallet & wallet_a) {
|
||||
wallet_a.work_cache_blocking (account_a, root_a);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1299,7 +1297,7 @@ void nano::wallet::init_free_accounts (nano::transaction const & transaction_a)
|
|||
free_accounts.clear ();
|
||||
for (auto i (store.begin (transaction_a)), n (store.end ()); i != n; ++i)
|
||||
{
|
||||
free_accounts.insert (nano::uint256_union (i->first));
|
||||
free_accounts.insert (i->first);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1308,9 +1306,8 @@ uint32_t nano::wallet::deterministic_check (nano::transaction const & transactio
|
|||
auto block_transaction (wallets.node.store.tx_begin_read ());
|
||||
for (uint32_t i (index + 1), n (index + 64); i < n; ++i)
|
||||
{
|
||||
nano::raw_key prv;
|
||||
store.deterministic_key (prv, transaction_a, i);
|
||||
nano::keypair pair (prv.data.to_string ());
|
||||
auto prv = store.deterministic_key (transaction_a, i);
|
||||
nano::keypair pair (prv.to_string ());
|
||||
// Check if account received at least 1 block
|
||||
auto latest (wallets.node.ledger.latest (block_transaction, pair.pub));
|
||||
if (!latest.is_zero ())
|
||||
|
@ -1366,7 +1363,7 @@ bool nano::wallet::live ()
|
|||
return store.handle != 0;
|
||||
}
|
||||
|
||||
void nano::wallet::work_cache_blocking (nano::account const & account_a, nano::block_hash const & root_a)
|
||||
void nano::wallet::work_cache_blocking (nano::account const & account_a, nano::root const & root_a)
|
||||
{
|
||||
auto opt_work_l (wallets.node.work_generate_blocking (root_a, account_a));
|
||||
if (opt_work_l.is_initialized ())
|
||||
|
@ -1570,7 +1567,7 @@ thread ([this]() {
|
|||
nano::store_iterator<std::array<char, 64>, nano::no_value> n (std::make_unique<nano::mdb_iterator<std::array<char, 64>, nano::no_value>> (transaction, handle, nano::mdb_val (end.size (), const_cast<char *> (end.c_str ()))));
|
||||
for (; i != n; ++i)
|
||||
{
|
||||
nano::uint256_union id;
|
||||
nano::wallet_id id;
|
||||
std::string text (i->first.data (), i->first.size ());
|
||||
auto error (id.decode_hex (text));
|
||||
assert (!error);
|
||||
|
@ -1623,7 +1620,7 @@ nano::wallets::~wallets ()
|
|||
stop ();
|
||||
}
|
||||
|
||||
std::shared_ptr<nano::wallet> nano::wallets::open (nano::uint256_union const & id_a)
|
||||
std::shared_ptr<nano::wallet> nano::wallets::open (nano::wallet_id const & id_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
std::shared_ptr<nano::wallet> result;
|
||||
|
@ -1635,7 +1632,7 @@ std::shared_ptr<nano::wallet> nano::wallets::open (nano::uint256_union const & i
|
|||
return result;
|
||||
}
|
||||
|
||||
std::shared_ptr<nano::wallet> nano::wallets::create (nano::uint256_union const & id_a)
|
||||
std::shared_ptr<nano::wallet> nano::wallets::create (nano::wallet_id const & id_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
assert (items.find (id_a) == items.end ());
|
||||
|
@ -1653,7 +1650,7 @@ std::shared_ptr<nano::wallet> nano::wallets::create (nano::uint256_union const &
|
|||
return result;
|
||||
}
|
||||
|
||||
bool nano::wallets::search_pending (nano::uint256_union const & wallet_a)
|
||||
bool nano::wallets::search_pending (nano::wallet_id const & wallet_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
auto result (false);
|
||||
|
@ -1676,7 +1673,7 @@ void nano::wallets::search_pending_all ()
|
|||
}
|
||||
}
|
||||
|
||||
void nano::wallets::destroy (nano::uint256_union const & id_a)
|
||||
void nano::wallets::destroy (nano::wallet_id const & id_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
auto transaction (tx_begin_write ());
|
||||
|
@ -1700,7 +1697,7 @@ void nano::wallets::reload ()
|
|||
nano::store_iterator<std::array<char, 64>, nano::no_value> n (std::make_unique<nano::mdb_iterator<std::array<char, 64>, nano::no_value>> (transaction, handle, nano::mdb_val (end.size (), const_cast<char *> (end.c_str ()))));
|
||||
for (; i != n; ++i)
|
||||
{
|
||||
nano::uint256_union id;
|
||||
nano::wallet_id id;
|
||||
std::string text (i->first.data (), i->first.size ());
|
||||
auto error (id.decode_hex (text));
|
||||
assert (!error);
|
||||
|
@ -1717,7 +1714,7 @@ void nano::wallets::reload ()
|
|||
stored_items.insert (id);
|
||||
}
|
||||
// Delete non existing wallets from memory
|
||||
std::vector<nano::uint256_union> deleted_items;
|
||||
std::vector<nano::wallet_id> deleted_items;
|
||||
for (auto i : items)
|
||||
{
|
||||
if (stored_items.find (i.first) == stored_items.end ())
|
||||
|
@ -1783,7 +1780,7 @@ void nano::wallets::foreach_representative (std::function<void(nano::public_key
|
|||
}
|
||||
}
|
||||
|
||||
bool nano::wallets::exists (nano::transaction const & transaction_a, nano::public_key const & account_a)
|
||||
bool nano::wallets::exists (nano::transaction const & transaction_a, nano::account const & account_a)
|
||||
{
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
auto result (false);
|
||||
|
@ -1955,25 +1952,25 @@ void nano::wallets::move_table (std::string const & name_a, MDB_txn * tx_source,
|
|||
nano::uint128_t const nano::wallets::generate_priority = std::numeric_limits<nano::uint128_t>::max ();
|
||||
nano::uint128_t const nano::wallets::high_priority = std::numeric_limits<nano::uint128_t>::max () - 1;
|
||||
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> nano::wallet_store::begin (nano::transaction const & transaction_a)
|
||||
nano::store_iterator<nano::account, nano::wallet_value> nano::wallet_store::begin (nano::transaction const & transaction_a)
|
||||
{
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> result (std::make_unique<nano::mdb_iterator<nano::uint256_union, nano::wallet_value>> (transaction_a, handle, nano::mdb_val (nano::uint256_union (special_count))));
|
||||
nano::store_iterator<nano::account, nano::wallet_value> result (std::make_unique<nano::mdb_iterator<nano::account, nano::wallet_value>> (transaction_a, handle, nano::mdb_val (nano::account (special_count))));
|
||||
return result;
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> nano::wallet_store::begin (nano::transaction const & transaction_a, nano::uint256_union const & key)
|
||||
nano::store_iterator<nano::account, nano::wallet_value> nano::wallet_store::begin (nano::transaction const & transaction_a, nano::account const & key)
|
||||
{
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> result (std::make_unique<nano::mdb_iterator<nano::uint256_union, nano::wallet_value>> (transaction_a, handle, nano::mdb_val (key)));
|
||||
nano::store_iterator<nano::account, nano::wallet_value> result (std::make_unique<nano::mdb_iterator<nano::account, nano::wallet_value>> (transaction_a, handle, nano::mdb_val (key)));
|
||||
return result;
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> nano::wallet_store::find (nano::transaction const & transaction_a, nano::uint256_union const & key)
|
||||
nano::store_iterator<nano::account, nano::wallet_value> nano::wallet_store::find (nano::transaction const & transaction_a, nano::account const & key)
|
||||
{
|
||||
auto result (begin (transaction_a, key));
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> end (nullptr);
|
||||
nano::store_iterator<nano::account, nano::wallet_value> end (nullptr);
|
||||
if (result != end)
|
||||
{
|
||||
if (nano::uint256_union (result->first) == key)
|
||||
if (result->first == key)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
@ -1989,9 +1986,9 @@ nano::store_iterator<nano::uint256_union, nano::wallet_value> nano::wallet_store
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> nano::wallet_store::end ()
|
||||
nano::store_iterator<nano::account, nano::wallet_value> nano::wallet_store::end ()
|
||||
{
|
||||
return nano::store_iterator<nano::uint256_union, nano::wallet_value> (nullptr);
|
||||
return nano::store_iterator<nano::account, nano::wallet_value> (nullptr);
|
||||
}
|
||||
nano::mdb_wallets_store::mdb_wallets_store (boost::filesystem::path const & path_a, int lmdb_max_dbs) :
|
||||
environment (error, path_a, lmdb_max_dbs, false, 1ULL * 1024 * 1024 * 1024)
|
||||
|
|
|
@ -61,7 +61,7 @@ public:
|
|||
nano::key_type key_type (nano::wallet_value const &);
|
||||
nano::public_key deterministic_insert (nano::transaction const &);
|
||||
nano::public_key deterministic_insert (nano::transaction const &, uint32_t const);
|
||||
void deterministic_key (nano::raw_key &, nano::transaction const &, uint32_t);
|
||||
nano::private_key deterministic_key (nano::transaction const &, uint32_t);
|
||||
uint32_t deterministic_index_get (nano::transaction const &);
|
||||
void deterministic_index_set (nano::transaction const &, uint32_t);
|
||||
void deterministic_clear (nano::transaction const &);
|
||||
|
@ -70,17 +70,17 @@ public:
|
|||
nano::account representative (nano::transaction const &);
|
||||
void representative_set (nano::transaction const &, nano::account const &);
|
||||
nano::public_key insert_adhoc (nano::transaction const &, nano::raw_key const &);
|
||||
bool insert_watch (nano::transaction const &, nano::public_key const &);
|
||||
void erase (nano::transaction const &, nano::public_key const &);
|
||||
nano::wallet_value entry_get_raw (nano::transaction const &, nano::public_key const &);
|
||||
void entry_put_raw (nano::transaction const &, nano::public_key const &, nano::wallet_value const &);
|
||||
bool fetch (nano::transaction const &, nano::public_key const &, nano::raw_key &);
|
||||
bool exists (nano::transaction const &, nano::public_key const &);
|
||||
bool insert_watch (nano::transaction const &, nano::account const &);
|
||||
void erase (nano::transaction const &, nano::account const &);
|
||||
nano::wallet_value entry_get_raw (nano::transaction const &, nano::account const &);
|
||||
void entry_put_raw (nano::transaction const &, nano::account const &, nano::wallet_value const &);
|
||||
bool fetch (nano::transaction const &, nano::account const &, nano::raw_key &);
|
||||
bool exists (nano::transaction const &, nano::account const &);
|
||||
void destroy (nano::transaction const &);
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> find (nano::transaction const &, nano::uint256_union const &);
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> begin (nano::transaction const &, nano::uint256_union const &);
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> begin (nano::transaction const &);
|
||||
nano::store_iterator<nano::uint256_union, nano::wallet_value> end ();
|
||||
nano::store_iterator<nano::account, nano::wallet_value> find (nano::transaction const &, nano::account const &);
|
||||
nano::store_iterator<nano::account, nano::wallet_value> begin (nano::transaction const &, nano::account const &);
|
||||
nano::store_iterator<nano::account, nano::wallet_value> begin (nano::transaction const &);
|
||||
nano::store_iterator<nano::account, nano::wallet_value> end ();
|
||||
void derive_key (nano::raw_key &, nano::transaction const &, std::string const &);
|
||||
void serialize_json (nano::transaction const &, std::string &);
|
||||
void write_backup (nano::transaction const &, boost::filesystem::path const &);
|
||||
|
@ -100,13 +100,13 @@ public:
|
|||
static unsigned const version_3 = 3;
|
||||
static unsigned const version_4 = 4;
|
||||
static unsigned constexpr version_current = version_4;
|
||||
static nano::uint256_union const version_special;
|
||||
static nano::uint256_union const wallet_key_special;
|
||||
static nano::uint256_union const salt_special;
|
||||
static nano::uint256_union const check_special;
|
||||
static nano::uint256_union const representative_special;
|
||||
static nano::uint256_union const seed_special;
|
||||
static nano::uint256_union const deterministic_index_special;
|
||||
static nano::account const version_special;
|
||||
static nano::account const wallet_key_special;
|
||||
static nano::account const salt_special;
|
||||
static nano::account const check_special;
|
||||
static nano::account const representative_special;
|
||||
static nano::account const seed_special;
|
||||
static nano::account const deterministic_index_special;
|
||||
static size_t const check_iv_index;
|
||||
static size_t const seed_iv_index;
|
||||
static int const special_count;
|
||||
|
@ -144,9 +144,9 @@ public:
|
|||
void receive_async (std::shared_ptr<nano::block>, nano::account const &, nano::uint128_t const &, std::function<void(std::shared_ptr<nano::block>)> const &, uint64_t = 0, bool = true);
|
||||
nano::block_hash send_sync (nano::account const &, nano::account const &, nano::uint128_t const &);
|
||||
void send_async (nano::account const &, nano::account const &, nano::uint128_t const &, std::function<void(std::shared_ptr<nano::block>)> const &, uint64_t = 0, bool = true, boost::optional<std::string> = {});
|
||||
void work_cache_blocking (nano::account const &, nano::block_hash const &);
|
||||
void work_update (nano::transaction const &, nano::account const &, nano::block_hash const &, uint64_t);
|
||||
void work_ensure (nano::account const &, nano::block_hash const &);
|
||||
void work_cache_blocking (nano::account const &, nano::root const &);
|
||||
void work_update (nano::transaction const &, nano::account const &, nano::root const &, uint64_t);
|
||||
void work_ensure (nano::account const &, nano::root const &);
|
||||
bool search_pending ();
|
||||
void init_free_accounts (nano::transaction const &);
|
||||
uint32_t deterministic_check (nano::transaction const & transaction_a, uint32_t index);
|
||||
|
@ -189,11 +189,11 @@ class wallets final
|
|||
public:
|
||||
wallets (bool, nano::node &);
|
||||
~wallets ();
|
||||
std::shared_ptr<nano::wallet> open (nano::uint256_union const &);
|
||||
std::shared_ptr<nano::wallet> create (nano::uint256_union const &);
|
||||
bool search_pending (nano::uint256_union const &);
|
||||
std::shared_ptr<nano::wallet> open (nano::wallet_id const &);
|
||||
std::shared_ptr<nano::wallet> create (nano::wallet_id const &);
|
||||
bool search_pending (nano::wallet_id const &);
|
||||
void search_pending_all ();
|
||||
void destroy (nano::uint256_union const &);
|
||||
void destroy (nano::wallet_id const &);
|
||||
void reload ();
|
||||
void do_wallet_actions ();
|
||||
void queue_wallet_action (nano::uint128_t const &, std::shared_ptr<nano::wallet>, std::function<void(nano::wallet &)> const &);
|
||||
|
@ -208,7 +208,7 @@ public:
|
|||
void move_table (std::string const &, MDB_txn *, MDB_txn *);
|
||||
nano::network_params network_params;
|
||||
std::function<void(bool)> observer;
|
||||
std::unordered_map<nano::uint256_union, std::shared_ptr<nano::wallet>> items;
|
||||
std::unordered_map<nano::wallet_id, std::shared_ptr<nano::wallet>> items;
|
||||
std::multimap<nano::uint128_t, std::pair<std::shared_ptr<nano::wallet>, std::function<void(nano::wallet &)>>, std::greater<nano::uint128_t>> actions;
|
||||
std::mutex mutex;
|
||||
std::mutex action_mutex;
|
||||
|
|
|
@ -685,7 +685,7 @@ wallet (wallet_a)
|
|||
rebroadcast->setToolTip ("Rebroadcast block into the network");
|
||||
}
|
||||
|
||||
void nano_qt::block_viewer::rebroadcast_action (nano::uint256_union const & hash_a)
|
||||
void nano_qt::block_viewer::rebroadcast_action (nano::block_hash const & hash_a)
|
||||
{
|
||||
auto done (true);
|
||||
auto transaction (wallet.node.ledger.store.tx_begin_read ());
|
||||
|
@ -1958,7 +1958,7 @@ void nano_qt::advanced_actions::refresh_ledger ()
|
|||
for (auto i (wallet.node.ledger.store.latest_begin (transaction)), j (wallet.node.ledger.store.latest_end ()); i != j; ++i)
|
||||
{
|
||||
QList<QStandardItem *> items;
|
||||
items.push_back (new QStandardItem (QString (nano::block_hash (i->first).to_account ().c_str ())));
|
||||
items.push_back (new QStandardItem (QString (i->first.to_account ().c_str ())));
|
||||
nano::account_info const & info (i->second);
|
||||
std::string balance;
|
||||
nano::amount (info.balance.number () / wallet.rendering_ratio).encode_dec (balance);
|
||||
|
|
|
@ -229,7 +229,7 @@ class block_viewer
|
|||
{
|
||||
public:
|
||||
block_viewer (nano_qt::wallet &);
|
||||
void rebroadcast_action (nano::uint256_union const &);
|
||||
void rebroadcast_action (nano::block_hash const &);
|
||||
QWidget * window;
|
||||
QVBoxLayout * layout;
|
||||
QLabel * hash_label;
|
||||
|
|
|
@ -22,9 +22,7 @@ int main (int argc, char ** argv)
|
|||
std::vector<std::unique_ptr<nano_qt::wallet>> guis;
|
||||
for (auto i (0); i < count; ++i)
|
||||
{
|
||||
nano::uint256_union wallet_id;
|
||||
nano::random_pool::generate_block (wallet_id.bytes.data (), wallet_id.bytes.size ());
|
||||
auto wallet (system.nodes[i]->wallets.create (wallet_id));
|
||||
auto wallet (system.nodes[i]->wallets.create (nano::random_wallet_id ()));
|
||||
nano::keypair key;
|
||||
wallet->insert_adhoc (key.prv);
|
||||
guis.push_back (std::unique_ptr<nano_qt::wallet> (new nano_qt::wallet (application, processor, *system.nodes[i], wallet, key.pub)));
|
||||
|
|
|
@ -18,7 +18,7 @@ TEST (wallet, construction)
|
|||
{
|
||||
nano_qt::eventloop_processor processor;
|
||||
nano::system system (24000, 1);
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::uint256_union ()));
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::random_wallet_id ()));
|
||||
auto key (wallet_l->deterministic_insert ());
|
||||
auto wallet (std::make_shared<nano_qt::wallet> (*test_application, processor, *system.nodes[0], wallet_l, key));
|
||||
wallet->start ();
|
||||
|
@ -33,7 +33,7 @@ TEST (wallet, status)
|
|||
{
|
||||
nano_qt::eventloop_processor processor;
|
||||
nano::system system (24000, 1);
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::uint256_union ()));
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::random_wallet_id ()));
|
||||
nano::keypair key;
|
||||
wallet_l->insert_adhoc (key.prv);
|
||||
auto wallet (std::make_shared<nano_qt::wallet> (*test_application, processor, *system.nodes[0], wallet_l, key.pub));
|
||||
|
@ -64,7 +64,7 @@ TEST (wallet, startup_balance)
|
|||
{
|
||||
nano_qt::eventloop_processor processor;
|
||||
nano::system system (24000, 1);
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::uint256_union ()));
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::random_wallet_id ()));
|
||||
nano::keypair key;
|
||||
wallet_l->insert_adhoc (key.prv);
|
||||
auto wallet (std::make_shared<nano_qt::wallet> (*test_application, processor, *system.nodes[0], wallet_l, key.pub));
|
||||
|
@ -78,7 +78,7 @@ TEST (wallet, select_account)
|
|||
{
|
||||
nano_qt::eventloop_processor processor;
|
||||
nano::system system (24000, 1);
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::uint256_union ()));
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::random_wallet_id ()));
|
||||
nano::public_key key1 (wallet_l->deterministic_insert ());
|
||||
nano::public_key key2 (wallet_l->deterministic_insert ());
|
||||
auto wallet (std::make_shared<nano_qt::wallet> (*test_application, processor, *system.nodes[0], wallet_l, key1));
|
||||
|
@ -110,7 +110,7 @@ TEST (wallet, main)
|
|||
{
|
||||
nano_qt::eventloop_processor processor;
|
||||
nano::system system (24000, 1);
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::uint256_union ()));
|
||||
auto wallet_l (system.nodes[0]->wallets.create (nano::random_wallet_id ()));
|
||||
nano::keypair key;
|
||||
wallet_l->insert_adhoc (key.prv);
|
||||
auto wallet (std::make_shared<nano_qt::wallet> (*test_application, processor, *system.nodes[0], wallet_l, key.pub));
|
||||
|
@ -712,9 +712,8 @@ TEST (wallet, seed_work_generation)
|
|||
QTest::mouseClick (wallet->accounts.import_wallet, Qt::LeftButton);
|
||||
ASSERT_EQ (wallet->import.window, wallet->main_stack->currentWidget ());
|
||||
nano::raw_key seed;
|
||||
nano::uint256_union prv;
|
||||
nano::deterministic_key (seed.data, 0, prv);
|
||||
nano::uint256_union pub (nano::pub_key (prv));
|
||||
auto prv = nano::deterministic_key (seed, 0);
|
||||
auto pub (nano::pub_key (prv));
|
||||
QTest::keyClicks (wallet->import.seed, seed.data.to_string ().c_str ());
|
||||
QTest::keyClicks (wallet->import.clear_line, "clear keys");
|
||||
uint64_t work (0);
|
||||
|
|
|
@ -226,7 +226,7 @@ TEST (rpc, account_create)
|
|||
}
|
||||
ASSERT_EQ (200, response0.status);
|
||||
auto account_text0 (response0.json.get<std::string> ("account"));
|
||||
nano::uint256_union account0;
|
||||
nano::account account0;
|
||||
ASSERT_FALSE (account0.decode_account (account_text0));
|
||||
ASSERT_TRUE (system.wallet (0)->exists (account0));
|
||||
uint64_t max_index (std::numeric_limits<uint32_t>::max ());
|
||||
|
@ -239,7 +239,7 @@ TEST (rpc, account_create)
|
|||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
auto account_text1 (response1.json.get<std::string> ("account"));
|
||||
nano::uint256_union account1;
|
||||
nano::account account1;
|
||||
ASSERT_FALSE (account1.decode_account (account_text1));
|
||||
ASSERT_TRUE (system.wallet (0)->exists (account1));
|
||||
request.put ("index", max_index + 1);
|
||||
|
@ -866,11 +866,11 @@ TEST (rpc, account_list)
|
|||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
auto & accounts_node (response.json.get_child ("accounts"));
|
||||
std::vector<nano::uint256_union> accounts;
|
||||
std::vector<nano::account> accounts;
|
||||
for (auto i (accounts_node.begin ()), j (accounts_node.end ()); i != j; ++i)
|
||||
{
|
||||
auto account (i->second.get<std::string> (""));
|
||||
nano::uint256_union number;
|
||||
nano::account number;
|
||||
ASSERT_FALSE (number.decode_account (account));
|
||||
accounts.push_back (number);
|
||||
}
|
||||
|
@ -932,7 +932,7 @@ TEST (rpc, wallet_create)
|
|||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
std::string wallet_text (response.json.get<std::string> ("wallet"));
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
ASSERT_FALSE (wallet_id.decode_hex (wallet_text));
|
||||
ASSERT_NE (system.nodes[0]->wallets.items.end (), system.nodes[0]->wallets.items.find (wallet_id));
|
||||
}
|
||||
|
@ -941,10 +941,9 @@ TEST (rpc, wallet_create_seed)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
nano::keypair seed;
|
||||
nano::raw_key prv;
|
||||
nano::deterministic_key (seed.pub, 0, prv.data);
|
||||
auto pub (nano::pub_key (prv.data));
|
||||
nano::raw_key seed;
|
||||
auto prv = nano::deterministic_key (seed, 0);
|
||||
auto pub (nano::pub_key (prv));
|
||||
auto node = system.nodes.front ();
|
||||
enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
|
@ -955,7 +954,7 @@ TEST (rpc, wallet_create_seed)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "wallet_create");
|
||||
request.put ("seed", seed.pub.to_string ());
|
||||
request.put ("seed", seed.data.to_string ());
|
||||
test_response response (request, rpc.config.port, system.io_ctx);
|
||||
while (response.status == 0)
|
||||
{
|
||||
|
@ -963,7 +962,7 @@ TEST (rpc, wallet_create_seed)
|
|||
}
|
||||
ASSERT_EQ (200, response.status);
|
||||
std::string wallet_text (response.json.get<std::string> ("wallet"));
|
||||
nano::uint256_union wallet_id;
|
||||
nano::wallet_id wallet_id;
|
||||
ASSERT_FALSE (wallet_id.decode_hex (wallet_text));
|
||||
auto existing (system.nodes[0]->wallets.items.find (wallet_id));
|
||||
ASSERT_NE (system.nodes[0]->wallets.items.end (), existing);
|
||||
|
@ -971,10 +970,10 @@ TEST (rpc, wallet_create_seed)
|
|||
auto transaction (system.nodes[0]->wallets.tx_begin_read ());
|
||||
nano::raw_key seed0;
|
||||
existing->second->store.seed (seed0, transaction);
|
||||
ASSERT_EQ (seed.pub, seed0.data);
|
||||
ASSERT_EQ (seed, seed0);
|
||||
}
|
||||
auto account_text (response.json.get<std::string> ("last_restored_account"));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_TRUE (existing->second->exists (account));
|
||||
ASSERT_EQ (pub, account);
|
||||
|
@ -1048,8 +1047,8 @@ TEST (rpc, account_move)
|
|||
auto destination (system.wallet (0));
|
||||
destination->insert_adhoc (nano::test_genesis_key.prv);
|
||||
nano::keypair key;
|
||||
nano::keypair source_id;
|
||||
auto source (system.nodes[0]->wallets.create (source_id.pub));
|
||||
auto source_id = nano::random_wallet_id ();
|
||||
auto source (system.nodes[0]->wallets.create (source_id));
|
||||
source->insert_adhoc (key.prv);
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
auto node = system.nodes.front ();
|
||||
|
@ -1063,7 +1062,7 @@ TEST (rpc, account_move)
|
|||
boost::property_tree::ptree request;
|
||||
request.put ("action", "account_move");
|
||||
request.put ("wallet", wallet_id.to_string ());
|
||||
request.put ("source", source_id.pub.to_string ());
|
||||
request.put ("source", source_id.to_string ());
|
||||
boost::property_tree::ptree keys;
|
||||
boost::property_tree::ptree entry;
|
||||
entry.put ("", key.pub.to_account ());
|
||||
|
@ -1266,9 +1265,11 @@ TEST (rpc, frontier)
|
|||
for (auto i (0); i < 1000; ++i)
|
||||
{
|
||||
nano::keypair key;
|
||||
source[key.pub] = key.prv.data;
|
||||
nano::block_hash hash;
|
||||
nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ());
|
||||
source[key.pub] = hash;
|
||||
system.nodes[0]->store.confirmation_height_put (transaction, key.pub, 0);
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (hash, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
}
|
||||
}
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
|
@ -1315,9 +1316,11 @@ TEST (rpc, frontier_limited)
|
|||
for (auto i (0); i < 1000; ++i)
|
||||
{
|
||||
nano::keypair key;
|
||||
source[key.pub] = key.prv.data;
|
||||
nano::block_hash hash;
|
||||
nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ());
|
||||
source[key.pub] = hash;
|
||||
system.nodes[0]->store.confirmation_height_put (transaction, key.pub, 0);
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (hash, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1355,9 +1358,11 @@ TEST (rpc, frontier_startpoint)
|
|||
for (auto i (0); i < 1000; ++i)
|
||||
{
|
||||
nano::keypair key;
|
||||
source[key.pub] = key.prv.data;
|
||||
nano::block_hash hash;
|
||||
nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ());
|
||||
source[key.pub] = hash;
|
||||
system.nodes[0]->store.confirmation_height_put (transaction, key.pub, 0);
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (key.prv.data, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
system.nodes[0]->store.account_put (transaction, key.pub, nano::account_info (hash, 0, 0, 0, 0, 0, nano::epoch::epoch_0));
|
||||
}
|
||||
}
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
|
@ -1556,7 +1561,7 @@ TEST (rpc, account_history)
|
|||
ASSERT_NE (nullptr, send2);
|
||||
auto receive2 (system.wallet (0)->receive_action (*send2, account2, system.nodes[0]->config.receive_minimum.number ()));
|
||||
scoped_thread_name_io.renew ();
|
||||
// Test filter for send blocks
|
||||
// Test filter for send state blocks
|
||||
ASSERT_NE (nullptr, receive2);
|
||||
{
|
||||
boost::property_tree::ptree request;
|
||||
|
@ -1574,10 +1579,9 @@ TEST (rpc, account_history)
|
|||
ASSERT_NO_ERROR (system.poll ());
|
||||
}
|
||||
auto history_node (response.json.get_child ("history"));
|
||||
ASSERT_EQ (history_node.size (), 1);
|
||||
ASSERT_EQ (history_node.size (), 2);
|
||||
}
|
||||
// Test filter for receive blocks
|
||||
ASSERT_NE (nullptr, receive2);
|
||||
// Test filter for receive state blocks
|
||||
{
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "account_history");
|
||||
|
@ -2008,9 +2012,9 @@ TEST (rpc, payment_init)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
auto node1 (system.nodes[0]);
|
||||
nano::keypair wallet_id;
|
||||
auto wallet (node1->wallets.create (wallet_id.pub));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ());
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
auto wallet (node1->wallets.create (wallet_id));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id) != node1->wallets.items.end ());
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
|
@ -2021,7 +2025,7 @@ TEST (rpc, payment_init)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request;
|
||||
request.put ("action", "payment_init");
|
||||
request.put ("wallet", wallet_id.pub.to_string ());
|
||||
request.put ("wallet", wallet_id.to_string ());
|
||||
test_response response (request, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
|
@ -2036,9 +2040,9 @@ TEST (rpc, payment_begin_end)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
auto node1 (system.nodes[0]);
|
||||
nano::keypair wallet_id;
|
||||
auto wallet (node1->wallets.create (wallet_id.pub));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ());
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
auto wallet (node1->wallets.create (wallet_id));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id) != node1->wallets.items.end ());
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
|
@ -2049,7 +2053,7 @@ TEST (rpc, payment_begin_end)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request1;
|
||||
request1.put ("action", "payment_begin");
|
||||
request1.put ("wallet", wallet_id.pub.to_string ());
|
||||
request1.put ("wallet", wallet_id.to_string ());
|
||||
test_response response1 (request1, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response1.status == 0)
|
||||
|
@ -2058,10 +2062,10 @@ TEST (rpc, payment_begin_end)
|
|||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
auto account_text (response1.json.get<std::string> ("account"));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_TRUE (wallet->exists (account));
|
||||
nano::block_hash root1;
|
||||
nano::root root1;
|
||||
{
|
||||
auto transaction (node1->store.tx_begin_read ());
|
||||
root1 = node1->ledger.latest_root (transaction, account);
|
||||
|
@ -2083,7 +2087,7 @@ TEST (rpc, payment_begin_end)
|
|||
ASSERT_EQ (wallet->free_accounts.end (), wallet->free_accounts.find (account));
|
||||
boost::property_tree::ptree request2;
|
||||
request2.put ("action", "payment_end");
|
||||
request2.put ("wallet", wallet_id.pub.to_string ());
|
||||
request2.put ("wallet", wallet_id.to_string ());
|
||||
request2.put ("account", account.to_account ());
|
||||
test_response response2 (request2, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
|
@ -2155,7 +2159,7 @@ TEST (rpc, payment_zero_balance)
|
|||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
auto account_text (response1.json.get<std::string> ("account"));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_NE (nano::test_genesis_key.pub, account);
|
||||
}
|
||||
|
@ -2164,9 +2168,9 @@ TEST (rpc, payment_begin_reuse)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
auto node1 (system.nodes[0]);
|
||||
nano::keypair wallet_id;
|
||||
auto wallet (node1->wallets.create (wallet_id.pub));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ());
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
auto wallet (node1->wallets.create (wallet_id));
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id) != node1->wallets.items.end ());
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
|
@ -2177,7 +2181,7 @@ TEST (rpc, payment_begin_reuse)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request1;
|
||||
request1.put ("action", "payment_begin");
|
||||
request1.put ("wallet", wallet_id.pub.to_string ());
|
||||
request1.put ("wallet", wallet_id.to_string ());
|
||||
test_response response1 (request1, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response1.status == 0)
|
||||
|
@ -2186,13 +2190,13 @@ TEST (rpc, payment_begin_reuse)
|
|||
}
|
||||
ASSERT_EQ (200, response1.status);
|
||||
auto account_text (response1.json.get<std::string> ("account"));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_TRUE (wallet->exists (account));
|
||||
ASSERT_EQ (wallet->free_accounts.end (), wallet->free_accounts.find (account));
|
||||
boost::property_tree::ptree request2;
|
||||
request2.put ("action", "payment_end");
|
||||
request2.put ("wallet", wallet_id.pub.to_string ());
|
||||
request2.put ("wallet", wallet_id.to_string ());
|
||||
request2.put ("account", account.to_account ());
|
||||
test_response response2 (request2, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
|
@ -2211,7 +2215,7 @@ TEST (rpc, payment_begin_reuse)
|
|||
}
|
||||
ASSERT_EQ (200, response3.status);
|
||||
auto account2_text (response1.json.get<std::string> ("account"));
|
||||
nano::uint256_union account2;
|
||||
nano::account account2;
|
||||
ASSERT_FALSE (account2.decode_account (account2_text));
|
||||
ASSERT_EQ (account, account2);
|
||||
}
|
||||
|
@ -2220,15 +2224,15 @@ TEST (rpc, payment_begin_locked)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
auto node1 (system.nodes[0]);
|
||||
nano::keypair wallet_id;
|
||||
auto wallet (node1->wallets.create (wallet_id.pub));
|
||||
auto wallet_id = nano::random_wallet_id ();
|
||||
auto wallet (node1->wallets.create (wallet_id));
|
||||
{
|
||||
auto transaction (wallet->wallets.tx_begin_write ());
|
||||
wallet->store.rekey (transaction, "1");
|
||||
ASSERT_TRUE (wallet->store.attempt_password (transaction, ""));
|
||||
}
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ());
|
||||
ASSERT_TRUE (node1->wallets.items.find (wallet_id) != node1->wallets.items.end ());
|
||||
enable_ipc_transport_tcp (node1->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
nano::ipc::ipc_server ipc_server (*node1, node_rpc_config);
|
||||
|
@ -2238,7 +2242,7 @@ TEST (rpc, payment_begin_locked)
|
|||
rpc.start ();
|
||||
boost::property_tree::ptree request1;
|
||||
request1.put ("action", "payment_begin");
|
||||
request1.put ("wallet", wallet_id.pub.to_string ());
|
||||
request1.put ("wallet", wallet_id.to_string ());
|
||||
test_response response1 (request1, rpc.config.port, system.io_ctx);
|
||||
system.deadline_set (5s);
|
||||
while (response1.status == 0)
|
||||
|
@ -3438,17 +3442,16 @@ TEST (rpc, wallet_seed)
|
|||
TEST (rpc, wallet_change_seed)
|
||||
{
|
||||
nano::system system0 (24000, 1);
|
||||
nano::keypair seed;
|
||||
nano::raw_key seed;
|
||||
{
|
||||
auto transaction (system0.nodes[0]->wallets.tx_begin_read ());
|
||||
nano::raw_key seed0;
|
||||
system0.wallet (0)->store.seed (seed0, transaction);
|
||||
ASSERT_NE (seed.pub, seed0.data);
|
||||
ASSERT_NE (seed, seed0);
|
||||
}
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
nano::raw_key prv;
|
||||
nano::deterministic_key (seed.pub, 0, prv.data);
|
||||
auto pub (nano::pub_key (prv.data));
|
||||
auto prv = nano::deterministic_key (seed, 0);
|
||||
auto pub (nano::pub_key (prv));
|
||||
auto & node = system0.nodes.front ();
|
||||
enable_ipc_transport_tcp (node->config.ipc_config.transport_tcp);
|
||||
nano::node_rpc_config node_rpc_config;
|
||||
|
@ -3460,7 +3463,7 @@ TEST (rpc, wallet_change_seed)
|
|||
boost::property_tree::ptree request;
|
||||
request.put ("action", "wallet_change_seed");
|
||||
request.put ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ());
|
||||
request.put ("seed", seed.pub.to_string ());
|
||||
request.put ("seed", seed.data.to_string ());
|
||||
test_response response (request, rpc.config.port, system0.io_ctx);
|
||||
system0.deadline_set (5s);
|
||||
while (response.status == 0)
|
||||
|
@ -3472,10 +3475,10 @@ TEST (rpc, wallet_change_seed)
|
|||
auto transaction (system0.nodes[0]->wallets.tx_begin_read ());
|
||||
nano::raw_key seed0;
|
||||
system0.wallet (0)->store.seed (seed0, transaction);
|
||||
ASSERT_EQ (seed.pub, seed0.data);
|
||||
ASSERT_EQ (seed, seed0);
|
||||
}
|
||||
auto account_text (response.json.get<std::string> ("last_restored_account"));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_TRUE (system0.wallet (0)->exists (account));
|
||||
ASSERT_EQ (pub, account);
|
||||
|
@ -3508,7 +3511,7 @@ TEST (rpc, wallet_frontiers)
|
|||
std::vector<nano::account> frontiers;
|
||||
for (auto i (frontiers_node.begin ()), n (frontiers_node.end ()); i != n; ++i)
|
||||
{
|
||||
frontiers.push_back (nano::block_hash (i->second.get<std::string> ("")));
|
||||
frontiers.push_back (nano::account (i->second.get<std::string> ("")));
|
||||
}
|
||||
ASSERT_EQ (1, frontiers.size ());
|
||||
ASSERT_EQ (system0.nodes[0]->latest (nano::genesis_account), frontiers[0]);
|
||||
|
@ -5226,7 +5229,7 @@ TEST (rpc, accounts_create)
|
|||
for (auto i (accounts.begin ()), n (accounts.end ()); i != n; ++i)
|
||||
{
|
||||
std::string account_text (i->second.get<std::string> (""));
|
||||
nano::uint256_union account;
|
||||
nano::account account;
|
||||
ASSERT_FALSE (account.decode_account (account_text));
|
||||
ASSERT_TRUE (system.wallet (0)->exists (account));
|
||||
}
|
||||
|
@ -5616,8 +5619,7 @@ TEST (rpc, wallet_create_fail)
|
|||
// lmdb_max_dbs should be removed once the wallet store is refactored to support more wallets.
|
||||
for (int i = 0; i < 127; i++)
|
||||
{
|
||||
nano::keypair key;
|
||||
node->wallets.create (key.pub);
|
||||
node->wallets.create (nano::random_wallet_id ());
|
||||
}
|
||||
rpc.start ();
|
||||
scoped_io_thread_name_change scoped_thread_name_io;
|
||||
|
|
|
@ -80,6 +80,12 @@ public:
|
|||
convert_buffer_to_value ();
|
||||
}
|
||||
|
||||
db_val (nano::unchecked_key const & val_a) :
|
||||
db_val (sizeof (val_a), const_cast<nano::unchecked_key *> (&val_a))
|
||||
{
|
||||
static_assert (std::is_standard_layout<nano::unchecked_key>::value, "Standard layout is required");
|
||||
}
|
||||
|
||||
db_val (nano::block_info const & val_a) :
|
||||
db_val (sizeof (val_a), const_cast<nano::block_info *> (&val_a))
|
||||
{
|
||||
|
@ -176,20 +182,38 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
explicit operator nano::unchecked_key () const
|
||||
{
|
||||
nano::unchecked_key result;
|
||||
assert (size () == sizeof (result));
|
||||
static_assert (sizeof (nano::unchecked_key::previous) + sizeof (nano::pending_key::hash) == sizeof (result), "Packed class");
|
||||
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), reinterpret_cast<uint8_t *> (&result));
|
||||
return result;
|
||||
}
|
||||
|
||||
explicit operator nano::uint128_union () const
|
||||
{
|
||||
nano::uint128_union result;
|
||||
assert (size () == sizeof (result));
|
||||
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), result.bytes.data ());
|
||||
return result;
|
||||
return convert<nano::uint128_union> ();
|
||||
}
|
||||
|
||||
explicit operator nano::amount () const
|
||||
{
|
||||
return convert<nano::amount> ();
|
||||
}
|
||||
|
||||
explicit operator nano::block_hash () const
|
||||
{
|
||||
return convert<nano::block_hash> ();
|
||||
}
|
||||
|
||||
explicit operator nano::public_key () const
|
||||
{
|
||||
return convert<nano::public_key> ();
|
||||
}
|
||||
|
||||
explicit operator nano::uint256_union () const
|
||||
{
|
||||
nano::uint256_union result;
|
||||
assert (size () == sizeof (result));
|
||||
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), result.bytes.data ());
|
||||
return result;
|
||||
return convert<nano::uint256_union> ();
|
||||
}
|
||||
|
||||
explicit operator std::array<char, 64> () const
|
||||
|
@ -296,6 +320,16 @@ public:
|
|||
Val value;
|
||||
std::shared_ptr<std::vector<uint8_t>> buffer;
|
||||
nano::epoch epoch{ nano::epoch::unspecified };
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
T convert () const
|
||||
{
|
||||
T result;
|
||||
assert (size () == sizeof (result));
|
||||
std::copy (reinterpret_cast<uint8_t const *> (data ()), reinterpret_cast<uint8_t const *> (data ()) + sizeof (result), result.bytes.data ());
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
class block_sideband final
|
||||
|
@ -584,7 +618,7 @@ public:
|
|||
virtual bool block_exists (nano::transaction const &, nano::block_hash const &) = 0;
|
||||
virtual bool block_exists (nano::transaction const &, nano::block_type, nano::block_hash const &) = 0;
|
||||
virtual nano::block_counts block_count (nano::transaction const &) = 0;
|
||||
virtual bool root_exists (nano::transaction const &, nano::uint256_union const &) = 0;
|
||||
virtual bool root_exists (nano::transaction const &, nano::root const &) = 0;
|
||||
virtual bool source_exists (nano::transaction const &, nano::block_hash const &) = 0;
|
||||
virtual nano::account block_account (nano::transaction const &, nano::block_hash const &) const = 0;
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
std::vector<nano::unchecked_info> unchecked_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a) override
|
||||
{
|
||||
std::vector<nano::unchecked_info> result;
|
||||
for (auto i (unchecked_begin (transaction_a, nano::unchecked_key (hash_a, 0))), n (unchecked_end ()); i != n && nano::block_hash (i->first.key ()) == hash_a; ++i)
|
||||
for (auto i (unchecked_begin (transaction_a, nano::unchecked_key (hash_a, 0))), n (unchecked_end ()); i != n && i->first.key () == hash_a; ++i)
|
||||
{
|
||||
nano::unchecked_info const & unchecked_info (i->second);
|
||||
result.push_back (unchecked_info);
|
||||
|
@ -163,7 +163,7 @@ public:
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
bool root_exists (nano::transaction const & transaction_a, nano::uint256_union const & root_a) override
|
||||
bool root_exists (nano::transaction const & transaction_a, nano::root const & root_a) override
|
||||
{
|
||||
return block_exists (transaction_a, root_a) || account_exists (transaction_a, root_a);
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ public:
|
|||
auto version (block_version (transaction_a, hash_a));
|
||||
assert (value.size () != 0);
|
||||
std::vector<uint8_t> data (static_cast<uint8_t *> (value.data ()), static_cast<uint8_t *> (value.data ()) + value.size ());
|
||||
std::fill_n (data.begin () + block_successor_offset (transaction_a, value.size (), type), sizeof (nano::uint256_union), uint8_t{ 0 });
|
||||
std::fill_n (data.begin () + block_successor_offset (transaction_a, value.size (), type), sizeof (nano::block_hash), uint8_t{ 0 });
|
||||
block_raw_put (transaction_a, data, type, version, hash_a);
|
||||
}
|
||||
|
||||
|
@ -500,7 +500,7 @@ public:
|
|||
nano::account result (0);
|
||||
if (success (status))
|
||||
{
|
||||
result = nano::uint256_union (value);
|
||||
result = static_cast<nano::account> (value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -1027,8 +1027,8 @@ protected:
|
|||
else
|
||||
{
|
||||
// Read old successor-only sideband
|
||||
assert (entry_size_a == nano::block::size (type_a) + sizeof (nano::uint256_union));
|
||||
result = entry_size_a - sizeof (nano::uint256_union);
|
||||
assert (entry_size_a == nano::block::size (type_a) + sizeof (nano::block_hash));
|
||||
result = entry_size_a - sizeof (nano::block_hash);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ genesis_block (network_a == nano::nano_networks::nano_test_network ? nano_test_g
|
|||
genesis_amount (std::numeric_limits<nano::uint128_t>::max ()),
|
||||
burn_account (0)
|
||||
{
|
||||
nano::uint256_union epoch_link;
|
||||
nano::link epoch_link;
|
||||
const char * epoch_message ("epoch v1 block");
|
||||
strncpy ((char *)epoch_link.bytes.data (), epoch_message, epoch_link.bytes.size ());
|
||||
epochs.add (nano::epoch::epoch_1, genesis_account, epoch_link);
|
||||
|
@ -299,7 +299,7 @@ bool nano::pending_key::operator== (nano::pending_key const & other_a) const
|
|||
return account == other_a.account && hash == other_a.hash;
|
||||
}
|
||||
|
||||
nano::block_hash nano::pending_key::key () const
|
||||
nano::account const & nano::pending_key::key () const
|
||||
{
|
||||
return account;
|
||||
}
|
||||
|
@ -517,9 +517,9 @@ std::string nano::vote::hashes_string () const
|
|||
|
||||
const std::string nano::vote::hash_prefix = "vote ";
|
||||
|
||||
nano::uint256_union nano::vote::hash () const
|
||||
nano::block_hash nano::vote::hash () const
|
||||
{
|
||||
nano::uint256_union result;
|
||||
nano::block_hash result;
|
||||
blake2b_state hash;
|
||||
blake2b_init (&hash, sizeof (result.bytes));
|
||||
if (blocks.size () > 1 || (!blocks.empty () && blocks.front ().which ()))
|
||||
|
@ -541,9 +541,9 @@ nano::uint256_union nano::vote::hash () const
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::uint256_union nano::vote::full_hash () const
|
||||
nano::block_hash nano::vote::full_hash () const
|
||||
{
|
||||
nano::uint256_union result;
|
||||
nano::block_hash result;
|
||||
blake2b_state state;
|
||||
blake2b_init (&state, sizeof (result.bytes));
|
||||
blake2b_update (&state, hash ().bytes.data (), sizeof (hash ().bytes));
|
||||
|
@ -691,7 +691,7 @@ std::shared_ptr<nano::vote> nano::vote_uniquer::unique (std::shared_ptr<nano::vo
|
|||
{
|
||||
result->blocks.front () = uniquer.unique (boost::get<std::shared_ptr<nano::block>> (result->blocks.front ()));
|
||||
}
|
||||
nano::uint256_union key (vote_a->full_hash ());
|
||||
nano::block_hash key (vote_a->full_hash ());
|
||||
nano::lock_guard<std::mutex> lock (mutex);
|
||||
auto & existing (votes[key]);
|
||||
if (auto block_l = existing.lock ())
|
||||
|
@ -761,3 +761,44 @@ nano::block_hash nano::genesis::hash () const
|
|||
{
|
||||
return open->hash ();
|
||||
}
|
||||
|
||||
nano::wallet_id nano::random_wallet_id ()
|
||||
{
|
||||
nano::wallet_id wallet_id;
|
||||
nano::uint256_union dummy_secret;
|
||||
random_pool::generate_block (dummy_secret.bytes.data (), dummy_secret.bytes.size ());
|
||||
ed25519_publickey (dummy_secret.bytes.data (), wallet_id.bytes.data ());
|
||||
return wallet_id;
|
||||
}
|
||||
|
||||
nano::unchecked_key::unchecked_key (nano::block_hash const & previous_a, nano::block_hash const & hash_a) :
|
||||
previous (previous_a),
|
||||
hash (hash_a)
|
||||
{
|
||||
}
|
||||
|
||||
bool nano::unchecked_key::deserialize (nano::stream & stream_a)
|
||||
{
|
||||
auto error (false);
|
||||
try
|
||||
{
|
||||
nano::read (stream_a, previous.bytes);
|
||||
nano::read (stream_a, hash.bytes);
|
||||
}
|
||||
catch (std::runtime_error const &)
|
||||
{
|
||||
error = true;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool nano::unchecked_key::operator== (nano::unchecked_key const & other_a) const
|
||||
{
|
||||
return previous == other_a.previous && hash == other_a.hash;
|
||||
}
|
||||
|
||||
nano::block_hash const & nano::unchecked_key::key () const
|
||||
{
|
||||
return previous;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,25 @@ struct hash<::nano::uint256_union>
|
|||
{
|
||||
size_t operator() (::nano::uint256_union const & value_a) const
|
||||
{
|
||||
std::hash<::nano::uint256_union> hash;
|
||||
return hash (value_a);
|
||||
return std::hash<::nano::uint256_union> () (value_a);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<::nano::block_hash>
|
||||
{
|
||||
size_t operator() (::nano::block_hash const & value_a) const
|
||||
{
|
||||
return std::hash<::nano::block_hash> () (value_a);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<::nano::public_key>
|
||||
{
|
||||
size_t operator() (::nano::public_key const & value_a) const
|
||||
{
|
||||
return std::hash<::nano::public_key> () (value_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
|
@ -31,8 +48,15 @@ struct hash<::nano::uint512_union>
|
|||
{
|
||||
size_t operator() (::nano::uint512_union const & value_a) const
|
||||
{
|
||||
std::hash<::nano::uint512_union> hash;
|
||||
return hash (value_a);
|
||||
return std::hash<::nano::uint512_union> () (value_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::qualified_root>
|
||||
{
|
||||
size_t operator() (::nano::qualified_root const & value_a) const
|
||||
{
|
||||
return std::hash<::nano::qualified_root> () (value_a);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -96,7 +120,7 @@ public:
|
|||
pending_key (nano::account const &, nano::block_hash const &);
|
||||
bool deserialize (nano::stream &);
|
||||
bool operator== (nano::pending_key const &) const;
|
||||
nano::block_hash key () const;
|
||||
nano::account const & key () const;
|
||||
nano::account account{ 0 };
|
||||
nano::block_hash hash{ 0 };
|
||||
};
|
||||
|
@ -133,8 +157,17 @@ enum class no_value
|
|||
dummy
|
||||
};
|
||||
|
||||
// Internally unchecked_key is equal to pending_key (2x uint256_union)
|
||||
using unchecked_key = pending_key;
|
||||
class unchecked_key final
|
||||
{
|
||||
public:
|
||||
unchecked_key () = default;
|
||||
unchecked_key (nano::block_hash const &, nano::block_hash const &);
|
||||
bool deserialize (nano::stream &);
|
||||
bool operator== (nano::unchecked_key const &) const;
|
||||
nano::block_hash const & key () const;
|
||||
nano::block_hash previous{ 0 };
|
||||
nano::block_hash hash{ 0 };
|
||||
};
|
||||
|
||||
/**
|
||||
* Tag for block signature verification result
|
||||
|
@ -200,8 +233,8 @@ public:
|
|||
vote (nano::account const &, nano::raw_key const &, uint64_t, std::shared_ptr<nano::block>);
|
||||
vote (nano::account const &, nano::raw_key const &, uint64_t, std::vector<nano::block_hash> const &);
|
||||
std::string hashes_string () const;
|
||||
nano::uint256_union hash () const;
|
||||
nano::uint256_union full_hash () const;
|
||||
nano::block_hash hash () const;
|
||||
nano::block_hash full_hash () const;
|
||||
bool operator== (nano::vote const &) const;
|
||||
bool operator!= (nano::vote const &) const;
|
||||
void serialize (nano::stream &, nano::block_type) const;
|
||||
|
@ -228,7 +261,7 @@ public:
|
|||
class vote_uniquer final
|
||||
{
|
||||
public:
|
||||
using value_type = std::pair<const nano::uint256_union, std::weak_ptr<nano::vote>>;
|
||||
using value_type = std::pair<const nano::block_hash, std::weak_ptr<nano::vote>>;
|
||||
|
||||
vote_uniquer (nano::block_uniquer &);
|
||||
std::shared_ptr<nano::vote> unique (std::shared_ptr<nano::vote>);
|
||||
|
@ -413,4 +446,6 @@ public:
|
|||
portmapping_constants portmapping;
|
||||
bootstrap_constants bootstrap;
|
||||
};
|
||||
|
||||
nano::wallet_id random_wallet_id ();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <nano/secure/epoch.hpp>
|
||||
|
||||
nano::uint256_union const & nano::epochs::link (nano::epoch epoch_a) const
|
||||
nano::link const & nano::epochs::link (nano::epoch epoch_a) const
|
||||
{
|
||||
return epochs_m.at (epoch_a).link;
|
||||
}
|
||||
|
||||
bool nano::epochs::is_epoch_link (nano::uint256_union const & link_a) const
|
||||
bool nano::epochs::is_epoch_link (nano::link const & link_a) const
|
||||
{
|
||||
return std::any_of (epochs_m.begin (), epochs_m.end (), [&link_a](auto const & item_a) { return item_a.second.link == link_a; });
|
||||
}
|
||||
|
@ -15,14 +15,14 @@ nano::public_key const & nano::epochs::signer (nano::epoch epoch_a) const
|
|||
return epochs_m.at (epoch_a).signer;
|
||||
}
|
||||
|
||||
nano::epoch nano::epochs::epoch (nano::uint256_union const & link_a) const
|
||||
nano::epoch nano::epochs::epoch (nano::link const & link_a) const
|
||||
{
|
||||
auto existing (std::find_if (epochs_m.begin (), epochs_m.end (), [&link_a](auto const & item_a) { return item_a.second.link == link_a; }));
|
||||
assert (existing != epochs_m.end ());
|
||||
return existing->first;
|
||||
}
|
||||
|
||||
void nano::epochs::add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::uint256_union const & link_a)
|
||||
void nano::epochs::add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a)
|
||||
{
|
||||
assert (epochs_m.find (epoch_a) == epochs_m.end ());
|
||||
epochs_m[epoch_a] = { signer_a, link_a };
|
||||
|
|
|
@ -37,16 +37,16 @@ class epoch_info
|
|||
{
|
||||
public:
|
||||
nano::public_key signer;
|
||||
nano::uint256_union link;
|
||||
nano::link link;
|
||||
};
|
||||
class epochs
|
||||
{
|
||||
public:
|
||||
bool is_epoch_link (nano::uint256_union const & link_a) const;
|
||||
nano::uint256_union const & link (nano::epoch epoch_a) const;
|
||||
bool is_epoch_link (nano::link const & link_a) const;
|
||||
nano::link const & link (nano::epoch epoch_a) const;
|
||||
nano::public_key const & signer (nano::epoch epoch_a) const;
|
||||
nano::epoch epoch (nano::uint256_union const & link_a) const;
|
||||
void add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::uint256_union const & link_a);
|
||||
nano::epoch epoch (nano::link const & link_a) const;
|
||||
void add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a);
|
||||
|
||||
private:
|
||||
std::unordered_map<nano::epoch, nano::epoch_info> epochs_m;
|
||||
|
|
|
@ -672,18 +672,6 @@ verification (verification_a)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
size_t nano::shared_ptr_block_hash::operator() (std::shared_ptr<nano::block> const & block_a) const
|
||||
{
|
||||
auto hash (block_a->hash ());
|
||||
auto result (static_cast<size_t> (hash.qwords[0]));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool nano::shared_ptr_block_hash::operator() (std::shared_ptr<nano::block> const & lhs, std::shared_ptr<nano::block> const & rhs) const
|
||||
{
|
||||
return lhs->hash () == rhs->hash ();
|
||||
}
|
||||
|
||||
nano::ledger::ledger (nano::block_store & store_a, nano::stat & stat_a, bool cache_reps_a, bool cache_cemented_count_a) :
|
||||
store (store_a),
|
||||
stats (stat_a),
|
||||
|
@ -821,19 +809,19 @@ bool nano::ledger::is_send (nano::transaction const & transaction_a, nano::state
|
|||
return result;
|
||||
}
|
||||
|
||||
nano::block_hash nano::ledger::block_destination (nano::transaction const & transaction_a, nano::block const & block_a)
|
||||
nano::account const & nano::ledger::block_destination (nano::transaction const & transaction_a, nano::block const & block_a)
|
||||
{
|
||||
nano::block_hash result (0);
|
||||
nano::send_block const * send_block (dynamic_cast<nano::send_block const *> (&block_a));
|
||||
nano::state_block const * state_block (dynamic_cast<nano::state_block const *> (&block_a));
|
||||
if (send_block != nullptr)
|
||||
{
|
||||
result = send_block->hashables.destination;
|
||||
return send_block->hashables.destination;
|
||||
}
|
||||
else if (state_block != nullptr && is_send (transaction_a, *state_block))
|
||||
{
|
||||
result = state_block->hashables.link;
|
||||
return state_block->hashables.link;
|
||||
}
|
||||
static nano::account result (0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -927,21 +915,18 @@ nano::account nano::ledger::account (nano::transaction const & transaction_a, na
|
|||
}
|
||||
|
||||
// Return amount decrease or increase for block
|
||||
nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, nano::account const & account_a)
|
||||
{
|
||||
release_assert (account_a == network_params.ledger.genesis_account);
|
||||
return network_params.ledger.genesis_amount;
|
||||
}
|
||||
|
||||
nano::uint128_t nano::ledger::amount (nano::transaction const & transaction_a, nano::block_hash const & hash_a)
|
||||
{
|
||||
nano::uint128_t result;
|
||||
if (hash_a != network_params.ledger.genesis_account)
|
||||
{
|
||||
auto block (store.block_get (transaction_a, hash_a));
|
||||
auto block_balance (balance (transaction_a, hash_a));
|
||||
auto previous_balance (balance (transaction_a, block->previous ()));
|
||||
result = block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = network_params.ledger.genesis_amount;
|
||||
}
|
||||
return result;
|
||||
auto block (store.block_get (transaction_a, hash_a));
|
||||
auto block_balance (balance (transaction_a, hash_a));
|
||||
auto previous_balance (balance (transaction_a, block->previous ()));
|
||||
return block_balance > previous_balance ? block_balance - previous_balance : previous_balance - block_balance;
|
||||
}
|
||||
|
||||
// Return latest block for account
|
||||
|
@ -952,21 +937,18 @@ nano::block_hash nano::ledger::latest (nano::transaction const & transaction_a,
|
|||
return latest_error ? 0 : info.head;
|
||||
}
|
||||
|
||||
// Return latest root for account, account number of there are no blocks for this account.
|
||||
nano::block_hash nano::ledger::latest_root (nano::transaction const & transaction_a, nano::account const & account_a)
|
||||
// Return latest root for account, account number if there are no blocks for this account.
|
||||
nano::root nano::ledger::latest_root (nano::transaction const & transaction_a, nano::account const & account_a)
|
||||
{
|
||||
nano::account_info info;
|
||||
auto latest_error (store.account_get (transaction_a, account_a, info));
|
||||
nano::block_hash result;
|
||||
if (latest_error)
|
||||
if (store.account_get (transaction_a, account_a, info))
|
||||
{
|
||||
result = account_a;
|
||||
return account_a;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = info.head;
|
||||
return info.head;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::ledger::dump_account_chain (nano::account const & account_a)
|
||||
|
@ -1028,17 +1010,17 @@ bool nano::ledger::could_fit (nano::transaction const & transaction_a, nano::blo
|
|||
return visitor.result;
|
||||
}
|
||||
|
||||
bool nano::ledger::is_epoch_link (nano::uint256_union const & link_a)
|
||||
bool nano::ledger::is_epoch_link (nano::link const & link_a)
|
||||
{
|
||||
return network_params.ledger.epochs.is_epoch_link (link_a);
|
||||
}
|
||||
|
||||
nano::account const & nano::ledger::signer (nano::uint256_union const & link_a) const
|
||||
nano::account const & nano::ledger::signer (nano::link const & link_a) const
|
||||
{
|
||||
return network_params.ledger.epochs.signer (network_params.ledger.epochs.epoch (link_a));
|
||||
}
|
||||
|
||||
nano::uint256_union const & nano::ledger::link (nano::epoch epoch_a) const
|
||||
nano::link const & nano::ledger::link (nano::epoch epoch_a) const
|
||||
{
|
||||
return network_params.ledger.epochs.link (nano::epoch::epoch_1);
|
||||
}
|
||||
|
@ -1069,17 +1051,27 @@ void nano::ledger::change_latest (nano::write_transaction const & transaction_a,
|
|||
std::shared_ptr<nano::block> nano::ledger::successor (nano::transaction const & transaction_a, nano::qualified_root const & root_a)
|
||||
{
|
||||
nano::block_hash successor (0);
|
||||
if (root_a.uint256s[0].is_zero () && store.account_exists (transaction_a, root_a.uint256s[1]))
|
||||
auto get_from_previous = false;
|
||||
if (root_a.previous ().is_zero ())
|
||||
{
|
||||
nano::account_info info;
|
||||
auto error (store.account_get (transaction_a, root_a.uint256s[1], info));
|
||||
(void)error;
|
||||
assert (!error);
|
||||
successor = info.open_block;
|
||||
if (!store.account_get (transaction_a, root_a.root (), info))
|
||||
{
|
||||
successor = info.open_block;
|
||||
}
|
||||
else
|
||||
{
|
||||
get_from_previous = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
successor = store.block_successor (transaction_a, root_a.uint256s[0]);
|
||||
get_from_previous = true;
|
||||
}
|
||||
|
||||
if (get_from_previous)
|
||||
{
|
||||
successor = store.block_successor (transaction_a, root_a.previous ());
|
||||
}
|
||||
std::shared_ptr<nano::block> result;
|
||||
if (!successor.is_zero ())
|
||||
|
|
|
@ -9,18 +9,13 @@ namespace nano
|
|||
class block_store;
|
||||
class stat;
|
||||
|
||||
class shared_ptr_block_hash final
|
||||
{
|
||||
public:
|
||||
size_t operator() (std::shared_ptr<nano::block> const &) const;
|
||||
bool operator() (std::shared_ptr<nano::block> const &, std::shared_ptr<nano::block> const &) const;
|
||||
};
|
||||
using tally_t = std::map<nano::uint128_t, std::shared_ptr<nano::block>, std::greater<nano::uint128_t>>;
|
||||
class ledger final
|
||||
{
|
||||
public:
|
||||
ledger (nano::block_store &, nano::stat &, bool = true, bool = true);
|
||||
nano::account account (nano::transaction const &, nano::block_hash const &) const;
|
||||
nano::uint128_t amount (nano::transaction const &, nano::account const &);
|
||||
nano::uint128_t amount (nano::transaction const &, nano::block_hash const &);
|
||||
nano::uint128_t balance (nano::transaction const &, nano::block_hash const &) const;
|
||||
nano::uint128_t account_balance (nano::transaction const &, nano::account const &);
|
||||
|
@ -31,7 +26,7 @@ public:
|
|||
bool block_confirmed (nano::transaction const & transaction_a, nano::block_hash const & hash_a) const;
|
||||
bool block_not_confirmed_or_not_exists (nano::block const & block_a) const;
|
||||
nano::block_hash latest (nano::transaction const &, nano::account const &);
|
||||
nano::block_hash latest_root (nano::transaction const &, nano::account const &);
|
||||
nano::root latest_root (nano::transaction const &, nano::account const &);
|
||||
nano::block_hash representative (nano::transaction const &, nano::block_hash const &);
|
||||
nano::block_hash representative_calculated (nano::transaction const &, nano::block_hash const &);
|
||||
bool block_exists (nano::block_hash const &);
|
||||
|
@ -39,7 +34,7 @@ public:
|
|||
std::string block_text (char const *);
|
||||
std::string block_text (nano::block_hash const &);
|
||||
bool is_send (nano::transaction const &, nano::state_block const &) const;
|
||||
nano::block_hash block_destination (nano::transaction const &, nano::block const &);
|
||||
nano::account const & block_destination (nano::transaction const &, nano::block const &);
|
||||
nano::block_hash block_source (nano::transaction const &, nano::block const &);
|
||||
nano::process_return process (nano::write_transaction const &, nano::block const &, nano::signature_verification = nano::signature_verification::unknown);
|
||||
bool rollback (nano::write_transaction const &, nano::block_hash const &, std::vector<std::shared_ptr<nano::block>> &);
|
||||
|
@ -47,10 +42,9 @@ public:
|
|||
void change_latest (nano::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &);
|
||||
void dump_account_chain (nano::account const &);
|
||||
bool could_fit (nano::transaction const &, nano::block const &);
|
||||
bool is_epoch_link (nano::uint256_union const &);
|
||||
nano::account const & signer (nano::uint256_union const &) const;
|
||||
nano::uint256_union const & link (nano::epoch) const;
|
||||
size_t block_count () const;
|
||||
bool is_epoch_link (nano::link const &);
|
||||
nano::account const & signer (nano::link const &) const;
|
||||
nano::link const & link (nano::epoch) const;
|
||||
static nano::uint128_t const unit;
|
||||
nano::network_params network_params;
|
||||
nano::block_store & store;
|
||||
|
|
|
@ -168,10 +168,10 @@ TEST (store, load)
|
|||
auto transaction (system.nodes[0]->store.tx_begin_write ());
|
||||
for (auto j (0); j != 10; ++j)
|
||||
{
|
||||
nano::block_hash hash;
|
||||
nano::random_pool::generate_block (hash.bytes.data (), hash.bytes.size ());
|
||||
system.nodes[0]->store.confirmation_height_put (transaction, hash, 0);
|
||||
system.nodes[0]->store.account_put (transaction, hash, nano::account_info ());
|
||||
nano::account account;
|
||||
nano::random_pool::generate_block (account.bytes.data (), account.bytes.size ());
|
||||
system.nodes[0]->store.confirmation_height_put (transaction, account, 0);
|
||||
system.nodes[0]->store.account_put (transaction, account, nano::account_info ());
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue