diff --git a/rai/config.hpp b/rai/config.hpp index 3e57bb21..dc35a2f5 100644 --- a/rai/config.hpp +++ b/rai/config.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include +#include namespace rai { diff --git a/rai/core_test/block.cpp b/rai/core_test/block.cpp index faa9e63d..99052728 100644 --- a/rai/core_test/block.cpp +++ b/rai/core_test/block.cpp @@ -20,7 +20,7 @@ TEST (ed25519, signing) 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); - signature.bytes [32] ^= 0x1; + signature.bytes[32] ^= 0x1; auto valid2 (ed25519_sign_open (message.bytes.data (), sizeof (message.bytes), pub.bytes.data (), signature.bytes.data ())); ASSERT_NE (0, valid2); } @@ -31,14 +31,14 @@ TEST (transaction_block, empty) rai::send_block block (0, 1, 13, key1.prv, key1.pub, 2); rai::uint256_union hash (block.hash ()); ASSERT_FALSE (rai::validate_message (key1.pub, hash, block.signature)); - block.signature.bytes [32] ^= 0x1; + block.signature.bytes[32] ^= 0x1; ASSERT_TRUE (rai::validate_message (key1.pub, hash, block.signature)); } TEST (block, send_serialize) { rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); block1.serialize (stream1); @@ -73,7 +73,7 @@ TEST (block, receive_serialize) { rai::receive_block block1 (0, 1, rai::keypair ().prv, 3, 4); rai::keypair key1; - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); block1.serialize (stream1); @@ -168,7 +168,7 @@ TEST (uint512_union, parse_error_symbol) rai::uint512_union input (rai::uint512_t (1000)); std::string text; input.encode_hex (text); - text [5] = '!'; + text[5] = '!'; rai::uint512_union output; auto error (output.decode_hex (text)); ASSERT_TRUE (error); @@ -176,7 +176,7 @@ TEST (uint512_union, parse_error_symbol) TEST (uint512_union, max) { - rai::uint512_union input (std::numeric_limits ::max ()); + rai::uint512_union input (std::numeric_limits::max ()); std::string text; input.encode_hex (text); rai::uint512_union output; @@ -188,7 +188,7 @@ TEST (uint512_union, max) TEST (uint512_union, parse_error_overflow) { - rai::uint512_union input (std::numeric_limits ::max ()); + rai::uint512_union input (std::numeric_limits::max ()); std::string text; input.encode_hex (text); text.push_back (0); @@ -201,7 +201,7 @@ TEST (send_block, deserialize) { rai::send_block block1 (0, 1, 2, rai::keypair ().prv, 4, 5); ASSERT_EQ (block1.hash (), block1.hash ()); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); block1.serialize (stream1); @@ -220,7 +220,7 @@ TEST (receive_block, deserialize) ASSERT_EQ (block1.hash (), block1.hash ()); block1.hashables.previous = 2; block1.hashables.source = 4; - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); block1.serialize (stream1); @@ -237,7 +237,7 @@ TEST (open_block, deserialize) { rai::open_block block1 (0, 1, 0, rai::keypair ().prv, 0, 0); ASSERT_EQ (block1.hash (), block1.hash ()); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); block1.serialize (stream); @@ -254,7 +254,7 @@ TEST (change_block, deserialize) { rai::change_block block1 (1, 2, rai::keypair ().prv, 4, 5); ASSERT_EQ (block1.hash (), block1.hash ()); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); block1.serialize (stream1); @@ -277,7 +277,7 @@ TEST (frontier_req, serialization) request1.start = 1; request1.age = 2; request1.count = 3; - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); request1.serialize (stream); @@ -292,9 +292,9 @@ TEST (block, publish_req_serialization) { rai::keypair key1; rai::keypair key2; - auto block (std::unique_ptr (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); + auto block (std::unique_ptr (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); rai::publish req (std::move (block)); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); req.serialize (stream); @@ -311,9 +311,9 @@ TEST (block, confirm_req_serialization) { rai::keypair key1; rai::keypair key2; - auto block (std::unique_ptr (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); + auto block (std::unique_ptr (new rai::send_block (0, key2.pub, 200, rai::keypair ().prv, 2, 3))); rai::confirm_req req (std::move (block)); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); req.serialize (stream); diff --git a/rai/core_test/block_store.cpp b/rai/core_test/block_store.cpp index ab39e12a..a6cd1796 100644 --- a/rai/core_test/block_store.cpp +++ b/rai/core_test/block_store.cpp @@ -127,7 +127,7 @@ TEST (block_store, pending_iterator) ASSERT_TRUE (!init); rai::transaction transaction (store.environment, nullptr, true); ASSERT_EQ (store.pending_end (), store.pending_begin (transaction)); - store.pending_put (transaction, rai::pending_key (1, 2), {2, 3}); + store.pending_put (transaction, rai::pending_key (1, 2), { 2, 3 }); auto current (store.pending_begin (transaction)); ASSERT_NE (store.pending_end (), current); rai::pending_key key1 (current->first); @@ -152,7 +152,7 @@ TEST (block_store, genesis) ASSERT_EQ (hash, info.head); auto block1 (store.block_get (transaction, info.head)); ASSERT_NE (nullptr, block1); - auto receive1 (dynamic_cast (block1.get ())); + auto receive1 (dynamic_cast (block1.get ())); ASSERT_NE (nullptr, receive1); ASSERT_LE (info.modified, store.now ()); auto test_pub_text (rai::test_genesis_key.pub.to_string ()); @@ -180,14 +180,14 @@ TEST (bootstrap, simple) bool init (false); rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); - auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); + auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); rai::transaction transaction (store.environment, nullptr, true); auto block2 (store.unchecked_get (transaction, block1->previous ())); ASSERT_TRUE (block2.empty ()); store.unchecked_put (transaction, block1->previous (), block1); auto block3 (store.unchecked_get (transaction, block1->previous ())); ASSERT_FALSE (block3.empty ()); - ASSERT_EQ (*block1, *block3 [0]); + ASSERT_EQ (*block1, *block3[0]); store.unchecked_del (transaction, block1->previous (), *block1); auto block4 (store.unchecked_get (transaction, block1->previous ())); ASSERT_TRUE (block4.empty ()); @@ -198,7 +198,7 @@ TEST (unchecked, multiple) bool init (false); rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); - auto block1 (std::make_shared (4, 1, 2, rai::keypair ().prv, 4, 5)); + auto block1 (std::make_shared (4, 1, 2, rai::keypair ().prv, 4, 5)); rai::transaction transaction (store.environment, nullptr, true); auto block2 (store.unchecked_get (transaction, block1->previous ())); ASSERT_TRUE (block2.empty ()); @@ -266,7 +266,7 @@ TEST (block_store, one_bootstrap) bool init (false); rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); - auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); + auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); rai::transaction transaction (store.environment, nullptr, true); store.unchecked_put (transaction, block1->hash (), block1); store.flush (transaction); @@ -313,7 +313,7 @@ TEST (block_store, one_account) rai::account account (0); rai::block_hash hash (0); rai::transaction transaction (store.environment, nullptr, true); - store.account_put (transaction, account, {hash, account, hash, 42, 100, 200}); + store.account_put (transaction, account, { hash, account, hash, 42, 100, 200 }); auto begin (store.latest_begin (transaction)); auto end (store.latest_end ()); ASSERT_NE (end, begin); @@ -334,16 +334,16 @@ TEST (block_store, two_block) ASSERT_TRUE (!init); rai::open_block block1 (0, 1, 1, rai::keypair ().prv, 0, 0); block1.hashables.account = 1; - std::vector hashes; - std::vector blocks; + std::vector hashes; + std::vector blocks; hashes.push_back (block1.hash ()); blocks.push_back (block1); rai::transaction transaction (store.environment, nullptr, true); - store.block_put (transaction, hashes [0], block1); + store.block_put (transaction, hashes[0], block1); rai::open_block block2 (0, 1, 2, rai::keypair ().prv, 0, 0); hashes.push_back (block2.hash ()); blocks.push_back (block2); - store.block_put (transaction, hashes [1], block2); + store.block_put (transaction, hashes[1], block2); ASSERT_TRUE (store.block_exists (transaction, block1.hash ())); ASSERT_TRUE (store.block_exists (transaction, block2.hash ())); } @@ -358,8 +358,8 @@ TEST (block_store, two_account) rai::account account2 (3); rai::block_hash hash2 (4); rai::transaction transaction (store.environment, nullptr, true); - store.account_put (transaction, account1, {hash1, account1, hash1, 42, 100, 300}); - store.account_put (transaction, account2, {hash2, account2, hash2, 84, 200, 400}); + store.account_put (transaction, account1, { hash1, account1, hash1, 42, 100, 300 }); + store.account_put (transaction, account2, { hash2, account2, hash2, 84, 200, 400 }); auto begin (store.latest_begin (transaction)); auto end (store.latest_end ()); ASSERT_NE (end, begin); @@ -391,8 +391,8 @@ TEST (block_store, latest_find) rai::account account2 (3); rai::block_hash hash2 (4); rai::transaction transaction (store.environment, nullptr, true); - store.account_put (transaction, account1, {hash1, account1, hash1, 100, 0, 300}); - store.account_put (transaction, account2, {hash2, account2, hash2, 200, 0, 400}); + store.account_put (transaction, account1, { hash1, account1, hash1, 100, 0, 300 }); + store.account_put (transaction, account2, { hash2, account2, hash2, 200, 0, 400 }); auto first (store.latest_begin (transaction)); auto second (store.latest_begin (transaction)); ++second; @@ -493,7 +493,7 @@ TEST (block_store, unsynced_iteration) store.unsynced_put (transaction, hash1); rai::block_hash hash2 (2); store.unsynced_put (transaction, hash2); - std::unordered_set hashes; + std::unordered_set hashes; for (auto i (store.unsynced_begin (transaction)), n (store.unsynced_end ()); i != n; ++i) { hashes.insert (rai::uint256_union (i->first.uint256 ())); @@ -508,7 +508,7 @@ TEST (block_store, large_iteration) bool init (false); rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); - std::unordered_set accounts1; + std::unordered_set accounts1; for (auto i (0); i < 1000; ++i) { rai::transaction transaction (store.environment, nullptr, true); @@ -517,7 +517,7 @@ TEST (block_store, large_iteration) accounts1.insert (account); store.account_put (transaction, account, rai::account_info ()); } - std::unordered_set accounts2; + std::unordered_set accounts2; rai::account previous (0); rai::transaction transaction (store.environment, nullptr, false); for (auto i (store.latest_begin (transaction, 0)), n (store.latest_end ()); i != n; ++i) @@ -591,7 +591,7 @@ TEST (block_store, sequence_increment) ASSERT_TRUE (!init); rai::keypair key1; rai::keypair key2; - auto block1 (std::make_shared (0, 1, 0, rai::keypair ().prv, 0, 0)); + auto block1 (std::make_shared (0, 1, 0, rai::keypair ().prv, 0, 0)); rai::transaction transaction (store.environment, nullptr, true); auto vote1 (store.vote_generate (transaction, key1.pub, key1.prv, block1)); ASSERT_EQ (1, vote1->sequence); @@ -631,7 +631,7 @@ TEST (block_store, upgrade_v2_v3) rai::change_block change (hash, key1.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); change_hash = change.hash (); ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, change).code); - ASSERT_EQ (0, ledger.weight(transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (0, ledger.weight (transaction, rai::test_genesis_key.pub)); ASSERT_EQ (rai::genesis_amount, ledger.weight (transaction, key1.pub)); store.version_put (transaction, 2); store.representation_put (transaction, key1.pub, 7); @@ -745,18 +745,18 @@ TEST (vote, validate) rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); rai::keypair key1; - auto send1 (std::make_shared (0, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto vote1 (std::make_shared (key1.pub, key1.prv, 2, send1)); + auto send1 (std::make_shared (0, key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto vote1 (std::make_shared (key1.pub, key1.prv, 2, send1)); rai::transaction transaction (store.environment, nullptr, true); auto vote_result1 (store.vote_validate (transaction, vote1)); ASSERT_EQ (rai::vote_code::vote, vote_result1.code); ASSERT_EQ (*vote1, *vote_result1.vote); - vote1->signature.bytes [8] ^= 1; + vote1->signature.bytes[8] ^= 1; auto vote_result2 (store.vote_validate (transaction, vote1)); ASSERT_EQ (rai::vote_code::invalid, vote_result2.code); // If the signature is invalid, we don't need to take the overhead of checking the current sequence value ASSERT_EQ (nullptr, vote_result2.vote); - auto vote2 (std::make_shared (key1.pub, key1.prv, 1, send1)); + auto vote2 (std::make_shared (key1.pub, key1.prv, 1, send1)); auto vote_result3 (store.vote_validate (transaction, vote2)); ASSERT_EQ (rai::vote_code::replay, vote_result3.code); ASSERT_EQ (*vote1, *vote_result3.vote); @@ -799,7 +799,7 @@ TEST (block_store, upgrade_v6_v7) rai::genesis genesis; genesis.initialize (transaction, store); store.version_put (transaction, 6); - auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); store.unchecked_put (transaction, send1->hash (), send1); store.flush (transaction); ASSERT_NE (store.unchecked_end (), store.unchecked_begin (transaction)); @@ -820,8 +820,8 @@ TEST (block_store, change_dupsort) rai::transaction transaction (store.environment, nullptr, true); ASSERT_EQ (0, mdb_drop (transaction, store.unchecked, 1)); ASSERT_EQ (0, mdb_dbi_open (transaction, "unchecked", MDB_CREATE, &store.unchecked)); - auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto send2 (std::make_shared (1, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send2 (std::make_shared (1, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_NE (send1->hash (), send2->hash ()); store.unchecked_put (transaction, send1->hash (), send1); store.unchecked_put (transaction, send1->hash (), send2); @@ -871,8 +871,8 @@ TEST (block_store, upgrade_v7_v8) rai::block_store store (init, path); ASSERT_FALSE (init); rai::transaction transaction (store.environment, nullptr, true); - auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto send2 (std::make_shared (1, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send2 (std::make_shared (1, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); store.unchecked_put (transaction, send1->hash (), send1); store.unchecked_put (transaction, send1->hash (), send2); store.flush (transaction); @@ -893,7 +893,7 @@ TEST (block_store, sequence_flush) ASSERT_FALSE (init); rai::transaction transaction (store.environment, nullptr, true); rai::keypair key1; - auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); auto vote1 (store.vote_generate (transaction, key1.pub, key1.prv, send1)); auto seq2 (store.vote_get (transaction, vote1->account)); ASSERT_EQ (nullptr, seq2); diff --git a/rai/core_test/conflicts.cpp b/rai/core_test/conflicts.cpp index 67e3a37a..13a6724a 100644 --- a/rai/core_test/conflicts.cpp +++ b/rai/core_test/conflicts.cpp @@ -4,13 +4,13 @@ TEST (conflicts, start_stop) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code); ASSERT_EQ (0, node1.active.roots.size ()); - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); @@ -27,24 +27,24 @@ TEST (conflicts, start_stop) TEST (conflicts, add_existing) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code); - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } rai::keypair key2; - auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send2); } ASSERT_EQ (1, node1.active.roots.size ()); - auto vote1 (std::make_shared (key2.pub, key2.prv, 0, send2)); + auto vote1 (std::make_shared (key2.pub, key2.prv, 0, send2)); node1.active.vote (vote1); ASSERT_EQ (1, node1.active.roots.size ()); auto votes1 (node1.active.roots.find (send2->root ())->election); @@ -56,18 +56,18 @@ TEST (conflicts, add_existing) TEST (conflicts, add_two) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*send1).code); - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } rai::keypair key2; - auto send2 (std::make_shared (send1->hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send2 (std::make_shared (send1->hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*send2).code); { rai::transaction transaction (node1.store.environment, nullptr, true); diff --git a/rai/core_test/daemon.cpp b/rai/core_test/daemon.cpp index ba615ca5..fc4c9fb7 100644 --- a/rai/core_test/daemon.cpp +++ b/rai/core_test/daemon.cpp @@ -2,5 +2,4 @@ TEST (daemon, fork) { - } \ No newline at end of file diff --git a/rai/core_test/entry.cpp b/rai/core_test/entry.cpp index 3767764a..8225ebb3 100644 --- a/rai/core_test/entry.cpp +++ b/rai/core_test/entry.cpp @@ -7,6 +7,6 @@ TEST (basic, basic) TEST (asan, DISABLED_memory) { - uint8_t array [1]; - auto value (array [-0x800000]); + uint8_t array[1]; + auto value (array[-0x800000]); } \ No newline at end of file diff --git a/rai/core_test/gap_cache.cpp b/rai/core_test/gap_cache.cpp index ebe5b3d4..0783cea5 100644 --- a/rai/core_test/gap_cache.cpp +++ b/rai/core_test/gap_cache.cpp @@ -4,69 +4,71 @@ TEST (gap_cache, add_new) { rai::system system (24000, 1); - rai::gap_cache cache (*system.nodes [0]); - auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::gap_cache cache (*system.nodes[0]); + auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); cache.add (transaction, block1); } TEST (gap_cache, add_existing) { rai::system system (24000, 1); - rai::gap_cache cache (*system.nodes [0]); - auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::gap_cache cache (*system.nodes[0]); + auto block1 (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); cache.add (transaction, block1); - auto existing1 (cache.blocks.get <1> ().find (block1->hash ())); - ASSERT_NE (cache.blocks.get <1> ().end (), existing1); + auto existing1 (cache.blocks.get<1> ().find (block1->hash ())); + ASSERT_NE (cache.blocks.get<1> ().end (), existing1); auto arrival (existing1->arrival); - while (arrival == std::chrono::system_clock::now ()); + while (arrival == std::chrono::system_clock::now ()) + ; cache.add (transaction, block1); ASSERT_EQ (1, cache.blocks.size ()); - auto existing2 (cache.blocks.get <1> ().find (block1->hash ())); - ASSERT_NE (cache.blocks.get <1> ().end (), existing2); + auto existing2 (cache.blocks.get<1> ().find (block1->hash ())); + ASSERT_NE (cache.blocks.get<1> ().end (), existing2); ASSERT_GT (existing2->arrival, arrival); } TEST (gap_cache, comparison) { rai::system system (24000, 1); - rai::gap_cache cache (*system.nodes [0]); - auto block1 (std::make_shared (1, 0, 2, rai::keypair ().prv, 4, 5)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::gap_cache cache (*system.nodes[0]); + auto block1 (std::make_shared (1, 0, 2, rai::keypair ().prv, 4, 5)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); cache.add (transaction, block1); - auto existing1 (cache.blocks.get <1> ().find (block1->hash ())); - ASSERT_NE (cache.blocks.get <1> ().end (), existing1); + auto existing1 (cache.blocks.get<1> ().find (block1->hash ())); + ASSERT_NE (cache.blocks.get<1> ().end (), existing1); auto arrival (existing1->arrival); - while (std::chrono::system_clock::now () == arrival); - auto block3 (std::make_shared (0, 42, 1, rai::keypair ().prv, 3, 4)); + while (std::chrono::system_clock::now () == arrival) + ; + auto block3 (std::make_shared (0, 42, 1, rai::keypair ().prv, 3, 4)); cache.add (transaction, block3); ASSERT_EQ (2, cache.blocks.size ()); - auto existing2 (cache.blocks.get <1> ().find (block3->hash ())); - ASSERT_NE (cache.blocks.get <1> ().end (), existing2); + auto existing2 (cache.blocks.get<1> ().find (block3->hash ())); + ASSERT_NE (cache.blocks.get<1> ().end (), existing2); ASSERT_GT (existing2->arrival, arrival); - ASSERT_EQ (arrival, cache.blocks.get <1> ().begin ()->arrival); + ASSERT_EQ (arrival, cache.blocks.get<1> ().begin ()->arrival); } TEST (gap_cache, gap_bootstrap) { rai::system system (24000, 2); - rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::keypair key; - auto send (std::make_shared (latest, key.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest))); + auto send (std::make_shared (latest, key.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest))); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->block_processor.process_receive_one (transaction, send).code); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->block_processor.process_receive_one (transaction, send).code); } - ASSERT_EQ (rai::genesis_amount - 100, system.nodes [0]->balance (rai::genesis_account)); - ASSERT_EQ (rai::genesis_amount, system.nodes [1]->balance (rai::genesis_account)); + ASSERT_EQ (rai::genesis_amount - 100, system.nodes[0]->balance (rai::genesis_account)); + ASSERT_EQ (rai::genesis_amount, system.nodes[1]->balance (rai::genesis_account)); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 100); - ASSERT_EQ (rai::genesis_amount - 200, system.nodes [0]->balance (rai::genesis_account)); - ASSERT_EQ (rai::genesis_amount, system.nodes [1]->balance (rai::genesis_account)); + ASSERT_EQ (rai::genesis_amount - 200, system.nodes[0]->balance (rai::genesis_account)); + ASSERT_EQ (rai::genesis_amount, system.nodes[1]->balance (rai::genesis_account)); auto iterations2 (0); - while (system.nodes [1]->balance (rai::genesis_account) != rai::genesis_amount - 200) + while (system.nodes[1]->balance (rai::genesis_account) != rai::genesis_amount - 200) { system.poll (); ++iterations2; @@ -79,18 +81,18 @@ TEST (gap_cache, two_dependencies) rai::system system (24000, 1); rai::keypair key; rai::genesis genesis; - auto send1 (std::make_shared (genesis.hash (), key.pub, 1, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); - auto send2 (std::make_shared (send1->hash (), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); - auto open (std::make_shared (send1->hash (), key.pub, key.pub, key.prv, key.pub, system.work.generate (key.pub))); - ASSERT_EQ (0, system.nodes [0]->gap_cache.blocks.size ()); - system.nodes [0]->block_processor.process_receive_many (rai::block_processor_item (send2)); - ASSERT_EQ (1, system.nodes [0]->gap_cache.blocks.size ()); - system.nodes [0]->block_processor.process_receive_many (rai::block_processor_item (open)); - ASSERT_EQ (2, system.nodes [0]->gap_cache.blocks.size ()); - system.nodes [0]->block_processor.process_receive_many (rai::block_processor_item (send1)); - ASSERT_EQ (0, system.nodes [0]->gap_cache.blocks.size ()); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, send1->hash ())); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, send2->hash ())); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, open->hash ())); + auto send1 (std::make_shared (genesis.hash (), key.pub, 1, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + auto send2 (std::make_shared (send1->hash (), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); + auto open (std::make_shared (send1->hash (), key.pub, key.pub, key.prv, key.pub, system.work.generate (key.pub))); + ASSERT_EQ (0, system.nodes[0]->gap_cache.blocks.size ()); + system.nodes[0]->block_processor.process_receive_many (rai::block_processor_item (send2)); + ASSERT_EQ (1, system.nodes[0]->gap_cache.blocks.size ()); + system.nodes[0]->block_processor.process_receive_many (rai::block_processor_item (open)); + ASSERT_EQ (2, system.nodes[0]->gap_cache.blocks.size ()); + system.nodes[0]->block_processor.process_receive_many (rai::block_processor_item (send1)); + ASSERT_EQ (0, system.nodes[0]->gap_cache.blocks.size ()); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send1->hash ())); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, send2->hash ())); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, open->hash ())); } diff --git a/rai/core_test/interface.cpp b/rai/core_test/interface.cpp index 1c5a0386..99c60048 100644 --- a/rai/core_test/interface.cpp +++ b/rai/core_test/interface.cpp @@ -3,14 +3,14 @@ #include #include -#include #include +#include #include TEST (interface, xrb_uint256_to_string) { rai::uint256_union zero (0); - char text [65] = { 0 }; + char text[65] = { 0 }; xrb_uint256_to_string (zero.bytes.data (), text); ASSERT_STREQ ("0000000000000000000000000000000000000000000000000000000000000000", text); } @@ -18,7 +18,7 @@ TEST (interface, xrb_uint256_to_string) TEST (interface, xrb_uint256_to_address) { rai::uint256_union zero (0); - char text [65] = { 0 }; + char text[65] = { 0 }; xrb_uint256_to_address (zero.bytes.data (), text); ASSERT_STREQ ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp", text); } @@ -26,7 +26,7 @@ TEST (interface, xrb_uint256_to_address) TEST (interface, xrb_uint512_to_string) { rai::uint512_union zero (0); - char text [129] = { 0 }; + char text[129] = { 0 }; xrb_uint512_to_string (zero.bytes.data (), text); ASSERT_STREQ ("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", text); } @@ -85,7 +85,7 @@ TEST (interface, sign_transaction) xrb_key_account (key.data.bytes.data (), pub.bytes.data ()); rai::send_block send (0, 0, 0, key, pub, 0); ASSERT_FALSE (rai::validate_message (pub, send.hash (), send.signature)); - send.signature.bytes [0] ^= 1; + send.signature.bytes[0] ^= 1; ASSERT_TRUE (rai::validate_message (pub, send.hash (), send.signature)); auto transaction (xrb_sign_transaction (send.to_json ().c_str (), key.data.bytes.data ())); boost::property_tree::ptree block_l; @@ -94,7 +94,7 @@ TEST (interface, sign_transaction) boost::property_tree::read_json (block_stream, block_l); auto block (rai::deserialize_block_json (block_l)); ASSERT_NE (nullptr, block); - auto send1 (dynamic_cast (block.get ())); + auto send1 (dynamic_cast (block.get ())); ASSERT_NE (nullptr, send1); ASSERT_FALSE (rai::validate_message (pub, send.hash (), send1->signature)); free (transaction); diff --git a/rai/core_test/ledger.cpp b/rai/core_test/ledger.cpp index f25062c3..d2498d77 100644 --- a/rai/core_test/ledger.cpp +++ b/rai/core_test/ledger.cpp @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include // Init returns an error if it can't open files at the path TEST (ledger, store_error) @@ -54,14 +54,14 @@ TEST (ledger, checksum_persistence) ASSERT_TRUE (!init); rai::uint256_union checksum1; rai::uint256_union max; - max.qwords [0] = 0; - max.qwords [0] = ~max.qwords [0]; - max.qwords [1] = 0; - max.qwords [1] = ~max.qwords [1]; - max.qwords [2] = 0; - max.qwords [2] = ~max.qwords [2]; - max.qwords [3] = 0; - max.qwords [3] = ~max.qwords [3]; + max.qwords[0] = 0; + max.qwords[0] = ~max.qwords[0]; + max.qwords[1] = 0; + max.qwords[1] = ~max.qwords[1]; + max.qwords[2] = 0; + max.qwords[2] = ~max.qwords[2]; + max.qwords[3] = 0; + max.qwords[3] = ~max.qwords[3]; rai::transaction transaction (store.environment, nullptr, true); { rai::ledger ledger (store); @@ -77,7 +77,7 @@ TEST (ledger, checksum_persistence) TEST (system, system_genesis) { rai::system system (24000, 2); - for (auto & i: system.nodes) + for (auto & i : system.nodes) { rai::transaction transaction (i->store.environment, nullptr, false); ASSERT_EQ (rai::genesis_amount, i->ledger.account_balance (transaction, rai::genesis_account)); @@ -116,7 +116,7 @@ TEST (ledger, process_send) ASSERT_EQ (2, info2.block_count); auto latest6 (store.block_get (transaction, info2.head)); ASSERT_NE (nullptr, latest6); - auto latest7 (dynamic_cast (latest6.get ())); + auto latest7 (dynamic_cast (latest6.get ())); ASSERT_NE (nullptr, latest7); ASSERT_EQ (send, *latest7); // Create an open block opening an account accepting the send we just created @@ -137,14 +137,14 @@ TEST (ledger, process_send) ASSERT_FALSE (store.account_get (transaction, rai::test_genesis_key.pub, info3)); auto latest2 (store.block_get (transaction, info3.head)); ASSERT_NE (nullptr, latest2); - auto latest3 (dynamic_cast (latest2.get ())); + auto latest3 (dynamic_cast (latest2.get ())); ASSERT_NE (nullptr, latest3); ASSERT_EQ (send, *latest3); rai::account_info info4; ASSERT_FALSE (store.account_get (transaction, key2.pub, info4)); auto latest4 (store.block_get (transaction, info4.head)); ASSERT_NE (nullptr, latest4); - auto latest5 (dynamic_cast (latest4.get ())); + auto latest5 (dynamic_cast (latest4.get ())); ASSERT_NE (nullptr, latest5); ASSERT_EQ (open, *latest5); ledger.rollback (transaction, hash2); @@ -219,7 +219,7 @@ TEST (ledger, process_receive) ASSERT_EQ (rai::genesis_amount - 25, ledger.account_balance (transaction, key2.pub)); ASSERT_EQ (rai::genesis_amount - 25, ledger.weight (transaction, key3.pub)); ledger.rollback (transaction, hash4); - ASSERT_TRUE (store.block_successor(transaction, hash2).is_zero ()); + ASSERT_TRUE (store.block_successor (transaction, hash2).is_zero ()); ASSERT_EQ (key2.pub, store.frontier_get (transaction, hash2)); ASSERT_TRUE (store.frontier_get (transaction, hash4).is_zero ()); ASSERT_EQ (25, ledger.account_balance (transaction, rai::test_genesis_key.pub)); @@ -481,12 +481,12 @@ TEST (ledger, checksum_single) genesis.initialize (transaction, store); rai::ledger ledger (store); store.checksum_put (transaction, 0, 0, genesis.hash ()); - ASSERT_EQ (genesis.hash (), ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + ASSERT_EQ (genesis.hash (), ledger.checksum (transaction, 0, std::numeric_limits::max ())); rai::change_block block1 (ledger.latest (transaction, rai::test_genesis_key.pub), rai::account (1), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); - rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits::max ())); ASSERT_EQ (genesis.hash (), check1); ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, block1).code); - rai::checksum check2 (ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + rai::checksum check2 (ledger.checksum (transaction, 0, std::numeric_limits::max ())); ASSERT_EQ (block1.hash (), check2); } @@ -503,10 +503,10 @@ TEST (ledger, checksum_two) rai::keypair key2; rai::send_block block1 (ledger.latest (transaction, rai::test_genesis_key.pub), key2.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, block1).code); - rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits::max ())); rai::open_block block2 (block1.hash (), 1, key2.pub, key2.prv, key2.pub, 0); ASSERT_EQ (rai::process_result::progress, ledger.process (transaction, block2).code); - rai::checksum check2 (ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + rai::checksum check2 (ledger.checksum (transaction, 0, std::numeric_limits::max ())); ASSERT_EQ (check1, check2 ^ block2.hash ()); } @@ -517,43 +517,43 @@ TEST (ledger, DISABLED_checksum_range) ASSERT_TRUE (!init); rai::ledger ledger (store); rai::transaction transaction (store.environment, nullptr, false); - rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits ::max ())); + rai::checksum check1 (ledger.checksum (transaction, 0, std::numeric_limits::max ())); ASSERT_TRUE (check1.is_zero ()); rai::block_hash hash1 (42); rai::checksum check2 (ledger.checksum (transaction, 0, 42)); ASSERT_TRUE (check2.is_zero ()); - rai::checksum check3 (ledger.checksum (transaction, 42, std::numeric_limits ::max ())); + rai::checksum check3 (ledger.checksum (transaction, 42, std::numeric_limits::max ())); ASSERT_EQ (hash1, check3); } TEST (system, generate_send_existing) { rai::system system (24000, 1); - rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads); + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::account_info info1; { rai::transaction transaction (system.wallet (0)->store.environment, nullptr, false); - ASSERT_FALSE (system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info1)); + ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, rai::test_genesis_key.pub, info1)); } - std::vector accounts; + std::vector accounts; accounts.push_back (rai::test_genesis_key.pub); - system.generate_send_existing (*system.nodes [0], accounts); + system.generate_send_existing (*system.nodes[0], accounts); rai::account_info info2; { rai::transaction transaction (system.wallet (0)->store.environment, nullptr, false); - ASSERT_FALSE (system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info2)); + ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, rai::test_genesis_key.pub, info2)); } ASSERT_NE (info1.head, info2.head); auto iterations1 (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 20); } auto iterations2 (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) { system.poll (); ++iterations2; @@ -566,21 +566,21 @@ TEST (system, generate_send_existing) TEST (system, generate_send_new) { rai::system system (24000, 1); - rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads); + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - auto iterator1 (system.nodes [0]->store.latest_begin (transaction)); - ASSERT_NE (system.nodes [0]->store.latest_end (), iterator1); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + auto iterator1 (system.nodes[0]->store.latest_begin (transaction)); + ASSERT_NE (system.nodes[0]->store.latest_end (), iterator1); ++iterator1; - ASSERT_EQ (system.nodes [0]->store.latest_end (), iterator1); + ASSERT_EQ (system.nodes[0]->store.latest_end (), iterator1); } - std::vector accounts; + std::vector accounts; accounts.push_back (rai::test_genesis_key.pub); - system.generate_send_new (*system.nodes [0], accounts); + system.generate_send_new (*system.nodes[0], accounts); rai::account new_account (0); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto iterator2 (system.wallet (0)->store.begin (transaction)); if (iterator2->first.uint256 () != rai::test_genesis_key.pub) { @@ -597,7 +597,7 @@ TEST (system, generate_send_new) ASSERT_FALSE (new_account.is_zero ()); } auto iterations (0); - while (system.nodes [0]->balance (new_account) == 0) + while (system.nodes[0]->balance (new_account) == 0) { system.poll (); ++iterations; @@ -718,30 +718,30 @@ TEST (ledegr, double_receive) TEST (votes, add_one) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); { rai::transaction transaction (node1.store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, node1.ledger.process (transaction, *send1).code); } - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } auto votes1 (node1.active.roots.find (send1->root ())->election); ASSERT_EQ (1, votes1->votes.rep_votes.size ()); - auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); + auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); votes1->vote (vote1); - auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send1)); + auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send1)); votes1->vote (vote1); ASSERT_EQ (2, votes1->votes.rep_votes.size ()); auto existing1 (votes1->votes.rep_votes.find (rai::test_genesis_key.pub)); ASSERT_NE (votes1->votes.rep_votes.end (), existing1); ASSERT_EQ (*send1, *existing1->second); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node1.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*send1, *winner.second); ASSERT_EQ (rai::genesis_amount - 100, winner.first); @@ -750,32 +750,32 @@ TEST (votes, add_one) TEST (votes, add_two) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); { rai::transaction transaction (node1.store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, node1.ledger.process (transaction, *send1).code); } - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } auto votes1 (node1.active.roots.find (send1->root ())->election); - auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); + auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); votes1->vote (vote1); rai::keypair key2; - auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto vote2 (std::make_shared (key2.pub, key2.prv, 1, send2)); + auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto vote2 (std::make_shared (key2.pub, key2.prv, 1, send2)); votes1->vote (vote2); ASSERT_EQ (3, votes1->votes.rep_votes.size ()); ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (rai::test_genesis_key.pub)); - ASSERT_EQ (*send1, *votes1->votes.rep_votes [rai::test_genesis_key.pub]); + ASSERT_EQ (*send1, *votes1->votes.rep_votes[rai::test_genesis_key.pub]); ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (key2.pub)); - ASSERT_EQ (*send2, *votes1->votes.rep_votes [key2.pub]); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + ASSERT_EQ (*send2, *votes1->votes.rep_votes[key2.pub]); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node1.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*send1, *winner.second); } @@ -784,30 +784,30 @@ TEST (votes, add_two) TEST (votes, add_existing) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); { rai::transaction transaction (node1.store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, node1.ledger.process (transaction, *send1).code); } - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } auto votes1 (node1.active.roots.find (send1->root ())->election); - auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); + auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send1)); votes1->vote (vote1); rai::keypair key2; - auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send2)); + auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send2)); votes1->vote (vote2); ASSERT_EQ (2, votes1->votes.rep_votes.size ()); ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (rai::test_genesis_key.pub)); - ASSERT_EQ (*send2, *votes1->votes.rep_votes [rai::test_genesis_key.pub]); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + ASSERT_EQ (*send2, *votes1->votes.rep_votes[rai::test_genesis_key.pub]); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node1.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*send2, *winner.second); } @@ -816,30 +816,30 @@ TEST (votes, add_existing) TEST (votes, add_old) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; rai::keypair key1; - auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); { rai::transaction transaction (node1.store.environment, nullptr, true); ASSERT_EQ (rai::process_result::progress, node1.ledger.process (transaction, *send1).code); } - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, send1); } auto votes1 (node1.active.roots.find (send1->root ())->election); - auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send1)); + auto vote1 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 2, send1)); node1.vote_processor.vote (vote1, rai::endpoint ()); rai::keypair key2; - auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); - auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send2)); + auto send2 (std::make_shared (genesis.hash (), key2.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto vote2 (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 1, send2)); node1.vote_processor.vote (vote2, rai::endpoint ()); ASSERT_EQ (2, votes1->votes.rep_votes.size ()); ASSERT_NE (votes1->votes.rep_votes.end (), votes1->votes.rep_votes.find (rai::test_genesis_key.pub)); - ASSERT_EQ (*send1, *votes1->votes.rep_votes [rai::test_genesis_key.pub]); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + ASSERT_EQ (*send1, *votes1->votes.rep_votes[rai::test_genesis_key.pub]); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node1.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*send1, *winner.second); } @@ -851,10 +851,10 @@ TEST (ledger, successor) rai::keypair key1; rai::genesis genesis; rai::send_block send1 (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (transaction, send1).code); - ASSERT_EQ (send1, *system.nodes [0]->ledger.successor (transaction, genesis.hash ())); - ASSERT_EQ (*genesis.open, *system.nodes [0]->ledger.successor (transaction, genesis.open->root ())); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->ledger.process (transaction, send1).code); + ASSERT_EQ (send1, *system.nodes[0]->ledger.successor (transaction, genesis.hash ())); + ASSERT_EQ (*genesis.open, *system.nodes[0]->ledger.successor (transaction, genesis.open->root ())); } TEST (ledger, fail_change_old) diff --git a/rai/core_test/message.cpp b/rai/core_test/message.cpp index 59b46775..d292f48f 100644 --- a/rai/core_test/message.cpp +++ b/rai/core_test/message.cpp @@ -5,7 +5,7 @@ TEST (message, keepalive_serialization) { rai::keepalive request1; - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); request1.serialize (stream); @@ -19,8 +19,8 @@ TEST (message, keepalive_serialization) TEST (message, keepalive_deserialize) { rai::keepalive message1; - message1.peers [0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); - std::vector bytes; + message1.peers[0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); + std::vector bytes; { rai::vectorstream stream (bytes); message1.serialize (stream); @@ -29,7 +29,7 @@ TEST (message, keepalive_deserialize) uint8_t version_using; uint8_t version_min; rai::message_type type; - std::bitset <16> extensions; + std::bitset<16> extensions; rai::bufferstream header_stream (bytes.data (), bytes.size ()); ASSERT_FALSE (rai::message::read_header (header_stream, version_max, version_using, version_min, type, extensions)); ASSERT_EQ (rai::message_type::keepalive, type); @@ -41,31 +41,31 @@ TEST (message, keepalive_deserialize) TEST (message, publish_serialization) { - rai::publish publish (std::unique_ptr (new rai::send_block (0, 1, 2, rai::keypair ().prv, 4, 5))); + rai::publish publish (std::unique_ptr (new rai::send_block (0, 1, 2, rai::keypair ().prv, 4, 5))); ASSERT_EQ (rai::block_type::send, publish.block_type ()); ASSERT_FALSE (publish.ipv4_only ()); publish.ipv4_only_set (true); ASSERT_TRUE (publish.ipv4_only ()); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); publish.write_header (stream); } ASSERT_EQ (8, bytes.size ()); - ASSERT_EQ (0x52, bytes [0]); - ASSERT_EQ (0x41, bytes [1]); - ASSERT_EQ (0x05, bytes [2]); - ASSERT_EQ (0x05, bytes [3]); - ASSERT_EQ (0x01, bytes [4]); - ASSERT_EQ (static_cast (rai::message_type::publish), bytes [5]); - ASSERT_EQ (0x02, bytes [6]); - ASSERT_EQ (static_cast (rai::block_type::send), bytes [7]); + ASSERT_EQ (0x52, bytes[0]); + ASSERT_EQ (0x41, bytes[1]); + ASSERT_EQ (0x05, bytes[2]); + ASSERT_EQ (0x05, bytes[3]); + ASSERT_EQ (0x01, bytes[4]); + ASSERT_EQ (static_cast (rai::message_type::publish), bytes[5]); + ASSERT_EQ (0x02, bytes[6]); + ASSERT_EQ (static_cast (rai::block_type::send), bytes[7]); rai::bufferstream stream (bytes.data (), bytes.size ()); uint8_t version_max; uint8_t version_using; uint8_t version_min; rai::message_type type; - std::bitset <16> extensions; + std::bitset<16> extensions; ASSERT_FALSE (rai::message::read_header (stream, version_max, version_using, version_min, type, extensions)); ASSERT_EQ (0x01, version_min); ASSERT_EQ (0x05, version_using); @@ -76,9 +76,9 @@ TEST (message, publish_serialization) TEST (message, confirm_ack_serialization) { rai::keypair key1; - auto vote (std::make_shared (key1.pub, key1.prv, 0, std::unique_ptr (new rai::send_block (0, 1, 2, key1.prv, 4, 5)))); + auto vote (std::make_shared (key1.pub, key1.prv, 0, std::unique_ptr (new rai::send_block (0, 1, 2, key1.prv, 4, 5)))); rai::confirm_ack con1 (vote); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream1 (bytes); con1.serialize (stream1); diff --git a/rai/core_test/message_parser.cpp b/rai/core_test/message_parser.cpp index 98eb538d..ce6cdb45 100644 --- a/rai/core_test/message_parser.cpp +++ b/rai/core_test/message_parser.cpp @@ -1,7 +1,8 @@ #include #include -namespace { +namespace +{ class test_visitor : public rai::message_visitor { public: @@ -58,10 +59,10 @@ TEST (message_parser, exact_confirm_ack_size) rai::system system (24000, 1); test_visitor visitor; rai::message_parser parser (visitor, system.work); - auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); - auto vote (std::make_shared (0, rai::keypair ().prv, 0, std::move (block))); + auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); + auto vote (std::make_shared (0, rai::keypair ().prv, 0, std::move (block))); rai::confirm_ack message (vote); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); message.serialize (stream); @@ -82,9 +83,9 @@ TEST (message_parser, exact_confirm_req_size) rai::system system (24000, 1); test_visitor visitor; rai::message_parser parser (visitor, system.work); - auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); + auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); rai::confirm_req message (std::move (block)); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); message.serialize (stream); @@ -105,9 +106,9 @@ TEST (message_parser, exact_publish_size) rai::system system (24000, 1); test_visitor visitor; rai::message_parser parser (visitor, system.work); - auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); + auto block (std::unique_ptr (new rai::send_block (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1)))); rai::publish message (std::move (block)); - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); message.serialize (stream); @@ -129,7 +130,7 @@ TEST (message_parser, exact_keepalive_size) test_visitor visitor; rai::message_parser parser (visitor, system.work); rai::keepalive message; - std::vector bytes; + std::vector bytes; { rai::vectorstream stream (bytes); message.serialize (stream); diff --git a/rai/core_test/network.cpp b/rai/core_test/network.cpp index e34d5158..44be2e4b 100644 --- a/rai/core_test/network.cpp +++ b/rai/core_test/network.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include TEST (network, tcp_connection) @@ -14,29 +14,26 @@ TEST (network, tcp_connection) boost::asio::ip::tcp::socket incoming (service); auto done1 (false); std::string message1; - acceptor.async_accept (incoming, - [&done1, &message1] (boost::system::error_code const & ec_a) - { + acceptor.async_accept (incoming, + [&done1, &message1](boost::system::error_code const & ec_a) { if (ec_a) { message1 = ec_a.message (); std::cerr << message1; } - done1 = true;} - ); + done1 = true; }); boost::asio::ip::tcp::socket connector (service); auto done2 (false); std::string message2; - connector.async_connect (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v4::loopback (), 24000), - [&done2, &message2] (boost::system::error_code const & ec_a) + connector.async_connect (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v4::loopback (), 24000), + [&done2, &message2](boost::system::error_code const & ec_a) { + if (ec_a) { - if (ec_a) - { - message2 = ec_a.message (); - std::cerr << message2; - } - done2 = true; - }); + message2 = ec_a.message (); + std::cerr << message2; + } + done2 = true; + }); while (!done1 || !done2) { service.poll (); @@ -49,58 +46,58 @@ TEST (network, construction) { rai::system system (24000, 1); ASSERT_EQ (1, system.nodes.size ()); - ASSERT_EQ (24000, system.nodes [0]->network.socket.local_endpoint ().port ()); + ASSERT_EQ (24000, system.nodes[0]->network.socket.local_endpoint ().port ()); } TEST (network, self_discard) { rai::system system (24000, 1); - system.nodes [0]->network.remote = system.nodes [0]->network.endpoint (); - ASSERT_EQ (0, system.nodes [0]->network.bad_sender_count); - system.nodes [0]->network.receive_action (boost::system::error_code {}, 0); - ASSERT_EQ (1, system.nodes [0]->network.bad_sender_count); + system.nodes[0]->network.remote = system.nodes[0]->network.endpoint (); + ASSERT_EQ (0, system.nodes[0]->network.bad_sender_count); + system.nodes[0]->network.receive_action (boost::system::error_code{}, 0); + ASSERT_EQ (1, system.nodes[0]->network.bad_sender_count); } TEST (network, send_keepalive) { rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); + auto list1 (system.nodes[0]->peers.list ()); ASSERT_EQ (0, list1.size ()); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); node1->start (); - system.nodes [0]->network.send_keepalive (node1->network.endpoint ()); - auto initial (system.nodes [0]->network.incoming.keepalive.load ()); - ASSERT_EQ (0, system.nodes [0]->peers.list ().size ()); + system.nodes[0]->network.send_keepalive (node1->network.endpoint ()); + auto initial (system.nodes[0]->network.incoming.keepalive.load ()); + ASSERT_EQ (0, system.nodes[0]->peers.list ().size ()); ASSERT_EQ (0, node1->peers.list ().size ()); auto iterations (0); - while (system.nodes [0]->network.incoming.keepalive == initial) + while (system.nodes[0]->network.incoming.keepalive == initial) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - auto peers1 (system.nodes [0]->peers.list ()); + auto peers1 (system.nodes[0]->peers.list ()); auto peers2 (node1->peers.list ()); ASSERT_EQ (1, peers1.size ()); ASSERT_EQ (1, peers2.size ()); - ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1] (rai::endpoint const & information_a) {return information_a == node1->network.endpoint ();})); - ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system] (rai::endpoint const & information_a) {return information_a == system.nodes [0]->network.endpoint ();})); + ASSERT_NE (peers1.end (), std::find_if (peers1.begin (), peers1.end (), [&node1](rai::endpoint const & information_a) { return information_a == node1->network.endpoint (); })); + ASSERT_NE (peers2.end (), std::find_if (peers2.begin (), peers2.end (), [&system](rai::endpoint const & information_a) { return information_a == system.nodes[0]->network.endpoint (); })); node1->stop (); } TEST (network, keepalive_ipv4) { rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); + auto list1 (system.nodes[0]->peers.list ()); ASSERT_EQ (0, list1.size ()); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); node1->start (); node1->send_keepalive (rai::endpoint (boost::asio::ip::address_v4::loopback (), 24000)); - auto initial (system.nodes [0]->network.incoming.keepalive.load ()); + auto initial (system.nodes[0]->network.incoming.keepalive.load ()); auto iterations (0); - while (system.nodes [0]->network.incoming.keepalive == initial) + while (system.nodes[0]->network.incoming.keepalive == initial) { system.poll (); ++iterations; @@ -112,30 +109,30 @@ TEST (network, keepalive_ipv4) TEST (network, multi_keepalive) { rai::system system (24000, 1); - auto list1 (system.nodes [0]->peers.list ()); + auto list1 (system.nodes[0]->peers.list ()); ASSERT_EQ (0, list1.size ()); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); node1->start (); ASSERT_EQ (0, node1->peers.size ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->network.send_keepalive (system.nodes[0]->network.endpoint ()); ASSERT_EQ (0, node1->peers.size ()); - ASSERT_EQ (0, system.nodes [0]->peers.size ()); + ASSERT_EQ (0, system.nodes[0]->peers.size ()); auto iterations1 (0); - while (system.nodes [0]->peers.size () != 1) + while (system.nodes[0]->peers.size () != 1) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); } rai::node_init init2; - auto node2 (std::make_shared (init2, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node2 (std::make_shared (init2, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init2.error ()); node2->start (); - node2->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node2->network.send_keepalive (system.nodes[0]->network.endpoint ()); auto iterations2 (0); - while (node1->peers.size () != 2 || system.nodes [0]->peers.size () != 2 || node2->peers.size () != 2) + while (node1->peers.size () != 2 || system.nodes[0]->peers.size () != 2 || node2->peers.size () != 2) { system.poll (); ++iterations2; @@ -148,47 +145,47 @@ TEST (network, multi_keepalive) TEST (network, send_discarded_publish) { rai::system system (24000, 2); - auto block (std::make_shared (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))); + auto block (std::make_shared (1, 1, 2, rai::keypair ().prv, 4, system.work.generate (1))); rai::genesis genesis; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->network.republish_block (transaction, block); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->network.republish_block (transaction, block); + ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (rai::test_genesis_key.pub)); } auto iterations (0); - while (system.nodes [1]->network.incoming.publish == 0) + while (system.nodes[1]->network.incoming.publish == 0) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (rai::test_genesis_key.pub)); } TEST (network, send_invalid_publish) { rai::system system (24000, 2); rai::genesis genesis; - auto block (std::make_shared (1, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (1))); + auto block (std::make_shared (1, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (1))); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->network.republish_block (transaction, block); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->network.republish_block (transaction, block); + ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (rai::test_genesis_key.pub)); } auto iterations (0); - while (system.nodes [1]->network.incoming.publish == 0) + while (system.nodes[1]->network.incoming.publish == 0) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (genesis.hash (), system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub)); - ASSERT_EQ (genesis.hash (), system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_EQ (genesis.hash (), system.nodes[0]->ledger.latest (transaction, rai::test_genesis_key.pub)); + ASSERT_EQ (genesis.hash (), system.nodes[1]->latest (rai::test_genesis_key.pub)); } TEST (network, send_valid_confirm_ack) @@ -197,20 +194,20 @@ TEST (network, send_valid_confirm_ack) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (1)->insert_adhoc (key2.prv); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); - rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); - system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (block2))); + rai::block_hash latest2 (system.nodes[1]->latest (rai::test_genesis_key.pub)); + system.nodes[0]->process_active (std::unique_ptr (new rai::send_block (block2))); auto iterations (0); // Keep polling until latest block changes - while (system.nodes [1]->latest (rai::test_genesis_key.pub) == latest2) + while (system.nodes[1]->latest (rai::test_genesis_key.pub) == latest2) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } // Make sure the balance has decreased after procssing the block. - ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (50, system.nodes[1]->balance (rai::test_genesis_key.pub)); } TEST (network, send_valid_publish) @@ -219,61 +216,61 @@ TEST (network, send_valid_publish) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block block2 (latest1, key2.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1)); auto hash2 (block2.hash ()); - rai::block_hash latest2 (system.nodes [1]->latest (rai::test_genesis_key.pub)); - system.nodes [1]->process_active (std::unique_ptr (new rai::send_block (block2))); + rai::block_hash latest2 (system.nodes[1]->latest (rai::test_genesis_key.pub)); + system.nodes[1]->process_active (std::unique_ptr (new rai::send_block (block2))); auto iterations (0); - while (system.nodes [0]->network.incoming.publish == 0) + while (system.nodes[0]->network.incoming.publish == 0) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - rai::block_hash latest3 (system.nodes [1]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest3 (system.nodes[1]->latest (rai::test_genesis_key.pub)); ASSERT_NE (latest2, latest3); ASSERT_EQ (hash2, latest3); - ASSERT_EQ (50, system.nodes [1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (50, system.nodes[1]->balance (rai::test_genesis_key.pub)); } TEST (network, send_insufficient_work) { rai::system system (24000, 2); - std::unique_ptr block (new rai::send_block (0, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + std::unique_ptr block (new rai::send_block (0, 1, 20, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); rai::publish publish (std::move (block)); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); publish.serialize (stream); } - auto node1 (system.nodes [1]->shared ()); - system.nodes [0]->network.send_buffer (bytes->data (), bytes->size (), system.nodes [1]->network.endpoint (), [bytes, node1] (boost::system::error_code const & ec, size_t size) {}); - ASSERT_EQ (0, system.nodes [0]->network.insufficient_work_count); + auto node1 (system.nodes[1]->shared ()); + system.nodes[0]->network.send_buffer (bytes->data (), bytes->size (), system.nodes[1]->network.endpoint (), [bytes, node1](boost::system::error_code const & ec, size_t size) {}); + ASSERT_EQ (0, system.nodes[0]->network.insufficient_work_count); auto iterations (0); - while (system.nodes [1]->network.insufficient_work_count == 0) + while (system.nodes[1]->network.insufficient_work_count == 0) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (1, system.nodes [1]->network.insufficient_work_count); + ASSERT_EQ (1, system.nodes[1]->network.insufficient_work_count); } TEST (receivable_processor, confirm_insufficient_pos) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; - auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*block1).code); - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, block1); } rai::keypair key1; - auto vote (std::make_shared (key1.pub, key1.prv, 0, block1)); + auto vote (std::make_shared (key1.pub, key1.prv, 0, block1)); rai::confirm_ack con1 (vote); node1.process_message (con1, node1.network.endpoint ()); } @@ -281,52 +278,52 @@ TEST (receivable_processor, confirm_insufficient_pos) TEST (receivable_processor, confirm_sufficient_pos) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::genesis genesis; - auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto block1 (std::make_shared (genesis.hash (), 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); ASSERT_EQ (rai::process_result::progress, node1.process (*block1).code); - auto node_l (system.nodes [0]); + auto node_l (system.nodes[0]); { rai::transaction transaction (node1.store.environment, nullptr, true); node1.active.start (transaction, block1); } - auto vote (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 0, block1)); + auto vote (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, 0, block1)); rai::confirm_ack con1 (vote); node1.process_message (con1, node1.network.endpoint ()); } TEST (receivable_processor, send_with_receive) { - auto amount (std::numeric_limits ::max ()); + auto amount (std::numeric_limits::max ()); rai::system system (24000, 2); rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); system.wallet (1)->insert_adhoc (key2.prv); - auto block1 (std::make_shared (latest1, key2.pub, amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1))); - ASSERT_EQ (amount, system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (0, system.nodes [0]->balance (key2.pub)); - ASSERT_EQ (amount, system.nodes [1]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (0, system.nodes [1]->balance (key2.pub)); - system.nodes [0]->process_active (block1); - system.nodes [0]->block_processor.flush (); - system.nodes [1]->process_active (block1); - system.nodes [1]->block_processor.flush (); - ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (0, system.nodes [0]->balance (key2.pub)); - ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [1]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (0, system.nodes [1]->balance (key2.pub)); + auto block1 (std::make_shared (latest1, key2.pub, amount - system.nodes[0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (latest1))); + ASSERT_EQ (amount, system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[0]->balance (key2.pub)); + ASSERT_EQ (amount, system.nodes[1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[1]->balance (key2.pub)); + system.nodes[0]->process_active (block1); + system.nodes[0]->block_processor.flush (); + system.nodes[1]->process_active (block1); + system.nodes[1]->block_processor.flush (); + ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[0]->balance (key2.pub)); + ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[1]->balance (key2.pub)); auto iterations (0); - while (system.nodes [0]->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (key2.pub)); - ASSERT_EQ (amount - system.nodes [0]->config.receive_minimum.number (), system.nodes [1]->balance (rai::test_genesis_key.pub)); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.number (), system.nodes [1]->balance (key2.pub)); + ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (key2.pub)); + ASSERT_EQ (amount - system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.number (), system.nodes[1]->balance (key2.pub)); } TEST (network, receive_weight_change) @@ -336,12 +333,12 @@ TEST (network, receive_weight_change) rai::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); { - rai::transaction transaction (system.nodes [1]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[1]->store.environment, nullptr, true); system.wallet (1)->store.representative_set (transaction, key2.pub); } - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) { return node_a->weight (key2.pub) != system.nodes [0]->config.receive_minimum.number (); })) + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->weight (key2.pub) != system.nodes[0]->config.receive_minimum.number (); })) { system.poll (); ++iterations; @@ -397,12 +394,12 @@ TEST (parse_endpoint, no_colon) TEST (bulk_pull, no_address) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::bulk_pull); req->start = 1; req->end = 2; - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_EQ (request->current, request->request->end); ASSERT_TRUE (request->current.is_zero ()); } @@ -410,13 +407,13 @@ TEST (bulk_pull, no_address) TEST (bulk_pull, genesis_to_end) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::bulk_pull{}); req->start = rai::test_genesis_key.pub; req->end.clear (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (system.nodes[0]->latest (rai::test_genesis_key.pub), request->current); ASSERT_EQ (request->request->end, request->request->end); } @@ -424,13 +421,13 @@ TEST (bulk_pull, genesis_to_end) TEST (bulk_pull, no_end) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::bulk_pull{}); req->start = rai::test_genesis_key.pub; req->end = 1; - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); - ASSERT_EQ (system.nodes [0]->latest (rai::test_genesis_key.pub), request->current); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); + ASSERT_EQ (system.nodes[0]->latest (rai::test_genesis_key.pub), request->current); ASSERT_TRUE (request->request->end.is_zero ()); } @@ -440,33 +437,33 @@ TEST (bulk_pull, end_not_owned) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 100)); - rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::open_block open (0, 1, 2, rai::keypair ().prv, 4, 5); open.hashables.account = key2.pub; open.hashables.representative = key2.pub; open.hashables.source = latest; open.signature = rai::sign_message (key2.prv, key2.pub, open.hash ()); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - auto connection (std::make_shared (nullptr, system.nodes [0])); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + auto connection (std::make_shared (nullptr, system.nodes[0])); rai::genesis genesis; - std::unique_ptr req (new rai::bulk_pull {}); + std::unique_ptr req (new rai::bulk_pull{}); req->start = key2.pub; req->end = genesis.hash (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_EQ (request->current, request->request->end); } TEST (bulk_pull, none) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); + auto connection (std::make_shared (nullptr, system.nodes[0])); rai::genesis genesis; - std::unique_ptr req (new rai::bulk_pull {}); + std::unique_ptr req (new rai::bulk_pull{}); req->start = genesis.hash (); req->end = genesis.hash (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); auto block (request->get_next ()); ASSERT_EQ (nullptr, block); } @@ -474,12 +471,12 @@ TEST (bulk_pull, none) TEST (bulk_pull, get_next_on_open) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::bulk_pull {}); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::bulk_pull{}); req->start = rai::test_genesis_key.pub; req->end.clear (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); auto block (request->get_next ()); ASSERT_NE (nullptr, block); ASSERT_TRUE (block->previous ().is_zero ()); @@ -491,10 +488,10 @@ TEST (bootstrap_processor, DISABLED_process_none) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); auto done (false); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); while (!done) { system.service.run_one (); @@ -509,14 +506,14 @@ TEST (bootstrap_processor, process_one) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, 100)); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); - rai::block_hash hash1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + rai::block_hash hash1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::block_hash hash2 (node1->latest (rai::test_genesis_key.pub)); ASSERT_NE (hash1, hash2); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); - ASSERT_NE (node1->latest (rai::test_genesis_key.pub), system.nodes [0]->latest (rai::test_genesis_key.pub)); - while (node1->latest (rai::test_genesis_key.pub) != system.nodes [0]->latest (rai::test_genesis_key.pub)) + ASSERT_NE (node1->latest (rai::test_genesis_key.pub), system.nodes[0]->latest (rai::test_genesis_key.pub)); + while (node1->latest (rai::test_genesis_key.pub) != system.nodes[0]->latest (rai::test_genesis_key.pub)) { system.poll (); ++iterations; @@ -530,21 +527,21 @@ TEST (bootstrap_processor, process_two) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::block_hash hash1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash hash1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, 50)); - rai::block_hash hash2 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash hash2 (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, 50)); - rai::block_hash hash3 (system.nodes [0]->latest ( rai::test_genesis_key.pub)); + rai::block_hash hash3 (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_NE (hash1, hash2); ASSERT_NE (hash1, hash3); ASSERT_NE (hash2, hash3); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); - ASSERT_NE (node1->latest (rai::test_genesis_key.pub), system.nodes [0]->latest (rai::test_genesis_key.pub)); - while (node1->latest (rai::test_genesis_key.pub) != system.nodes [0]->latest (rai::test_genesis_key.pub)) + ASSERT_NE (node1->latest (rai::test_genesis_key.pub), system.nodes[0]->latest (rai::test_genesis_key.pub)); + while (node1->latest (rai::test_genesis_key.pub) != system.nodes[0]->latest (rai::test_genesis_key.pub)) { system.poll (); ++iterations; @@ -559,20 +556,20 @@ TEST (bootstrap_processor, process_new) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; system.wallet (1)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations1 (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); } - rai::uint128_t balance1 (system.nodes [0]->balance (rai::test_genesis_key.pub)); - rai::uint128_t balance2 (system.nodes [0]->balance (key2.pub)); + rai::uint128_t balance1 (system.nodes[0]->balance (rai::test_genesis_key.pub)); + rai::uint128_t balance2 (system.nodes[0]->balance (key2.pub)); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations2 (0); while (node1->balance (key2.pub) != balance2) { @@ -588,18 +585,18 @@ TEST (bootstrap_processor, pull_diamond) { rai::system system (24000, 1); rai::keypair key; - std::unique_ptr send1 (new rai::send_block (system.nodes [0]->latest (rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (system.nodes [0]->latest (rai::test_genesis_key.pub)))); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (*send1).code); - std::unique_ptr open (new rai::open_block (send1->hash (), 1, key.pub, key.prv, key.pub, system.work.generate (key.pub))); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (*open).code); - std::unique_ptr send2 (new rai::send_block (open->hash (), rai::test_genesis_key.pub, std::numeric_limits ::max () - 100, key.prv, key.pub, system.work.generate (open->hash ()))); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (*send2).code); - std::unique_ptr receive (new rai::receive_block (send1->hash (), send2->hash (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (*receive).code); + std::unique_ptr send1 (new rai::send_block (system.nodes[0]->latest (rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (system.nodes[0]->latest (rai::test_genesis_key.pub)))); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (*send1).code); + std::unique_ptr open (new rai::open_block (send1->hash (), 1, key.pub, key.prv, key.pub, system.work.generate (key.pub))); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (*open).code); + std::unique_ptr send2 (new rai::send_block (open->hash (), rai::test_genesis_key.pub, std::numeric_limits::max () - 100, key.prv, key.pub, system.work.generate (open->hash ()))); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (*send2).code); + std::unique_ptr receive (new rai::receive_block (send1->hash (), send2->hash (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (*receive).code); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); while (node1->balance (rai::test_genesis_key.pub) != 100) { @@ -616,28 +613,28 @@ TEST (bootstrap_processor, push_diamond) rai::system system (24000, 1); rai::keypair key; rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24002, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); auto wallet1 (node1->wallets.create (100)); wallet1->insert_adhoc (rai::test_genesis_key.prv); wallet1->insert_adhoc (key.prv); - std::unique_ptr send1 (new rai::send_block (system.nodes [0]->latest (rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (system.nodes [0]->latest (rai::test_genesis_key.pub)))); + std::unique_ptr send1 (new rai::send_block (system.nodes[0]->latest (rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (system.nodes[0]->latest (rai::test_genesis_key.pub)))); ASSERT_EQ (rai::process_result::progress, node1->process (*send1).code); - std::unique_ptr open (new rai::open_block (send1->hash (), 1, key.pub, key.prv, key.pub, system.work.generate (key.pub))); + std::unique_ptr open (new rai::open_block (send1->hash (), 1, key.pub, key.prv, key.pub, system.work.generate (key.pub))); ASSERT_EQ (rai::process_result::progress, node1->process (*open).code); - std::unique_ptr send2 (new rai::send_block (open->hash (), rai::test_genesis_key.pub, std::numeric_limits ::max () - 100, key.prv, key.pub, system.work.generate (open->hash ()))); + std::unique_ptr send2 (new rai::send_block (open->hash (), rai::test_genesis_key.pub, std::numeric_limits::max () - 100, key.prv, key.pub, system.work.generate (open->hash ()))); ASSERT_EQ (rai::process_result::progress, node1->process (*send2).code); - std::unique_ptr receive (new rai::receive_block (send1->hash (), send2->hash (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); + std::unique_ptr receive (new rai::receive_block (send1->hash (), send2->hash (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1->hash ()))); ASSERT_EQ (rai::process_result::progress, node1->process (*receive).code); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) != 100) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != 100) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (100, system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (100, system.nodes[0]->balance (rai::test_genesis_key.pub)); node1->stop (); } @@ -646,16 +643,16 @@ TEST (bootstrap_processor, push_one) rai::system system (24000, 1); rai::node_init init1; rai::keypair key1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); auto wallet (node1->wallets.create (rai::uint256_union ())); ASSERT_NE (nullptr, wallet); wallet->insert_adhoc (rai::test_genesis_key.prv); rai::uint128_t balance1 (node1->balance (rai::test_genesis_key.pub)); ASSERT_NE (nullptr, wallet->send_action (rai::test_genesis_key.pub, key1.pub, 100)); ASSERT_NE (balance1, node1->balance (rai::test_genesis_key.pub)); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance1) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) == balance1) { system.poll (); ++iterations; @@ -667,16 +664,16 @@ TEST (bootstrap_processor, push_one) TEST (frontier_req_response, DISABLED_destruction) { { - std::shared_ptr hold; // Destructing tcp acceptor on non-existent io_service + std::shared_ptr hold; // Destructing tcp acceptor on non-existent io_service { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::frontier_req); req->start.clear (); - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - hold = std::make_shared (connection, std::move (req)); + req->age = std::numeric_limitsage)>::max (); + req->count = std::numeric_limitscount)>::max (); + connection->requests.push (std::unique_ptr{}); + hold = std::make_shared (connection, std::move (req)); } } ASSERT_TRUE (true); @@ -685,13 +682,13 @@ TEST (frontier_req_response, DISABLED_destruction) TEST (frontier_req, begin) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::frontier_req); req->start.clear (); - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + req->age = std::numeric_limitsage)>::max (); + req->count = std::numeric_limitscount)>::max (); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_EQ (rai::test_genesis_key.pub, request->current); rai::genesis genesis; ASSERT_EQ (genesis.hash (), request->info.head); @@ -700,39 +697,39 @@ TEST (frontier_req, begin) TEST (frontier_req, end) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::frontier_req); req->start = rai::test_genesis_key.pub.number () + 1; - req->age = std::numeric_limits age)>::max (); - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + req->age = std::numeric_limitsage)>::max (); + req->count = std::numeric_limitscount)>::max (); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_TRUE (request->current.is_zero ()); } TEST (frontier_req, time_bound) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::frontier_req); req->start.clear (); req->age = 0; - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + req->count = std::numeric_limitscount)>::max (); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_TRUE (request->current.is_zero ()); } TEST (frontier_req, time_cutoff) { rai::system system (24000, 1); - auto connection (std::make_shared (nullptr, system.nodes [0])); - std::unique_ptr req (new rai::frontier_req); + auto connection (std::make_shared (nullptr, system.nodes[0])); + std::unique_ptr req (new rai::frontier_req); req->start.clear (); req->age = 10; - req->count = std::numeric_limits count)>::max (); - connection->requests.push (std::unique_ptr {}); - auto request (std::make_shared (connection, std::move (req))); + req->count = std::numeric_limitscount)>::max (); + connection->requests.push (std::unique_ptr{}); + auto request (std::make_shared (connection, std::move (req))); ASSERT_EQ (rai::test_genesis_key.pub, request->current); rai::genesis genesis; ASSERT_EQ (genesis.hash (), request->info.head); @@ -743,24 +740,24 @@ TEST (bulk, genesis) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::block_hash latest2 (node1->latest (rai::test_genesis_key.pub)); ASSERT_EQ (latest1, latest2); rai::keypair key2; ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 100)); - rai::block_hash latest3 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest3 (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_NE (latest1, latest3); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations (0); - while (node1->latest (rai::test_genesis_key.pub) != system.nodes [0]->latest (rai::test_genesis_key.pub)) + while (node1->latest (rai::test_genesis_key.pub) != system.nodes[0]->latest (rai::test_genesis_key.pub)) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (node1->latest (rai::test_genesis_key.pub), system.nodes [0]->latest (rai::test_genesis_key.pub)); + ASSERT_EQ (node1->latest (rai::test_genesis_key.pub), system.nodes[0]->latest (rai::test_genesis_key.pub)); node1->stop (); } @@ -769,9 +766,9 @@ TEST (bulk, offline_send) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->network.send_keepalive (system.nodes[0]->network.endpoint ()); node1->start (); auto iterations (0); do @@ -779,15 +776,15 @@ TEST (bulk, offline_send) system.poll (); ++iterations; ASSERT_LT (iterations, 200); - } while (system.nodes [0]->peers.empty () || node1->peers.empty ()); + } while (system.nodes[0]->peers.empty () || node1->peers.empty ()); rai::keypair key2; auto wallet (node1->wallets.create (rai::uint256_union ())); wallet->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_NE (std::numeric_limits ::max (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - node1->bootstrap_initiator.bootstrap (system.nodes [0]->network.endpoint ()); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_NE (std::numeric_limits::max (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + node1->bootstrap_initiator.bootstrap (system.nodes[0]->network.endpoint ()); auto iterations2 (0); - while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations2; @@ -801,7 +798,7 @@ TEST (network, ipv6) boost::asio::ip::address_v6 address (boost::asio::ip::address_v6::from_string ("::ffff:127.0.0.1")); ASSERT_TRUE (address.is_v4_mapped ()); rai::endpoint endpoint1 (address, 16384); - std::vector bytes1; + std::vector bytes1; { rai::vectorstream stream (bytes1); rai::write (stream, address.to_bytes ()); @@ -811,9 +808,9 @@ TEST (network, ipv6) { ASSERT_EQ (0, *i); } - ASSERT_EQ (0xff, bytes1 [10]); - ASSERT_EQ (0xff, bytes1 [11]); - std::array bytes2; + ASSERT_EQ (0xff, bytes1[10]); + ASSERT_EQ (0xff, bytes1[11]); + std::array bytes2; rai::bufferstream stream (bytes1.data (), bytes1.size ()); rai::read (stream, bytes2); rai::endpoint endpoint2 (boost::asio::ip::address_v6 (bytes2), 16384); @@ -822,7 +819,7 @@ TEST (network, ipv6) TEST (network, ipv6_from_ipv4) { - rai::endpoint endpoint1 (boost::asio::ip::address_v4::loopback(), 16000); + rai::endpoint endpoint1 (boost::asio::ip::address_v4::loopback (), 16000); ASSERT_TRUE (endpoint1.address ().is_v4 ()); rai::endpoint endpoint2 (boost::asio::ip::address_v6::v4_mapped (endpoint1.address ().to_v4 ()), 16000); ASSERT_TRUE (endpoint2.address ().is_v6 ()); @@ -833,12 +830,11 @@ TEST (network, ipv6_bind_send_ipv4) boost::asio::io_service service; rai::endpoint endpoint1 (boost::asio::ip::address_v6::any (), 24000); rai::endpoint endpoint2 (boost::asio::ip::address_v4::any (), 24001); - std::array bytes1; + std::array bytes1; auto finish1 (false); rai::endpoint endpoint3; boost::asio::ip::udp::socket socket1 (service, endpoint1); - socket1.async_receive_from (boost::asio::buffer (bytes1.data (), bytes1.size ()), endpoint3, [&finish1] (boost::system::error_code const & error, size_t size_a) - { + socket1.async_receive_from (boost::asio::buffer (bytes1.data (), bytes1.size ()), endpoint3, [&finish1](boost::system::error_code const & error, size_t size_a) { ASSERT_FALSE (error); ASSERT_EQ (16, size_a); finish1 = true; @@ -846,8 +842,7 @@ TEST (network, ipv6_bind_send_ipv4) boost::asio::ip::udp::socket socket2 (service, endpoint2); rai::endpoint endpoint5 (boost::asio::ip::address_v4::loopback (), 24000); rai::endpoint endpoint6 (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4::loopback ()), 24001); - socket2.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint5, [] (boost::system::error_code const & error, size_t size_a) - { + socket2.async_send_to (boost::asio::buffer (std::array{}, 16), endpoint5, [](boost::system::error_code const & error, size_t size_a) { ASSERT_FALSE (error); ASSERT_EQ (16, size_a); }); @@ -855,20 +850,18 @@ TEST (network, ipv6_bind_send_ipv4) while (!finish1) { service.poll (); - ++iterations; - ASSERT_LT (iterations, 200); + ++iterations; + ASSERT_LT (iterations, 200); } ASSERT_EQ (endpoint6, endpoint3); - std::array bytes2; + std::array bytes2; auto finish2 (false); rai::endpoint endpoint4; - socket2.async_receive_from (boost::asio::buffer (bytes2.data (), bytes2.size ()), endpoint4, [&finish2] (boost::system::error_code const & error, size_t size_a) - { + socket2.async_receive_from (boost::asio::buffer (bytes2.data (), bytes2.size ()), endpoint4, [&finish2](boost::system::error_code const & error, size_t size_a) { ASSERT_FALSE (!error); ASSERT_EQ (16, size_a); }); - socket1.async_send_to (boost::asio::buffer (std::array {}, 16), endpoint6, [] (boost::system::error_code const & error, size_t size_a) - { + socket1.async_send_to (boost::asio::buffer (std::array{}, 16), endpoint6, [](boost::system::error_code const & error, size_t size_a) { ASSERT_FALSE (error); ASSERT_EQ (16, size_a); }); @@ -877,8 +870,8 @@ TEST (network, ipv6_bind_send_ipv4) TEST (network, endpoint_bad_fd) { rai::system system (24000, 1); - system.nodes [0]->stop (); - auto endpoint (system.nodes [0]->network.endpoint ()); + system.nodes[0]->stop (); + auto endpoint (system.nodes[0]->network.endpoint ()); ASSERT_TRUE (endpoint.address ().is_loopback ()); ASSERT_EQ (0, endpoint.port ()); } @@ -891,7 +884,7 @@ TEST (network, reserved_address) TEST (node, port_mapping) { rai::system system (24000, 1); - auto node0 (system.nodes [0]); + auto node0 (system.nodes[0]); node0->port_mapping.refresh_devices (); node0->port_mapping.start (); auto end (std::chrono::system_clock::now () + std::chrono::seconds (500)); diff --git a/rai/core_test/node.cpp b/rai/core_test/node.cpp index 7e9eee88..55c6f91d 100644 --- a/rai/core_test/node.cpp +++ b/rai/core_test/node.cpp @@ -7,8 +7,8 @@ TEST (node, stop) { rai::system system (24000, 1); - ASSERT_NE (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.begin ()); - system.nodes [0]->stop (); + ASSERT_NE (system.nodes[0]->wallets.items.end (), system.nodes[0]->wallets.items.begin ()); + system.nodes[0]->stop (); system.service.run (); ASSERT_TRUE (true); } @@ -16,13 +16,13 @@ TEST (node, stop) TEST (node, block_store_path_failure) { rai::node_init init; - auto service (boost::make_shared ()); + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::logging logging; logging.init (path); - rai::work_pool work (std::numeric_limits ::max (), nullptr); - auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); + rai::work_pool work (std::numeric_limits::max (), nullptr); + auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); ASSERT_TRUE (node->wallets.items.empty ()); node->stop (); } @@ -30,14 +30,14 @@ TEST (node, block_store_path_failure) TEST (node, inactive_supply) { rai::node_init init; - auto service (boost::make_shared ()); + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::node_config config; config.logging.init (path); - rai::work_pool work (std::numeric_limits ::max (), nullptr); + rai::work_pool work (std::numeric_limits::max (), nullptr); config.inactive_supply = 10; - auto node (std::make_shared (init, *service, path, alarm, config, work)); + auto node (std::make_shared (init, *service, path, alarm, config, work)); ASSERT_EQ (10, node->ledger.inactive_supply); node->stop (); } @@ -45,14 +45,14 @@ TEST (node, inactive_supply) TEST (node, password_fanout) { rai::node_init init; - auto service (boost::make_shared ()); + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::node_config config; config.logging.init (path); - rai::work_pool work (std::numeric_limits ::max (), nullptr); + rai::work_pool work (std::numeric_limits::max (), nullptr); config.password_fanout = 10; - auto node (std::make_shared (init, *service, path, alarm, config, work)); + auto node (std::make_shared (init, *service, path, alarm, config, work)); auto wallet (node->wallets.create (100)); ASSERT_EQ (10, wallet->store.password.values.size ()); node->stop (); @@ -62,20 +62,20 @@ TEST (node, balance) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); - ASSERT_EQ (std::numeric_limits ::max (), system.nodes [0]->ledger.account_balance (transaction, rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); + ASSERT_EQ (std::numeric_limits::max (), system.nodes[0]->ledger.account_balance (transaction, rai::test_genesis_key.pub)); } TEST (node, representative) { rai::system system (24000, 1); - auto block1 (system.nodes [0]->representative (rai::test_genesis_key.pub)); + auto block1 (system.nodes[0]->representative (rai::test_genesis_key.pub)); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_TRUE (system.nodes [0]->ledger.store.block_exists (transaction, block1)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_TRUE (system.nodes[0]->ledger.store.block_exists (transaction, block1)); } rai::keypair key; - ASSERT_TRUE (system.nodes [0]->representative (key.pub).is_zero ()); + ASSERT_TRUE (system.nodes[0]->representative (key.pub).is_zero ()); } TEST (node, send_unkeyed) @@ -84,7 +84,7 @@ TEST (node, send_unkeyed) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->store.password.value_set (rai::keypair ().prv); - ASSERT_EQ (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_EQ (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); } TEST (node, send_self) @@ -93,15 +93,15 @@ TEST (node, send_self) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); } TEST (node, send_single) @@ -110,11 +110,11 @@ TEST (node, send_single) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (1)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_EQ (std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ()); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); auto iterations (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations; @@ -128,11 +128,11 @@ TEST (node, send_single_observing_peer) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (1)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_EQ (std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ()); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero (); })) + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero (); })) { system.poll (); ++iterations; @@ -146,11 +146,11 @@ TEST (node, send_single_many_peers) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (1)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_EQ (std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); - ASSERT_TRUE (system.nodes [0]->balance (key2.pub).is_zero ()); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); + ASSERT_TRUE (system.nodes[0]->balance (key2.pub).is_zero ()); auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero(); })) + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (key2.pub).is_zero (); })) { system.poll (); ++iterations; @@ -163,12 +163,12 @@ TEST (node, send_out_of_order) rai::system system (24000, 2); rai::keypair key2; rai::genesis genesis; - rai::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())); - rai::send_block send2 (send1.hash (), key2.pub, std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number () * 2, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1.hash ())); - system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (send2))); - system.nodes [0]->process_active (std::unique_ptr (new rai::send_block (send1))); + rai::send_block send1 (genesis.hash (), key2.pub, std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ())); + rai::send_block send2 (send1.hash (), key2.pub, std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number () * 2, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (send1.hash ())); + system.nodes[0]->process_active (std::unique_ptr (new rai::send_block (send2))); + system.nodes[0]->process_active (std::unique_ptr (new rai::send_block (send1))); auto iterations (0); - while (std::any_of (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) {return node_a->balance (rai::test_genesis_key.pub) != rai::genesis_amount - system.nodes [0]->config.receive_minimum.number () * 2;})) + while (std::any_of (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { return node_a->balance (rai::test_genesis_key.pub) != rai::genesis_amount - system.nodes[0]->config.receive_minimum.number () * 2; })) { system.poll (); ++iterations; @@ -180,12 +180,12 @@ TEST (node, quick_confirm) { rai::system system (24000, 1); rai::keypair key; - rai::block_hash previous (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash previous (system.nodes[0]->latest (rai::test_genesis_key.pub)); system.wallet (0)->insert_adhoc (key.prv); - auto send (std::make_shared (previous, key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (previous))); - system.nodes [0]->process_active (send); + auto send (std::make_shared (previous, key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (previous))); + system.nodes[0]->process_active (send); auto iterations (0); - while (system.nodes [0]->balance (key.pub).is_zero ()) + while (system.nodes[0]->balance (key.pub).is_zero ()) { system.poll (); ++iterations; @@ -199,25 +199,25 @@ TEST (node, auto_bootstrap) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations1 (0); - while (system.nodes [0]->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + while (system.nodes[0]->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); } rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->network.send_keepalive (system.nodes[0]->network.endpoint ()); node1->start (); while (!node1->bootstrap_initiator.in_progress ()) { system.poll (); } auto iterations3 (0); - while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations3; @@ -240,13 +240,13 @@ TEST (node, auto_bootstrap_reverse) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - system.nodes [0]->network.send_keepalive (node1->network.endpoint ()); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + system.nodes[0]->network.send_keepalive (node1->network.endpoint ()); node1->start (); auto iterations (0); - while (node1->balance (key2.pub) != system.nodes [0]->config.receive_minimum.number ()) + while (node1->balance (key2.pub) != system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations; @@ -258,9 +258,9 @@ TEST (node, auto_bootstrap_reverse) TEST (node, receive_gap) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); ASSERT_EQ (0, node1.gap_cache.blocks.size ()); - auto block (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); + auto block (std::make_shared (0, 1, 2, rai::keypair ().prv, 4, 5)); rai::confirm_req message; message.block = block; node1.process_message (message, node1.network.endpoint ()); @@ -271,11 +271,11 @@ TEST (node, receive_gap) TEST (node, merge_peers) { rai::system system (24000, 1); - std::array endpoints; + std::array endpoints; endpoints.fill (rai::endpoint (boost::asio::ip::address_v6::loopback (), 24000)); - endpoints [0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 24001); - system.nodes [0]->network.merge_peers (endpoints); - ASSERT_EQ (0, system.nodes [0]->peers.peers.size ()); + endpoints[0] = rai::endpoint (boost::asio::ip::address_v6::loopback (), 24001); + system.nodes[0]->network.merge_peers (endpoints); + ASSERT_EQ (0, system.nodes[0]->peers.peers.size ()); } TEST (node, search_pending) @@ -283,12 +283,12 @@ TEST (node, search_pending) rai::system system (24000, 1); rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); - auto node (system.nodes [0]); + auto node (system.nodes[0]); ASSERT_FALSE (system.wallet (0)->search_pending ()); auto iterations2 (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations2; @@ -301,13 +301,13 @@ TEST (node, search_pending_same) rai::system system (24000, 1); rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); - auto node (system.nodes [0]); + auto node (system.nodes[0]); ASSERT_FALSE (system.wallet (0)->search_pending ()); auto iterations2 (0); - while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ()) + while (system.nodes[0]->balance (key2.pub) != 2 * system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations2; @@ -322,21 +322,21 @@ TEST (node, search_pending_multiple) rai::keypair key3; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key3.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key3.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key3.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations1 (0); - while (system.nodes [0]->balance (key3.pub).is_zero ()) + while (system.nodes[0]->balance (key3.pub).is_zero ()) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); } - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); - ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (key3.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); system.wallet (0)->insert_adhoc (key2.prv); - auto node (system.nodes [0]); + auto node (system.nodes[0]); ASSERT_FALSE (system.wallet (0)->search_pending ()); auto iterations2 (0); - while (system.nodes [0]->balance (key2.pub) != 2 * system.nodes [0]->config.receive_minimum.number ()) + while (system.nodes[0]->balance (key2.pub) != 2 * system.nodes[0]->config.receive_minimum.number ()) { system.poll (); ++iterations2; @@ -348,15 +348,15 @@ TEST (node, unlock_search) { rai::system system (24000, 1); rai::keypair key2; - rai::uint128_t balance (system.nodes [0]->balance (rai::test_genesis_key.pub)); + rai::uint128_t balance (system.nodes[0]->balance (rai::test_genesis_key.pub)); { rai::transaction transaction (system.wallet (0)->store.environment, nullptr, true); system.wallet (0)->store.rekey (transaction, ""); } system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations1 (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) == balance) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) == balance) { system.poll (); ++iterations1; @@ -364,10 +364,10 @@ TEST (node, unlock_search) } system.wallet (0)->insert_adhoc (key2.prv); system.wallet (0)->store.password.value_set (rai::keypair ().prv); - auto node (system.nodes [0]); + auto node (system.nodes[0]); ASSERT_FALSE (system.wallet (0)->enter_password ("")); auto iterations2 (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations2; @@ -379,18 +379,18 @@ TEST (node, connect_after_junk) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); uint64_t junk (0); - node1->network.socket.async_send_to (boost::asio::buffer (&junk, sizeof (junk)), system.nodes [0]->network.endpoint (), [] (boost::system::error_code const &, size_t) {}); + node1->network.socket.async_send_to (boost::asio::buffer (&junk, sizeof (junk)), system.nodes[0]->network.endpoint (), [](boost::system::error_code const &, size_t) {}); auto iterations1 (0); - while (system.nodes [0]->network.error_count == 0) + while (system.nodes[0]->network.error_count == 0) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); } node1->start (); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->network.send_keepalive (system.nodes[0]->network.endpoint ()); auto iterations2 (0); while (node1->peers.empty ()) { @@ -463,20 +463,20 @@ TEST (logging, upgrade_v1_v2) tree.erase ("vote"); bool upgraded (false); ASSERT_FALSE (logging2.deserialize_json (upgraded, tree)); - ASSERT_EQ ("2", tree.get ("version")); - ASSERT_EQ (false, tree.get ("vote")); + ASSERT_EQ ("2", tree.get ("version")); + ASSERT_EQ (false, tree.get ("vote")); } TEST (node, price) { rai::system system (24000, 1); - auto price1 (system.nodes [0]->price (rai::Gxrb_ratio, 1)); + auto price1 (system.nodes[0]->price (rai::Gxrb_ratio, 1)); ASSERT_EQ (rai::node::price_max * 100.0, price1); - auto price2 (system.nodes [0]->price (rai::Gxrb_ratio * int (rai::node::free_cutoff + 1), 1)); + auto price2 (system.nodes[0]->price (rai::Gxrb_ratio * int(rai::node::free_cutoff + 1), 1)); ASSERT_EQ (0, price2); - auto price3 (system.nodes [0]->price (rai::Gxrb_ratio * int (rai::node::free_cutoff + 2) / 2, 1)); + auto price3 (system.nodes[0]->price (rai::Gxrb_ratio * int(rai::node::free_cutoff + 2) / 2, 1)); ASSERT_EQ (rai::node::price_max * 100.0 / 2, price3); - auto price4 (system.nodes [0]->price (rai::Gxrb_ratio * int (rai::node::free_cutoff) * 2, 1)); + auto price4 (system.nodes[0]->price (rai::Gxrb_ratio * int(rai::node::free_cutoff) * 2, 1)); ASSERT_EQ (0, price4); } @@ -509,7 +509,7 @@ TEST (node_config, serialization) ASSERT_NE (config2.callback_address, config1.callback_address); ASSERT_NE (config2.callback_port, config1.callback_port); ASSERT_NE (config2.callback_target, config1.callback_target); - + bool upgraded (false); config2.deserialize_json (upgraded, tree); ASSERT_FALSE (upgraded); @@ -579,15 +579,15 @@ TEST (node_config, unversioned_v2_upgrade) bool upgraded (false); rai::node_config config1; config1.logging.init (path); - ASSERT_FALSE (tree.get_optional ("version")); + ASSERT_FALSE (tree.get_optional ("version")); config1.deserialize_json (upgraded, tree); ASSERT_TRUE (upgraded); ASSERT_EQ (1, config1.preconfigured_representatives.size ()); - ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", config1.preconfigured_representatives [0].to_account ()); + ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", config1.preconfigured_representatives[0].to_account ()); auto reps (tree.get_child ("preconfigured_representatives")); ASSERT_EQ (1, reps.size ()); - ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", reps.begin ()->second.get ("")); - auto version (tree.get ("version")); + ASSERT_EQ ("xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo", reps.begin ()->second.get ("")); + auto version (tree.get ("version")); ASSERT_GT (std::stoull (version), 1); } @@ -619,17 +619,17 @@ TEST (node_config, v2_v3_upgrade) bool upgraded (false); rai::node_config config1; config1.logging.init (path); - ASSERT_FALSE (tree.get_optional ("inactive_supply")); - ASSERT_FALSE (tree.get_optional ("password_fanout")); - ASSERT_FALSE (tree.get_optional ("io_threads")); - ASSERT_FALSE (tree.get_optional ("work_threads")); + ASSERT_FALSE (tree.get_optional ("inactive_supply")); + ASSERT_FALSE (tree.get_optional ("password_fanout")); + ASSERT_FALSE (tree.get_optional ("io_threads")); + ASSERT_FALSE (tree.get_optional ("work_threads")); config1.deserialize_json (upgraded, tree); - ASSERT_EQ (rai::uint128_union (0).to_string_dec (), tree.get ("inactive_supply")); - ASSERT_EQ ("1024", tree.get ("password_fanout")); - ASSERT_NE (0, std::stoul (tree.get ("password_fanout"))); - ASSERT_NE (0, std::stoul (tree.get ("password_fanout"))); + ASSERT_EQ (rai::uint128_union (0).to_string_dec (), tree.get ("inactive_supply")); + ASSERT_EQ ("1024", tree.get ("password_fanout")); + ASSERT_NE (0, std::stoul (tree.get ("password_fanout"))); + ASSERT_NE (0, std::stoul (tree.get ("password_fanout"))); ASSERT_TRUE (upgraded); - auto version (tree.get ("version")); + auto version (tree.get ("version")); ASSERT_GT (std::stoull (version), 2); } @@ -638,9 +638,9 @@ TEST (node, confirm_locked) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->enter_password ("1"); - auto block (std::make_shared (0, 0, 0, rai::keypair ().prv, 0, 0)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->network.republish_block (transaction, block); + auto block (std::make_shared (0, 0, 0, rai::keypair ().prv, 0, 0)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->network.republish_block (transaction, block); } TEST (node_config, random_rep) @@ -663,34 +663,34 @@ TEST (node, block_replace) auto initial_work (block1->block_work ()); while (rai::work_value (block1->root (), block1->block_work ()) <= rai::work_value (block1->root (), initial_work)) { - system.nodes [1]->generate_work (*block1); + system.nodes[1]->generate_work (*block1); } { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (block3->hash (), system.nodes [0]->store.block_successor (transaction, block1->hash ())); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_EQ (block3->hash (), system.nodes[0]->store.block_successor (transaction, block1->hash ())); } for (auto i (0); i < 1; ++i) { - rai::transaction transaction_a (system.nodes [1]->store.environment, nullptr, false); - system.nodes [1]->network.republish_block (transaction_a, block1); + rai::transaction transaction_a (system.nodes[1]->store.environment, nullptr, false); + system.nodes[1]->network.republish_block (transaction_a, block1); } auto iterations1 (0); - std::unique_ptr block2; + std::unique_ptr block2; while (block2 == nullptr) { system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - auto block (system.nodes [0]->store.block_get (transaction, block1->hash ())); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + auto block (system.nodes[0]->store.block_get (transaction, block1->hash ())); if (block->block_work () != initial_work) { block2 = std::move (block); } } { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (block3->hash (), system.nodes [0]->store.block_successor(transaction, block1->hash ())); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_EQ (block3->hash (), system.nodes[0]->store.block_successor (transaction, block1->hash ())); } ASSERT_NE (initial_work, block1->block_work ()); ASSERT_EQ (block1->block_work (), block2->block_work ()); @@ -699,17 +699,17 @@ TEST (node, block_replace) TEST (node, fork_publish) { - std::weak_ptr node0; + std::weak_ptr node0; { rai::system system (24000, 1); - node0 = system.nodes [0]; - auto & node1 (*system.nodes [0]); + node0 = system.nodes[0]; + auto & node1 (*system.nodes[0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::genesis genesis; - auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); rai::keypair key2; - auto send2 (std::make_shared (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto send2 (std::make_shared (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); node1.process_active (send1); node1.block_processor.flush (); ASSERT_EQ (1, node1.active.roots.size ()); @@ -733,16 +733,16 @@ TEST (node, fork_publish) TEST (node, fork_keep) { rai::system system (24000, 2); - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); ASSERT_EQ (1, node1.peers.size ()); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::keypair key2; rai::genesis genesis; // send1 and send2 fork to different accounts - auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); - auto send2 (std::make_shared (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + auto send2 (std::make_shared (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); node1.process_active (send1); node1.block_processor.flush (); node2.process_active (send1); @@ -759,10 +759,10 @@ TEST (node, fork_keep) ASSERT_NE (nullptr, votes1); ASSERT_EQ (1, votes1->votes.rep_votes.size ()); { - rai::transaction transaction0 (system.nodes [0]->store.environment, nullptr, false); - rai::transaction transaction1 (system.nodes [1]->store.environment, nullptr, false); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction0, send1->hash ())); - ASSERT_TRUE (system.nodes [1]->store.block_exists (transaction1, send1->hash ())); + rai::transaction transaction0 (system.nodes[0]->store.environment, nullptr, false); + rai::transaction transaction1 (system.nodes[1]->store.environment, nullptr, false); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction0, send1->hash ())); + ASSERT_TRUE (system.nodes[1]->store.block_exists (transaction1, send1->hash ())); } auto iterations (0); // Wait until the genesis rep makes a vote @@ -772,30 +772,30 @@ TEST (node, fork_keep) ++iterations; ASSERT_LT (iterations, 2000); } - rai::transaction transaction0 (system.nodes [0]->store.environment, nullptr, false); - rai::transaction transaction1 (system.nodes [1]->store.environment, nullptr, false); + rai::transaction transaction0 (system.nodes[0]->store.environment, nullptr, false); + rai::transaction transaction1 (system.nodes[1]->store.environment, nullptr, false); // The vote should be in agreement with what we already have. auto winner (node1.ledger.winner (transaction0, votes1->votes)); ASSERT_EQ (*send1, *winner.second); ASSERT_EQ (rai::genesis_amount - 100, winner.first); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction0, send1->hash ())); - ASSERT_TRUE (system.nodes [1]->store.block_exists (transaction1, send1->hash ())); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction0, send1->hash ())); + ASSERT_TRUE (system.nodes[1]->store.block_exists (transaction1, send1->hash ())); } TEST (node, fork_flip) { rai::system system (24000, 2); - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); ASSERT_EQ (1, node1.peers.size ()); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::genesis genesis; - std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); rai::publish publish1; publish1.block = std::move (send1); rai::keypair key2; - std::unique_ptr send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + std::unique_ptr send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); rai::publish publish2; publish2.block = std::move (send2); node1.process_message (publish1, node1.network.endpoint ()); @@ -814,11 +814,11 @@ TEST (node, fork_flip) ASSERT_NE (nullptr, votes1); ASSERT_EQ (1, votes1->votes.rep_votes.size ()); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ())); } { - rai::transaction transaction (system.nodes [1]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[1]->store.environment, nullptr, false); ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ())); } auto iterations (0); @@ -828,7 +828,7 @@ TEST (node, fork_flip) ++iterations; ASSERT_LT (iterations, 200); } - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node2.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*publish1.block, *winner.second); ASSERT_EQ (rai::genesis_amount - 100, winner.first); @@ -840,20 +840,20 @@ TEST (node, fork_flip) TEST (node, fork_multi_flip) { rai::system system (24000, 2); - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); ASSERT_EQ (1, node1.peers.size ()); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::genesis genesis; - std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); rai::publish publish1; publish1.block = std::move (send1); rai::keypair key2; - std::unique_ptr send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + std::unique_ptr send2 (new rai::send_block (genesis.hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); rai::publish publish2; publish2.block = std::move (send2); - std::unique_ptr send3 (new rai::send_block (publish2.block->hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (publish2.block->hash ()))); + std::unique_ptr send3 (new rai::send_block (publish2.block->hash (), key2.pub, rai::genesis_amount - 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (publish2.block->hash ()))); rai::publish publish3; publish3.block = std::move (send3); node1.process_message (publish1, node1.network.endpoint ()); @@ -874,11 +874,11 @@ TEST (node, fork_multi_flip) ASSERT_NE (nullptr, votes1); ASSERT_EQ (1, votes1->votes.rep_votes.size ()); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); ASSERT_TRUE (node1.store.block_exists (transaction, publish1.block->hash ())); } { - rai::transaction transaction (system.nodes [1]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[1]->store.environment, nullptr, false); ASSERT_TRUE (node2.store.block_exists (transaction, publish2.block->hash ())); ASSERT_TRUE (node2.store.block_exists (transaction, publish3.block->hash ())); } @@ -889,7 +889,7 @@ TEST (node, fork_multi_flip) ++iterations; ASSERT_LT (iterations, 200); } - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node1.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*publish1.block, *winner.second); ASSERT_EQ (rai::genesis_amount - 100, winner.first); @@ -905,14 +905,14 @@ TEST (node, fork_bootstrap_flip) { rai::system system0 (24000, 1); rai::system system1 (24001, 1); - auto & node1 (*system0.nodes [0]); - auto & node2 (*system1.nodes [0]); + auto & node1 (*system0.nodes[0]); + auto & node2 (*system1.nodes[0]); system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::block_hash latest (system0.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest (system0.nodes[0]->latest (rai::test_genesis_key.pub)); rai::keypair key1; - auto send1 (std::make_shared (latest, key1.pub, rai::genesis_amount - rai::Gxrb_ratio, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system0.work.generate (latest))); + auto send1 (std::make_shared (latest, key1.pub, rai::genesis_amount - rai::Gxrb_ratio, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system0.work.generate (latest))); rai::keypair key2; - auto send2 (std::make_shared (latest, key2.pub, rai::genesis_amount - rai::Gxrb_ratio, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system0.work.generate (latest))); + auto send2 (std::make_shared (latest, key2.pub, rai::genesis_amount - rai::Gxrb_ratio, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system0.work.generate (latest))); // Insert but don't rebroadcast, simulating settled blocks node1.block_processor.process_receive_many (rai::block_processor_item (send1)); node1.block_processor.flush (); @@ -948,21 +948,21 @@ TEST (node, fork_bootstrap_flip) TEST (node, fork_open) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); - system.wallet (0)->insert_adhoc ( rai::test_genesis_key.prv); + auto & node1 (*system.nodes[0]); + system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::genesis genesis; - std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + std::unique_ptr send1 (new rai::send_block (genesis.hash (), key1.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); rai::publish publish1; publish1.block = std::move (send1); node1.process_message (publish1, node1.network.endpoint ()); node1.block_processor.flush (); - std::unique_ptr open1 (new rai::open_block (publish1.block->hash (), 1, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); + std::unique_ptr open1 (new rai::open_block (publish1.block->hash (), 1, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); rai::publish publish2; publish2.block = std::move (open1); node1.process_message (publish2, node1.network.endpoint ()); node1.block_processor.flush (); - std::unique_ptr open2 (new rai::open_block (publish1.block->hash (), 2, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); + std::unique_ptr open2 (new rai::open_block (publish1.block->hash (), 2, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); rai::publish publish3; publish3.block = std::move (open2); ASSERT_EQ (2, node1.active.roots.size ()); @@ -973,21 +973,21 @@ TEST (node, fork_open) TEST (node, fork_open_flip) { rai::system system (24000, 2); - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); ASSERT_EQ (1, node1.peers.size ()); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key1; rai::genesis genesis; rai::keypair rep1; rai::keypair rep2; - auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 1, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); + auto send1 (std::make_shared (genesis.hash (), key1.pub, rai::genesis_amount - 1, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (genesis.hash ()))); node1.process_active (send1); node2.process_active (send1); // We should be keeping this block - auto open1 (std::make_shared (send1->hash (), rep1.pub, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); + auto open1 (std::make_shared (send1->hash (), rep1.pub, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); // This block should be evicted - auto open2 (std::make_shared (send1->hash (), rep2.pub, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); + auto open2 (std::make_shared (send1->hash (), rep2.pub, key1.pub, key1.prv, key1.pub, system.work.generate (key1.pub))); ASSERT_FALSE (*open1 == *open2); // node1 gets copy that will remain node1.process_active (open1); @@ -1017,7 +1017,7 @@ TEST (node, fork_open_flip) ++iterations; ASSERT_LT (iterations, 200); } - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); auto winner (node2.ledger.winner (transaction, votes1->votes)); ASSERT_EQ (*open1, *winner.second); ASSERT_EQ (rai::genesis_amount - 1, winner.first); @@ -1029,9 +1029,8 @@ TEST (node, fork_open_flip) TEST (node, coherent_observer) { rai::system system (24000, 1); - auto & node1 (*system.nodes [0]); - node1.observers.blocks.add ([&node1] (std::shared_ptr block_a, rai::account const & account_a, rai::amount const &) - { + auto & node1 (*system.nodes[0]); + node1.observers.blocks.add ([&node1](std::shared_ptr block_a, rai::account const & account_a, rai::amount const &) { rai::transaction transaction (node1.store.environment, nullptr, false); ASSERT_TRUE (node1.store.block_exists (transaction, block_a->hash ())); }); @@ -1043,9 +1042,9 @@ TEST (node, coherent_observer) TEST (node, fork_no_vote_quorum) { rai::system system (24000, 3); - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); - auto & node3 (*system.nodes [2]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); + auto & node3 (*system.nodes[2]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto key4 (system.wallet (0)->deterministic_insert ()); system.wallet (0)->send_action (rai::test_genesis_key.pub, key4, rai::genesis_amount / 4); @@ -1068,12 +1067,12 @@ TEST (node, fork_no_vote_quorum) ASSERT_EQ (rai::process_result::progress, node2.process (send1).code); ASSERT_EQ (rai::process_result::progress, node3.process (send1).code); auto key2 (system.wallet (2)->deterministic_insert ()); - auto send2 (std::make_shared (block->hash (), key2, (rai::genesis_amount / 4) - (node1.config.receive_minimum.number () * 2), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (block->hash ()))); + auto send2 (std::make_shared (block->hash (), key2, (rai::genesis_amount / 4) - (node1.config.receive_minimum.number () * 2), rai::test_genesis_key.prv, rai::test_genesis_key.pub, system.work.generate (block->hash ()))); rai::raw_key key3; ASSERT_FALSE (system.wallet (1)->store.fetch (rai::transaction (system.wallet (1)->store.environment, nullptr, false), key1, key3)); - auto vote (std::make_shared (key1, key3, 0, send2)); + auto vote (std::make_shared (key1, key3, 0, send2)); rai::confirm_ack confirm (vote); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); confirm.serialize (stream); @@ -1091,9 +1090,9 @@ TEST (node, fork_no_vote_quorum) TEST (node, broadcast_elected) { rai::system system (24000, 3); - auto node0 (system.nodes [0]); - auto node1 (system.nodes [1]); - auto node2 (system.nodes [2]); + auto node0 (system.nodes[0]); + auto node1 (system.nodes[1]); + auto node2 (system.nodes[2]); rai::keypair rep_big; rai::keypair rep_small; rai::keypair rep_other; @@ -1136,11 +1135,11 @@ TEST (node, broadcast_elected) system.wallet (0)->insert_adhoc (rep_big.prv); system.wallet (1)->insert_adhoc (rep_small.prv); system.wallet (2)->insert_adhoc (rep_other.prv); - auto fork0 (std::make_shared (node2->latest (rai::test_genesis_key.pub), rep_small.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto fork0 (std::make_shared (node2->latest (rai::test_genesis_key.pub), rep_small.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); node0->generate_work (*fork0); node0->process_active (fork0); node1->process_active (fork0); - auto fork1 (std::make_shared (node2->latest (rai::test_genesis_key.pub), rep_big.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto fork1 (std::make_shared (node2->latest (rai::test_genesis_key.pub), rep_big.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); node0->generate_work (*fork1); system.wallet (2)->insert_adhoc (rep_small.prv); node2->process_active (fork1); @@ -1160,7 +1159,7 @@ TEST (node, broadcast_elected) TEST (node, rep_self_vote) { rai::system system (24000, 1); - auto node0 (system.nodes [0]); + auto node0 (system.nodes[0]); rai::keypair rep_big; { rai::transaction transaction0 (node0->store.environment, nullptr, true); @@ -1173,13 +1172,13 @@ TEST (node, rep_self_vote) } system.wallet (0)->insert_adhoc (rep_big.prv); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - auto block0 (std::make_shared (node0->latest (rai::test_genesis_key.pub), rep_big.pub, rai::uint128_t ("0x60000000000000000000000000000000"), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto block0 (std::make_shared (node0->latest (rai::test_genesis_key.pub), rep_big.pub, rai::uint128_t ("0x60000000000000000000000000000000"), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); node0->generate_work (*block0); ASSERT_EQ (rai::process_result::progress, node0->process (*block0).code); auto & active (node0->active); { rai::transaction transaction (node0->store.environment, nullptr, true); - active.start (transaction, block0, [] (std::shared_ptr ) {}); + active.start (transaction, block0, [](std::shared_ptr) {}); } auto existing (active.roots.find (block0->root ())); ASSERT_NE (active.roots.end (), existing); @@ -1194,14 +1193,14 @@ TEST (node, bootstrap_no_publish) { rai::system system0 (24000, 1); rai::system system1 (24001, 1); - auto node0 (system0.nodes [0]); - auto node1 (system1.nodes [0]); + auto node0 (system0.nodes[0]); + auto node1 (system1.nodes[0]); rai::keypair key0; // node0 knows about send0 but node1 doesn't. - rai::send_block send0 (system0.nodes [0]->latest (rai::test_genesis_key.pub), key0.pub, 500, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); + rai::send_block send0 (system0.nodes[0]->latest (rai::test_genesis_key.pub), key0.pub, 500, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); { rai::transaction transaction (node0->store.environment, nullptr, true); - ASSERT_EQ (rai::process_result::progress, system0.nodes [0]->ledger.process (transaction, send0).code); + ASSERT_EQ (rai::process_result::progress, system0.nodes[0]->ledger.process (transaction, send0).code); } ASSERT_FALSE (node1->bootstrap_initiator.in_progress ()); node1->bootstrap_initiator.bootstrap (node0->network.endpoint ()); @@ -1223,11 +1222,11 @@ TEST (node, bootstrap_no_publish) TEST (node, bootstrap_fork_open) { rai::system system0 (24000, 2); - system0.wallet(0)->insert_adhoc (rai::test_genesis_key.prv); - auto node0 (system0.nodes [0]); - auto node1 (system0.nodes [1]); + system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); + auto node0 (system0.nodes[0]); + auto node1 (system0.nodes[1]); rai::keypair key0; - rai::send_block send0 (system0.nodes [0]->latest (rai::test_genesis_key.pub), key0.pub, rai::genesis_amount - 500, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); + rai::send_block send0 (system0.nodes[0]->latest (rai::test_genesis_key.pub), key0.pub, rai::genesis_amount - 500, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); rai::open_block open0 (send0.hash (), 1, key0.pub, key0.prv, key0.pub, 0); rai::open_block open1 (send0.hash (), 2, key0.pub, key0.prv, key0.pub, 0); node0->generate_work (send0); @@ -1260,8 +1259,8 @@ TEST (node, bootstrap_fork_open) TEST (node, unconfirmed_send) { rai::system system (24000, 2); - auto & node0 (*system.nodes [0]); - auto & node1 (*system.nodes [1]); + auto & node0 (*system.nodes[0]); + auto & node1 (*system.nodes[1]); auto wallet0 (system.wallet (0)); auto wallet1 (system.wallet (1)); rai::keypair key0; @@ -1295,8 +1294,8 @@ TEST (node, unconfirmed_send) TEST (node, rep_list) { rai::system system (24000, 2); - auto & node0 (*system.nodes [0]); - auto & node1 (*system.nodes [1]); + auto & node0 (*system.nodes[0]); + auto & node1 (*system.nodes[1]); auto wallet0 (system.wallet (0)); auto wallet1 (system.wallet (1)); // Node0 has a rep @@ -1312,9 +1311,9 @@ TEST (node, rep_list) auto reps (node1.peers.representatives (1)); if (!reps.empty ()) { - if (reps [0].endpoint == node0.network.endpoint ()) + if (reps[0].endpoint == node0.network.endpoint ()) { - if (!reps [0].rep_weight.is_zero ()) + if (!reps[0].rep_weight.is_zero ()) { done = true; } @@ -1330,8 +1329,8 @@ TEST (node, rep_list) TEST (node, no_voting) { rai::system system (24000, 2); - auto & node0 (*system.nodes [0]); - auto & node1 (*system.nodes [1]); + auto & node0 (*system.nodes[0]); + auto & node1 (*system.nodes[1]); auto wallet0 (system.wallet (0)); auto wallet1 (system.wallet (1)); node0.config.enable_voting = false; @@ -1354,16 +1353,15 @@ TEST (node, no_voting) TEST (node, start_observer) { rai::node_init init; - auto service (boost::make_shared ()); + auto service (boost::make_shared ()); rai::alarm alarm (*service); auto path (rai::unique_path ()); rai::logging logging; logging.init (path); - rai::work_pool work (std::numeric_limits ::max (), nullptr); - auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); + rai::work_pool work (std::numeric_limits::max (), nullptr); + auto node (std::make_shared (init, *service, 0, path, alarm, logging, work)); auto started (false); - node->observers.started.add([&started] () - { + node->observers.started.add ([&started]() { started = true; }); node->start (); @@ -1377,18 +1375,18 @@ TEST (node, send_callback) rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); - system.nodes [0]->config.callback_address = "localhost"; - system.nodes [0]->config.callback_port = 8010; - system.nodes [0]->config.callback_target = "/"; - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes [0]->config.receive_minimum.number ())); + system.nodes[0]->config.callback_address = "localhost"; + system.nodes[0]->config.callback_port = 8010; + system.nodes[0]->config.callback_target = "/"; + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, system.nodes[0]->config.receive_minimum.number ())); auto iterations (0); - while (system.nodes [0]->balance (key2.pub).is_zero ()) + while (system.nodes[0]->balance (key2.pub).is_zero ()) { system.poll (); ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_EQ (std::numeric_limits ::max () - system.nodes [0]->config.receive_minimum.number (), system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (std::numeric_limits::max () - system.nodes[0]->config.receive_minimum.number (), system.nodes[0]->balance (rai::test_genesis_key.pub)); } // Check that votes get replayed back to nodes if they sent an old sequence number. @@ -1397,17 +1395,17 @@ TEST (node, vote_replay) { rai::system system (24000, 2); rai::keypair key; - auto open (std::make_shared (0, 1, key.pub, key.prv, key.pub, 0)); - system.nodes [0]->generate_work (*open); + auto open (std::make_shared (0, 1, key.pub, key.prv, key.pub, 0)); + system.nodes[0]->generate_work (*open); for (auto i (0); i < 11000; ++i) { - rai::transaction transaction (system.nodes [1]->store.environment, nullptr, false); - auto vote (system.nodes [1]->store.vote_generate (transaction, rai::test_genesis_key.pub, rai::test_genesis_key.prv, open)); + rai::transaction transaction (system.nodes[1]->store.environment, nullptr, false); + auto vote (system.nodes[1]->store.vote_generate (transaction, rai::test_genesis_key.pub, rai::test_genesis_key.prv, open)); } { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - std::lock_guard lock (system.nodes [0]->store.cache_mutex); - auto vote (system.nodes [0]->store.vote_current (transaction, rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + std::lock_guard lock (system.nodes[0]->store.cache_mutex); + auto vote (system.nodes[0]->store.vote_current (transaction, rai::test_genesis_key.pub)); ASSERT_EQ (nullptr, vote); } system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); @@ -1418,9 +1416,9 @@ TEST (node, vote_replay) while (!done) { system.poll (); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - std::lock_guard lock (system.nodes [0]->store.cache_mutex); - auto vote (system.nodes [0]->store.vote_current (transaction, rai::test_genesis_key.pub)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + std::lock_guard lock (system.nodes[0]->store.cache_mutex); + auto vote (system.nodes[0]->store.vote_current (transaction, rai::test_genesis_key.pub)); done = vote && (vote->sequence >= 10000); ++iterations; ASSERT_GT (400, iterations); diff --git a/rai/core_test/peer_container.cpp b/rai/core_test/peer_container.cpp index a202172f..8b4dc347 100644 --- a/rai/core_test/peer_container.cpp +++ b/rai/core_test/peer_container.cpp @@ -3,20 +3,20 @@ TEST (peer_container, empty_peers) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); auto list (peers.purge_list (std::chrono::system_clock::now ())); ASSERT_EQ (0, list.size ()); } TEST (peer_container, no_recontact) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); auto observed_peer (0); auto observed_disconnect (false); rai::endpoint endpoint1 (boost::asio::ip::address_v6::loopback (), 10000); ASSERT_EQ (0, peers.size ()); - peers.peer_observer = [&observed_peer] (rai::endpoint const &) {++observed_peer;}; - peers.disconnect_observer = [&observed_disconnect] () {observed_disconnect = true;}; + peers.peer_observer = [&observed_peer](rai::endpoint const &) { ++observed_peer; }; + peers.disconnect_observer = [&observed_disconnect]() { observed_disconnect = true; }; ASSERT_FALSE (peers.insert (endpoint1, 0)); ASSERT_EQ (1, peers.size ()); ASSERT_TRUE (peers.insert (endpoint1, 0)); @@ -44,7 +44,7 @@ TEST (peer_container, no_self_contacting) TEST (peer_container, reserved_peers_no_contact) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0x00000001)), 10000), 0)); ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc0000201)), 10000), 0)); ASSERT_TRUE (peers.insert (rai::endpoint (boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (0xc6336401)), 10000), 0)); @@ -57,7 +57,7 @@ TEST (peer_container, reserved_peers_no_contact) TEST (peer_container, split) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); auto now (std::chrono::system_clock::now ()); rai::endpoint endpoint1 (boost::asio::ip::address_v6::any (), 100); rai::endpoint endpoint2 (boost::asio::ip::address_v6::any (), 101); @@ -67,35 +67,35 @@ TEST (peer_container, split) auto list (peers.purge_list (now)); ASSERT_EQ (1, peers.peers.size ()); ASSERT_EQ (1, list.size ()); - ASSERT_EQ (endpoint2, list [0].endpoint); + ASSERT_EQ (endpoint2, list[0].endpoint); } TEST (peer_container, fill_random_clear) { - rai::peer_container peers (rai::endpoint {}); - std::array target; + rai::peer_container peers (rai::endpoint{}); + std::array target; std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); - ASSERT_TRUE (std::all_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); + ASSERT_TRUE (std::all_of (target.begin (), target.end (), [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); } TEST (peer_container, fill_random_full) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); for (auto i (0); i < 100; ++i) { peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), i), 0); } - std::array target; + std::array target; std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); - ASSERT_TRUE (std::none_of (target.begin (), target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); + ASSERT_TRUE (std::none_of (target.begin (), target.end (), [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); } TEST (peer_container, fill_random_part) { - rai::peer_container peers (rai::endpoint {}); - std::array target; + rai::peer_container peers (rai::endpoint{}); + std::array target; auto half (target.size () / 2); for (auto i (0); i < half; ++i) { @@ -103,14 +103,14 @@ TEST (peer_container, fill_random_part) } std::fill (target.begin (), target.end (), rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000)); peers.random_fill (target); - ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); - ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); })); - ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [] (rai::endpoint const & endpoint_a) {return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); + ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000); })); + ASSERT_TRUE (std::none_of (target.begin (), target.begin () + half, [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::loopback (), 0); })); + ASSERT_TRUE (std::all_of (target.begin () + half, target.end (), [](rai::endpoint const & endpoint_a) { return endpoint_a == rai::endpoint (boost::asio::ip::address_v6::any (), 0); })); } TEST (peer_container, list_sqrt) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); auto list1 (peers.list_sqrt ()); ASSERT_TRUE (list1.empty ()); for (auto i (0); i < 1000; ++i) @@ -123,7 +123,7 @@ TEST (peer_container, list_sqrt) TEST (peer_container, rep_weight) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 24001), 0); ASSERT_TRUE (peers.representatives (1).empty ()); rai::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), 24000); @@ -136,14 +136,14 @@ TEST (peer_container, rep_weight) peers.rep_response (endpoint0, amount); auto reps (peers.representatives (1)); ASSERT_EQ (1, reps.size ()); - ASSERT_EQ (100, reps [0].rep_weight.number ()); - ASSERT_EQ (endpoint0, reps [0].endpoint); + ASSERT_EQ (100, reps[0].rep_weight.number ()); + ASSERT_EQ (endpoint0, reps[0].endpoint); } // Test to make sure we don't repeatedly send keepalive messages to nodes that aren't responding TEST (peer_container, reachout) { - rai::peer_container peers (rai::endpoint {}); + rai::peer_container peers (rai::endpoint{}); rai::endpoint endpoint0 (boost::asio::ip::address_v6::loopback (), 24000); // Make sure having been contacted by them already indicates we shouldn't reach out peers.contacted (endpoint0, 0); diff --git a/rai/core_test/processor_service.cpp b/rai/core_test/processor_service.cpp index 8cdd793c..99bcdd34 100644 --- a/rai/core_test/processor_service.cpp +++ b/rai/core_test/processor_service.cpp @@ -20,7 +20,7 @@ TEST (processor_service, bad_send_signature) rai::keypair key2; rai::send_block send (info1.head, rai::test_genesis_key.pub, 50, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); rai::block_hash hash1 (send.hash ()); - send.signature.bytes [32] ^= 0x1; + send.signature.bytes[32] ^= 0x1; ASSERT_EQ (rai::process_result::bad_signature, ledger.process (transaction, send).code); } @@ -41,7 +41,7 @@ TEST (processor_service, bad_receive_signature) rai::account_info info2; ASSERT_FALSE (store.account_get (transaction, rai::test_genesis_key.pub, info2)); rai::receive_block receive (hash1, hash1, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); - receive.signature.bytes [32] ^= 0x1; + receive.signature.bytes[32] ^= 0x1; ASSERT_EQ (rai::process_result::bad_signature, ledger.process (transaction, receive).code); } @@ -49,19 +49,18 @@ TEST (alarm, one) { boost::asio::io_service service; rai::alarm alarm (service); - std::atomic done (false); + std::atomic done (false); std::mutex mutex; std::condition_variable condition; - alarm.add (std::chrono::system_clock::now (), [&] () - { - std::lock_guard lock (mutex); + alarm.add (std::chrono::system_clock::now (), [&]() { + std::lock_guard lock (mutex); done = true; condition.notify_one (); }); boost::asio::io_service::work work (service); - std::thread thread ([&service] () {service.run ();}); - std::unique_lock unique (mutex); - condition.wait (unique, [&] () {return !!done;}); + std::thread thread ([&service]() { service.run (); }); + std::unique_lock unique (mutex); + condition.wait (unique, [&]() { return !!done; }); service.stop (); thread.join (); } @@ -70,26 +69,25 @@ TEST (alarm, many) { boost::asio::io_service service; rai::alarm alarm (service); - std::atomic count (0); + std::atomic count (0); std::mutex mutex; std::condition_variable condition; for (auto i (0); i < 50; ++i) { - alarm.add (std::chrono::system_clock::now (), [&] () - { - std::lock_guard lock (mutex); + alarm.add (std::chrono::system_clock::now (), [&]() { + std::lock_guard lock (mutex); count += 1; condition.notify_one (); }); } boost::asio::io_service::work work (service); - std::vector threads; + std::vector threads; for (auto i (0); i < 50; ++i) { - threads.push_back (std::thread ([&service] () {service.run ();})); + threads.push_back (std::thread ([&service]() { service.run (); })); } - std::unique_lock unique (mutex); - condition.wait (unique, [&] () { return count == 50;}); + std::unique_lock unique (mutex); + condition.wait (unique, [&]() { return count == 50; }); service.stop (); for (auto i (threads.begin ()), j (threads.end ()); i != j; ++i) { @@ -104,26 +102,23 @@ TEST (alarm, top_execution) int value1 (0); int value2 (0); std::mutex mutex; - std::promise promise; - alarm.add (std::chrono::system_clock::now (), [&] () - { - std::lock_guard lock (mutex); + std::promise promise; + alarm.add (std::chrono::system_clock::now (), [&]() { + std::lock_guard lock (mutex); value1 = 1; value2 = 1; }); - alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (1), [&] () - { - std::lock_guard lock (mutex); + alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (1), [&]() { + std::lock_guard lock (mutex); value2 = 2; promise.set_value (false); }); boost::asio::io_service::work work (service); - std::thread thread ([&service] () - { + std::thread thread ([&service]() { service.run (); }); promise.get_future ().get (); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); ASSERT_EQ (1, value1); ASSERT_EQ (2, value2); service.stop (); diff --git a/rai/core_test/rpc.cpp b/rai/core_test/rpc.cpp index f4c121ca..b9e3ce9e 100644 --- a/rai/core_test/rpc.cpp +++ b/rai/core_test/rpc.cpp @@ -1,13 +1,13 @@ #include -#include #include +#include #include #include -#include #include +#include #include class test_response @@ -18,8 +18,7 @@ public: sock (service_a), status (0) { - sock.async_connect (rai::tcp_endpoint (boost::asio::ip::address_v6::loopback (), rpc_a.config.port), [this] (boost::system::error_code const & ec) - { + sock.async_connect (rai::tcp_endpoint (boost::asio::ip::address_v6::loopback (), rpc_a.config.port), [this](boost::system::error_code const & ec) { if (!ec) { std::stringstream ostream; @@ -28,17 +27,15 @@ public: req.target ("/"); req.version (11); ostream.flush (); - req.body() = ostream.str (); + req.body () = ostream.str (); req.prepare_payload (); - boost::beast::http::async_write (sock, req, [this] (boost::system::error_code const & ec, size_t bytes_transferred) - { + boost::beast::http::async_write (sock, req, [this](boost::system::error_code const & ec, size_t bytes_transferred) { if (!ec) { - boost::beast::http::async_read(sock, sb, resp, [this] (boost::system::error_code const & ec, size_t bytes_transferred) - { + boost::beast::http::async_read (sock, sb, resp, [this](boost::system::error_code const & ec, size_t bytes_transferred) { if (!ec) { - std::stringstream body (resp.body()); + std::stringstream body (resp.body ()); try { boost::property_tree::read_json (body, json); @@ -79,7 +76,7 @@ public: TEST (rpc, account_balance) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "account_balance"); @@ -90,16 +87,16 @@ TEST (rpc, account_balance) system.poll (); } ASSERT_EQ (200, response.status); - std::string balance_text (response.json.get ("balance")); + std::string balance_text (response.json.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); - std::string pending_text (response.json.get ("pending")); + std::string pending_text (response.json.get ("pending")); ASSERT_EQ ("0", pending_text); } TEST (rpc, account_block_count) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "account_block_count"); @@ -110,25 +107,25 @@ TEST (rpc, account_block_count) system.poll (); } ASSERT_EQ (200, response.status); - std::string block_count_text (response.json.get ("block_count")); + std::string block_count_text (response.json.get ("block_count")); ASSERT_EQ ("1", block_count_text); } TEST (rpc, account_create) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "account_create"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - auto account_text (response.json.get ("account")); + auto account_text (response.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_TRUE (system.wallet (0)->exists (account)); @@ -138,8 +135,8 @@ TEST (rpc, account_weight) { rai::keypair key; rai::system system (24000, 1); - rai::block_hash latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); - auto & node1 (*system.nodes [0]); + rai::block_hash latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); rai::change_block block (latest, key.pub, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); ASSERT_EQ (rai::process_result::progress, node1.process (block).code); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); @@ -153,19 +150,19 @@ TEST (rpc, account_weight) system.poll (); } ASSERT_EQ (200, response.status); - std::string balance_text (response.json.get ("weight")); + std::string balance_text (response.json.get ("weight")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); } TEST (rpc, wallet_contains) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_contains"); request.put ("account", rai::test_genesis_key.pub.to_account ()); @@ -175,18 +172,18 @@ TEST (rpc, wallet_contains) system.poll (); } ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("exists")); + std::string exists_text (response.json.get ("exists")); ASSERT_EQ ("1", exists_text); } TEST (rpc, wallet_doesnt_contain) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_contains"); request.put ("account", rai::test_genesis_key.pub.to_account ()); @@ -196,14 +193,14 @@ TEST (rpc, wallet_doesnt_contain) system.poll (); } ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("exists")); + std::string exists_text (response.json.get ("exists")); ASSERT_EQ ("0", exists_text); } TEST (rpc, validate_account_number) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; @@ -214,18 +211,18 @@ TEST (rpc, validate_account_number) { system.poll (); } - std::string exists_text (response.json.get ("valid")); + std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("1", exists_text); } TEST (rpc, validate_account_invalid) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); std::string account; rai::test_genesis_key.pub.encode_account (account); - account [0] ^= 0x1; + account[0] ^= 0x1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "validate_account_number"); @@ -236,28 +233,27 @@ TEST (rpc, validate_account_invalid) system.poll (); } ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("valid")); + std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("0", exists_text); } TEST (rpc, send) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", rai::test_genesis_key.pub.to_account ()); request.put ("destination", rai::test_genesis_key.pub.to_account ()); request.put ("amount", "100"); - std::thread thread2 ([&system] () - { + std::thread thread2 ([&system]() { auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) == rai::genesis_amount) { system.poll (); ++iterations; @@ -270,29 +266,28 @@ TEST (rpc, send) system.poll (); } ASSERT_EQ (200, response.status); - std::string block_text (response.json.get ("block")); + std::string block_text (response.json.get ("block")); rai::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); - ASSERT_TRUE (system.nodes [0]->ledger.block_exists (block)); + ASSERT_TRUE (system.nodes[0]->ledger.block_exists (block)); thread2.join (); } TEST (rpc, send_fail) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "send"); request.put ("source", rai::test_genesis_key.pub.to_account ()); request.put ("destination", rai::test_genesis_key.pub.to_account ()); request.put ("amount", "100"); - std::atomic done (false); - std::thread thread2 ([&system, &done] () - { + std::atomic done (false); + std::thread thread2 ([&system, &done]() { auto iterations (0); while (!done) { @@ -308,7 +303,7 @@ TEST (rpc, send_fail) } done = true; ASSERT_EQ (200, response.status); - std::string block_text (response.json.get ("block")); + std::string block_text (response.json.get ("block")); rai::block_hash block; ASSERT_FALSE (block.decode_hex (block_text)); ASSERT_TRUE (block.is_zero ()); @@ -318,7 +313,7 @@ TEST (rpc, send_fail) TEST (rpc, stop) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "stop"); @@ -327,13 +322,13 @@ TEST (rpc, stop) { system.poll (); }; - ASSERT_FALSE (system.nodes [0]->network.on); + ASSERT_FALSE (system.nodes[0]->network.on); } TEST (rpc, wallet_add) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); rai::keypair key1; std::string key_text; @@ -341,7 +336,7 @@ TEST (rpc, wallet_add) system.wallet (0)->insert_adhoc (key1.prv); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_add"); request.put ("key", key_text); @@ -351,18 +346,18 @@ TEST (rpc, wallet_add) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("account")); + std::string account_text1 (response.json.get ("account")); ASSERT_EQ (account_text1, key1.pub.to_account ()); } TEST (rpc, wallet_password_valid) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "password_valid"); test_response response (request, rpc, system.service); @@ -371,18 +366,18 @@ TEST (rpc, wallet_password_valid) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("valid")); + std::string account_text1 (response.json.get ("valid")); ASSERT_EQ (account_text1, "1"); } TEST (rpc, wallet_password_change) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "password_change"); request.put ("password", "test"); @@ -392,7 +387,7 @@ TEST (rpc, wallet_password_change) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("changed")); + std::string account_text1 (response.json.get ("changed")); ASSERT_EQ (account_text1, "1"); ASSERT_TRUE (system.wallet (0)->valid_password ()); ASSERT_TRUE (system.wallet (0)->enter_password ("")); @@ -414,11 +409,11 @@ TEST (rpc, wallet_password_enter) ASSERT_LT (iterations, 200); system.wallet (0)->store.password.value (password_l); } - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "password_enter"); request.put ("password", ""); @@ -428,18 +423,18 @@ TEST (rpc, wallet_password_enter) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("valid")); + std::string account_text1 (response.json.get ("valid")); ASSERT_EQ (account_text1, "1"); } TEST (rpc, wallet_representative) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_representative"); test_response response (request, rpc, system.service); @@ -448,18 +443,18 @@ TEST (rpc, wallet_representative) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("representative")); + std::string account_text1 (response.json.get ("representative")); ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); } TEST (rpc, wallet_representative_set) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); rai::keypair key; request.put ("action", "wallet_representative_set"); @@ -470,21 +465,21 @@ TEST (rpc, wallet_representative_set) system.poll (); } ASSERT_EQ (200, response.status); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_EQ (key.pub, system.nodes [0]->wallets.items.begin ()->second->store.representative (transaction)); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_EQ (key.pub, system.nodes[0]->wallets.items.begin ()->second->store.representative (transaction)); } TEST (rpc, account_list) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); rai::keypair key2; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key2.prv); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "account_list"); test_response response (request, rpc, system.service); @@ -494,10 +489,10 @@ TEST (rpc, account_list) } ASSERT_EQ (200, response.status); auto & accounts_node (response.json.get_child ("accounts")); - std::vector accounts; + std::vector accounts; for (auto i (accounts_node.begin ()), j (accounts_node.end ()); i != j; ++i) { - auto account (i->second.get ("")); + auto account (i->second.get ("")); rai::uint256_union number; ASSERT_FALSE (number.decode_account (account)); accounts.push_back (number); @@ -512,12 +507,12 @@ TEST (rpc, account_list) TEST (rpc, wallet_key_valid) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_key_valid"); test_response response (request, rpc, system.service); @@ -526,14 +521,14 @@ TEST (rpc, wallet_key_valid) system.poll (); } ASSERT_EQ (200, response.status); - std::string exists_text (response.json.get ("valid")); + std::string exists_text (response.json.get ("valid")); ASSERT_EQ ("1", exists_text); } TEST (rpc, wallet_create) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_create"); @@ -543,30 +538,30 @@ TEST (rpc, wallet_create) system.poll (); } ASSERT_EQ (200, response.status); - std::string wallet_text (response.json.get ("wallet")); + std::string wallet_text (response.json.get ("wallet")); rai::uint256_union 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)); + ASSERT_NE (system.nodes[0]->wallets.items.end (), system.nodes[0]->wallets.items.find (wallet_id)); } TEST (rpc, wallet_export) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; request.put ("action", "wallet_export"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - std::string wallet_json (response.json.get ("json")); + std::string wallet_json (response.json.get ("json")); bool error (false); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); rai::kdf kdf; rai::wallet_store store (error, kdf, transaction, rai::genesis_account, 1, "0", wallet_json); ASSERT_FALSE (error); @@ -576,8 +571,8 @@ TEST (rpc, wallet_export) TEST (rpc, wallet_destroy) { rai::system system (24000, 1); - auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + auto wallet_id (system.nodes[0]->wallets.items.begin ()->first); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); boost::property_tree::ptree request; @@ -589,20 +584,20 @@ TEST (rpc, wallet_destroy) system.poll (); } ASSERT_EQ (200, response.status); - ASSERT_EQ (system.nodes [0]->wallets.items.end (), system.nodes [0]->wallets.items.find (wallet_id)); + ASSERT_EQ (system.nodes[0]->wallets.items.end (), system.nodes[0]->wallets.items.find (wallet_id)); } TEST (rpc, account_move) { rai::system system (24000, 1); - auto wallet_id (system.nodes [0]->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + auto wallet_id (system.nodes[0]->wallets.items.begin ()->first); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); auto destination (system.wallet (0)); rai::keypair key; destination->insert_adhoc (rai::test_genesis_key.prv); rai::keypair source_id; - auto source (system.nodes [0]->wallets.create (source_id.pub)); + auto source (system.nodes[0]->wallets.create (source_id.pub)); source->insert_adhoc (key.prv); boost::property_tree::ptree request; request.put ("action", "account_move"); @@ -619,35 +614,35 @@ TEST (rpc, account_move) system.poll (); } ASSERT_EQ (200, response.status); - ASSERT_EQ ("1", response.json.get ("moved")); + ASSERT_EQ ("1", response.json.get ("moved")); ASSERT_TRUE (destination->exists (key.pub)); ASSERT_TRUE (destination->exists (rai::test_genesis_key.pub)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); ASSERT_EQ (source->store.end (), source->store.begin (transaction)); } TEST (rpc, block) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "block"); - request.put ("hash", system.nodes [0]->latest (rai::genesis_account).to_string ()); + request.put ("hash", system.nodes[0]->latest (rai::genesis_account).to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - auto contents (response.json.get ("contents")); + auto contents (response.json.get ("contents")); ASSERT_FALSE (contents.empty ()); } TEST (rpc, block_account) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); rai::genesis genesis; boost::property_tree::ptree request; @@ -659,7 +654,7 @@ TEST (rpc, block_account) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text (response.json.get ("account")); + std::string account_text (response.json.get ("account")); rai::account account; ASSERT_FALSE (account.decode_account (account_text)); } @@ -669,16 +664,16 @@ TEST (rpc, chain) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; - auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto genesis (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "chain"); - request.put ("block", block->hash().to_string ()); - request.put ("count", std::to_string (std::numeric_limits ::max ())); + request.put ("block", block->hash ().to_string ()); + request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -686,14 +681,14 @@ TEST (rpc, chain) } ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); - std::vector blocks; + std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (2, blocks.size ()); - ASSERT_EQ (block->hash(), blocks [0]); - ASSERT_EQ (genesis, blocks [1]); + ASSERT_EQ (block->hash (), blocks[0]); + ASSERT_EQ (genesis, blocks[1]); } TEST (rpc, chain_limit) @@ -701,15 +696,15 @@ TEST (rpc, chain_limit) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; - auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto genesis (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "chain"); - request.put ("block", block->hash().to_string ()); + request.put ("block", block->hash ().to_string ()); request.put ("count", 1); test_response response (request, rpc, system.service); while (response.status == 0) @@ -718,35 +713,35 @@ TEST (rpc, chain_limit) } ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); - std::vector blocks; + std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (1, blocks.size ()); - ASSERT_EQ (block->hash(), blocks [0]); + ASSERT_EQ (block->hash (), blocks[0]); } TEST (rpc, frontier) { rai::system system (24000, 1); - std::unordered_map source; + std::unordered_map source; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); for (auto i (0); i < 1000; ++i) { rai::keypair key; - source [key.pub] = key.prv.data; - system.nodes [0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); + source[key.pub] = key.prv.data; + system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "frontiers"); request.put ("account", rai::account (0).to_account ()); - request.put ("count", std::to_string (std::numeric_limits ::max ())); + request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -754,14 +749,14 @@ TEST (rpc, frontier) } ASSERT_EQ (200, response.status); auto & frontiers_node (response.json.get_child ("frontiers")); - std::unordered_map frontiers; + std::unordered_map frontiers; for (auto i (frontiers_node.begin ()), j (frontiers_node.end ()); i != j; ++i) { rai::account account; account.decode_account (i->first); rai::block_hash frontier; - frontier.decode_hex (i->second.get ("")); - frontiers [account] = frontier; + frontier.decode_hex (i->second.get ("")); + frontiers[account] = frontier; } ASSERT_EQ (1, frontiers.erase (rai::test_genesis_key.pub)); ASSERT_EQ (source, frontiers); @@ -770,18 +765,18 @@ TEST (rpc, frontier) TEST (rpc, frontier_limited) { rai::system system (24000, 1); - std::unordered_map source; + std::unordered_map source; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); for (auto i (0); i < 1000; ++i) { rai::keypair key; - source [key.pub] = key.prv.data; - system.nodes [0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); + source[key.pub] = key.prv.data; + system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "frontiers"); @@ -800,18 +795,18 @@ TEST (rpc, frontier_limited) TEST (rpc, frontier_startpoint) { rai::system system (24000, 1); - std::unordered_map source; + std::unordered_map source; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); for (auto i (0); i < 1000; ++i) { rai::keypair key; - source [key.pub] = key.prv.data; - system.nodes [0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); + source[key.pub] = key.prv.data; + system.nodes[0]->store.account_put (transaction, key.pub, rai::account_info (key.prv.data, 0, 0, 0, 0, 0)); } } rai::keypair key; - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "frontiers"); @@ -834,15 +829,15 @@ TEST (rpc, history) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto change (system.wallet (0)->change_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub)); ASSERT_NE (nullptr, change); - auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "history"); - request.put ("hash", receive->hash().to_string ()); + request.put ("hash", receive->hash ().to_string ()); request.put ("count", 100); test_response response (request, rpc, system.service); while (response.status == 0) @@ -850,26 +845,26 @@ TEST (rpc, history) system.poll (); } ASSERT_EQ (200, response.status); - std::vector > history_l; + std::vector> history_l; auto & history_node (response.json.get_child ("history")); for (auto i (history_node.begin ()), n (history_node.end ()); i != n; ++i) { - history_l.push_back (std::make_tuple (i->second.get ("type"), i->second.get ("account"), i->second.get ("amount"), i->second.get ("hash"))); + history_l.push_back (std::make_tuple (i->second.get ("type"), i->second.get ("account"), i->second.get ("amount"), i->second.get ("hash"))); } ASSERT_EQ (3, history_l.size ()); - ASSERT_EQ ("receive", std::get <0> (history_l [0])); - ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get <1> (history_l [0])); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.to_string_dec (), std::get <2> (history_l [0])); - ASSERT_EQ (receive->hash ().to_string (), std::get <3> (history_l [0])); - ASSERT_EQ ("send", std::get <0> (history_l [1])); - ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get <1> (history_l [1])); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.to_string_dec (), std::get <2> (history_l [1])); - ASSERT_EQ (send->hash ().to_string (), std::get <3> (history_l [1])); + ASSERT_EQ ("receive", std::get<0> (history_l[0])); + ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get<1> (history_l[0])); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.to_string_dec (), std::get<2> (history_l[0])); + ASSERT_EQ (receive->hash ().to_string (), std::get<3> (history_l[0])); + ASSERT_EQ ("send", std::get<0> (history_l[1])); + ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get<1> (history_l[1])); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.to_string_dec (), std::get<2> (history_l[1])); + ASSERT_EQ (send->hash ().to_string (), std::get<3> (history_l[1])); rai::genesis genesis; - ASSERT_EQ ("receive", std::get <0> (history_l [2])); - ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get <1> (history_l [2])); - ASSERT_EQ (rai::genesis_amount.convert_to (), std::get <2> (history_l [2])); - ASSERT_EQ (genesis.hash ().to_string (), std::get <3> (history_l [2])); + ASSERT_EQ ("receive", std::get<0> (history_l[2])); + ASSERT_EQ (rai::test_genesis_key.pub.to_account (), std::get<1> (history_l[2])); + ASSERT_EQ (rai::genesis_amount.convert_to (), std::get<2> (history_l[2])); + ASSERT_EQ (genesis.hash ().to_string (), std::get<3> (history_l[2])); } TEST (rpc, history_count) @@ -878,15 +873,15 @@ TEST (rpc, history_count) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto change (system.wallet (0)->change_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub)); ASSERT_NE (nullptr, change); - auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "history"); - request.put ("hash", receive->hash().to_string ()); + request.put ("hash", receive->hash ().to_string ()); request.put ("count", 1); test_response response (request, rpc, system.service); while (response.status == 0) @@ -902,8 +897,8 @@ TEST (rpc, process_block) { rai::system system (24000, 1); rai::keypair key; - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); - auto & node1 (*system.nodes [0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); @@ -918,8 +913,8 @@ TEST (rpc, process_block) system.poll (); } ASSERT_EQ (200, response.status); - ASSERT_EQ (send.hash (), system.nodes [0]->latest (rai::test_genesis_key.pub)); - std::string send_hash (response.json.get ("hash")); + ASSERT_EQ (send.hash (), system.nodes[0]->latest (rai::test_genesis_key.pub)); + std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); } @@ -927,10 +922,10 @@ TEST (rpc, process_block_no_work) { rai::system system (24000, 1); rai::keypair key; - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); - auto & node1 (*system.nodes [0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - send.block_work_set(0); + send.block_work_set (0); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; @@ -944,16 +939,16 @@ TEST (rpc, process_block_no_work) system.poll (); } ASSERT_EQ (200, response.status); - ASSERT_FALSE (response.json.get ("error").empty ()); + ASSERT_FALSE (response.json.get ("error").empty ()); } TEST (rpc, keepalive) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); node1->start (); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "keepalive"); @@ -961,8 +956,8 @@ TEST (rpc, keepalive) auto port (boost::str (boost::format ("%1%") % node1->network.endpoint ().port ())); request.put ("address", address); request.put ("port", port); - ASSERT_FALSE (system.nodes [0]->peers.known_peer (node1->network.endpoint ())); - ASSERT_EQ (0, system.nodes [0]->peers.size()); + ASSERT_FALSE (system.nodes[0]->peers.known_peer (node1->network.endpoint ())); + ASSERT_EQ (0, system.nodes[0]->peers.size ()); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -970,9 +965,9 @@ TEST (rpc, keepalive) } ASSERT_EQ (200, response.status); auto iterations (0); - while (!system.nodes [0]->peers.known_peer (node1->network.endpoint ())) + while (!system.nodes[0]->peers.known_peer (node1->network.endpoint ())) { - ASSERT_EQ (0, system.nodes [0]->peers.size()); + ASSERT_EQ (0, system.nodes[0]->peers.size ()); system.poll (); ++iterations; ASSERT_LT (iterations, 200); @@ -984,11 +979,11 @@ TEST (rpc, payment_init) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "payment_init"); @@ -999,18 +994,18 @@ TEST (rpc, payment_init) system.poll (); } ASSERT_EQ (200, response.status); - ASSERT_EQ ("Ready", response.json.get ("status")); + ASSERT_EQ ("Ready", response.json.get ("status")); } TEST (rpc, payment_begin_end) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); @@ -1021,11 +1016,11 @@ TEST (rpc, payment_begin_end) system.poll (); } ASSERT_EQ (200, response1.status); - auto account_text (response1.json.get ("account")); + auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_TRUE (wallet->exists (account)); - auto root1 (system.nodes [0]->ledger.latest_root (rai::transaction (wallet->store.environment, nullptr, false), account)); + auto root1 (system.nodes[0]->ledger.latest_root (rai::transaction (wallet->store.environment, nullptr, false), account)); uint64_t work (0); auto iteration (0); ASSERT_TRUE (rai::work_validate (root1, work)); @@ -1057,11 +1052,11 @@ TEST (rpc, payment_end_nonempty) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->init_free_accounts (rai::transaction (node1->store.environment, nullptr, false)); auto wallet_id (node1->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_end"); @@ -1073,18 +1068,18 @@ TEST (rpc, payment_end_nonempty) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_FALSE (response1.json.get ("error").empty ()); + ASSERT_FALSE (response1.json.get ("error").empty ()); } TEST (rpc, payment_zero_balance) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->init_free_accounts (rai::transaction (node1->store.environment, nullptr, false)); auto wallet_id (node1->wallets.items.begin ()->first); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); @@ -1095,7 +1090,7 @@ TEST (rpc, payment_zero_balance) system.poll (); } ASSERT_EQ (200, response1.status); - auto account_text (response1.json.get ("account")); + auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_NE (rai::test_genesis_key.pub, account); @@ -1105,11 +1100,11 @@ TEST (rpc, payment_begin_reuse) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); @@ -1120,7 +1115,7 @@ TEST (rpc, payment_begin_reuse) system.poll (); } ASSERT_EQ (200, response1.status); - auto account_text (response1.json.get ("account")); + auto account_text (response1.json.get ("account")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_TRUE (wallet->exists (account)); @@ -1143,7 +1138,7 @@ TEST (rpc, payment_begin_reuse) system.poll (); } ASSERT_EQ (200, response3.status); - auto account2_text (response1.json.get ("account")); + auto account2_text (response1.json.get ("account")); rai::uint256_union account2; ASSERT_FALSE (account2.decode_account (account2_text)); ASSERT_EQ (account, account2); @@ -1153,16 +1148,16 @@ TEST (rpc, payment_begin_locked) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair wallet_id; auto wallet (node1->wallets.create (wallet_id.pub)); { rai::transaction transaction (wallet->store.environment, nullptr, true); - wallet->store.rekey(transaction, "1"); - ASSERT_TRUE (wallet->store.attempt_password(transaction, "")); + wallet->store.rekey (transaction, "1"); + ASSERT_TRUE (wallet->store.attempt_password (transaction, "")); } ASSERT_TRUE (node1->wallets.items.find (wallet_id.pub) != node1->wallets.items.end ()); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_begin"); @@ -1173,18 +1168,18 @@ TEST (rpc, payment_begin_locked) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_FALSE (response1.json.get ("error").empty ()); + ASSERT_FALSE (response1.json.get ("error").empty ()); } TEST (rpc, DISABLED_payment_wait) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "payment_wait"); @@ -1197,11 +1192,10 @@ TEST (rpc, DISABLED_payment_wait) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("nothing", response1.json.get ("status")); + ASSERT_EQ ("nothing", response1.json.get ("status")); request1.put ("timeout", "100000"); system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, rai::Mxrb_ratio); - system.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds(500), [&] () - { + system.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (500), [&]() { system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, rai::Mxrb_ratio); }); test_response response2 (request1, rpc, system.service); @@ -1210,7 +1204,7 @@ TEST (rpc, DISABLED_payment_wait) system.poll (); } ASSERT_EQ (200, response2.status); - ASSERT_EQ ("success", response2.json.get ("status")); + ASSERT_EQ ("success", response2.json.get ("status")); request1.put ("amount", rai::amount (rai::Mxrb_ratio * 2).to_string_dec ()); test_response response3 (request1, rpc, system.service); while (response3.status == 0) @@ -1218,14 +1212,14 @@ TEST (rpc, DISABLED_payment_wait) system.poll (); } ASSERT_EQ (200, response3.status); - ASSERT_EQ ("success", response2.json.get ("status")); + ASSERT_EQ ("success", response2.json.get ("status")); } TEST (rpc, peers) { rai::system system (24000, 2); - system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::from_string ("::ffff:80.80.80.80"), 4000), 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + system.nodes[0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::from_string ("::ffff:80.80.80.80"), 4000), 1); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "peers"); @@ -1245,7 +1239,7 @@ TEST (rpc, pending) rai::keypair key1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "pending"); @@ -1259,7 +1253,7 @@ TEST (rpc, pending) ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); ASSERT_EQ (1, blocks_node.size ()); - rai::block_hash hash1 (blocks_node.begin ()->second.get ("")); + rai::block_hash hash1 (blocks_node.begin ()->second.get ("")); ASSERT_EQ (block1->hash (), hash1); request.put ("threshold", "100"); // Threshold test test_response response0 (request, rpc, system.service); @@ -1270,14 +1264,14 @@ TEST (rpc, pending) ASSERT_EQ (200, response0.status); blocks_node = response0.json.get_child ("blocks"); ASSERT_EQ (1, blocks_node.size ()); - std::unordered_map blocks; + std::unordered_map blocks; for (auto i (blocks_node.begin ()), j (blocks_node.end ()); i != j; ++i) { rai::block_hash hash; hash.decode_hex (i->first); rai::uint128_union amount; - amount.decode_dec (i->second.get ("")); - blocks [hash] = amount; + amount.decode_dec (i->second.get ("")); + blocks[hash] = amount; } ASSERT_EQ (blocks[block1->hash ()], 100); request.put ("threshold", "101"); @@ -1299,14 +1293,14 @@ TEST (rpc, pending) ASSERT_EQ (200, response2.status); blocks_node = response2.json.get_child ("blocks"); ASSERT_EQ (1, blocks_node.size ()); - std::unordered_map amounts; - std::unordered_map sources; + std::unordered_map amounts; + std::unordered_map sources; for (auto i (blocks_node.begin ()), j (blocks_node.end ()); i != j; ++i) { rai::block_hash hash; hash.decode_hex (i->first); - amounts[hash].decode_dec (i->second.get ("amount")); - sources[hash].decode_account (i->second.get ("source")); + amounts[hash].decode_dec (i->second.get ("amount")); + sources[hash].decode_account (i->second.get ("source")); } ASSERT_EQ (amounts[block1->hash ()], 100); ASSERT_EQ (sources[block1->hash ()], rai::test_genesis_key.pub); @@ -1315,7 +1309,7 @@ TEST (rpc, pending) TEST (rpc_config, serialization) { rai::rpc_config config1; - config1.address = boost::asio::ip::address_v6::any(); + config1.address = boost::asio::ip::address_v6::any (); config1.port = 10; config1.enable_control = true; config1.frontier_request_limit = 8192; @@ -1340,10 +1334,10 @@ TEST (rpc, search_pending) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - auto wallet (system.nodes [0]->wallets.items.begin ()->first.to_string ()); - rai::send_block block (system.nodes [0]->latest (rai::test_genesis_key.pub), rai::test_genesis_key.pub, rai::genesis_amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (rai::transaction (system.nodes [0]->store.environment, nullptr, true), block).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + auto wallet (system.nodes[0]->wallets.items.begin ()->first.to_string ()); + rai::send_block block (system.nodes[0]->latest (rai::test_genesis_key.pub), rai::test_genesis_key.pub, rai::genesis_amount - system.nodes[0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->ledger.process (rai::transaction (system.nodes[0]->store.environment, nullptr, true), block).code); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "search_pending"); @@ -1355,7 +1349,7 @@ TEST (rpc, search_pending) } ASSERT_EQ (200, response.status); auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) { system.poll (); ++iterations; @@ -1367,11 +1361,11 @@ TEST (rpc, version) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "version"); @@ -1381,11 +1375,11 @@ TEST (rpc, version) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("rpc_version")); + ASSERT_EQ ("1", response1.json.get ("rpc_version")); ASSERT_EQ (200, response1.status); - ASSERT_EQ ("10", response1.json.get ("store_version")); - ASSERT_EQ (boost::str (boost::format ("RaiBlocks %1%.%2%") % RAIBLOCKS_VERSION_MAJOR % RAIBLOCKS_VERSION_MINOR), response1.json.get ("node_vendor")); - auto headers (response1.resp.base()); + ASSERT_EQ ("10", response1.json.get ("store_version")); + ASSERT_EQ (boost::str (boost::format ("RaiBlocks %1%.%2%") % RAIBLOCKS_VERSION_MAJOR % RAIBLOCKS_VERSION_MINOR), response1.json.get ("node_vendor")); + auto headers (response1.resp.base ()); auto allowed_origin (headers.at ("Access-Control-Allow-Origin")); auto allowed_headers (headers.at ("Access-Control-Allow-Headers")); ASSERT_EQ ("*", allowed_origin); @@ -1396,11 +1390,11 @@ TEST (rpc, work_generate) { rai::system system (24000, 1); rai::node_init init1; - auto node1 (system.nodes [0]); + auto node1 (system.nodes[0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); rai::block_hash hash1 (1); boost::property_tree::ptree request1; @@ -1412,7 +1406,7 @@ TEST (rpc, work_generate) system.poll (); } ASSERT_EQ (200, response1.status); - auto work1 (response1.json.get ("work")); + auto work1 (response1.json.get ("work")); uint64_t work2; ASSERT_FALSE (rai::from_string_hex (work1, work2)); ASSERT_FALSE (rai::work_validate (hash1, work2)); @@ -1422,7 +1416,7 @@ TEST (rpc, work_cancel) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); @@ -1432,9 +1426,8 @@ TEST (rpc, work_cancel) boost::property_tree::ptree request1; request1.put ("action", "work_cancel"); request1.put ("hash", hash1.to_string ()); - boost::optional work; - std::thread thread ([&] () - { + boost::optional work; + std::thread thread ([&]() { work = system.work.generate (hash1); }); test_response response1 (request1, rpc, system.service); @@ -1450,8 +1443,8 @@ TEST (rpc, work_peer_bad) { rai::system system (24000, 2); rai::node_init init1; - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); @@ -1459,9 +1452,8 @@ TEST (rpc, work_peer_bad) rpc.start (); node2.config.work_peers.push_back (std::make_pair (boost::asio::ip::address_v6::any (), 0)); rai::block_hash hash1 (1); - std::atomic work (0); - node2.generate_work (hash1, [&work] (uint64_t work_a) - { + std::atomic work (0); + node2.generate_work (hash1, [&work](uint64_t work_a) { work = work_a; }); while (rai::work_validate (hash1, work)) @@ -1474,8 +1466,8 @@ TEST (rpc, work_peer_one) { rai::system system (24000, 2); rai::node_init init1; - auto & node1 (*system.nodes [0]); - auto & node2 (*system.nodes [1]); + auto & node1 (*system.nodes[0]); + auto & node2 (*system.nodes[1]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); @@ -1484,8 +1476,7 @@ TEST (rpc, work_peer_one) node2.config.work_peers.push_back (std::make_pair (node1.network.endpoint ().address (), rpc.config.port)); rai::keypair key1; uint64_t work (0); - node2.generate_work (key1.pub, [&work] (uint64_t work_a) - { + node2.generate_work (key1.pub, [&work](uint64_t work_a) { work = work_a; }); while (rai::work_validate (key1.pub, work)) @@ -1501,10 +1492,10 @@ TEST (rpc, work_peer_many) rai::system system3 (24002, 1); rai::system system4 (24003, 1); rai::node_init init1; - auto & node1 (*system1.nodes [0]); - auto & node2 (*system2.nodes [0]); - auto & node3 (*system3.nodes [0]); - auto & node4 (*system4.nodes [0]); + auto & node1 (*system1.nodes[0]); + auto & node2 (*system2.nodes[0]); + auto & node3 (*system3.nodes[0]); + auto & node4 (*system4.nodes[0]); rai::keypair key; rai::rpc_config config2 (true); config2.port += 0; @@ -1525,8 +1516,7 @@ TEST (rpc, work_peer_many) { rai::keypair key1; uint64_t work (0); - node1.generate_work (key1.pub, [&work] (uint64_t work_a) - { + node1.generate_work (key1.pub, [&work](uint64_t work_a) { work = work_a; }); while (rai::work_validate (key1.pub, work)) @@ -1543,7 +1533,7 @@ TEST (rpc, block_count) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1554,15 +1544,15 @@ TEST (rpc, block_count) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("count")); - ASSERT_EQ ("0", response1.json.get ("unchecked")); + ASSERT_EQ ("1", response1.json.get ("count")); + ASSERT_EQ ("0", response1.json.get ("unchecked")); } TEST (rpc, frontier_count) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1573,14 +1563,14 @@ TEST (rpc, frontier_count) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("count")); + ASSERT_EQ ("1", response1.json.get ("count")); } TEST (rpc, available_supply) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1591,7 +1581,7 @@ TEST (rpc, available_supply) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("0", response1.json.get ("available")); + ASSERT_EQ ("0", response1.json.get ("available")); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); @@ -1601,7 +1591,7 @@ TEST (rpc, available_supply) system.poll (); } ASSERT_EQ (200, response2.status); - ASSERT_EQ ("1", response2.json.get ("available")); + ASSERT_EQ ("1", response2.json.get ("available")); auto block2 (system.wallet (0)->send_action (rai::test_genesis_key.pub, 0, 100)); // Sending to burning 0 account test_response response3 (request1, rpc, system.service); while (response3.status == 0) @@ -1609,14 +1599,14 @@ TEST (rpc, available_supply) system.poll (); } ASSERT_EQ (200, response3.status); - ASSERT_EQ ("1", response3.json.get ("available")); + ASSERT_EQ ("1", response3.json.get ("available")); } TEST (rpc, mrai_to_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1628,33 +1618,33 @@ TEST (rpc, mrai_to_raw) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ (rai::Mxrb_ratio.convert_to (), response1.json.get ("amount")); + ASSERT_EQ (rai::Mxrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, mrai_from_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "mrai_from_raw"); - request1.put ("amount", rai::Mxrb_ratio.convert_to ()); + request1.put ("amount", rai::Mxrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("amount")); + ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, krai_to_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1666,33 +1656,33 @@ TEST (rpc, krai_to_raw) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ (rai::kxrb_ratio.convert_to (), response1.json.get ("amount")); + ASSERT_EQ (rai::kxrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, krai_from_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "krai_from_raw"); - request1.put ("amount", rai::kxrb_ratio.convert_to ()); + request1.put ("amount", rai::kxrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("amount")); + ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, rai_to_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; @@ -1704,32 +1694,32 @@ TEST (rpc, rai_to_raw) system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ (rai::xrb_ratio.convert_to (), response1.json.get ("amount")); + ASSERT_EQ (rai::xrb_ratio.convert_to (), response1.json.get ("amount")); } TEST (rpc, rai_from_raw) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request1; request1.put ("action", "rai_from_raw"); - request1.put ("amount", rai::xrb_ratio.convert_to ()); + request1.put ("amount", rai::xrb_ratio.convert_to ()); test_response response1 (request1, rpc, system.service); while (response1.status == 0) { system.poll (); } ASSERT_EQ (200, response1.status); - ASSERT_EQ ("1", response1.json.get ("amount")); + ASSERT_EQ ("1", response1.json.get ("amount")); } TEST (rpc, account_representative) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; @@ -1741,7 +1731,7 @@ TEST (rpc, account_representative) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("representative")); + std::string account_text1 (response.json.get ("representative")); ASSERT_EQ (account_text1, rai::genesis_account.to_account ()); } @@ -1749,13 +1739,13 @@ TEST (rpc, account_representative_set) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; rai::keypair rep; request.put ("account", rai::genesis_account.to_account ()); request.put ("representative", rep.pub.to_account ()); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("action", "account_representative_set"); test_response response (request, rpc, system.service); while (response.status == 0) @@ -1763,38 +1753,38 @@ TEST (rpc, account_representative_set) system.poll (); } ASSERT_EQ (200, response.status); - std::string block_text1 (response.json.get ("block")); + std::string block_text1 (response.json.get ("block")); rai::block_hash hash; ASSERT_FALSE (hash.decode_hex (block_text1)); ASSERT_FALSE (hash.is_zero ()); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - ASSERT_TRUE (system.nodes [0]->store.block_exists (transaction, hash)); - ASSERT_EQ (rep.pub, system.nodes [0]->store.block_get (transaction, hash)->representative ()); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + ASSERT_TRUE (system.nodes[0]->store.block_exists (transaction, hash)); + ASSERT_EQ (rep.pub, system.nodes[0]->store.block_get (transaction, hash)->representative ()); } TEST (rpc, bootstrap) { rai::system system0 (24000, 1); rai::system system1 (24001, 1); - auto latest (system1.nodes [0]->latest (rai::test_genesis_key.pub)); - rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes [0]->generate_work (latest)); + auto latest (system1.nodes[0]->latest (rai::test_genesis_key.pub)); + rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes[0]->generate_work (latest)); { - rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); - ASSERT_EQ (rai::process_result::progress, system1.nodes [0]->ledger.process (transaction, send).code); + rai::transaction transaction (system1.nodes[0]->store.environment, nullptr, true); + ASSERT_EQ (rai::process_result::progress, system1.nodes[0]->ledger.process (transaction, send).code); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "bootstrap"); request.put ("address", "::ffff:127.0.0.1"); - request.put ("port", system1.nodes [0]->network.endpoint ().port ()); + request.put ("port", system1.nodes[0]->network.endpoint ().port ()); test_response response (request, rpc, system0.service); while (response.status == 0) { system0.poll (); } auto iterations (0); - while (system0.nodes [0]->latest (rai::genesis_account) != system1.nodes [0]->latest (rai::genesis_account)) + while (system0.nodes[0]->latest (rai::genesis_account) != system1.nodes[0]->latest (rai::genesis_account)) { system0.poll (); system1.poll (); @@ -1808,11 +1798,11 @@ TEST (rpc, account_remove) rai::system system0 (24000, 1); auto key1 (system0.wallet (0)->deterministic_insert ()); ASSERT_TRUE (system0.wallet (0)->exists (key1)); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "account_remove"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("account", key1.to_account ()); test_response response (request, rpc, system0.service); while (response.status == 0) @@ -1825,7 +1815,7 @@ TEST (rpc, account_remove) TEST (rpc, representatives) { rai::system system0 (24000, 1); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "representatives"); @@ -1836,7 +1826,7 @@ TEST (rpc, representatives) } ASSERT_EQ (200, response.status); auto & representatives_node (response.json.get_child ("representatives")); - std::vector representatives; + std::vector representatives; for (auto i (representatives_node.begin ()), n (representatives_node.end ()); i != n; ++i) { rai::account account; @@ -1844,7 +1834,7 @@ TEST (rpc, representatives) representatives.push_back (account); } ASSERT_EQ (1, representatives.size ()); - ASSERT_EQ (rai::genesis_account, representatives [0]); + ASSERT_EQ (rai::genesis_account, representatives[0]); } TEST (rpc, wallet_change_seed) @@ -1852,16 +1842,16 @@ TEST (rpc, wallet_change_seed) rai::system system0 (24000, 1); rai::keypair seed; { - rai::transaction transaction (system0.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system0.nodes[0]->store.environment, nullptr, false); rai::raw_key seed0; system0.wallet (0)->store.seed (seed0, transaction); ASSERT_NE (seed.pub, seed0.data); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); 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 ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("seed", seed.pub.to_string ()); test_response response (request, rpc, system0.service); while (response.status == 0) @@ -1870,7 +1860,7 @@ TEST (rpc, wallet_change_seed) } ASSERT_EQ (200, response.status); { - rai::transaction transaction (system0.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system0.nodes[0]->store.environment, nullptr, false); rai::raw_key seed0; system0.wallet (0)->store.seed (seed0, transaction); ASSERT_EQ (seed.pub, seed0.data); @@ -1881,11 +1871,11 @@ TEST (rpc, wallet_frontiers) { rai::system system0 (24000, 1); system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_frontiers"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system0.service); while (response.status == 0) { @@ -1893,20 +1883,20 @@ TEST (rpc, wallet_frontiers) } ASSERT_EQ (200, response.status); auto & frontiers_node (response.json.get_child ("frontiers")); - std::vector frontiers; + std::vector frontiers; for (auto i (frontiers_node.begin ()), n (frontiers_node.end ()); i != n; ++i) { - frontiers.push_back (rai::block_hash (i->second.get (""))); + frontiers.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (1, frontiers.size ()); - ASSERT_EQ (system0.nodes [0]->latest (rai::genesis_account), frontiers [0]); + ASSERT_EQ (system0.nodes[0]->latest (rai::genesis_account), frontiers[0]); } TEST (rpc, work_validate) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); @@ -1924,7 +1914,7 @@ TEST (rpc, work_validate) system.poll (); } ASSERT_EQ (200, response1.status); - std::string validate_text1 (response1.json.get ("valid")); + std::string validate_text1 (response1.json.get ("valid")); ASSERT_EQ ("1", validate_text1); uint64_t work2 (0); request.put ("work", rai::to_string_hex (work2)); @@ -1934,7 +1924,7 @@ TEST (rpc, work_validate) system.poll (); } ASSERT_EQ (200, response2.status); - std::string validate_text2 (response2.json.get ("valid")); + std::string validate_text2 (response2.json.get ("valid")); ASSERT_EQ ("0", validate_text2); } @@ -1943,16 +1933,16 @@ TEST (rpc, successors) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key; - auto genesis (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto genesis (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_FALSE (genesis.is_zero ()); auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); ASSERT_NE (nullptr, block); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "successors"); request.put ("block", genesis.to_string ()); - request.put ("count", std::to_string (std::numeric_limits ::max ())); + request.put ("count", std::to_string (std::numeric_limits::max ())); test_response response (request, rpc, system.service); while (response.status == 0) { @@ -1960,27 +1950,27 @@ TEST (rpc, successors) } ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); - std::vector blocks; + std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (2, blocks.size ()); - ASSERT_EQ (genesis, blocks [0]); - ASSERT_EQ (block->hash(), blocks [1]); + ASSERT_EQ (genesis, blocks[0]); + ASSERT_EQ (block->hash (), blocks[1]); } TEST (rpc, bootstrap_any) { rai::system system0 (24000, 1); rai::system system1 (24001, 1); - auto latest (system1.nodes [0]->latest (rai::test_genesis_key.pub)); - rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes [0]->generate_work (latest)); + auto latest (system1.nodes[0]->latest (rai::test_genesis_key.pub)); + rai::send_block send (latest, rai::genesis_account, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.nodes[0]->generate_work (latest)); { - rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); - ASSERT_EQ (rai::process_result::progress, system1.nodes [0]->ledger.process (transaction, send).code); + rai::transaction transaction (system1.nodes[0]->store.environment, nullptr, true); + ASSERT_EQ (rai::process_result::progress, system1.nodes[0]->ledger.process (transaction, send).code); } - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "bootstrap_any"); @@ -1989,8 +1979,8 @@ TEST (rpc, bootstrap_any) { system0.poll (); } - std::string success (response.json.get ("success")); - ASSERT_TRUE (success.empty()); + std::string success (response.json.get ("success")); + ASSERT_TRUE (success.empty ()); } TEST (rpc, republish) @@ -1998,12 +1988,12 @@ TEST (rpc, republish) rai::system system (24000, 2); rai::keypair key; rai::genesis genesis; - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); - auto & node1 (*system.nodes [0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); + system.nodes[0]->process (send); rai::open_block open (send.hash (), key.pub, key.pub, key.prv, key.pub, node1.generate_work (key.pub)); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; @@ -2023,14 +2013,14 @@ TEST (rpc, republish) ASSERT_GT (200, iterations); } auto & blocks_node (response.json.get_child ("blocks")); - std::vector blocks; + std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (1, blocks.size ()); - ASSERT_EQ (send.hash (), blocks [0]); - + ASSERT_EQ (send.hash (), blocks[0]); + request.put ("hash", genesis.hash ().to_string ()); request.put ("count", 1); test_response response1 (request, rpc, system.service); @@ -2040,14 +2030,14 @@ TEST (rpc, republish) } ASSERT_EQ (200, response1.status); blocks_node = response1.json.get_child ("blocks"); - blocks.clear(); + blocks.clear (); for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (1, blocks.size ()); - ASSERT_EQ (genesis.hash (), blocks [0]); - + ASSERT_EQ (genesis.hash (), blocks[0]); + request.put ("hash", open.hash ().to_string ()); request.put ("sources", 2); test_response response2 (request, rpc, system.service); @@ -2057,15 +2047,15 @@ TEST (rpc, republish) } ASSERT_EQ (200, response2.status); blocks_node = response2.json.get_child ("blocks"); - blocks.clear(); + blocks.clear (); for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (3, blocks.size ()); - ASSERT_EQ (genesis.hash (), blocks [0]); - ASSERT_EQ (send.hash (), blocks [1]); - ASSERT_EQ (open.hash (), blocks [2]); + ASSERT_EQ (genesis.hash (), blocks[0]); + ASSERT_EQ (send.hash (), blocks[1]); + ASSERT_EQ (open.hash (), blocks[2]); } TEST (rpc, deterministic_key) @@ -2073,13 +2063,13 @@ TEST (rpc, deterministic_key) rai::system system0 (24000, 1); rai::raw_key seed; { - rai::transaction transaction (system0.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system0.nodes[0]->store.environment, nullptr, false); system0.wallet (0)->store.seed (seed, transaction); } rai::account account0 (system0.wallet (0)->deterministic_insert ()); rai::account account1 (system0.wallet (0)->deterministic_insert ()); rai::account account2 (system0.wallet (0)->deterministic_insert ()); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "deterministic_key"); @@ -2091,7 +2081,7 @@ TEST (rpc, deterministic_key) system0.poll (); } ASSERT_EQ (200, response0.status); - std::string validate_text (response0.json.get ("account")); + std::string validate_text (response0.json.get ("account")); ASSERT_EQ (account0.to_account (), validate_text); request.put ("index", "2"); test_response response1 (request, rpc, system0.service); @@ -2100,7 +2090,7 @@ TEST (rpc, deterministic_key) system0.poll (); } ASSERT_EQ (200, response1.status); - validate_text = response1.json.get ("account"); + validate_text = response1.json.get ("account"); ASSERT_NE (account1.to_account (), validate_text); ASSERT_EQ (account2.to_account (), validate_text); } @@ -2108,7 +2098,7 @@ TEST (rpc, deterministic_key) TEST (rpc, accounts_balances) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "accounts_balances"); @@ -2127,9 +2117,9 @@ TEST (rpc, accounts_balances) { std::string account_text (balances.first); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string balance_text (balances.second.get ("balance")); + std::string balance_text (balances.second.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); - std::string pending_text (balances.second.get ("pending")); + std::string pending_text (balances.second.get ("pending")); ASSERT_EQ ("0", pending_text); } } @@ -2138,7 +2128,7 @@ TEST (rpc, accounts_frontiers) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "accounts_frontiers"); @@ -2157,8 +2147,8 @@ TEST (rpc, accounts_frontiers) { std::string account_text (frontiers.first); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string frontier_text (frontiers.second.get ("")); - ASSERT_EQ (system.nodes [0]->latest (rai::genesis_account), frontier_text); + std::string frontier_text (frontiers.second.get ("")); + ASSERT_EQ (system.nodes[0]->latest (rai::genesis_account), frontier_text); } } @@ -2168,7 +2158,7 @@ TEST (rpc, accounts_pending) rai::keypair key1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "accounts_pending"); @@ -2184,11 +2174,11 @@ TEST (rpc, accounts_pending) system.poll (); } ASSERT_EQ (200, response.status); - for (auto & blocks : response.json.get_child("blocks")) + for (auto & blocks : response.json.get_child ("blocks")) { std::string account_text (blocks.first); ASSERT_EQ (key1.pub.to_account (), account_text); - rai::block_hash hash1 (blocks.second.begin ()->second.get ("")); + rai::block_hash hash1 (blocks.second.begin ()->second.get ("")); ASSERT_EQ (block1->hash (), hash1); } request.put ("threshold", "100"); // Threshold test @@ -2198,8 +2188,8 @@ TEST (rpc, accounts_pending) system.poll (); } ASSERT_EQ (200, response1.status); - std::unordered_map blocks; - for (auto & pending : response1.json.get_child("blocks")) + std::unordered_map blocks; + for (auto & pending : response1.json.get_child ("blocks")) { std::string account_text (pending.first); ASSERT_EQ (key1.pub.to_account (), account_text); @@ -2208,8 +2198,8 @@ TEST (rpc, accounts_pending) rai::block_hash hash; hash.decode_hex (i->first); rai::uint128_union amount; - amount.decode_dec (i->second.get ("")); - blocks [hash] = amount; + amount.decode_dec (i->second.get ("")); + blocks[hash] = amount; } } ASSERT_EQ (blocks[block1->hash ()], 100); @@ -2220,9 +2210,9 @@ TEST (rpc, accounts_pending) system.poll (); } ASSERT_EQ (200, response2.status); - std::unordered_map amounts; - std::unordered_map sources; - for (auto & pending : response2.json.get_child("blocks")) + std::unordered_map amounts; + std::unordered_map sources; + for (auto & pending : response2.json.get_child ("blocks")) { std::string account_text (pending.first); ASSERT_EQ (key1.pub.to_account (), account_text); @@ -2230,8 +2220,8 @@ TEST (rpc, accounts_pending) { rai::block_hash hash; hash.decode_hex (i->first); - amounts[hash].decode_dec (i->second.get ("amount")); - sources[hash].decode_account (i->second.get ("source")); + amounts[hash].decode_dec (i->second.get ("amount")); + sources[hash].decode_account (i->second.get ("source")); } } ASSERT_EQ (amounts[block1->hash ()], 100); @@ -2241,13 +2231,13 @@ TEST (rpc, accounts_pending) TEST (rpc, blocks) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "blocks"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", system.nodes [0]->latest (rai::genesis_account).to_string ()); + entry.put ("", system.nodes[0]->latest (rai::genesis_account).to_string ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("hashes", peers_l); test_response response (request, rpc, system.service); @@ -2259,8 +2249,8 @@ TEST (rpc, blocks) for (auto & blocks : response.json.get_child ("blocks")) { std::string hash_text (blocks.first); - ASSERT_EQ (system.nodes [0]->latest (rai::genesis_account).to_string (), hash_text); - std::string blocks_text (blocks.second.get ("")); + ASSERT_EQ (system.nodes[0]->latest (rai::genesis_account).to_string (), hash_text); + std::string blocks_text (blocks.second.get ("")); ASSERT_FALSE (blocks_text.empty ()); } } @@ -2272,20 +2262,20 @@ TEST (rpc, wallet_balance_total) rai::keypair key; system.wallet (0)->insert_adhoc (key.prv); auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 1)); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_balance_total"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - std::string balance_text (response.json.get ("balance")); + std::string balance_text (response.json.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211454", balance_text); - std::string pending_text (response.json.get ("pending")); + std::string pending_text (response.json.get ("pending")); ASSERT_EQ ("1", pending_text); } @@ -2293,24 +2283,24 @@ TEST (rpc, wallet_balances) { rai::system system0 (24000, 1); system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_balances"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system0.service); while (response.status == 0) { system0.poll (); } ASSERT_EQ (200, response.status); - for (auto & balances : response.json.get_child("balances")) + for (auto & balances : response.json.get_child ("balances")) { std::string account_text (balances.first); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string balance_text (balances.second.get ("balance")); + std::string balance_text (balances.second.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211455", balance_text); - std::string pending_text (balances.second.get ("pending")); + std::string pending_text (balances.second.get ("pending")); ASSERT_EQ ("0", pending_text); } rai::keypair key; @@ -2323,13 +2313,13 @@ TEST (rpc, wallet_balances) system0.poll (); } ASSERT_EQ (200, response1.status); - for (auto & balances : response1.json.get_child("balances")) + for (auto & balances : response1.json.get_child ("balances")) { std::string account_text (balances.first); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string balance_text (balances.second.get ("balance")); + std::string balance_text (balances.second.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211454", balance_text); - std::string pending_text (balances.second.get ("pending")); + std::string pending_text (balances.second.get ("pending")); ASSERT_EQ ("0", pending_text); } } @@ -2339,9 +2329,9 @@ TEST (rpc, pending_exists) rai::system system (24000, 1); rai::keypair key1; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - auto hash0 (system.nodes [0]->latest (rai::genesis_account)); + auto hash0 (system.nodes[0]->latest (rai::genesis_account)); auto block1 (system.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "pending_exists"); @@ -2352,7 +2342,7 @@ TEST (rpc, pending_exists) system.poll (); } ASSERT_EQ (200, response0.status); - std::string exists_text (response0.json.get ("exists")); + std::string exists_text (response0.json.get ("exists")); ASSERT_EQ ("0", exists_text); request.put ("hash", block1->hash ().to_string ()); test_response response1 (request, rpc, system.service); @@ -2361,7 +2351,7 @@ TEST (rpc, pending_exists) system.poll (); } ASSERT_EQ (200, response1.status); - std::string exists_text1 (response1.json.get ("exists")); + std::string exists_text1 (response1.json.get ("exists")); ASSERT_EQ ("1", exists_text1); } @@ -2372,11 +2362,11 @@ TEST (rpc, wallet_pending) system0.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system0.wallet (0)->insert_adhoc (key1.prv); auto block1 (system0.wallet (0)->send_action (rai::test_genesis_key.pub, key1.pub, 100)); - rai::rpc rpc (system0.service, *system0.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system0.service, *system0.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_pending"); - request.put ("wallet", system0.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system0.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("count", "100"); test_response response (request, rpc, system0.service); while (response.status == 0) @@ -2384,11 +2374,11 @@ TEST (rpc, wallet_pending) system0.poll (); } ASSERT_EQ (200, response.status); - for (auto & pending : response.json.get_child("blocks")) + for (auto & pending : response.json.get_child ("blocks")) { std::string account_text (pending.first); ASSERT_EQ (key1.pub.to_account (), account_text); - rai::block_hash hash1 (pending.second.begin ()->second.get ("")); + rai::block_hash hash1 (pending.second.begin ()->second.get ("")); ASSERT_EQ (block1->hash (), hash1); } request.put ("threshold", "100"); // Threshold test @@ -2398,8 +2388,8 @@ TEST (rpc, wallet_pending) system0.poll (); } ASSERT_EQ (200, response0.status); - std::unordered_map blocks; - for (auto & pending : response0.json.get_child("blocks")) + std::unordered_map blocks; + for (auto & pending : response0.json.get_child ("blocks")) { std::string account_text (pending.first); ASSERT_EQ (key1.pub.to_account (), account_text); @@ -2408,8 +2398,8 @@ TEST (rpc, wallet_pending) rai::block_hash hash; hash.decode_hex (i->first); rai::uint128_union amount; - amount.decode_dec (i->second.get ("")); - blocks [hash] = amount; + amount.decode_dec (i->second.get ("")); + blocks[hash] = amount; } } ASSERT_EQ (blocks[block1->hash ()], 100); @@ -2430,9 +2420,9 @@ TEST (rpc, wallet_pending) system0.poll (); } ASSERT_EQ (200, response2.status); - std::unordered_map amounts; - std::unordered_map sources; - for (auto & pending : response2.json.get_child("blocks")) + std::unordered_map amounts; + std::unordered_map sources; + for (auto & pending : response2.json.get_child ("blocks")) { std::string account_text (pending.first); ASSERT_EQ (key1.pub.to_account (), account_text); @@ -2440,8 +2430,8 @@ TEST (rpc, wallet_pending) { rai::block_hash hash; hash.decode_hex (i->first); - amounts[hash].decode_dec (i->second.get ("amount")); - sources[hash].decode_account (i->second.get ("source")); + amounts[hash].decode_dec (i->second.get ("amount")); + sources[hash].decode_account (i->second.get ("source")); } } ASSERT_EQ (amounts[block1->hash ()], 100); @@ -2451,7 +2441,7 @@ TEST (rpc, wallet_pending) TEST (rpc, receive_minimum) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "receive_minimum"); @@ -2461,39 +2451,39 @@ TEST (rpc, receive_minimum) system.poll (); } ASSERT_EQ (200, response.status); - std::string amount (response.json.get ("amount")); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.to_string_dec (), amount); + std::string amount (response.json.get ("amount")); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.to_string_dec (), amount); } TEST (rpc, receive_minimum_set) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "receive_minimum_set"); request.put ("amount", "100"); - ASSERT_NE (system.nodes [0]->config.receive_minimum.to_string_dec (), "100"); + ASSERT_NE (system.nodes[0]->config.receive_minimum.to_string_dec (), "100"); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - std::string success (response.json.get ("success")); - ASSERT_TRUE (success.empty()); - ASSERT_EQ (system.nodes [0]->config.receive_minimum.to_string_dec (), "100"); + std::string success (response.json.get ("success")); + ASSERT_TRUE (success.empty ()); + ASSERT_EQ (system.nodes[0]->config.receive_minimum.to_string_dec (), "100"); } TEST (rpc, work_get) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "work_get"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("account", rai::test_genesis_key.pub.to_account ()); test_response response (request, rpc, system.service); while (response.status == 0) @@ -2501,10 +2491,10 @@ TEST (rpc, work_get) system.poll (); } ASSERT_EQ (200, response.status); - std::string work_text (response.json.get ("work")); + std::string work_text (response.json.get ("work")); uint64_t work (1); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work); ASSERT_EQ (rai::to_string_hex (work), work_text); } @@ -2512,25 +2502,25 @@ TEST (rpc, wallet_work_get) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_work_get"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); test_response response (request, rpc, system.service); while (response.status == 0) { system.poll (); } ASSERT_EQ (200, response.status); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - for (auto & works : response.json.get_child("works")) + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + for (auto & works : response.json.get_child ("works")) { std::string account_text (works.first); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string work_text (works.second.get ("")); + std::string work_text (works.second.get ("")); uint64_t work (1); - system.nodes [0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work); + system.nodes[0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work); ASSERT_EQ (rai::to_string_hex (work), work_text); } } @@ -2540,11 +2530,11 @@ TEST (rpc, work_set) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); uint64_t work0 (100); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "work_set"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("account", rai::test_genesis_key.pub.to_account ()); request.put ("work", rai::to_string_hex (work0)); test_response response (request, rpc, system.service); @@ -2553,11 +2543,11 @@ TEST (rpc, work_set) system.poll (); } ASSERT_EQ (200, response.status); - std::string success (response.json.get ("success")); - ASSERT_TRUE (success.empty()); + std::string success (response.json.get ("success")); + ASSERT_TRUE (success.empty ()); uint64_t work1 (1); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work1); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->wallets.items.begin ()->second->store.work_get (transaction, rai::genesis_account, work1); ASSERT_EQ (work1, work0); } @@ -2565,9 +2555,9 @@ TEST (rpc, search_pending_all) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::send_block block (system.nodes [0]->latest (rai::test_genesis_key.pub), rai::test_genesis_key.pub, rai::genesis_amount - system.nodes [0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (rai::transaction (system.nodes [0]->store.environment, nullptr, true), block).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::send_block block (system.nodes[0]->latest (rai::test_genesis_key.pub), rai::test_genesis_key.pub, rai::genesis_amount - system.nodes[0]->config.receive_minimum.number (), rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->ledger.process (rai::transaction (system.nodes[0]->store.environment, nullptr, true), block).code); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "search_pending_all"); @@ -2578,7 +2568,7 @@ TEST (rpc, search_pending_all) } ASSERT_EQ (200, response.status); auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount) { system.poll (); ++iterations; @@ -2599,17 +2589,17 @@ TEST (rpc, wallet_republish) } system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); + system.nodes[0]->process (send); rai::open_block open (send.hash (), key.pub, key.pub, key.prv, key.pub, node1.generate_work (key.pub)); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "wallet_republish"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("count", 1); test_response response (request, rpc, system.service); while (response.status == 0) @@ -2618,14 +2608,14 @@ TEST (rpc, wallet_republish) } ASSERT_EQ (200, response.status); auto & blocks_node (response.json.get_child ("blocks")); - std::vector blocks; + std::vector blocks; for (auto i (blocks_node.begin ()), n (blocks_node.end ()); i != n; ++i) { - blocks.push_back (rai::block_hash (i->second.get (""))); + blocks.push_back (rai::block_hash (i->second.get (""))); } ASSERT_EQ (2, blocks.size ()); - ASSERT_EQ (send.hash (), blocks [0]); - ASSERT_EQ (open.hash (), blocks [1]); + ASSERT_EQ (send.hash (), blocks[0]); + ASSERT_EQ (open.hash (), blocks[1]); } TEST (rpc, delegators) @@ -2634,13 +2624,13 @@ TEST (rpc, delegators) rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); + system.nodes[0]->process (send); rai::open_block open (send.hash (), rai::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.generate_work (key.pub)); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "delegators"); @@ -2655,11 +2645,11 @@ TEST (rpc, delegators) boost::property_tree::ptree delegators; for (auto i (delegators_node.begin ()), n (delegators_node.end ()); i != n; ++i) { - delegators.put ((i->first), (i->second.get (""))); + delegators.put ((i->first), (i->second.get (""))); } ASSERT_EQ (2, delegators.size ()); - ASSERT_EQ ("100", delegators.get (rai::test_genesis_key.pub.to_account ())); - ASSERT_EQ ("340282366920938463463374607431768211355", delegators.get (key.pub.to_account ())); + ASSERT_EQ ("100", delegators.get (rai::test_genesis_key.pub.to_account ())); + ASSERT_EQ ("340282366920938463463374607431768211355", delegators.get (key.pub.to_account ())); } TEST (rpc, delegators_count) @@ -2668,13 +2658,13 @@ TEST (rpc, delegators_count) rai::keypair key; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); + system.nodes[0]->process (send); rai::open_block open (send.hash (), rai::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.generate_work (key.pub)); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "delegators_count"); @@ -2685,7 +2675,7 @@ TEST (rpc, delegators_count) system.poll (); } ASSERT_EQ (200, response.status); - std::string count (response.json.get ("count")); + std::string count (response.json.get ("count")); ASSERT_EQ ("2", count); } @@ -2696,12 +2686,12 @@ TEST (rpc, account_info) rai::genesis genesis; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); - auto time (std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + system.nodes[0]->process (send); + auto time (std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ())); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "account_info"); @@ -2712,30 +2702,30 @@ TEST (rpc, account_info) system.poll (); } ASSERT_EQ (200, response.status); - std::string frontier (response.json.get ("frontier")); + std::string frontier (response.json.get ("frontier")); ASSERT_EQ (send.hash ().to_string (), frontier); - std::string open_block (response.json.get ("open_block")); + std::string open_block (response.json.get ("open_block")); ASSERT_EQ (genesis.hash ().to_string (), open_block); - std::string representative_block (response.json.get ("representative_block")); + std::string representative_block (response.json.get ("representative_block")); ASSERT_EQ (genesis.hash ().to_string (), representative_block); - std::string balance (response.json.get ("balance")); + std::string balance (response.json.get ("balance")); ASSERT_EQ ("100", balance); - std::string modified_timestamp (response.json.get ("modified_timestamp")); + std::string modified_timestamp (response.json.get ("modified_timestamp")); ASSERT_EQ (std::to_string (time), modified_timestamp); - std::string block_count (response.json.get ("block_count")); + std::string block_count (response.json.get ("block_count")); ASSERT_EQ ("2", block_count); } TEST (rpc, blocks_info) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "blocks_info"); boost::property_tree::ptree entry; boost::property_tree::ptree peers_l; - entry.put ("", system.nodes [0]->latest (rai::genesis_account).to_string ()); + entry.put ("", system.nodes[0]->latest (rai::genesis_account).to_string ()); peers_l.push_back (std::make_pair ("", entry)); request.add_child ("hashes", peers_l); test_response response (request, rpc, system.service); @@ -2747,12 +2737,12 @@ TEST (rpc, blocks_info) for (auto & blocks : response.json.get_child ("blocks")) { std::string hash_text (blocks.first); - ASSERT_EQ (system.nodes [0]->latest (rai::genesis_account).to_string (), hash_text); - std::string account_text (blocks.second.get ("block_account")); + ASSERT_EQ (system.nodes[0]->latest (rai::genesis_account).to_string (), hash_text); + std::string account_text (blocks.second.get ("block_account")); ASSERT_EQ (rai::test_genesis_key.pub.to_account (), account_text); - std::string amount_text (blocks.second.get ("amount")); - ASSERT_EQ (rai::genesis_amount.convert_to (), amount_text); - std::string blocks_text (blocks.second.get ("contents")); + std::string amount_text (blocks.second.get ("amount")); + ASSERT_EQ (rai::genesis_amount.convert_to (), amount_text); + std::string blocks_text (blocks.second.get ("contents")); ASSERT_FALSE (blocks_text.empty ()); } } @@ -2761,7 +2751,7 @@ TEST (rpc, work_peers_all) { rai::system system (24000, 1); rai::node_init init1; - auto & node1 (*system.nodes [0]); + auto & node1 (*system.nodes[0]); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::rpc rpc (system.service, node1, rai::rpc_config (true)); rpc.start (); @@ -2775,8 +2765,8 @@ TEST (rpc, work_peers_all) system.poll (); } ASSERT_EQ (200, response.status); - std::string success (response.json.get ("success")); - ASSERT_TRUE (success.empty()); + std::string success (response.json.get ("success")); + ASSERT_TRUE (success.empty ()); boost::property_tree::ptree request1; request1.put ("action", "work_peers"); test_response response1 (request1, rpc, system.service); @@ -2786,10 +2776,10 @@ TEST (rpc, work_peers_all) } ASSERT_EQ (200, response1.status); auto & peers_node (response1.json.get_child ("work_peers")); - std::vector peers; + std::vector peers; for (auto i (peers_node.begin ()), n (peers_node.end ()); i != n; ++i) { - peers.push_back (i->second.get ("")); + peers.push_back (i->second.get ("")); } ASSERT_EQ (1, peers.size ()); ASSERT_EQ ("::1:0", peers[0]); @@ -2801,8 +2791,8 @@ TEST (rpc, work_peers_all) system.poll (); } ASSERT_EQ (200, response2.status); - success = response2.json.get ("success"); - ASSERT_TRUE (success.empty()); + success = response2.json.get ("success"); + ASSERT_TRUE (success.empty ()); test_response response3 (request1, rpc, system.service); while (response3.status == 0) { @@ -2817,11 +2807,11 @@ TEST (rpc, block_count_type) { rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto send (system.wallet (0)->send_action (rai::test_genesis_key.pub, rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, send); - auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes [0]->config.receive_minimum.number ())); + auto receive (system.wallet (0)->receive_action (static_cast (*send), rai::test_genesis_key.pub, system.nodes[0]->config.receive_minimum.number ())); ASSERT_NE (nullptr, receive); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "block_count_type"); @@ -2831,13 +2821,13 @@ TEST (rpc, block_count_type) system.poll (); } ASSERT_EQ (200, response.status); - std::string send_count (response.json.get ("send")); + std::string send_count (response.json.get ("send")); ASSERT_EQ ("1", send_count); - std::string receive_count (response.json.get ("receive")); + std::string receive_count (response.json.get ("receive")); ASSERT_EQ ("1", receive_count); - std::string open_count (response.json.get ("open")); + std::string open_count (response.json.get ("open")); ASSERT_EQ ("1", open_count); - std::string change_count (response.json.get ("change")); + std::string change_count (response.json.get ("change")); ASSERT_EQ ("0", change_count); } @@ -2848,14 +2838,14 @@ TEST (rpc, ledger) rai::genesis genesis; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (latest)); - system.nodes [0]->process (send); + system.nodes[0]->process (send); rai::open_block open (send.hash (), rai::test_genesis_key.pub, key.pub, key.prv, key.pub, node1.generate_work (key.pub)); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - auto time (std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + auto time (std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ())); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "ledger"); @@ -2866,21 +2856,21 @@ TEST (rpc, ledger) { system.poll (); } - for (auto & accounts : response.json.get_child("accounts")) + for (auto & accounts : response.json.get_child ("accounts")) { std::string account_text (accounts.first); ASSERT_EQ (key.pub.to_account (), account_text); - std::string frontier (accounts.second.get ("frontier")); + std::string frontier (accounts.second.get ("frontier")); ASSERT_EQ (open.hash ().to_string (), frontier); - std::string open_block (accounts.second.get ("open_block")); + std::string open_block (accounts.second.get ("open_block")); ASSERT_EQ (open.hash ().to_string (), open_block); - std::string representative_block (accounts.second.get ("representative_block")); + std::string representative_block (accounts.second.get ("representative_block")); ASSERT_EQ (open.hash ().to_string (), representative_block); - std::string balance_text (accounts.second.get ("balance")); + std::string balance_text (accounts.second.get ("balance")); ASSERT_EQ ("340282366920938463463374607431768211355", balance_text); - std::string modified_timestamp (accounts.second.get ("modified_timestamp")); + std::string modified_timestamp (accounts.second.get ("modified_timestamp")); ASSERT_EQ (std::to_string (time), modified_timestamp); - std::string block_count (accounts.second.get ("block_count")); + std::string block_count (accounts.second.get ("block_count")); ASSERT_EQ ("1", block_count); } } @@ -2888,11 +2878,11 @@ TEST (rpc, ledger) TEST (rpc, accounts_create) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "accounts_create"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("count", "8"); test_response response (request, rpc, system.service); while (response.status == 0) @@ -2903,7 +2893,7 @@ TEST (rpc, accounts_create) auto & accounts (response.json.get_child ("accounts")); for (auto i (accounts.begin ()), n (accounts.end ()); i != n; ++i) { - std::string account_text (i->second.get ("")); + std::string account_text (i->second.get ("")); rai::uint256_union account; ASSERT_FALSE (account.decode_account (account_text)); ASSERT_TRUE (system.wallet (0)->exists (account)); @@ -2918,18 +2908,18 @@ TEST (rpc, block_create) rai::genesis genesis; system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); - auto & node1 (*system.nodes [0]); - auto latest (system.nodes [0]->latest (rai::test_genesis_key.pub)); + auto & node1 (*system.nodes[0]); + auto latest (system.nodes[0]->latest (rai::test_genesis_key.pub)); auto send_work = node1.generate_work (latest); rai::send_block send (latest, key.pub, 100, rai::test_genesis_key.prv, rai::test_genesis_key.pub, send_work); auto open_work = node1.generate_work (key.pub); rai::open_block open (send.hash (), rai::test_genesis_key.pub, key.pub, key.prv, key.pub, open_work); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; request.put ("action", "block_create"); request.put ("type", "send"); - request.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request.put ("account", rai::test_genesis_key.pub.to_account ()); request.put ("previous", latest.to_string ()); request.put ("amount", "340282366920938463463374607431768211355"); @@ -2941,15 +2931,15 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response.status); - std::string send_hash (response.json.get ("hash")); + std::string send_hash (response.json.get ("hash")); ASSERT_EQ (send.hash ().to_string (), send_hash); - auto send_text (response.json.get ("block")); + auto send_text (response.json.get ("block")); boost::property_tree::ptree block_l; std::stringstream block_stream (send_text); boost::property_tree::read_json (block_stream, block_l); auto send_block (rai::deserialize_block_json (block_l)); ASSERT_EQ (send.hash (), send_block->hash ()); - system.nodes [0]->process (send); + system.nodes[0]->process (send); boost::property_tree::ptree request1; request1.put ("action", "block_create"); request1.put ("type", "open"); @@ -2965,14 +2955,14 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response1.status); - std::string open_hash (response1.json.get ("hash")); + std::string open_hash (response1.json.get ("hash")); ASSERT_EQ (open.hash ().to_string (), open_hash); - auto open_text (response1.json.get ("block")); + auto open_text (response1.json.get ("block")); std::stringstream block_stream1 (open_text); boost::property_tree::read_json (block_stream1, block_l); auto open_block (rai::deserialize_block_json (block_l)); ASSERT_EQ (open.hash (), open_block->hash ()); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); request1.put ("representative", key.pub.to_account ()); test_response response2 (request1, rpc, system.service); while (response2.status == 0) @@ -2980,7 +2970,7 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response2.status); - std::string open2_hash (response2.json.get ("hash")); + std::string open2_hash (response2.json.get ("hash")); ASSERT_NE (open.hash ().to_string (), open2_hash); // different blocks with wrong representative auto change_work = node1.generate_work (open.hash ()); rai::change_block change (open.hash (), key.pub, key.prv, key.pub, change_work); @@ -2992,7 +2982,7 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response3.status); - ASSERT_FALSE (response3.json.get ("error").empty ()); // error with missing previous block + ASSERT_FALSE (response3.json.get ("error").empty ()); // error with missing previous block request1.put ("previous", open.hash ().to_string ()); test_response response4 (request1, rpc, system.service); while (response4.status == 0) @@ -3000,20 +2990,20 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response4.status); - std::string change_hash (response4.json.get ("hash")); + std::string change_hash (response4.json.get ("hash")); ASSERT_EQ (change.hash ().to_string (), change_hash); - auto change_text (response4.json.get ("block")); + auto change_text (response4.json.get ("block")); std::stringstream block_stream4 (change_text); boost::property_tree::read_json (block_stream4, block_l); auto change_block (rai::deserialize_block_json (block_l)); ASSERT_EQ (change.hash (), change_block->hash ()); ASSERT_EQ (rai::process_result::progress, node1.process (change).code); rai::send_block send2 (send.hash (), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, node1.generate_work (send.hash ())); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (send2).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (send2).code); boost::property_tree::ptree request2; request2.put ("action", "block_create"); request2.put ("type", "receive"); - request2.put ("wallet", system.nodes [0]->wallets.items.begin ()->first.to_string ()); + request2.put ("wallet", system.nodes[0]->wallets.items.begin ()->first.to_string ()); request2.put ("account", key.pub.to_account ()); request2.put ("source", send2.hash ().to_string ()); request2.put ("previous", change.hash ().to_string ()); @@ -3024,25 +3014,25 @@ TEST (rpc, block_create) system.poll (); } ASSERT_EQ (200, response5.status); - std::string receive_hash (response4.json.get ("hash")); - auto receive_text (response5.json.get ("block")); + std::string receive_hash (response4.json.get ("hash")); + auto receive_text (response5.json.get ("block")); std::stringstream block_stream5 (change_text); boost::property_tree::read_json (block_stream5, block_l); auto receive_block (rai::deserialize_block_json (block_l)); ASSERT_EQ (receive_hash, receive_block->hash ().to_string ()); - system.nodes [0]->process_active (std::move (receive_block)); - latest = system.nodes [0]->latest (key.pub); + system.nodes[0]->process_active (std::move (receive_block)); + latest = system.nodes[0]->latest (key.pub); ASSERT_EQ (receive_hash, latest.to_string ()); } TEST (rpc, wallet_lock) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); ASSERT_TRUE (system.wallet (0)->valid_password ()); request.put ("wallet", wallet); request.put ("action", "wallet_lock"); @@ -3052,7 +3042,7 @@ TEST (rpc, wallet_lock) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("locked")); + std::string account_text1 (response.json.get ("locked")); ASSERT_EQ (account_text1, "1"); ASSERT_FALSE (system.wallet (0)->valid_password ()); } @@ -3060,11 +3050,11 @@ TEST (rpc, wallet_lock) TEST (rpc, wallet_locked) { rai::system system (24000, 1); - rai::rpc rpc (system.service, *system.nodes [0], rai::rpc_config (true)); + rai::rpc rpc (system.service, *system.nodes[0], rai::rpc_config (true)); rpc.start (); boost::property_tree::ptree request; std::string wallet; - system.nodes [0]->wallets.items.begin ()->first.encode_hex (wallet); + system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet); request.put ("wallet", wallet); request.put ("action", "wallet_locked"); test_response response (request, rpc, system.service); @@ -3073,6 +3063,6 @@ TEST (rpc, wallet_locked) system.poll (); } ASSERT_EQ (200, response.status); - std::string account_text1 (response.json.get ("locked")); + std::string account_text1 (response.json.get ("locked")); ASSERT_EQ (account_text1, "0"); } diff --git a/rai/core_test/uint256_union.cpp b/rai/core_test/uint256_union.cpp index 4a1e4134..a09cf7c5 100644 --- a/rai/core_test/uint256_union.cpp +++ b/rai/core_test/uint256_union.cpp @@ -10,7 +10,7 @@ TEST (uint128_union, decode_dec) rai::uint128_union value; std::string text ("16"); ASSERT_FALSE (value.decode_dec (text)); - ASSERT_EQ (16, value.bytes [15]); + ASSERT_EQ (16, value.bytes[15]); } TEST (uint128_union, decode_dec_negative) @@ -37,12 +37,28 @@ TEST (uint128_union, decode_dec_leading_zero) ASSERT_TRUE (error); } -struct test_punct : std::moneypunct { - pattern do_pos_format () const { return { {value, none, none, none} }; } - int do_frac_digits () const { return 0; } - char_type do_decimal_point () const { return '+'; } - char_type do_thousands_sep () const { return '-'; } - string_type do_grouping () const { return "\3\4"; } +struct test_punct : std::moneypunct +{ + pattern do_pos_format () const + { + return { { value, none, none, none } }; + } + int do_frac_digits () const + { + return 0; + } + char_type do_decimal_point () const + { + return '+'; + } + char_type do_thousands_sep () const + { + return '-'; + } + string_type do_grouping () const + { + return "\3\4"; + } }; TEST (uint128_union, balance_format) @@ -76,9 +92,9 @@ TEST (uint128_union, balance_format) TEST (unions, identity) { - ASSERT_EQ (1, rai::uint128_union (1).number ().convert_to ()); - ASSERT_EQ (1, rai::uint256_union (1).number ().convert_to ()); - ASSERT_EQ (1, rai::uint512_union (1).number ().convert_to ()); + ASSERT_EQ (1, rai::uint128_union (1).number ().convert_to ()); + ASSERT_EQ (1, rai::uint256_union (1).number ().convert_to ()); + ASSERT_EQ (1, rai::uint512_union (1).number ().convert_to ()); } TEST (uint256_union, key_encryption) @@ -87,9 +103,9 @@ TEST (uint256_union, key_encryption) rai::raw_key secret_key; secret_key.data.bytes.fill (0); rai::uint256_union encrypted; - encrypted.encrypt (key1.prv, secret_key, key1.pub.owords [0]); + encrypted.encrypt (key1.prv, secret_key, key1.pub.owords[0]); rai::raw_key key4; - key4.decrypt (encrypted, secret_key, key1.pub.owords [0]); + key4.decrypt (encrypted, secret_key, key1.pub.owords[0]); ASSERT_EQ (key1.prv, key4); rai::public_key pub; ed25519_publickey (key4.data.bytes.data (), pub.bytes.data ()); @@ -103,12 +119,12 @@ TEST (uint256_union, encryption) rai::raw_key number1; number1.data = 1; rai::uint256_union encrypted1; - encrypted1.encrypt (number1, key, key.data.owords [0]); + encrypted1.encrypt (number1, key, key.data.owords[0]); rai::uint256_union encrypted2; - encrypted2.encrypt (number1, key, key.data.owords [0]); + encrypted2.encrypt (number1, key, key.data.owords[0]); ASSERT_EQ (encrypted1, encrypted2); rai::raw_key number2; - number2.decrypt (encrypted1, key, key.data.owords [0]); + number2.decrypt (encrypted1, key, key.data.owords[0]); ASSERT_EQ (number1, number2); } @@ -157,7 +173,7 @@ TEST (uint256_union, parse_error_symbol) rai::uint256_union input (rai::uint256_t (1000)); std::string text; input.encode_hex (text); - text [5] = '!'; + text[5] = '!'; rai::uint256_union output; auto error (output.decode_hex (text)); ASSERT_TRUE (error); @@ -165,7 +181,7 @@ TEST (uint256_union, parse_error_symbol) TEST (uint256_union, max_hex) { - rai::uint256_union input (std::numeric_limits ::max ()); + rai::uint256_union input (std::numeric_limits::max ()); std::string text; input.encode_hex (text); rai::uint256_union output; @@ -180,12 +196,12 @@ TEST (uint256_union, decode_dec) rai::uint256_union value; std::string text ("16"); ASSERT_FALSE (value.decode_dec (text)); - ASSERT_EQ (16, value.bytes [31]); + ASSERT_EQ (16, value.bytes[31]); } TEST (uint256_union, max_dec) { - rai::uint256_union input (std::numeric_limits ::max ()); + rai::uint256_union input (std::numeric_limits::max ()); std::string text; input.encode_dec (text); rai::uint256_union output; @@ -221,7 +237,7 @@ TEST (uint256_union, decode_dec_leading_zero) TEST (uint256_union, parse_error_overflow) { - rai::uint256_union input (std::numeric_limits ::max ()); + rai::uint256_union input (std::numeric_limits::max ()); std::string text; input.encode_hex (text); text.push_back (0); @@ -234,52 +250,52 @@ TEST (uint256_union, big_endian_union_constructor) { rai::uint256_t value1 (1); rai::uint256_union bytes1 (value1); - ASSERT_EQ (1, bytes1.bytes [31]); + ASSERT_EQ (1, bytes1.bytes[31]); rai::uint512_t value2 (1); rai::uint512_union bytes2 (value2); - ASSERT_EQ (1, bytes2.bytes [63]); + ASSERT_EQ (1, bytes2.bytes[63]); } TEST (uint256_union, big_endian_union_function) { rai::uint256_union bytes1 ("FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210"); - ASSERT_EQ (0xfe, bytes1.bytes [0x00]); - ASSERT_EQ (0xdc, bytes1.bytes [0x01]); - ASSERT_EQ (0xba, bytes1.bytes [0x02]); - ASSERT_EQ (0x98, bytes1.bytes [0x03]); - ASSERT_EQ (0x76, bytes1.bytes [0x04]); - ASSERT_EQ (0x54, bytes1.bytes [0x05]); - ASSERT_EQ (0x32, bytes1.bytes [0x06]); - ASSERT_EQ (0x10, bytes1.bytes [0x07]); - ASSERT_EQ (0xfe, bytes1.bytes [0x08]); - ASSERT_EQ (0xdc, bytes1.bytes [0x09]); - ASSERT_EQ (0xba, bytes1.bytes [0x0a]); - ASSERT_EQ (0x98, bytes1.bytes [0x0b]); - ASSERT_EQ (0x76, bytes1.bytes [0x0c]); - ASSERT_EQ (0x54, bytes1.bytes [0x0d]); - ASSERT_EQ (0x32, bytes1.bytes [0x0e]); - ASSERT_EQ (0x10, bytes1.bytes [0x0f]); - ASSERT_EQ (0xfe, bytes1.bytes [0x10]); - ASSERT_EQ (0xdc, bytes1.bytes [0x11]); - ASSERT_EQ (0xba, bytes1.bytes [0x12]); - ASSERT_EQ (0x98, bytes1.bytes [0x13]); - ASSERT_EQ (0x76, bytes1.bytes [0x14]); - ASSERT_EQ (0x54, bytes1.bytes [0x15]); - ASSERT_EQ (0x32, bytes1.bytes [0x16]); - ASSERT_EQ (0x10, bytes1.bytes [0x17]); - ASSERT_EQ (0xfe, bytes1.bytes [0x18]); - ASSERT_EQ (0xdc, bytes1.bytes [0x19]); - ASSERT_EQ (0xba, bytes1.bytes [0x1a]); - ASSERT_EQ (0x98, bytes1.bytes [0x1b]); - ASSERT_EQ (0x76, bytes1.bytes [0x1c]); - ASSERT_EQ (0x54, bytes1.bytes [0x1d]); - ASSERT_EQ (0x32, bytes1.bytes [0x1e]); - ASSERT_EQ (0x10, bytes1.bytes [0x1f]); + ASSERT_EQ (0xfe, bytes1.bytes[0x00]); + ASSERT_EQ (0xdc, bytes1.bytes[0x01]); + ASSERT_EQ (0xba, bytes1.bytes[0x02]); + ASSERT_EQ (0x98, bytes1.bytes[0x03]); + ASSERT_EQ (0x76, bytes1.bytes[0x04]); + ASSERT_EQ (0x54, bytes1.bytes[0x05]); + ASSERT_EQ (0x32, bytes1.bytes[0x06]); + ASSERT_EQ (0x10, bytes1.bytes[0x07]); + ASSERT_EQ (0xfe, bytes1.bytes[0x08]); + ASSERT_EQ (0xdc, bytes1.bytes[0x09]); + ASSERT_EQ (0xba, bytes1.bytes[0x0a]); + ASSERT_EQ (0x98, bytes1.bytes[0x0b]); + ASSERT_EQ (0x76, bytes1.bytes[0x0c]); + ASSERT_EQ (0x54, bytes1.bytes[0x0d]); + ASSERT_EQ (0x32, bytes1.bytes[0x0e]); + ASSERT_EQ (0x10, bytes1.bytes[0x0f]); + ASSERT_EQ (0xfe, bytes1.bytes[0x10]); + ASSERT_EQ (0xdc, bytes1.bytes[0x11]); + ASSERT_EQ (0xba, bytes1.bytes[0x12]); + ASSERT_EQ (0x98, bytes1.bytes[0x13]); + ASSERT_EQ (0x76, bytes1.bytes[0x14]); + ASSERT_EQ (0x54, bytes1.bytes[0x15]); + ASSERT_EQ (0x32, bytes1.bytes[0x16]); + ASSERT_EQ (0x10, bytes1.bytes[0x17]); + ASSERT_EQ (0xfe, bytes1.bytes[0x18]); + ASSERT_EQ (0xdc, bytes1.bytes[0x19]); + ASSERT_EQ (0xba, bytes1.bytes[0x1a]); + ASSERT_EQ (0x98, bytes1.bytes[0x1b]); + ASSERT_EQ (0x76, bytes1.bytes[0x1c]); + ASSERT_EQ (0x54, bytes1.bytes[0x1d]); + ASSERT_EQ (0x32, bytes1.bytes[0x1e]); + ASSERT_EQ (0x10, bytes1.bytes[0x1f]); ASSERT_EQ ("FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210", bytes1.to_string ()); ASSERT_EQ (rai::uint256_t ("0xFEDCBA9876543210FEDCBA9876543210FEDCBA9876543210FEDCBA9876543210"), bytes1.number ()); rai::uint512_union bytes2; bytes2.clear (); - bytes2.bytes [63] = 1; + bytes2.bytes[63] = 1; ASSERT_EQ (rai::uint512_t (1), bytes2.number ()); } @@ -296,8 +312,8 @@ TEST (uint256_union, account_transcode) auto text (rai::test_genesis_key.pub.to_account ()); ASSERT_FALSE (value.decode_account (text)); ASSERT_EQ (rai::test_genesis_key.pub, value); - ASSERT_EQ ('_', text [3]); - text [3] = '-'; + ASSERT_EQ ('_', text[3]); + text[3] = '-'; rai::uint256_union value2; ASSERT_FALSE (value2.decode_account (text)); ASSERT_EQ (value, value2); @@ -336,16 +352,16 @@ TEST (uint256_union, bounds) { rai::uint256_union key; std::string bad1 (64, '\x000'); - bad1 [0] = 'x'; - bad1 [1] = 'r'; - bad1 [2] = 'b'; - bad1 [3] = '-'; + bad1[0] = 'x'; + bad1[1] = 'r'; + bad1[2] = 'b'; + bad1[3] = '-'; ASSERT_TRUE (key.decode_account (bad1)); std::string bad2 (64, '\x0ff'); - bad2 [0] = 'x'; - bad2 [1] = 'r'; - bad2 [2] = 'b'; - bad2 [3] = '-'; + bad2[0] = 'x'; + bad2[1] = 'r'; + bad2[2] = 'b'; + bad2[3] = '-'; ASSERT_TRUE (key.decode_account (bad2)); } @@ -357,7 +373,7 @@ public: auto error (false); if (!tree_a.empty ()) { - auto text_l (tree_a.get ("thing")); + auto text_l (tree_a.get ("thing")); if (text_l == "junktest") { upgraded = true; @@ -397,7 +413,7 @@ TEST (json, fetch_object) stream1.close (); rai::open_or_create (stream1, path1.string ()); boost::property_tree::read_json (stream1, tree1); - ASSERT_EQ ("changed", tree1.get ("thing")); + ASSERT_EQ ("changed", tree1.get ("thing")); std::string string2 ("{ \"thing\": \"junktest2\" }"); std::stringstream stream2 (string2); json_upgrade_test object2; @@ -412,25 +428,25 @@ TEST (json, fetch_object) ASSERT_TRUE (error3); auto path2 (rai::unique_path ()); std::fstream stream4; - rai::open_or_create (stream4, path2.string()); + rai::open_or_create (stream4, path2.string ()); json_upgrade_test object4; auto error4 (rai::fetch_object (object4, path2, stream4)); ASSERT_FALSE (error4); ASSERT_EQ ("created", object4.text); boost::property_tree::ptree tree2; stream4.close (); - rai::open_or_create (stream4, path2.string()); + rai::open_or_create (stream4, path2.string ()); boost::property_tree::read_json (stream4, tree2); - ASSERT_EQ ("created", tree2.get ("thing")); + ASSERT_EQ ("created", tree2.get ("thing")); } -TEST(json, DISABLED_fetch_write_fail) +TEST (json, DISABLED_fetch_write_fail) { - std::string string4(""); - std::stringstream stream4(string4, std::ios_base::in); + std::string string4 (""); + std::stringstream stream4 (string4, std::ios_base::in); json_upgrade_test object4; - auto error4(rai::fetch_object(object4, stream4)); - ASSERT_TRUE(error4); + auto error4 (rai::fetch_object (object4, stream4)); + ASSERT_TRUE (error4); } TEST (uint64_t, parse) diff --git a/rai/core_test/wallet.cpp b/rai/core_test/wallet.cpp index d9a3ac7c..9c1294cc 100644 --- a/rai/core_test/wallet.cpp +++ b/rai/core_test/wallet.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include TEST (wallet, no_key) { @@ -56,7 +56,7 @@ TEST (wallet, retrieval) ASSERT_FALSE (wallet.fetch (transaction, key1.pub, prv1)); ASSERT_TRUE (wallet.valid_password (transaction)); ASSERT_EQ (key1.prv, prv1); - wallet.password.values [0]->bytes [16] ^= 1; + wallet.password.values[0]->bytes[16] ^= 1; rai::raw_key prv2; ASSERT_TRUE (wallet.fetch (transaction, key1.pub, prv2)); ASSERT_FALSE (wallet.valid_password (transaction)); @@ -93,7 +93,7 @@ TEST (wallet, one_item_iteration) rai::raw_key password; wallet.wallet_key (password, transaction); rai::raw_key key; - key.decrypt (rai::wallet_value (i->second).key, password, wallet.salt (transaction).owords [0]); + key.decrypt (rai::wallet_value (i->second).key, password, wallet.salt (transaction).owords[0]); ASSERT_EQ (key1.prv, key); } } @@ -106,8 +106,8 @@ TEST (wallet, two_item_iteration) rai::keypair key1; rai::keypair key2; ASSERT_NE (key1.pub, key2.pub); - std::unordered_set pubs; - std::unordered_set prvs; + std::unordered_set pubs; + std::unordered_set prvs; rai::kdf kdf; { rai::transaction transaction (environment, nullptr, true); @@ -121,7 +121,7 @@ TEST (wallet, two_item_iteration) rai::raw_key password; wallet.wallet_key (password, transaction); rai::raw_key key; - key.decrypt (rai::wallet_value (i->second).key, password, wallet.salt (transaction).owords [0]); + key.decrypt (rai::wallet_value (i->second).key, password, wallet.salt (transaction).owords[0]); prvs.insert (key.data); } } @@ -146,21 +146,21 @@ TEST (wallet, insufficient_spend_one) TEST (wallet, spend_all_one) { rai::system system (24000, 1); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits ::max ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits::max ())); rai::account_info info2; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info2); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->store.account_get (transaction, rai::test_genesis_key.pub, info2); ASSERT_NE (latest1, info2.head); - auto block (system.nodes [0]->store.block_get (transaction, info2.head)); + auto block (system.nodes[0]->store.block_get (transaction, info2.head)); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); } ASSERT_TRUE (info2.balance.is_zero ()); - ASSERT_EQ (0, system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[0]->balance (rai::test_genesis_key.pub)); } TEST (wallet, send_async) @@ -168,10 +168,9 @@ TEST (wallet, send_async) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; - std::thread thread ([&system] () - { + std::thread thread ([&system]() { auto iterations (0); - while (!system.nodes [0]->balance (rai::test_genesis_key.pub).is_zero ()) + while (!system.nodes[0]->balance (rai::test_genesis_key.pub).is_zero ()) { system.poll (); ++iterations; @@ -179,7 +178,7 @@ TEST (wallet, send_async) } }); bool success (false); - system.wallet (0)->send_async (rai::test_genesis_key.pub, key2.pub, std::numeric_limits ::max (), [&success] (std::shared_ptr block_a) { ASSERT_NE (nullptr, block_a); success = true; }); + system.wallet (0)->send_async (rai::test_genesis_key.pub, key2.pub, std::numeric_limits::max (), [&success](std::shared_ptr block_a) { ASSERT_NE (nullptr, block_a); success = true; }); thread.join (); ASSERT_TRUE (success); } @@ -187,23 +186,23 @@ TEST (wallet, send_async) TEST (wallet, spend) { rai::system system (24000, 1); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; // Sending from empty accounts should always be an error. Accounts need to be opened with an open block, not a send block. ASSERT_EQ (nullptr, system.wallet (0)->send_action (0, key2.pub, 0)); - ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits ::max ())); + ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits::max ())); rai::account_info info2; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info2); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + system.nodes[0]->store.account_get (transaction, rai::test_genesis_key.pub, info2); ASSERT_NE (latest1, info2.head); - auto block (system.nodes [0]->store.block_get (transaction, info2.head)); + auto block (system.nodes[0]->store.block_get (transaction, info2.head)); ASSERT_NE (nullptr, block); ASSERT_EQ (latest1, block->previous ()); } ASSERT_TRUE (info2.balance.is_zero ()); - ASSERT_EQ (0, system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (0, system.nodes[0]->balance (rai::test_genesis_key.pub)); } TEST (wallet, change) @@ -211,10 +210,10 @@ TEST (wallet, change) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; - auto block1 (system.nodes [0]->representative (rai::test_genesis_key.pub)); + auto block1 (system.nodes[0]->representative (rai::test_genesis_key.pub)); ASSERT_FALSE (block1.is_zero ()); ASSERT_NE (nullptr, system.wallet (0)->change_action (rai::test_genesis_key.pub, key2.pub)); - auto block2 (system.nodes [0]->representative (rai::test_genesis_key.pub)); + auto block2 (system.nodes[0]->representative (rai::test_genesis_key.pub)); ASSERT_FALSE (block2.is_zero ()); ASSERT_NE (block1, block2); } @@ -225,7 +224,7 @@ TEST (wallet, partial_spend) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 500)); - ASSERT_EQ (std::numeric_limits ::max () - 500, system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (std::numeric_limits::max () - 500, system.nodes[0]->balance (rai::test_genesis_key.pub)); } TEST (wallet, spend_no_previous) @@ -233,9 +232,9 @@ TEST (wallet, spend_no_previous) rai::system system (24000, 1); { system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); rai::account_info info1; - ASSERT_FALSE (system.nodes [0]->store.account_get (transaction, rai::test_genesis_key.pub, info1)); + ASSERT_FALSE (system.nodes[0]->store.account_get (transaction, rai::test_genesis_key.pub, info1)); for (auto i (0); i < 50; ++i) { rai::keypair key; @@ -244,7 +243,7 @@ TEST (wallet, spend_no_previous) } rai::keypair key2; ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, 500)); - ASSERT_EQ (std::numeric_limits ::max () - 500, system.nodes [0]->balance (rai::test_genesis_key.pub)); + ASSERT_EQ (std::numeric_limits::max () - 500, system.nodes[0]->balance (rai::test_genesis_key.pub)); } TEST (wallet, find_none) @@ -305,7 +304,7 @@ TEST (wallet, rekey) rai::raw_key prv2; wallet.fetch (transaction, key1.pub, prv2); ASSERT_EQ (key1.prv, prv2); - *wallet.password.values [0] = 2; + *wallet.password.values[0] = 2; ASSERT_TRUE (wallet.rekey (transaction, "2")); } @@ -337,7 +336,7 @@ TEST (account, encode_fail) rai::uint256_union number0 (0); std::string str0; number0.encode_account (str0); - str0 [16] ^= 1; + str0[16] ^= 1; rai::uint256_union number1; ASSERT_TRUE (number1.decode_account (str0)); } @@ -365,7 +364,7 @@ TEST (fan, reconstitute) { rai::uint256_union value0 (0); rai::fan fan (value0, 1024); - for (auto & i: fan.values) + for (auto & i : fan.values) { ASSERT_NE (value0, *i); } @@ -552,7 +551,7 @@ TEST (wallet_store, move) wallet2.insert_adhoc (transaction, key2.prv); ASSERT_FALSE (wallet1.exists (transaction, key2.pub)); ASSERT_TRUE (wallet2.exists (transaction, key2.pub)); - std::vector keys; + std::vector keys; keys.push_back (key2.pub); ASSERT_FALSE (wallet1.move (transaction, wallet2, keys)); ASSERT_TRUE (wallet1.exists (transaction, key2.pub)); @@ -602,7 +601,7 @@ TEST (wallet, empty_work) { rai::system system (24000, 1); auto wallet (system.wallet (0)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); ASSERT_FALSE (rai::work_validate (1, wallet->work_fetch (transaction, 0, 1))); } @@ -616,9 +615,9 @@ TEST (wallet, work) rai::uint256_union root1; rai::account account1; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account1 = system.account (transaction, 0); - root1 = system.nodes [0]->ledger.latest_root (transaction, account1); + root1 = system.nodes[0]->ledger.latest_root (transaction, account1); work4 = wallet->work_fetch (transaction, account1, root1); } ASSERT_FALSE (rai::work_validate (root1, work4)); @@ -627,7 +626,7 @@ TEST (wallet, work) while (rai::work_validate (root1, work3)) { system.poll (); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); // Make sure work_get and work_fetch retrieve the same thing ASSERT_FALSE (wallet->store.work_get (transaction, account1, work3)); ++iteration; @@ -639,18 +638,18 @@ TEST (wallet, work_generate) { rai::system system (24000, 1); auto wallet (system.wallet (0)); - rai::uint128_t amount1 (system.nodes [0]->balance (rai::test_genesis_key.pub)); + rai::uint128_t amount1 (system.nodes[0]->balance (rai::test_genesis_key.pub)); uint64_t work1; wallet->insert_adhoc (rai::test_genesis_key.prv); rai::account account1; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account1 = system.account (transaction, 0); } rai::keypair key; wallet->send_action (rai::test_genesis_key.pub, key.pub, 100); auto iterations1 (0); - while (system.nodes [0]->ledger.account_balance (rai::transaction (system.nodes [0]->store.environment, nullptr, false), rai::test_genesis_key.pub) == amount1) + while (system.nodes[0]->ledger.account_balance (rai::transaction (system.nodes[0]->store.environment, nullptr, false), rai::test_genesis_key.pub) == amount1) { system.poll (); ++iterations1; @@ -663,8 +662,8 @@ TEST (wallet, work_generate) system.poll (); ++iterations2; ASSERT_LT (iterations2, 200); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - again = wallet->store.work_get (transaction, account1, work1) || rai::work_validate (system.nodes [0]->ledger.latest_root (transaction, account1), work1); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + again = wallet->store.work_get (transaction, account1, work1) || rai::work_validate (system.nodes[0]->ledger.latest_root (transaction, account1), work1); } } @@ -672,7 +671,7 @@ TEST (wallet, unsynced_work) { rai::system system (24000, 1); auto wallet (system.wallet (0)); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); wallet->store.work_put (transaction, 0, 0); auto work1 (wallet->work_fetch (transaction, 0, 1)); ASSERT_FALSE (rai::work_validate (1, work1)); @@ -705,29 +704,29 @@ TEST (wallet, version_1_2_upgrade) rai::wallet_value value (wallet->store.entry_get_raw (transaction, rai::wallet_store::wallet_key_special)); rai::raw_key kdf; kdf.data.clear (); - password_l.decrypt (value.key, kdf, wallet->store.salt (transaction).owords [0]); + password_l.decrypt (value.key, kdf, wallet->store.salt (transaction).owords[0]); rai::uint256_union ciphertext; - ciphertext.encrypt (key.prv, password_l, wallet->store.salt (transaction).owords [0]); + ciphertext.encrypt (key.prv, password_l, wallet->store.salt (transaction).owords[0]); wallet->store.entry_put_raw (transaction, key.pub, rai::wallet_value (ciphertext, 0)); wallet->store.version_put (transaction, 1); } - + wallet->enter_password ("1"); ASSERT_EQ (true, wallet->valid_password ()); ASSERT_EQ (2, wallet->store.version (rai::transaction (wallet->store.environment, nullptr, false))); rai::raw_key prv; ASSERT_FALSE (wallet->store.fetch (rai::transaction (wallet->store.environment, nullptr, false), key.pub, prv)); ASSERT_EQ (key.prv, prv); - + { rai::transaction transaction (wallet->store.environment, nullptr, true); rai::raw_key password_l; rai::wallet_value value (wallet->store.entry_get_raw (transaction, rai::wallet_store::wallet_key_special)); rai::raw_key kdf; wallet->store.derive_key (kdf, transaction, ""); - password_l.decrypt (value.key, kdf, wallet->store.salt (transaction).owords [0]); + password_l.decrypt (value.key, kdf, wallet->store.salt (transaction).owords[0]); rai::uint256_union ciphertext; - ciphertext.encrypt (key.prv, password_l, wallet->store.salt (transaction).owords [0]); + ciphertext.encrypt (key.prv, password_l, wallet->store.salt (transaction).owords[0]); wallet->store.entry_put_raw (transaction, key.pub, rai::wallet_value (ciphertext, 0)); wallet->store.version_put (transaction, 1); } @@ -860,7 +859,7 @@ TEST (wallet, no_work) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; - auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits ::max (), false)); + auto block (system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, std::numeric_limits::max (), false)); ASSERT_NE (nullptr, block); ASSERT_EQ (0, block->block_work ()); } @@ -870,13 +869,13 @@ TEST (wallet, send_race) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::keypair key2; - system.nodes [0]->block_processor.stop (); + system.nodes[0]->block_processor.stop (); { ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, rai::Gxrb_ratio)); ASSERT_NE (nullptr, system.wallet (0)->send_action (rai::test_genesis_key.pub, key2.pub, rai::Gxrb_ratio)); } auto iterations (0); - while (system.nodes [0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount - rai::Gxrb_ratio * 2) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != rai::genesis_amount - rai::Gxrb_ratio * 2) { system.poll (); ++iterations; diff --git a/rai/core_test/wallets.cpp b/rai/core_test/wallets.cpp index 6e5f3508..fabf5e2f 100644 --- a/rai/core_test/wallets.cpp +++ b/rai/core_test/wallets.cpp @@ -6,7 +6,7 @@ TEST (wallets, DISABLED_open_create) { rai::system system (24000, 1); bool error (false); - rai::wallets wallets (error, *system.nodes [0]); + rai::wallets wallets (error, *system.nodes[0]); ASSERT_FALSE (error); ASSERT_EQ (0, wallets.items.size ()); rai::uint256_union id; @@ -22,7 +22,7 @@ TEST (wallets, DISABLED_open_existing) rai::uint256_union id; { bool error (false); - rai::wallets wallets (error, *system.nodes [0]); + rai::wallets wallets (error, *system.nodes[0]); ASSERT_FALSE (error); ASSERT_EQ (0, wallets.items.size ()); auto wallet (wallets.create (id)); @@ -41,7 +41,7 @@ TEST (wallets, DISABLED_open_existing) } { bool error (false); - rai::wallets wallets (error, *system.nodes [0]); + rai::wallets wallets (error, *system.nodes[0]); ASSERT_FALSE (error); ASSERT_EQ (1, wallets.items.size ()); ASSERT_NE (nullptr, wallets.open (id)); @@ -54,7 +54,7 @@ TEST (wallets, DISABLED_remove) rai::uint256_union one (1); { bool error (false); - rai::wallets wallets (error, *system.nodes [0]); + rai::wallets wallets (error, *system.nodes[0]); ASSERT_FALSE (error); ASSERT_EQ (0, wallets.items.size ()); auto wallet (wallets.create (one)); @@ -65,7 +65,7 @@ TEST (wallets, DISABLED_remove) } { bool error (false); - rai::wallets wallets (error, *system.nodes [0]); + rai::wallets wallets (error, *system.nodes[0]); ASSERT_FALSE (error); ASSERT_EQ (0, wallets.items.size ()); } diff --git a/rai/core_test/work_pool.cpp b/rai/core_test/work_pool.cpp index 8c0fe73d..cf4bcc80 100644 --- a/rai/core_test/work_pool.cpp +++ b/rai/core_test/work_pool.cpp @@ -5,7 +5,7 @@ TEST (work, one) { - rai::work_pool pool (std::numeric_limits ::max (), nullptr); + rai::work_pool pool (std::numeric_limits::max (), nullptr); rai::change_block block (1, 1, rai::keypair ().prv, 3, 4); block.block_work_set (pool.generate (block.root ())); ASSERT_FALSE (rai::work_validate (block)); @@ -13,7 +13,7 @@ TEST (work, one) TEST (work, validate) { - rai::work_pool pool (std::numeric_limits ::max (), nullptr); + rai::work_pool pool (std::numeric_limits::max (), nullptr); rai::send_block send_block (1, 1, 2, rai::keypair ().prv, 4, 6); ASSERT_TRUE (rai::work_validate (send_block)); send_block.block_work_set (pool.generate (send_block.root ())); @@ -22,11 +22,10 @@ TEST (work, validate) TEST (work, cancel) { - rai::work_pool pool (std::numeric_limits ::max (), nullptr); + rai::work_pool pool (std::numeric_limits::max (), nullptr); rai::uint256_union key (1); - boost::optional work (0); - pool.generate (key, [&work] (boost::optional work_a) - { + boost::optional work (0); + pool.generate (key, [&work](boost::optional work_a) { work = work_a; }); pool.cancel (key); @@ -35,19 +34,19 @@ TEST (work, cancel) TEST (work, cancel_many) { - rai::work_pool pool (std::numeric_limits ::max (), nullptr); + rai::work_pool pool (std::numeric_limits::max (), nullptr); rai::uint256_union key1 (1); rai::uint256_union key2 (2); rai::uint256_union key3 (1); rai::uint256_union key4 (1); rai::uint256_union key5 (3); rai::uint256_union key6 (1); - pool.generate (key1, [] (boost::optional ) {}); - pool.generate (key2, [] (boost::optional ) {}); - pool.generate (key3, [] (boost::optional ) {}); - pool.generate (key4, [] (boost::optional ) {}); - pool.generate (key5, [] (boost::optional ) {}); - pool.generate (key6, [] (boost::optional ) {}); + pool.generate (key1, [](boost::optional) {}); + pool.generate (key2, [](boost::optional) {}); + pool.generate (key3, [](boost::optional) {}); + pool.generate (key4, [](boost::optional) {}); + pool.generate (key5, [](boost::optional) {}); + pool.generate (key6, [](boost::optional) {}); pool.cancel (key1); } @@ -55,13 +54,13 @@ TEST (work, DISABLED_opencl) { rai::logging logging; logging.init (rai::unique_path ()); - auto opencl (rai::opencl_work::create (true, {0, 1, 1024 * 1024}, logging)); + auto opencl (rai::opencl_work::create (true, { 0, 1, 1024 * 1024 }, logging)); if (opencl != nullptr) { - rai::work_pool pool (std::numeric_limits ::max (), opencl ? [&opencl] (rai::uint256_union const & root_a) - { + rai::work_pool pool (std::numeric_limits::max (), opencl ? [&opencl](rai::uint256_union const & root_a) { return opencl->generate_work (root_a); - } : std::function (rai::uint256_union const &)> (nullptr)); + } + : std::function (rai::uint256_union const &)> (nullptr)); ASSERT_NE (nullptr, pool.opencl); rai::uint256_union root; for (auto i (0); i < 1; ++i) diff --git a/rai/lib/blocks.cpp b/rai/lib/blocks.cpp index a4922553..5ddbe4e7 100644 --- a/rai/lib/blocks.cpp +++ b/rai/lib/blocks.cpp @@ -23,7 +23,7 @@ bool rai::from_string_hex (std::string const & value_a, uint64_t & target_a) { stream >> number_l; target_a = number_l; - if (!stream.eof()) + if (!stream.eof ()) { result = true; } @@ -100,9 +100,9 @@ rai::send_hashables::send_hashables (bool & error_a, boost::property_tree::ptree { try { - auto previous_l (tree_a.get ("previous")); - auto destination_l (tree_a.get ("destination")); - auto balance_l (tree_a.get ("balance")); + auto previous_l (tree_a.get ("previous")); + auto destination_l (tree_a.get ("destination")); + auto balance_l (tree_a.get ("balance")); error_a = previous.decode_hex (previous_l); if (!error_a) { @@ -186,12 +186,12 @@ bool rai::send_block::deserialize_json (boost::property_tree::ptree const & tree auto result (false); try { - assert (tree_a.get ("type") == "send"); - auto previous_l (tree_a.get ("previous")); - auto destination_l (tree_a.get ("destination")); - auto balance_l (tree_a.get ("balance")); - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + assert (tree_a.get ("type") == "send"); + auto previous_l (tree_a.get ("previous")); + auto destination_l (tree_a.get ("destination")); + auto balance_l (tree_a.get ("balance")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); result = hashables.previous.decode_hex (previous_l); if (!result) { @@ -244,8 +244,8 @@ hashables (error_a, tree_a) { try { - auto signature_l (tree_a.get ("signature")); - auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); + auto work_l (tree_a.get ("work")); error_a = signature.decode_hex (signature_l); if (!error_a) { @@ -259,9 +259,9 @@ hashables (error_a, tree_a) } } -bool rai::send_block::operator == (rai::block const & other_a) const +bool rai::send_block::operator== (rai::block const & other_a) const { - auto other_l (dynamic_cast (&other_a)); + auto other_l (dynamic_cast (&other_a)); auto result (other_l != nullptr); if (result) { @@ -275,7 +275,7 @@ rai::block_type rai::send_block::type () const return rai::block_type::send; } -bool rai::send_block::operator == (rai::send_block const & other_a) const +bool rai::send_block::operator== (rai::send_block const & other_a) const { auto result (hashables.destination == other_a.hashables.destination && hashables.previous == other_a.hashables.previous && hashables.balance == other_a.hashables.balance && work == other_a.work && signature == other_a.signature); return result; @@ -330,9 +330,9 @@ rai::open_hashables::open_hashables (bool & error_a, boost::property_tree::ptree { try { - auto source_l (tree_a.get ("source")); - auto representative_l (tree_a.get ("representative")); - auto account_l (tree_a.get ("account")); + auto source_l (tree_a.get ("source")); + auto representative_l (tree_a.get ("representative")); + auto account_l (tree_a.get ("account")); error_a = source.decode_hex (source_l); if (!error_a) { @@ -391,8 +391,8 @@ hashables (error_a, tree_a) { try { - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); error_a = rai::from_string_hex (work_l, work); if (!error_a) { @@ -424,7 +424,7 @@ void rai::open_block::block_work_set (uint64_t work_a) rai::block_hash rai::open_block::previous () const { rai::block_hash result (0); -return result; + return result; } void rai::open_block::serialize (rai::stream & stream_a) const @@ -479,12 +479,12 @@ bool rai::open_block::deserialize_json (boost::property_tree::ptree const & tree auto result (false); try { - assert (tree_a.get ("type") == "open"); - auto source_l (tree_a.get ("source")); - auto representative_l (tree_a.get ("representative")); - auto account_l (tree_a.get ("account")); - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + assert (tree_a.get ("type") == "open"); + auto source_l (tree_a.get ("source")); + auto representative_l (tree_a.get ("representative")); + auto account_l (tree_a.get ("account")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); result = hashables.source.decode_hex (source_l); if (!result) { @@ -520,9 +520,9 @@ rai::block_type rai::open_block::type () const return rai::block_type::open; } -bool rai::open_block::operator == (rai::block const & other_a) const +bool rai::open_block::operator== (rai::block const & other_a) const { - auto other_l (dynamic_cast (&other_a)); + auto other_l (dynamic_cast (&other_a)); auto result (other_l != nullptr); if (result) { @@ -531,7 +531,7 @@ bool rai::open_block::operator == (rai::block const & other_a) const return result; } -bool rai::open_block::operator == (rai::open_block const & other_a) const +bool rai::open_block::operator== (rai::open_block const & other_a) const { return hashables.source == other_a.hashables.source && hashables.representative == other_a.hashables.representative && hashables.account == other_a.hashables.account && work == other_a.work && signature == other_a.signature; } @@ -575,8 +575,8 @@ rai::change_hashables::change_hashables (bool & error_a, boost::property_tree::p { try { - auto previous_l (tree_a.get ("previous")); - auto representative_l (tree_a.get ("representative")); + auto previous_l (tree_a.get ("previous")); + auto representative_l (tree_a.get ("representative")); error_a = previous.decode_hex (previous_l); if (!error_a) { @@ -622,8 +622,8 @@ hashables (error_a, tree_a) { try { - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); error_a = rai::from_string_hex (work_l, work); if (!error_a) { @@ -703,11 +703,11 @@ bool rai::change_block::deserialize_json (boost::property_tree::ptree const & tr auto result (false); try { - assert (tree_a.get ("type") == "change"); - auto previous_l (tree_a.get ("previous")); - auto representative_l (tree_a.get ("representative")); - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + assert (tree_a.get ("type") == "change"); + auto previous_l (tree_a.get ("previous")); + auto representative_l (tree_a.get ("representative")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); result = hashables.previous.decode_hex (previous_l); if (!result) { @@ -739,9 +739,9 @@ rai::block_type rai::change_block::type () const return rai::block_type::change; } -bool rai::change_block::operator == (rai::block const & other_a) const +bool rai::change_block::operator== (rai::block const & other_a) const { - auto other_l (dynamic_cast (&other_a)); + auto other_l (dynamic_cast (&other_a)); auto result (other_l != nullptr); if (result) { @@ -750,7 +750,7 @@ bool rai::change_block::operator == (rai::block const & other_a) const return result; } -bool rai::change_block::operator == (rai::change_block const & other_a) const +bool rai::change_block::operator== (rai::change_block const & other_a) const { return hashables.previous == other_a.hashables.previous && hashables.representative == other_a.hashables.representative && work == other_a.work && signature == other_a.signature; } @@ -775,16 +775,16 @@ void rai::change_block::signature_set (rai::uint512_union const & signature_a) signature = signature_a; } -std::unique_ptr rai::deserialize_block_json (boost::property_tree::ptree const & tree_a) +std::unique_ptr rai::deserialize_block_json (boost::property_tree::ptree const & tree_a) { - std::unique_ptr result; + std::unique_ptr result; try { - auto type (tree_a.get ("type")); + auto type (tree_a.get ("type")); if (type == "receive") { bool error; - std::unique_ptr obj (new rai::receive_block (error, tree_a)); + std::unique_ptr obj (new rai::receive_block (error, tree_a)); if (!error) { result = std::move (obj); @@ -793,7 +793,7 @@ std::unique_ptr rai::deserialize_block_json (boost::property_tree:: else if (type == "send") { bool error; - std::unique_ptr obj (new rai::send_block (error, tree_a)); + std::unique_ptr obj (new rai::send_block (error, tree_a)); if (!error) { result = std::move (obj); @@ -802,7 +802,7 @@ std::unique_ptr rai::deserialize_block_json (boost::property_tree:: else if (type == "open") { bool error; - std::unique_ptr obj (new rai::open_block (error, tree_a)); + std::unique_ptr obj (new rai::open_block (error, tree_a)); if (!error) { result = std::move (obj); @@ -811,7 +811,7 @@ std::unique_ptr rai::deserialize_block_json (boost::property_tree:: else if (type == "change") { bool error; - std::unique_ptr obj (new rai::change_block (error, tree_a)); + std::unique_ptr obj (new rai::change_block (error, tree_a)); if (!error) { result = std::move (obj); @@ -824,27 +824,27 @@ std::unique_ptr rai::deserialize_block_json (boost::property_tree:: return result; } -std::unique_ptr rai::deserialize_block (rai::stream & stream_a) +std::unique_ptr rai::deserialize_block (rai::stream & stream_a) { rai::block_type type; auto error (read (stream_a, type)); - std::unique_ptr result; + std::unique_ptr result; if (!error) { - result = rai::deserialize_block (stream_a, type); + result = rai::deserialize_block (stream_a, type); } return result; } -std::unique_ptr rai::deserialize_block (rai::stream & stream_a, rai::block_type type_a) +std::unique_ptr rai::deserialize_block (rai::stream & stream_a, rai::block_type type_a) { - std::unique_ptr result; + std::unique_ptr result; switch (type_a) { case rai::block_type::receive: { bool error; - std::unique_ptr obj (new rai::receive_block (error, stream_a)); + std::unique_ptr obj (new rai::receive_block (error, stream_a)); if (!error) { result = std::move (obj); @@ -854,7 +854,7 @@ std::unique_ptr rai::deserialize_block (rai::stream & stream_a, rai case rai::block_type::send: { bool error; - std::unique_ptr obj (new rai::send_block (error, stream_a)); + std::unique_ptr obj (new rai::send_block (error, stream_a)); if (!error) { result = std::move (obj); @@ -864,7 +864,7 @@ std::unique_ptr rai::deserialize_block (rai::stream & stream_a, rai case rai::block_type::open: { bool error; - std::unique_ptr obj (new rai::open_block (error, stream_a)); + std::unique_ptr obj (new rai::open_block (error, stream_a)); if (!error) { result = std::move (obj); @@ -874,7 +874,7 @@ std::unique_ptr rai::deserialize_block (rai::stream & stream_a, rai case rai::block_type::change: { bool error; - std::unique_ptr obj (new rai::change_block (error, stream_a)); + std::unique_ptr obj (new rai::change_block (error, stream_a)); if (!error) { result = std::move (obj); @@ -893,7 +893,7 @@ void rai::receive_block::visit (rai::block_visitor & visitor_a) const visitor_a.receive_block (*this); } -bool rai::receive_block::operator == (rai::receive_block const & other_a) const +bool rai::receive_block::operator== (rai::receive_block const & other_a) const { auto result (hashables.previous == other_a.hashables.previous && hashables.source == other_a.hashables.source && work == other_a.work && signature == other_a.signature); return result; @@ -923,11 +923,11 @@ bool rai::receive_block::deserialize_json (boost::property_tree::ptree const & t auto result (false); try { - assert (tree_a.get ("type") == "receive"); - auto previous_l (tree_a.get ("previous")); - auto source_l (tree_a.get ("source")); - auto work_l (tree_a.get ("work")); - auto signature_l (tree_a.get ("signature")); + assert (tree_a.get ("type") == "receive"); + auto previous_l (tree_a.get ("previous")); + auto source_l (tree_a.get ("source")); + auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); result = hashables.previous.decode_hex (previous_l); if (!result) { @@ -978,7 +978,7 @@ void rai::receive_block::serialize_json (std::string & string_a) const rai::receive_block::receive_block (rai::block_hash const & previous_a, rai::block_hash const & source_a, rai::raw_key const & prv_a, rai::public_key const & pub_a, uint64_t work_a) : hashables (previous_a, source_a), -signature (rai::sign_message (prv_a, pub_a, hash())), +signature (rai::sign_message (prv_a, pub_a, hash ())), work (work_a) { } @@ -1003,8 +1003,8 @@ hashables (error_a, tree_a) { try { - auto signature_l (tree_a.get ("signature")); - auto work_l (tree_a.get ("work")); + auto signature_l (tree_a.get ("signature")); + auto work_l (tree_a.get ("work")); error_a = signature.decode_hex (signature_l); if (!error_a) { @@ -1033,9 +1033,9 @@ void rai::receive_block::block_work_set (uint64_t work_a) work = work_a; } -bool rai::receive_block::operator == (rai::block const & other_a) const +bool rai::receive_block::operator== (rai::block const & other_a) const { - auto other_l (dynamic_cast (&other_a)); + auto other_l (dynamic_cast (&other_a)); auto result (other_l != nullptr); if (result) { @@ -1093,8 +1093,8 @@ rai::receive_hashables::receive_hashables (bool & error_a, boost::property_tree: { try { - auto previous_l (tree_a.get ("previous")); - auto source_l (tree_a.get ("source")); + auto previous_l (tree_a.get ("previous")); + auto source_l (tree_a.get ("source")); error_a = previous.decode_hex (previous_l); if (!error_a) { diff --git a/rai/lib/blocks.hpp b/rai/lib/blocks.hpp index 9659c380..637cac0b 100644 --- a/rai/lib/blocks.hpp +++ b/rai/lib/blocks.hpp @@ -12,20 +12,20 @@ namespace rai std::string to_string_hex (uint64_t); bool from_string_hex (std::string const &, uint64_t &); // We operate on streams of uint8_t by convention -using stream = std::basic_streambuf ; +using stream = std::basic_streambuf; // Read a raw byte stream the size of `T' and fill value. template bool read (rai::stream & stream_a, T & value) { - static_assert (std::is_pod ::value, "Can't stream read non-standard layout types"); - auto amount_read (stream_a.sgetn (reinterpret_cast (&value), sizeof (value))); + static_assert (std::is_pod::value, "Can't stream read non-standard layout types"); + auto amount_read (stream_a.sgetn (reinterpret_cast (&value), sizeof (value))); return amount_read != sizeof (value); } template void write (rai::stream & stream_a, T const & value) { - static_assert (std::is_pod ::value, "Can't stream write non-standard layout types"); - auto amount_written (stream_a.sputn (reinterpret_cast (&value), sizeof (value))); + static_assert (std::is_pod::value, "Can't stream write non-standard layout types"); + auto amount_written (stream_a.sputn (reinterpret_cast (&value), sizeof (value))); assert (amount_written == sizeof (value)); } class block_visitor; @@ -57,7 +57,7 @@ public: virtual void serialize (rai::stream &) const = 0; virtual void serialize_json (std::string &) const = 0; virtual void visit (rai::block_visitor &) const = 0; - virtual bool operator == (rai::block const &) const = 0; + virtual bool operator== (rai::block const &) const = 0; virtual rai::block_type type () const = 0; virtual void signature_set (rai::uint512_union const &) = 0; }; @@ -93,8 +93,8 @@ public: void visit (rai::block_visitor &) const override; rai::block_type type () const override; void signature_set (rai::uint512_union const &) override; - bool operator == (rai::block const &) const override; - bool operator == (rai::send_block const &) const; + bool operator== (rai::block const &) const override; + bool operator== (rai::send_block const &) const; static size_t constexpr size = sizeof (rai::account) + sizeof (rai::block_hash) + sizeof (rai::amount) + sizeof (rai::signature) + sizeof (uint64_t); send_hashables hashables; rai::signature signature; @@ -131,8 +131,8 @@ public: void visit (rai::block_visitor &) const override; rai::block_type type () const override; void signature_set (rai::uint512_union const &) override; - bool operator == (rai::block const &) const override; - bool operator == (rai::receive_block const &) const; + bool operator== (rai::block const &) const override; + bool operator== (rai::receive_block const &) const; static size_t constexpr size = sizeof (rai::block_hash) + sizeof (rai::block_hash) + sizeof (rai::signature) + sizeof (uint64_t); receive_hashables hashables; rai::signature signature; @@ -171,8 +171,8 @@ public: void visit (rai::block_visitor &) const override; rai::block_type type () const override; void signature_set (rai::uint512_union const &) override; - bool operator == (rai::block const &) const override; - bool operator == (rai::open_block const &) const; + bool operator== (rai::block const &) const override; + bool operator== (rai::open_block const &) const; static size_t constexpr size = sizeof (rai::block_hash) + sizeof (rai::account) + sizeof (rai::account) + sizeof (rai::signature) + sizeof (uint64_t); rai::open_hashables hashables; rai::signature signature; @@ -209,8 +209,8 @@ public: void visit (rai::block_visitor &) const override; rai::block_type type () const override; void signature_set (rai::uint512_union const &) override; - bool operator == (rai::block const &) const override; - bool operator == (rai::change_block const &) const; + bool operator== (rai::block const &) const override; + bool operator== (rai::change_block const &) const; static size_t constexpr size = sizeof (rai::block_hash) + sizeof (rai::account) + sizeof (rai::signature) + sizeof (uint64_t); rai::change_hashables hashables; rai::signature signature; @@ -224,8 +224,8 @@ public: virtual void open_block (rai::open_block const &) = 0; virtual void change_block (rai::change_block const &) = 0; }; -std::unique_ptr deserialize_block (rai::stream &); -std::unique_ptr deserialize_block (rai::stream &, rai::block_type); -std::unique_ptr deserialize_block_json (boost::property_tree::ptree const &); +std::unique_ptr deserialize_block (rai::stream &); +std::unique_ptr deserialize_block (rai::stream &, rai::block_type); +std::unique_ptr deserialize_block_json (boost::property_tree::ptree const &); void serialize_block (rai::stream &, rai::block const &); } diff --git a/rai/lib/interface.cpp b/rai/lib/interface.cpp index 40f24e3a..9b32d36c 100644 --- a/rai/lib/interface.cpp +++ b/rai/lib/interface.cpp @@ -17,25 +17,25 @@ extern "C" { void xrb_uint256_to_string (xrb_uint256 source, char * destination) { - auto const & number (*reinterpret_cast (source)); + auto const & number (*reinterpret_cast (source)); strncpy (destination, number.to_string ().c_str (), 64); } void xrb_uint256_to_address (xrb_uint256 source, char * destination) { - auto const & number (*reinterpret_cast (source)); + auto const & number (*reinterpret_cast (source)); strncpy (destination, number.to_account ().c_str (), 65); } void xrb_uint512_to_string (xrb_uint512 source, char * destination) { - auto const & number (*reinterpret_cast (source)); + auto const & number (*reinterpret_cast (source)); strncpy (destination, number.to_string ().c_str (), 128); } int xrb_uint256_from_string (const char * source, xrb_uint256 destination) { - auto & number (*reinterpret_cast (destination)); + auto & number (*reinterpret_cast (destination)); auto error (number.decode_hex (source)); auto result (error ? 1 : 0); return result; @@ -43,7 +43,7 @@ int xrb_uint256_from_string (const char * source, xrb_uint256 destination) int xrb_uint512_from_string (const char * source, xrb_uint512 destination) { - auto & number (*reinterpret_cast (destination)); + auto & number (*reinterpret_cast (destination)); auto error (number.decode_hex (source)); auto result (error ? 1 : 0); return result; @@ -59,14 +59,14 @@ int xrb_valid_address (const char * account_a) void xrb_generate_random (xrb_uint256 seed) { - auto & number (*reinterpret_cast (seed)); + auto & number (*reinterpret_cast (seed)); rai::random_pool.GenerateBlock (number.bytes.data (), number.bytes.size ()); } void xrb_seed_key (xrb_uint256 seed, int index, xrb_uint256 destination) { - auto & seed_l (*reinterpret_cast (seed)); - auto & destination_l (*reinterpret_cast (destination)); + auto & seed_l (*reinterpret_cast (seed)); + auto & destination_l (*reinterpret_cast (destination)); rai::deterministic_key (seed_l, index, destination_l); } @@ -90,10 +90,10 @@ char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private rai::uint256_union pub; ed25519_publickey (private_key, pub.bytes.data ()); rai::raw_key prv; - prv.data = *reinterpret_cast (private_key); + prv.data = *reinterpret_cast (private_key); block->signature_set (rai::sign_message (prv, pub, block->hash ())); auto json (block->to_json ()); - result = reinterpret_cast (malloc (json.size () + 1)); + result = reinterpret_cast (malloc (json.size () + 1)); strncpy (result, json.c_str (), json.size () + 1); } } @@ -119,7 +119,7 @@ char * xrb_work_transaction (const char * transaction) auto work (pool.generate (block->root ())); block->block_work_set (work); auto json (block->to_json ()); - result = reinterpret_cast (malloc (json.size () + 1)); + result = reinterpret_cast (malloc (json.size () + 1)); strncpy (result, json.c_str (), json.size () + 1); } } @@ -132,23 +132,23 @@ char * xrb_work_transaction (const char * transaction) #include void ed25519_randombytes_unsafe (void * out, size_t outlen) { - rai::random_pool.GenerateBlock (reinterpret_cast (out), outlen); + rai::random_pool.GenerateBlock (reinterpret_cast (out), outlen); } void ed25519_hash_init (ed25519_hash_context * ctx) { ctx->blake2 = new blake2b_state; - blake2b_init (reinterpret_cast (ctx->blake2), 64); + blake2b_init (reinterpret_cast (ctx->blake2), 64); } void ed25519_hash_update (ed25519_hash_context * ctx, uint8_t const * in, size_t inlen) { - blake2b_update (reinterpret_cast (ctx->blake2), in, inlen); + blake2b_update (reinterpret_cast (ctx->blake2), in, inlen); } void ed25519_hash_final (ed25519_hash_context * ctx, uint8_t * out) { - blake2b_final (reinterpret_cast (ctx->blake2), out, 64); - delete reinterpret_cast (ctx->blake2); + blake2b_final (reinterpret_cast (ctx->blake2), out, 64); + delete reinterpret_cast (ctx->blake2); } void ed25519_hash (uint8_t * out, uint8_t const * in, size_t inlen) diff --git a/rai/lib/numbers.cpp b/rai/lib/numbers.cpp index def158d0..9d6ac495 100644 --- a/rai/lib/numbers.cpp +++ b/rai/lib/numbers.cpp @@ -11,29 +11,29 @@ thread_local CryptoPP::AutoSeededRandomPool rai::random_pool; namespace { - char const * base58_reverse ("~012345678~~~~~~~9:;<=>?@~ABCDE~FGHIJKLMNOP~~~~~~QRSTUVWXYZ[~\\]^_`abcdefghi"); - uint8_t base58_decode (char value) - { - assert (value >= '0'); - assert (value <= '~'); - auto result (base58_reverse [value - 0x30] - 0x30); - return result; - } - char const * account_lookup ("13456789abcdefghijkmnopqrstuwxyz"); - char const * account_reverse ("~0~1234567~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~89:;<=>?@AB~CDEFGHIJK~LMNO~~~~~"); - char account_encode (uint8_t value) - { - assert (value < 32); - auto result (account_lookup [value]); - return result; - } - uint8_t account_decode (char value) - { - assert (value >= '0'); - assert (value <= '~'); - auto result (account_reverse [value - 0x30] - 0x30); - return result; - } +char const * base58_reverse ("~012345678~~~~~~~9:;<=>?@~ABCDE~FGHIJKLMNOP~~~~~~QRSTUVWXYZ[~\\]^_`abcdefghi"); +uint8_t base58_decode (char value) +{ + assert (value >= '0'); + assert (value <= '~'); + auto result (base58_reverse[value - 0x30] - 0x30); + return result; +} +char const * account_lookup ("13456789abcdefghijkmnopqrstuwxyz"); +char const * account_reverse ("~0~1234567~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~89:;<=>?@AB~CDEFGHIJK~LMNO~~~~~"); +char account_encode (uint8_t value) +{ + assert (value < 32); + auto result (account_lookup[value]); + return result; +} +uint8_t account_decode (char value) +{ + assert (value >= '0'); + assert (value <= '~'); + auto result (account_reverse[value - 0x30] - 0x30); + return result; +} } void rai::uint256_union::encode_account (std::string & destination_a) const @@ -44,13 +44,13 @@ void rai::uint256_union::encode_account (std::string & destination_a) const blake2b_state hash; blake2b_init (&hash, 5); blake2b_update (&hash, bytes.data (), bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&check), 5); + blake2b_final (&hash, reinterpret_cast (&check), 5); rai::uint512_t number_l (number ()); number_l <<= 40; number_l |= rai::uint512_t (check); for (auto i (0); i < 60; ++i) { - auto r (number_l.convert_to () & 0x1f); + auto r (number_l.convert_to () & 0x1f); number_l >>= 5; destination_a.push_back (account_encode (r)); } @@ -96,8 +96,8 @@ bool rai::uint256_union::decode_account_v1 (std::string const & source_a) } if (!result) { - *this = number_l.convert_to (); - uint32_t check ((number_l >> 256).convert_to ()); + *this = number_l.convert_to (); + uint32_t check ((number_l >> 256).convert_to ()); result = (number_l >> (256 + 32)) != 13; if (!result) { @@ -105,7 +105,7 @@ bool rai::uint256_union::decode_account_v1 (std::string const & source_a) blake2b_state hash; blake2b_init (&hash, sizeof (validation)); blake2b_update (&hash, bytes.data (), sizeof (bytes)); - blake2b_final (&hash, reinterpret_cast (&validation), sizeof (validation)); + blake2b_final (&hash, reinterpret_cast (&validation), sizeof (validation)); result = check != validation; } } @@ -118,7 +118,7 @@ bool rai::uint256_union::decode_account (std::string const & source_a) auto result (source_a.size () != 64); if (!result) { - if (source_a [0] == 'x' && source_a [1] == 'r' && source_a [2] == 'b' && (source_a [3] == '_' || source_a [3] == '-')) + if (source_a[0] == 'x' && source_a[1] == 'r' && source_a[2] == 'b' && (source_a[3] == '_' || source_a[3] == '-')) { rai::uint512_t number_l; for (auto i (source_a.begin () + 4), j (source_a.end ()); !result && i != j; ++i) @@ -138,14 +138,14 @@ bool rai::uint256_union::decode_account (std::string const & source_a) } if (!result) { - *this = (number_l >> 40).convert_to (); - uint64_t check (number_l.convert_to ()); - check &= 0xffffffffff; + *this = (number_l >> 40).convert_to (); + uint64_t check (number_l.convert_to ()); + check &= 0xffffffffff; uint64_t validation (0); blake2b_state hash; blake2b_init (&hash, 5); blake2b_update (&hash, bytes.data (), bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&validation), 5); + blake2b_final (&hash, reinterpret_cast (&validation), 5); result = check != validation; } } @@ -166,12 +166,12 @@ rai::uint256_union::uint256_union (rai::uint256_t const & number_a) rai::uint256_t number_l (number_a); for (auto i (bytes.rbegin ()), n (bytes.rend ()); i != n; ++i) { - *i = ((number_l) & 0xff).convert_to (); + *i = ((number_l)&0xff).convert_to (); number_l >>= 8; } } -bool rai::uint256_union::operator == (rai::uint256_union const & other_a) const +bool rai::uint256_union::operator== (rai::uint256_union const & other_a) const { return bytes == other_a.bytes; } @@ -186,7 +186,7 @@ void rai::uint256_union::encrypt (rai::raw_key const & cleartext, rai::raw_key c bool rai::uint256_union::is_zero () const { - return qwords [0] == 0 && qwords [1] == 0 && qwords [2] == 0 && qwords [3] == 0; + return qwords[0] == 0 && qwords[1] == 0 && qwords[2] == 0 && qwords[3] == 0; } std::string rai::uint256_union::to_string () const @@ -196,12 +196,12 @@ std::string rai::uint256_union::to_string () const return result; } -bool rai::uint256_union::operator < (rai::uint256_union const & other_a) const +bool rai::uint256_union::operator< (rai::uint256_union const & other_a) const { return number () < other_a.number (); } -rai::uint256_union & rai::uint256_union::operator ^= (rai::uint256_union const & other_a) +rai::uint256_union & rai::uint256_union::operator^= (rai::uint256_union const & other_a) { auto j (other_a.qwords.begin ()); for (auto i (qwords.begin ()), n (qwords.end ()); i != n; ++i, ++j) @@ -211,7 +211,7 @@ rai::uint256_union & rai::uint256_union::operator ^= (rai::uint256_union const & return *this; } -rai::uint256_union rai::uint256_union::operator ^ (rai::uint256_union const & other_a) const +rai::uint256_union rai::uint256_union::operator^ (rai::uint256_union const & other_a) const { rai::uint256_union result; auto k (result.qwords.begin ()); @@ -329,12 +329,12 @@ rai::uint256_union::uint256_union (uint64_t value0) *this = rai::uint256_t (value0); } -bool rai::uint256_union::operator != (rai::uint256_union const & other_a) const +bool rai::uint256_union::operator!= (rai::uint256_union const & other_a) const { - return ! (*this == other_a); + return !(*this == other_a); } -bool rai::uint512_union::operator == (rai::uint512_union const & other_a) const +bool rai::uint512_union::operator== (rai::uint512_union const & other_a) const { return bytes == other_a.bytes; } @@ -344,7 +344,7 @@ rai::uint512_union::uint512_union (rai::uint512_t const & number_a) rai::uint512_t number_l (number_a); for (auto i (bytes.rbegin ()), n (bytes.rend ()); i != n; ++i) { - *i = ((number_l) & 0xff).convert_to (); + *i = ((number_l)&0xff).convert_to (); number_l >>= 8; } } @@ -401,15 +401,15 @@ bool rai::uint512_union::decode_hex (std::string const & text) return result; } -bool rai::uint512_union::operator != (rai::uint512_union const & other_a) const +bool rai::uint512_union::operator!= (rai::uint512_union const & other_a) const { - return ! (*this == other_a); + return !(*this == other_a); } -rai::uint512_union & rai::uint512_union::operator ^= (rai::uint512_union const & other_a) +rai::uint512_union & rai::uint512_union::operator^= (rai::uint512_union const & other_a) { - uint256s [0] ^= other_a.uint256s [0]; - uint256s [1] ^= other_a.uint256s [1]; + uint256s[0] ^= other_a.uint256s[0]; + uint256s[1] ^= other_a.uint256s[1]; return *this; } @@ -425,12 +425,12 @@ rai::raw_key::~raw_key () data.clear (); } -bool rai::raw_key::operator == (rai::raw_key const & other_a) const +bool rai::raw_key::operator== (rai::raw_key const & other_a) const { return data == other_a.data; } -bool rai::raw_key::operator != (rai::raw_key const & other_a) const +bool rai::raw_key::operator!= (rai::raw_key const & other_a) const { return !(*this == other_a); } @@ -456,7 +456,7 @@ void rai::deterministic_key (rai::uint256_union const & seed_a, uint32_t index_a blake2b_init (&hash, prv_a.bytes.size ()); blake2b_update (&hash, seed_a.bytes.data (), seed_a.bytes.size ()); rai::uint256_union index (index_a); - blake2b_update (&hash, reinterpret_cast (&index.dwords [7]), sizeof (uint32_t)); + blake2b_update (&hash, reinterpret_cast (&index.dwords[7]), sizeof (uint32_t)); blake2b_final (&hash, prv_a.bytes.data (), prv_a.bytes.size ()); } @@ -481,27 +481,27 @@ rai::uint128_union::uint128_union (rai::uint128_t const & value_a) rai::uint128_t number_l (value_a); for (auto i (bytes.rbegin ()), n (bytes.rend ()); i != n; ++i) { - *i = ((number_l) & 0xff).convert_to (); + *i = ((number_l)&0xff).convert_to (); number_l >>= 8; } } -bool rai::uint128_union::operator == (rai::uint128_union const & other_a) const +bool rai::uint128_union::operator== (rai::uint128_union const & other_a) const { - return qwords [0] == other_a.qwords [0] && qwords [1] == other_a.qwords [1]; + return qwords[0] == other_a.qwords[0] && qwords[1] == other_a.qwords[1]; } -bool rai::uint128_union::operator != (rai::uint128_union const & other_a) const +bool rai::uint128_union::operator!= (rai::uint128_union const & other_a) const { return !(*this == other_a); } -bool rai::uint128_union::operator < (rai::uint128_union const & other_a) const +bool rai::uint128_union::operator< (rai::uint128_union const & other_a) const { return number () < other_a.number (); } -bool rai::uint128_union::operator > (rai::uint128_union const & other_a) const +bool rai::uint128_union::operator> (rai::uint128_union const & other_a) const { return number () > other_a.number (); } @@ -587,10 +587,12 @@ bool rai::uint128_union::decode_dec (std::string const & text) return result; } -void format_frac(std::ostringstream & stream, rai::uint128_t value, rai::uint128_t scale, int precision) { +void format_frac (std::ostringstream & stream, rai::uint128_t value, rai::uint128_t scale, int precision) +{ auto reduce = scale; auto rem = value; - while (reduce > 1 && rem > 0 && precision > 0) { + while (reduce > 1 && rem > 0 && precision > 0) + { reduce /= 10; auto val = rem / reduce; rem -= val * reduce; @@ -599,50 +601,60 @@ void format_frac(std::ostringstream & stream, rai::uint128_t value, rai::uint128 } } - -void format_dec(std::ostringstream & stream, rai::uint128_t value, char group_sep, const std::string & groupings) { +void format_dec (std::ostringstream & stream, rai::uint128_t value, char group_sep, const std::string & groupings) +{ auto largestPow10 = rai::uint256_t (1); int dec_count = 1; - while (1) { + while (1) + { auto next = largestPow10 * 10; - if (next > value) { + if (next > value) + { break; } largestPow10 = next; dec_count++; } - if (dec_count > 39) { + if (dec_count > 39) + { // Impossible. return; } // This could be cached per-locale. bool emit_group[39]; - if (group_sep != 0) { + if (group_sep != 0) + { int group_index = 0; int group_count = 0; - for (int i = 0; i < dec_count; i++) { - int groupMax = groupings [group_index]; + for (int i = 0; i < dec_count; i++) + { + int groupMax = groupings[group_index]; group_count++; - if (group_count > groupings [group_index]) { - group_index = std::min (group_index + 1, (int)groupings.length() - 1); + if (group_count > groupings[group_index]) + { + group_index = std::min (group_index + 1, (int)groupings.length () - 1); group_count = 1; - emit_group [i] = true; - } else { - emit_group [i] = false; + emit_group[i] = true; + } + else + { + emit_group[i] = false; } } } - auto reduce = rai::uint128_t(largestPow10); + auto reduce = rai::uint128_t (largestPow10); rai::uint128_t rem = value; - while (reduce > 0) { + while (reduce > 0) + { auto val = rem / reduce; rem -= val * reduce; stream << val; dec_count--; - if (group_sep != 0 && emit_group [dec_count] && reduce > 1) { + if (group_sep != 0 && emit_group[dec_count] && reduce > 1) + { stream << group_sep; } reduce /= 10; @@ -655,43 +667,50 @@ std::string format_balance (rai::uint128_t balance, rai::uint128_t scale, int pr auto int_part = balance / scale; auto frac_part = balance % scale; auto prec_scale = scale; - for (int i = 0; i < precision; i++) { + for (int i = 0; i < precision; i++) + { prec_scale /= 10; } - if (int_part == 0 && frac_part > 0 && frac_part / prec_scale == 0) { + if (int_part == 0 && frac_part > 0 && frac_part / prec_scale == 0) + { // Display e.g. "< 0.01" rather than 0. stream << "< "; - if (precision > 0) { + if (precision > 0) + { stream << "0"; stream << decimal_point; - for (int i = 0; i < precision - 1; i++) { + for (int i = 0; i < precision - 1; i++) + { stream << "0"; } } stream << "1"; - } else { + } + else + { format_dec (stream, int_part, group_digits && grouping.length () > 0 ? thousands_sep : 0, grouping); - if (precision > 0 && frac_part > 0) { + if (precision > 0 && frac_part > 0) + { stream << decimal_point; format_frac (stream, frac_part, scale, precision); } } - return stream.str(); + return stream.str (); } -std::string rai::uint128_union::format_balance(rai::uint128_t scale, int precision, bool group_digits) +std::string rai::uint128_union::format_balance (rai::uint128_t scale, int precision, bool group_digits) { - auto thousands_sep = std::use_facet< std::numpunct >(std::locale ()).thousands_sep (); - auto decimal_point = std::use_facet< std::numpunct >(std::locale ()).decimal_point (); + auto thousands_sep = std::use_facet> (std::locale ()).thousands_sep (); + auto decimal_point = std::use_facet> (std::locale ()).decimal_point (); std::string grouping = "\3"; return ::format_balance (number (), scale, precision, group_digits, thousands_sep, decimal_point, grouping); } std::string rai::uint128_union::format_balance (rai::uint128_t scale, int precision, bool group_digits, const std::locale & locale) { - auto thousands_sep = std::use_facet< std::moneypunct >(locale).thousands_sep (); - auto decimal_point = std::use_facet< std::moneypunct >(locale).decimal_point (); - std::string grouping = std::use_facet< std::moneypunct >(locale).grouping (); + auto thousands_sep = std::use_facet> (locale).thousands_sep (); + auto decimal_point = std::use_facet> (locale).decimal_point (); + std::string grouping = std::use_facet> (locale).grouping (); return ::format_balance (number (), scale, precision, group_digits, thousands_sep, decimal_point, grouping); } @@ -702,7 +721,7 @@ void rai::uint128_union::clear () bool rai::uint128_union::is_zero () const { - return qwords [0] == 0 && qwords [1] == 0; + return qwords[0] == 0 && qwords[1] == 0; } std::string rai::uint128_union::to_string () const diff --git a/rai/lib/numbers.hpp b/rai/lib/numbers.hpp index 42648ec4..0b33a77f 100644 --- a/rai/lib/numbers.hpp +++ b/rai/lib/numbers.hpp @@ -4,7 +4,8 @@ #include -namespace rai { +namespace rai +{ // Random pool used by RaiBlocks. // This must be thread_local as long as the AutoSeededRandomPool implementation requires it extern thread_local CryptoPP::AutoSeededRandomPool random_pool; @@ -15,7 +16,7 @@ using uint512_t = boost::multiprecision::uint512_t; rai::uint128_t const Gxrb_ratio = rai::uint128_t ("1000000000000000000000000000000000"); // 10^33 rai::uint128_t const Mxrb_ratio = rai::uint128_t ("1000000000000000000000000000000"); // 10^30 rai::uint128_t const kxrb_ratio = rai::uint128_t ("1000000000000000000000000000"); // 10^27 -rai::uint128_t const xrb_ratio = rai::uint128_t ("1000000000000000000000000"); // 10^24 +rai::uint128_t const xrb_ratio = rai::uint128_t ("1000000000000000000000000"); // 10^24 rai::uint128_t const mxrb_ratio = rai::uint128_t ("1000000000000000000000"); // 10^21 rai::uint128_t const uxrb_ratio = rai::uint128_t ("1000000000000000000"); // 10^18 @@ -27,10 +28,10 @@ public: uint128_union (uint64_t); uint128_union (rai::uint128_union const &) = default; uint128_union (rai::uint128_t const &); - bool operator == (rai::uint128_union const &) const; - bool operator != (rai::uint128_union const &) const; - bool operator < (rai::uint128_union const &) const; - bool operator > (rai::uint128_union const &) const; + bool operator== (rai::uint128_union const &) const; + bool operator!= (rai::uint128_union const &) const; + bool operator< (rai::uint128_union const &) const; + bool operator> (rai::uint128_union const &) const; void encode_hex (std::string &) const; bool decode_hex (std::string const &); void encode_dec (std::string &) const; @@ -42,10 +43,10 @@ public: bool is_zero () const; std::string to_string () const; std::string to_string_dec () const; - std::array bytes; - std::array chars; - std::array dwords; - std::array qwords; + std::array bytes; + std::array chars; + std::array dwords; + std::array qwords; }; // Balances are 128 bit. using amount = uint128_union; @@ -57,11 +58,11 @@ union uint256_union uint256_union (uint64_t); uint256_union (rai::uint256_t const &); void encrypt (rai::raw_key const &, rai::raw_key const &, uint128_union const &); - uint256_union & operator ^= (rai::uint256_union const &); - uint256_union operator ^ (rai::uint256_union const &) const; - bool operator == (rai::uint256_union const &) const; - bool operator != (rai::uint256_union const &) const; - bool operator < (rai::uint256_union const &) const; + uint256_union & operator^= (rai::uint256_union const &); + uint256_union operator^ (rai::uint256_union const &) const; + bool operator== (rai::uint256_union const &) const; + bool operator!= (rai::uint256_union const &) const; + bool operator< (rai::uint256_union const &) const; void encode_hex (std::string &) const; bool decode_hex (std::string const &); void encode_dec (std::string &) const; @@ -71,11 +72,11 @@ union uint256_union std::string to_account_split () const; bool decode_account_v1 (std::string const &); bool decode_account (std::string const &); - std::array bytes; - std::array chars; - std::array dwords; - std::array qwords; - std::array owords; + std::array bytes; + std::array chars; + std::array dwords; + std::array qwords; + std::array owords; void clear (); bool is_zero () const; std::string to_string () const; @@ -96,24 +97,24 @@ public: void decrypt (rai::uint256_union const &, rai::raw_key const &, uint128_union const &); raw_key (rai::raw_key const &) = delete; raw_key (rai::raw_key const &&) = delete; - rai::raw_key & operator = (rai::raw_key const &) = delete; - bool operator == (rai::raw_key const &) const; - bool operator != (rai::raw_key const &) const; + rai::raw_key & operator= (rai::raw_key const &) = delete; + bool operator== (rai::raw_key const &) const; + bool operator!= (rai::raw_key const &) const; rai::uint256_union data; }; union uint512_union { uint512_union () = default; uint512_union (rai::uint512_t const &); - bool operator == (rai::uint512_union const &) const; - bool operator != (rai::uint512_union const &) const; - rai::uint512_union & operator ^= (rai::uint512_union const &); + bool operator== (rai::uint512_union const &) const; + bool operator!= (rai::uint512_union const &) const; + rai::uint512_union & operator^= (rai::uint512_union const &); void encode_hex (std::string &) const; bool decode_hex (std::string const &); - std::array bytes; - std::array dwords; - std::array qwords; - std::array uint256s; + std::array bytes; + std::array dwords; + std::array qwords; + std::array uint256s; void clear (); rai::uint512_t number () const; std::string to_string () const; @@ -129,19 +130,19 @@ void deterministic_key (rai::uint256_union const &, uint32_t, rai::uint256_union namespace std { template <> -struct hash +struct hash { - size_t operator () (rai::uint256_union const & data_a) const + size_t operator() (rai::uint256_union const & data_a) const { - return *reinterpret_cast (data_a.bytes.data ()); + return *reinterpret_cast (data_a.bytes.data ()); } }; template <> -struct hash +struct hash { - size_t operator () (rai::uint256_t const & number_a) const + size_t operator() (rai::uint256_t const & number_a) const { - return number_a.convert_to (); + return number_a.convert_to (); } }; } diff --git a/rai/lib/utility.hpp b/rai/lib/utility.hpp index c924b07a..7e8d8805 100644 --- a/rai/lib/utility.hpp +++ b/rai/lib/utility.hpp @@ -9,24 +9,24 @@ namespace rai { // Lower priority of calling work generating thread void work_thread_reprioritize (); -template +template class observer_set { public: - void add (std::function const & observer_a) + void add (std::function const & observer_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); observers.push_back (observer_a); } - void operator () (T ... args) + void operator() (T... args) { - std::lock_guard lock (mutex); - for (auto & i: observers) + std::lock_guard lock (mutex); + for (auto & i : observers) { i (args...); } } std::mutex mutex; - std::vector > observers; + std::vector> observers; }; } diff --git a/rai/lib/work.cpp b/rai/lib/work.cpp index 4cb7ef5c..d43231cb 100644 --- a/rai/lib/work.cpp +++ b/rai/lib/work.cpp @@ -21,13 +21,13 @@ uint64_t rai::work_value (rai::block_hash const & root_a, uint64_t work_a) uint64_t result; blake2b_state hash; blake2b_init (&hash, sizeof (result)); - blake2b_update (&hash, reinterpret_cast (&work_a), sizeof (work_a)); + blake2b_update (&hash, reinterpret_cast (&work_a), sizeof (work_a)); blake2b_update (&hash, root_a.bytes.data (), root_a.bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&result), sizeof (result)); + blake2b_final (&hash, reinterpret_cast (&result), sizeof (result)); return result; } -rai::work_pool::work_pool (unsigned max_threads_a, std::function (rai::uint256_union const &)> opencl_a) : +rai::work_pool::work_pool (unsigned max_threads_a, std::function (rai::uint256_union const &)> opencl_a) : ticket (0), done (false), opencl (opencl_a) @@ -36,8 +36,7 @@ opencl (opencl_a) auto count (rai::rai_network == rai::rai_networks::rai_test_network ? 1 : std::max (1u, std::min (max_threads_a, std::thread::hardware_concurrency ()))); for (auto i (0); i < count; ++i) { - auto thread (std::thread ([this, i] () - { + auto thread (std::thread ([this, i]() { rai::work_thread_reprioritize (); loop (i); })); @@ -48,7 +47,7 @@ opencl (opencl_a) rai::work_pool::~work_pool () { stop (); - for (auto &i: threads) + for (auto & i : threads) { i.join (); } @@ -58,13 +57,13 @@ void rai::work_pool::loop (uint64_t thread) { // Quick RNG for work attempts. xorshift1024star rng; - rai::random_pool.GenerateBlock (reinterpret_cast (rng.s.data ()), rng.s.size () * sizeof (decltype (rng.s)::value_type)); + rai::random_pool.GenerateBlock (reinterpret_cast (rng.s.data ()), rng.s.size () * sizeof (decltype (rng.s)::value_type)); uint64_t work; uint64_t output; blake2b_state hash; blake2b_init (&hash, sizeof (output)); - std::unique_lock lock (mutex); - while (!done || !pending.empty()) + std::unique_lock lock (mutex); + while (!done || !pending.empty ()) { auto empty (pending.empty ()); if (thread == 0) @@ -88,9 +87,9 @@ void rai::work_pool::loop (uint64_t thread) while (iteration && output < rai::work_pool::publish_threshold) { work = rng.next (); - blake2b_update (&hash, reinterpret_cast (&work), sizeof (work)); + blake2b_update (&hash, reinterpret_cast (&work), sizeof (work)); blake2b_update (&hash, current_l.first.bytes.data (), current_l.first.bytes.size ()); - blake2b_final (&hash, reinterpret_cast (&output), sizeof (output)); + blake2b_final (&hash, reinterpret_cast (&output), sizeof (output)); blake2b_init (&hash, sizeof (output)); iteration -= 1; } @@ -121,7 +120,7 @@ void rai::work_pool::loop (uint64_t thread) void rai::work_pool::cancel (rai::uint256_union const & root_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); if (!pending.empty ()) { if (pending.front ().first == root_a) @@ -129,8 +128,7 @@ void rai::work_pool::cancel (rai::uint256_union const & root_a) ++ticket; } } - pending.remove_if ([&root_a] (decltype (pending)::value_type const & item_a) - { + pending.remove_if ([&root_a](decltype (pending)::value_type const & item_a) { bool result; if (item_a.first == root_a) { @@ -147,22 +145,22 @@ void rai::work_pool::cancel (rai::uint256_union const & root_a) void rai::work_pool::stop () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); done = true; producer_condition.notify_all (); } -void rai::work_pool::generate (rai::uint256_union const & root_a, std::function const &)> callback_a) +void rai::work_pool::generate (rai::uint256_union const & root_a, std::function const &)> callback_a) { assert (!root_a.is_zero ()); - boost::optional result; + boost::optional result; if (opencl) { result = opencl (root_a); } if (!result) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); pending.push_back (std::make_pair (root_a, callback_a)); producer_condition.notify_all (); } @@ -174,9 +172,8 @@ void rai::work_pool::generate (rai::uint256_union const & root_a, std::function uint64_t rai::work_pool::generate (rai::uint256_union const & hash_a) { - std::promise > work; - generate (hash_a, [&work] (boost::optional work_a) - { + std::promise> work; + generate (hash_a, [&work](boost::optional work_a) { work.set_value (work_a); }); auto result (work.get_future ().get ()); diff --git a/rai/lib/work.hpp b/rai/lib/work.hpp index ce3fb2a1..2102bdf7 100644 --- a/rai/lib/work.hpp +++ b/rai/lib/work.hpp @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include namespace rai { @@ -20,25 +20,24 @@ class opencl_work; class work_pool { public: - work_pool (unsigned, std::function (rai::uint256_union const &)> = nullptr); + work_pool (unsigned, std::function (rai::uint256_union const &)> = nullptr); ~work_pool (); void loop (uint64_t); void stop (); void cancel (rai::uint256_union const &); - void generate (rai::uint256_union const &, std::function const &)>); + void generate (rai::uint256_union const &, std::function const &)>); uint64_t generate (rai::uint256_union const &); - std::atomic ticket; + std::atomic ticket; bool done; - std::vector threads; - std::list const &)>>> pending; + std::vector threads; + std::list const &)>>> pending; std::mutex mutex; std::condition_variable producer_condition; - std::function (rai::uint256_union const &)> opencl; - rai::observer_set work_observers; + std::function (rai::uint256_union const &)> opencl; + rai::observer_set work_observers; // Local work threshold for rate-limiting publishing blocks. ~5 seconds of work. static uint64_t const publish_test_threshold = 0xff00000000000000; static uint64_t const publish_full_threshold = 0xffffffc000000000; static uint64_t const publish_threshold = rai::rai_network == rai::rai_networks::rai_test_network ? publish_test_threshold : publish_full_threshold; }; } - diff --git a/rai/node/bootstrap.cpp b/rai/node/bootstrap.cpp old mode 100755 new mode 100644 index 2027ea36..b304c46d --- a/rai/node/bootstrap.cpp +++ b/rai/node/bootstrap.cpp @@ -14,7 +14,8 @@ rai::block_synchronization::~block_synchronization () { } -namespace { +namespace +{ class add_dependency_visitor : public rai::block_visitor { public: @@ -119,7 +120,7 @@ rai::sync_result rai::block_synchronization::synchronize (MDB_txn * transaction_ return result; } -rai::push_synchronization::push_synchronization (rai::node & node_a, std::function const & target_a) : +rai::push_synchronization::push_synchronization (rai::node & node_a, std::function const & target_a) : block_synchronization (node_a.log), target_m (target_a), node (node_a) @@ -136,7 +137,7 @@ bool rai::push_synchronization::synchronized (MDB_txn * transaction_a, rai::bloc return result; } -std::unique_ptr rai::push_synchronization::retrieve (MDB_txn * transaction_a, rai::block_hash const & hash_a) +std::unique_ptr rai::push_synchronization::retrieve (MDB_txn * transaction_a, rai::block_hash const & hash_a) { return node.store.block_get (transaction_a, hash_a); } @@ -146,7 +147,7 @@ rai::sync_result rai::push_synchronization::target (MDB_txn * transaction_a, rai return target_m (transaction_a, block_a); } -rai::bootstrap_client::bootstrap_client (std::shared_ptr node_a, std::shared_ptr attempt_a, rai::tcp_endpoint const & endpoint_a) : +rai::bootstrap_client::bootstrap_client (std::shared_ptr node_a, std::shared_ptr attempt_a, rai::tcp_endpoint const & endpoint_a) : node (node_a), attempt (attempt_a), socket (node_a->service), @@ -164,9 +165,8 @@ rai::bootstrap_client::~bootstrap_client () void rai::bootstrap_client::start_timeout () { timeout.expires_from_now (boost::posix_time::seconds (15)); - std::weak_ptr this_w (shared ()); - timeout.async_wait ([this_w] (boost::system::error_code const & ec) - { + std::weak_ptr this_w (shared ()); + timeout.async_wait ([this_w](boost::system::error_code const & ec) { if (ec != boost::asio::error::operation_aborted) { auto this_l (this_w.lock ()); @@ -185,15 +185,14 @@ void rai::bootstrap_client::start_timeout () void rai::bootstrap_client::stop_timeout () { size_t killed (timeout.cancel ()); - (void) killed; + (void)killed; } void rai::bootstrap_client::run () { auto this_l (shared_from_this ()); start_timeout (); - socket.async_connect (endpoint, [this_l] (boost::system::error_code const & ec) - { + socket.async_connect (endpoint, [this_l](boost::system::error_code const & ec) { this_l->stop_timeout (); if (!ec) { @@ -204,7 +203,7 @@ void rai::bootstrap_client::run () { if (this_l->node->config.logging.network_logging ()) { - switch (ec.value()) + switch (ec.value ()) { default: BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Error initiating bootstrap connection to %2%: %1%") % ec.message () % this_l->endpoint); @@ -221,19 +220,18 @@ void rai::bootstrap_client::run () void rai::frontier_req_client::run () { - std::unique_ptr request (new rai::frontier_req); + std::unique_ptr request (new rai::frontier_req); request->start.clear (); - request->age = std::numeric_limits age)>::max (); - request->count = std::numeric_limits age)>::max (); - auto send_buffer (std::make_shared > ()); + request->age = std::numeric_limitsage)>::max (); + request->count = std::numeric_limitsage)>::max (); + auto send_buffer (std::make_shared> ()); { rai::vectorstream stream (*send_buffer); request->serialize (stream); } auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_write (connection->socket, boost::asio::buffer (send_buffer->data (), send_buffer->size ()), [this_l, send_buffer] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_write (connection->socket, boost::asio::buffer (send_buffer->data (), send_buffer->size ()), [this_l, send_buffer](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); if (!ec) { @@ -249,12 +247,12 @@ void rai::frontier_req_client::run () }); } -std::shared_ptr rai::bootstrap_client::shared () +std::shared_ptr rai::bootstrap_client::shared () { return shared_from_this (); } -rai::frontier_req_client::frontier_req_client (std::shared_ptr connection_a) : +rai::frontier_req_client::frontier_req_client (std::shared_ptr connection_a) : connection (connection_a), current (0), count (0), @@ -274,8 +272,7 @@ void rai::frontier_req_client::receive_frontier () { auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); this_l->received_frontier (ec, size_a); }); @@ -439,7 +436,7 @@ void rai::frontier_req_client::next (MDB_txn * transaction_a) } } -rai::bulk_pull_client::bulk_pull_client (std::shared_ptr connection_a) : +rai::bulk_pull_client::bulk_pull_client (std::shared_ptr connection_a) : connection (connection_a) { assert (!connection->attempt->mutex.try_lock ()); @@ -450,7 +447,7 @@ connection (connection_a) rai::bulk_pull_client::~bulk_pull_client () { { - std::lock_guard mutex (connection->attempt->mutex); + std::lock_guard mutex (connection->attempt->mutex); --connection->attempt->pulling; connection->attempt->condition.notify_all (); } @@ -467,7 +464,7 @@ void rai::bulk_pull_client::request (rai::pull_info const & pull_a) rai::bulk_pull req; req.start = pull_a.account; req.end = pull_a.end; - auto buffer (std::make_shared > ()); + auto buffer (std::make_shared> ()); { rai::vectorstream stream (*buffer); req.serialize (stream); @@ -482,8 +479,7 @@ void rai::bulk_pull_client::request (rai::pull_info const & pull_a) } auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); if (!ec) { @@ -500,8 +496,7 @@ void rai::bulk_pull_client::receive_block () { auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data (), 1), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); if (!ec) { @@ -517,14 +512,13 @@ void rai::bulk_pull_client::receive_block () void rai::bulk_pull_client::received_type () { auto this_l (shared_from_this ()); - rai::block_type type (static_cast (connection->receive_buffer [0])); + rai::block_type type (static_cast (connection->receive_buffer[0])); switch (type) { case rai::block_type::send: { connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::send_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::send_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); this_l->received_block (ec, size_a); }); @@ -533,8 +527,7 @@ void rai::bulk_pull_client::received_type () case rai::block_type::receive: { connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::receive_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::receive_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); this_l->received_block (ec, size_a); }); @@ -543,8 +536,7 @@ void rai::bulk_pull_client::received_type () case rai::block_type::open: { connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::open_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::open_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); this_l->received_block (ec, size_a); }); @@ -553,8 +545,7 @@ void rai::bulk_pull_client::received_type () case rai::block_type::change: { connection->start_timeout (); - boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::change_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (connection->socket, boost::asio::buffer (connection->receive_buffer.data () + 1, rai::change_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); this_l->received_block (ec, size_a); }); @@ -571,7 +562,7 @@ void rai::bulk_pull_client::received_type () } default: { - BOOST_LOG (connection->node->log) << boost::str (boost::format ("Unknown type received as block type: %1%") % static_cast (type)); + BOOST_LOG (connection->node->log) << boost::str (boost::format ("Unknown type received as block type: %1%") % static_cast (type)); break; } } @@ -582,7 +573,7 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec if (!ec) { rai::bufferstream stream (connection->receive_buffer.data (), 1 + size_a); - std::shared_ptr block (rai::deserialize_block (stream)); + std::shared_ptr block (rai::deserialize_block (stream)); if (block != nullptr) { auto hash (block->hash ()); @@ -598,8 +589,7 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec } auto attempt_l (connection->attempt); auto pull_l (pull); - attempt_l->node->block_processor.add (rai::block_processor_item (block, [attempt_l, pull_l] (MDB_txn * transaction_a, rai::process_return result_a, std::shared_ptr block_a) - { + attempt_l->node->block_processor.add (rai::block_processor_item (block, [attempt_l, pull_l](MDB_txn * transaction_a, rai::process_return result_a, std::shared_ptr block_a) { switch (result_a.code) { case rai::process_result::progress: @@ -608,7 +598,7 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec case rai::process_result::fork: { auto node_l (attempt_l->node); - std::shared_ptr block (node_l->ledger.forked_block (transaction_a, *block_a)); + std::shared_ptr block (node_l->ledger.forked_block (transaction_a, *block_a)); if (!node_l->active.start (transaction_a, block)) { node_l->network.broadcast_confirm_req (block_a); @@ -636,10 +626,9 @@ void rai::bulk_pull_client::received_block (boost::system::error_code const & ec } } -rai::bulk_push_client::bulk_push_client (std::shared_ptr const & connection_a) : +rai::bulk_push_client::bulk_push_client (std::shared_ptr const & connection_a) : connection (connection_a), -synchronization (*connection->node, [this] (MDB_txn * transaction_a, rai::block const & block_a) -{ +synchronization (*connection->node, [this](MDB_txn * transaction_a, rai::block const & block_a) { push_block (block_a); return rai::sync_result::success; }) @@ -653,15 +642,14 @@ rai::bulk_push_client::~bulk_push_client () void rai::bulk_push_client::start () { rai::bulk_push message; - auto buffer (std::make_shared > ()); + auto buffer (std::make_shared> ()); { rai::vectorstream stream (*buffer); message.serialize (stream); } auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); rai::transaction transaction (this_l->connection->node->store.environment, nullptr, true); if (!ec) @@ -707,15 +695,14 @@ void rai::bulk_push_client::push (MDB_txn * transaction_a) void rai::bulk_push_client::send_finished () { - auto buffer (std::make_shared > ()); - buffer->push_back (static_cast (rai::block_type::not_a_block)); + auto buffer (std::make_shared> ()); + buffer->push_back (static_cast (rai::block_type::not_a_block)); if (connection->node->config.logging.network_logging ()) { BOOST_LOG (connection->node->log) << "Bulk push finished"; } auto this_l (shared_from_this ()); - async_write (connection->socket, boost::asio::buffer (buffer->data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + async_write (connection->socket, boost::asio::buffer (buffer->data (), 1), [this_l](boost::system::error_code const & ec, size_t size_a) { try { this_l->promise.set_value (false); @@ -728,15 +715,14 @@ void rai::bulk_push_client::send_finished () void rai::bulk_push_client::push_block (rai::block const & block_a) { - auto buffer (std::make_shared > ()); + auto buffer (std::make_shared> ()); { rai::vectorstream stream (*buffer); rai::serialize_block (stream, block_a); } auto this_l (shared_from_this ()); connection->start_timeout (); - boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_write (connection->socket, boost::asio::buffer (buffer->data (), buffer->size ()), [this_l, buffer](boost::system::error_code const & ec, size_t size_a) { this_l->connection->stop_timeout (); if (!ec) { @@ -772,7 +758,7 @@ attempts (0) { } -rai::bootstrap_attempt::bootstrap_attempt (std::shared_ptr node_a) : +rai::bootstrap_attempt::bootstrap_attempt (std::shared_ptr node_a) : connections (0), pulling (0), node (node_a), @@ -789,15 +775,15 @@ rai::bootstrap_attempt::~bootstrap_attempt () node->bootstrap_initiator.notify_listeners (false); } -bool rai::bootstrap_attempt::request_frontier (std::unique_lock & lock_a) +bool rai::bootstrap_attempt::request_frontier (std::unique_lock & lock_a) { auto result (true); auto connection_l (connection (lock_a)); if (connection_l) { - std::future future; + std::future future; { - auto client (std::make_shared (connection_l)); + auto client (std::make_shared (connection_l)); client->run (); frontiers = client; future = client->promise.get_future (); @@ -824,32 +810,31 @@ bool rai::bootstrap_attempt::request_frontier (std::unique_lock & l return result; } -void rai::bootstrap_attempt::request_pull (std::unique_lock & lock_a) +void rai::bootstrap_attempt::request_pull (std::unique_lock & lock_a) { auto connection_l (connection (lock_a)); if (connection_l) { auto pull (pulls.front ()); pulls.pop_front (); - auto client (std::make_shared (connection_l)); + auto client (std::make_shared (connection_l)); // The bulk_pull_client destructor attempt to requeue_pull which can cause a deadlock if this is the last reference // Dispatch request in an external thread in case it needs to be destroyed - node->background ([client, pull] () - { + node->background ([client, pull]() { client->request (pull); }); } } -bool rai::bootstrap_attempt::request_push (std::unique_lock & lock_a) +bool rai::bootstrap_attempt::request_push (std::unique_lock & lock_a) { auto result (true); auto connection_l (connection (lock_a)); if (connection_l) { - std::future future; + std::future future; { - auto client (std::make_shared (connection_l)); + auto client (std::make_shared (connection_l)); client->start (); push = client; future = client->promise.get_future (); @@ -881,7 +866,7 @@ bool rai::bootstrap_attempt::still_pulling () void rai::bootstrap_attempt::run () { populate_connections (); - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); auto frontier_failure (true); while (!stopped && frontier_failure) { @@ -921,13 +906,13 @@ void rai::bootstrap_attempt::run () idle.clear (); } -std::shared_ptr rai::bootstrap_attempt::connection (std::unique_lock & lock_a) +std::shared_ptr rai::bootstrap_attempt::connection (std::unique_lock & lock_a) { while (!stopped && idle.empty ()) { condition.wait (lock_a); } - std::shared_ptr result; + std::shared_ptr result; if (!idle.empty ()) { result = idle.back (); @@ -936,7 +921,7 @@ std::shared_ptr rai::bootstrap_attempt::connection (std: return result; } -bool rai::bootstrap_attempt::consume_future (std::future & future_a) +bool rai::bootstrap_attempt::consume_future (std::future & future_a) { bool result; try @@ -957,9 +942,9 @@ void rai::bootstrap_attempt::populate_connections () auto peer (node->peers.bootstrap_peer ()); if (peer != rai::endpoint (boost::asio::ip::address_v6::any (), 0)) { - auto client (std::make_shared (node, shared_from_this (), rai::tcp_endpoint (peer.address (), peer.port ()))); + auto client (std::make_shared (node, shared_from_this (), rai::tcp_endpoint (peer.address (), peer.port ()))); client->run (); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); clients.push_back (client); } else @@ -971,9 +956,8 @@ void rai::bootstrap_attempt::populate_connections () } if (!stopped) { - std::weak_ptr this_w (shared_from_this ()); - node->alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + std::weak_ptr this_w (shared_from_this ()); + node->alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { this_l->populate_connections (); @@ -984,20 +968,20 @@ void rai::bootstrap_attempt::populate_connections () void rai::bootstrap_attempt::add_connection (rai::endpoint const & endpoint_a) { - auto client (std::make_shared (node, shared_from_this (), rai::tcp_endpoint (endpoint_a.address (), endpoint_a.port ()))); + auto client (std::make_shared (node, shared_from_this (), rai::tcp_endpoint (endpoint_a.address (), endpoint_a.port ()))); client->run (); } -void rai::bootstrap_attempt::pool_connection (std::shared_ptr client_a) +void rai::bootstrap_attempt::pool_connection (std::shared_ptr client_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); idle.push_back (client_a); condition.notify_all (); } void rai::bootstrap_attempt::stop () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); stopped = true; condition.notify_all (); for (auto i : clients) @@ -1034,7 +1018,7 @@ void rai::bootstrap_attempt::requeue_pull (rai::pull_info const & pull_a) auto pull (pull_a); if (++pull.attempts < 4) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); pulls.push_front (pull); condition.notify_all (); } @@ -1060,15 +1044,14 @@ rai::bootstrap_initiator::~bootstrap_initiator () void rai::bootstrap_initiator::bootstrap () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); if (!stopped && attempt == nullptr) { stop_attempt (lock); - attempt = std::make_shared (node.shared ()); - attempt_thread.reset (new std::thread ([this] () - { + attempt = std::make_shared (node.shared ()); + attempt_thread.reset (new std::thread ([this]() { attempt->run (); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); attempt.reset (); condition.notify_all (); })); @@ -1079,33 +1062,33 @@ void rai::bootstrap_initiator::bootstrap (rai::endpoint const & endpoint_a) { node.peers.insert (endpoint_a, 0x5); bootstrap (); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); if (attempt != nullptr) { attempt->add_connection (endpoint_a); } } -void rai::bootstrap_initiator::add_observer (std::function const & observer_a) +void rai::bootstrap_initiator::add_observer (std::function const & observer_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); observers.push_back (observer_a); } bool rai::bootstrap_initiator::in_progress () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); return attempt != nullptr; } void rai::bootstrap_initiator::stop () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); stopped = true; stop_attempt (lock); } -void rai::bootstrap_initiator::stop_attempt (std::unique_lock & lock_a) +void rai::bootstrap_initiator::stop_attempt (std::unique_lock & lock_a) { assert (!mutex.try_lock ()); if (attempt != nullptr) @@ -1125,7 +1108,7 @@ void rai::bootstrap_initiator::stop_attempt (std::unique_lock & loc void rai::bootstrap_initiator::notify_listeners (bool in_progress_a) { - for (auto & i: observers) + for (auto & i : observers) { i (in_progress_a); } @@ -1148,8 +1131,8 @@ void rai::bootstrap_listener::start () acceptor.bind (local, ec); if (ec) { - BOOST_LOG (node.log) << boost::str (boost::format ("Error while binding for bootstrap on port %1%: %2%") % local.port() % ec.message ()); - throw std::runtime_error (ec.message()); + BOOST_LOG (node.log) << boost::str (boost::format ("Error while binding for bootstrap on port %1%: %2%") % local.port () % ec.message ()); + throw std::runtime_error (ec.message ()); } acceptor.listen (); @@ -1159,7 +1142,7 @@ void rai::bootstrap_listener::start () void rai::bootstrap_listener::stop () { on = false; - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); acceptor.close (); for (auto & i : connections) { @@ -1173,24 +1156,23 @@ void rai::bootstrap_listener::stop () void rai::bootstrap_listener::accept_connection () { - auto socket (std::make_shared (service)); - acceptor.async_accept (*socket, [this, socket] (boost::system::error_code const & ec) - { + auto socket (std::make_shared (service)); + acceptor.async_accept (*socket, [this, socket](boost::system::error_code const & ec) { accept_action (ec, socket); }); } -void rai::bootstrap_listener::accept_action (boost::system::error_code const & ec, std::shared_ptr socket_a) +void rai::bootstrap_listener::accept_action (boost::system::error_code const & ec, std::shared_ptr socket_a) { if (!ec) { accept_connection (); - auto connection (std::make_shared (socket_a, node.shared ())); + auto connection (std::make_shared (socket_a, node.shared ())); { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); if (acceptor.is_open ()) { - connections [connection.get ()] = connection; + connections[connection.get ()] = connection; connection->receive (); } } @@ -1212,11 +1194,11 @@ rai::bootstrap_server::~bootstrap_server () { BOOST_LOG (node->log) << "Exiting bootstrap server"; } - std::lock_guard lock (node->bootstrap.mutex); + std::lock_guard lock (node->bootstrap.mutex); node->bootstrap.connections.erase (this); } -rai::bootstrap_server::bootstrap_server (std::shared_ptr socket_a, std::shared_ptr node_a) : +rai::bootstrap_server::bootstrap_server (std::shared_ptr socket_a, std::shared_ptr node_a) : socket (socket_a), node (node_a) { @@ -1225,8 +1207,7 @@ node (node_a) void rai::bootstrap_server::receive () { auto this_l (shared_from_this ()); - boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data (), 8), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data (), 8), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->receive_header_action (ec, size_a); }); } @@ -1241,7 +1222,7 @@ void rai::bootstrap_server::receive_header_action (boost::system::error_code con uint8_t version_using; uint8_t version_min; rai::message_type type; - std::bitset <16> extensions; + std::bitset<16> extensions; if (!rai::message::read_header (type_stream, version_max, version_using, version_min, type, extensions)) { switch (type) @@ -1249,8 +1230,7 @@ void rai::bootstrap_server::receive_header_action (boost::system::error_code con case rai::message_type::bulk_pull: { auto this_l (shared_from_this ()); - boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data () + 8, sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data () + 8, sizeof (rai::uint256_union) + sizeof (rai::uint256_union)), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->receive_bulk_pull_action (ec, size_a); }); break; @@ -1258,22 +1238,21 @@ void rai::bootstrap_server::receive_header_action (boost::system::error_code con case rai::message_type::frontier_req: { auto this_l (shared_from_this ()); - boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data () + 8, sizeof (rai::uint256_union) + sizeof (uint32_t) + sizeof (uint32_t)), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*socket, boost::asio::buffer (receive_buffer.data () + 8, sizeof (rai::uint256_union) + sizeof (uint32_t) + sizeof (uint32_t)), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->receive_frontier_req_action (ec, size_a); }); break; } case rai::message_type::bulk_push: { - add_request (std::unique_ptr (new rai::bulk_push)); + add_request (std::unique_ptr (new rai::bulk_push)); break; } default: { if (node->config.logging.network_logging ()) { - BOOST_LOG (node->log) << boost::str (boost::format ("Received invalid type from bootstrap connection %1%") % static_cast (type)); + BOOST_LOG (node->log) << boost::str (boost::format ("Received invalid type from bootstrap connection %1%") % static_cast (type)); } break; } @@ -1293,7 +1272,7 @@ void rai::bootstrap_server::receive_bulk_pull_action (boost::system::error_code { if (!ec) { - std::unique_ptr request (new rai::bulk_pull); + std::unique_ptr request (new rai::bulk_pull); rai::bufferstream stream (receive_buffer.data (), 8 + sizeof (rai::uint256_union) + sizeof (rai::uint256_union)); auto error (request->deserialize (stream)); if (!error) @@ -1302,7 +1281,7 @@ void rai::bootstrap_server::receive_bulk_pull_action (boost::system::error_code { BOOST_LOG (node->log) << boost::str (boost::format ("Received bulk pull for %1% down to %2%") % request->start.to_string () % request->end.to_string ()); } - add_request (std::unique_ptr (request.release ())); + add_request (std::unique_ptr (request.release ())); receive (); } } @@ -1312,7 +1291,7 @@ void rai::bootstrap_server::receive_frontier_req_action (boost::system::error_co { if (!ec) { - std::unique_ptr request (new rai::frontier_req); + std::unique_ptr request (new rai::frontier_req); rai::bufferstream stream (receive_buffer.data (), 8 + sizeof (rai::uint256_union) + sizeof (uint32_t) + sizeof (uint32_t)); auto error (request->deserialize (stream)); if (!error) @@ -1321,7 +1300,7 @@ void rai::bootstrap_server::receive_frontier_req_action (boost::system::error_co { BOOST_LOG (node->log) << boost::str (boost::format ("Received frontier request for %1% with age %2%") % request->start.to_string () % request->age); } - add_request (std::unique_ptr (request.release ())); + add_request (std::unique_ptr (request.release ())); receive (); } } @@ -1334,9 +1313,9 @@ void rai::bootstrap_server::receive_frontier_req_action (boost::system::error_co } } -void rai::bootstrap_server::add_request (std::unique_ptr message_a) +void rai::bootstrap_server::add_request (std::unique_ptr message_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto start (requests.empty ()); requests.push (std::move (message_a)); if (start) @@ -1347,7 +1326,7 @@ void rai::bootstrap_server::add_request (std::unique_ptr message_ void rai::bootstrap_server::finish_request () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); requests.pop (); if (!requests.empty ()) { @@ -1360,7 +1339,7 @@ namespace class request_response_visitor : public rai::message_visitor { public: - request_response_visitor (std::shared_ptr connection_a) : + request_response_visitor (std::shared_ptr connection_a) : connection (connection_a) { } @@ -1382,20 +1361,20 @@ public: } void bulk_pull (rai::bulk_pull const &) override { - auto response (std::make_shared (connection, std::unique_ptr (static_cast (connection->requests.front ().release ())))); + auto response (std::make_shared (connection, std::unique_ptr (static_cast (connection->requests.front ().release ())))); response->send_next (); } void bulk_push (rai::bulk_push const &) override { - auto response (std::make_shared (connection)); + auto response (std::make_shared (connection)); response->receive (); } void frontier_req (rai::frontier_req const &) override { - auto response (std::make_shared (connection, std::unique_ptr (static_cast (connection->requests.front ().release ())))); + auto response (std::make_shared (connection, std::unique_ptr (static_cast (connection->requests.front ().release ())))); response->send_next (); } - std::shared_ptr connection; + std::shared_ptr connection; }; } @@ -1451,7 +1430,7 @@ void rai::bulk_pull_server::set_current_end () void rai::bulk_pull_server::send_next () { - std::unique_ptr block (get_next ()); + std::unique_ptr block (get_next ()); if (block != nullptr) { { @@ -1464,8 +1443,7 @@ void rai::bulk_pull_server::send_next () { BOOST_LOG (connection->node->log) << boost::str (boost::format ("Sending block: %1%") % block->hash ().to_string ()); } - async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->sent_action (ec, size_a); }); } @@ -1475,9 +1453,9 @@ void rai::bulk_pull_server::send_next () } } -std::unique_ptr rai::bulk_pull_server::get_next () +std::unique_ptr rai::bulk_pull_server::get_next () { - std::unique_ptr result; + std::unique_ptr result; if (current != request->end) { rai::transaction transaction (connection->node->store.environment, nullptr, false); @@ -1517,14 +1495,13 @@ void rai::bulk_pull_server::sent_action (boost::system::error_code const & ec, s void rai::bulk_pull_server::send_finished () { send_buffer.clear (); - send_buffer.push_back (static_cast (rai::block_type::not_a_block)); + send_buffer.push_back (static_cast (rai::block_type::not_a_block)); auto this_l (shared_from_this ()); if (connection->node->config.logging.bulk_pull_logging ()) { BOOST_LOG (connection->node->log) << "Bulk sending finished"; } - async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), 1), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->no_block_sent (ec, size_a); }); } @@ -1542,14 +1519,14 @@ void rai::bulk_pull_server::no_block_sent (boost::system::error_code const & ec, } } -rai::bulk_pull_server::bulk_pull_server (std::shared_ptr const & connection_a, std::unique_ptr request_a) : +rai::bulk_pull_server::bulk_pull_server (std::shared_ptr const & connection_a, std::unique_ptr request_a) : connection (connection_a), request (std::move (request_a)) { set_current_end (); } -rai::bulk_push_server::bulk_push_server (std::shared_ptr const & connection_a) : +rai::bulk_push_server::bulk_push_server (std::shared_ptr const & connection_a) : connection (connection_a) { } @@ -1557,8 +1534,7 @@ connection (connection_a) void rai::bulk_push_server::receive () { auto this_l (shared_from_this ()); - boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data (), 1), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data (), 1), [this_l](boost::system::error_code const & ec, size_t size_a) { if (!ec) { this_l->received_type (); @@ -1573,37 +1549,33 @@ void rai::bulk_push_server::receive () void rai::bulk_push_server::received_type () { auto this_l (shared_from_this ()); - rai::block_type type (static_cast (receive_buffer [0])); + rai::block_type type (static_cast (receive_buffer[0])); switch (type) { case rai::block_type::send: { - boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::send_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::send_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->received_block (ec, size_a); }); break; } case rai::block_type::receive: { - boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::receive_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::receive_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->received_block (ec, size_a); }); break; } case rai::block_type::open: { - boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::open_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::open_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->received_block (ec, size_a); }); break; } case rai::block_type::change: { - boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::change_block::size), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + boost::asio::async_read (*connection->socket, boost::asio::buffer (receive_buffer.data () + 1, rai::change_block::size), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->received_block (ec, size_a); }); break; @@ -1642,7 +1614,7 @@ void rai::bulk_push_server::received_block (boost::system::error_code const & ec } } -rai::frontier_req_server::frontier_req_server (std::shared_ptr const & connection_a, std::unique_ptr request_a) : +rai::frontier_req_server::frontier_req_server (std::shared_ptr const & connection_a, std::unique_ptr request_a) : connection (connection_a), current (request_a->start.number () - 1), info (0, 0, 0, 0, 0, 0), @@ -1680,8 +1652,7 @@ void rai::frontier_req_server::send_next () BOOST_LOG (connection->node->log) << boost::str (boost::format ("Sending frontier for %1% %2%") % current.to_account () % info.head.to_string ()); } next (); - async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->sent_action (ec, size_a); }); } @@ -1705,8 +1676,7 @@ void rai::frontier_req_server::send_finished () { BOOST_LOG (connection->node->log) << "Frontier sending finished"; } - async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l] (boost::system::error_code const & ec, size_t size_a) - { + async_write (*connection->socket, boost::asio::buffer (send_buffer.data (), send_buffer.size ()), [this_l](boost::system::error_code const & ec, size_t size_a) { this_l->no_block_sent (ec, size_a); }); } diff --git a/rai/node/bootstrap.hpp b/rai/node/bootstrap.hpp index 66f1cacd..5f60ad01 100644 --- a/rai/node/bootstrap.hpp +++ b/rai/node/bootstrap.hpp @@ -1,13 +1,13 @@ #pragma once -#include #include +#include #include #include #include -#include #include +#include #include @@ -28,7 +28,7 @@ public: ~block_synchronization (); // Return true if target already has block virtual bool synchronized (MDB_txn *, rai::block_hash const &) = 0; - virtual std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) = 0; + virtual std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) = 0; virtual rai::sync_result target (MDB_txn *, rai::block const &) = 0; // return true if all dependencies are synchronized bool add_dependency (MDB_txn *, rai::block const &); @@ -36,16 +36,16 @@ public: rai::sync_result synchronize_one (MDB_txn *); rai::sync_result synchronize (MDB_txn *, rai::block_hash const &); boost::log::sources::logger_mt & log; - std::deque blocks; + std::deque blocks; }; class push_synchronization : public rai::block_synchronization { public: - push_synchronization (rai::node &, std::function const &); + push_synchronization (rai::node &, std::function const &); bool synchronized (MDB_txn *, rai::block_hash const &) override; - std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; + std::unique_ptr retrieve (MDB_txn *, rai::block_hash const &) override; rai::sync_result target (MDB_txn *, rai::block const &) override; - std::function target_m; + std::function target_m; rai::node & node; }; class bootstrap_client; @@ -61,40 +61,40 @@ public: }; class frontier_req_client; class bulk_push_client; -class bootstrap_attempt : public std::enable_shared_from_this +class bootstrap_attempt : public std::enable_shared_from_this { public: - bootstrap_attempt (std::shared_ptr node_a); + bootstrap_attempt (std::shared_ptr node_a); ~bootstrap_attempt (); void run (); - std::shared_ptr connection (std::unique_lock &); - bool consume_future (std::future &); + std::shared_ptr connection (std::unique_lock &); + bool consume_future (std::future &); void populate_connections (); - bool request_frontier (std::unique_lock &); - void request_pull (std::unique_lock &); - bool request_push (std::unique_lock &); + bool request_frontier (std::unique_lock &); + void request_pull (std::unique_lock &); + bool request_push (std::unique_lock &); void add_connection (rai::endpoint const &); - void pool_connection (std::shared_ptr ); + void pool_connection (std::shared_ptr); void stop (); void requeue_pull (rai::pull_info const &); bool still_pulling (); - std::deque > clients; - std::weak_ptr frontiers; - std::weak_ptr push; - std::deque pulls; - std::vector > idle; - std::atomic connections; - std::atomic pulling; - std::shared_ptr node; - std::atomic account_count; + std::deque> clients; + std::weak_ptr frontiers; + std::weak_ptr push; + std::deque pulls; + std::vector> idle; + std::atomic connections; + std::atomic pulling; + std::shared_ptr node; + std::atomic account_count; bool stopped; std::mutex mutex; std::condition_variable condition; }; -class frontier_req_client : public std::enable_shared_from_this +class frontier_req_client : public std::enable_shared_from_this { public: - frontier_req_client (std::shared_ptr ); + frontier_req_client (std::shared_ptr); ~frontier_req_client (); void run (); void receive_frontier (); @@ -103,57 +103,57 @@ public: void unsynced (MDB_txn *, rai::account const &, rai::block_hash const &); void next (MDB_txn *); void insert_pull (rai::pull_info const &); - std::shared_ptr connection; + std::shared_ptr connection; rai::account current; rai::account_info info; unsigned count; rai::account landing; rai::account faucet; std::chrono::system_clock::time_point next_report; - std::promise promise; + std::promise promise; }; -class bulk_pull_client : public std::enable_shared_from_this +class bulk_pull_client : public std::enable_shared_from_this { public: - bulk_pull_client (std::shared_ptr ); + bulk_pull_client (std::shared_ptr); ~bulk_pull_client (); void request (rai::pull_info const &); void receive_block (); void received_type (); void received_block (boost::system::error_code const &, size_t); rai::block_hash first (); - std::shared_ptr connection; + std::shared_ptr connection; rai::block_hash expected; rai::pull_info pull; }; -class bootstrap_client : public std::enable_shared_from_this +class bootstrap_client : public std::enable_shared_from_this { public: - bootstrap_client (std::shared_ptr , std::shared_ptr , rai::tcp_endpoint const &); + bootstrap_client (std::shared_ptr, std::shared_ptr, rai::tcp_endpoint const &); ~bootstrap_client (); void run (); - std::shared_ptr shared (); + std::shared_ptr shared (); void start_timeout (); void stop_timeout (); - std::shared_ptr node; - std::shared_ptr attempt; + std::shared_ptr node; + std::shared_ptr attempt; boost::asio::ip::tcp::socket socket; - std::array receive_buffer; + std::array receive_buffer; rai::tcp_endpoint endpoint; boost::asio::deadline_timer timeout; }; -class bulk_push_client : public std::enable_shared_from_this +class bulk_push_client : public std::enable_shared_from_this { public: - bulk_push_client (std::shared_ptr const &); + bulk_push_client (std::shared_ptr const &); ~bulk_push_client (); void start (); void push (MDB_txn *); void push_block (rai::block const &); void send_finished (); - std::shared_ptr connection; + std::shared_ptr connection; rai::push_synchronization synchronization; - std::promise promise; + std::promise promise; }; class bootstrap_initiator { @@ -163,18 +163,19 @@ public: void bootstrap (rai::endpoint const &); void bootstrap (); void notify_listeners (bool); - void add_observer (std::function const &); + void add_observer (std::function const &); bool in_progress (); void stop (); rai::node & node; - std::shared_ptr attempt; - std::unique_ptr attempt_thread; + std::shared_ptr attempt; + std::unique_ptr attempt_thread; bool stopped; + private: - void stop_attempt (std::unique_lock &); + void stop_attempt (std::unique_lock &); std::mutex mutex; std::condition_variable condition; - std::vector > observers; + std::vector> observers; }; class bootstrap_server; class bootstrap_listener @@ -184,9 +185,9 @@ public: void start (); void stop (); void accept_connection (); - void accept_action (boost::system::error_code const &, std::shared_ptr ); + void accept_action (boost::system::error_code const &, std::shared_ptr); std::mutex mutex; - std::unordered_map > connections; + std::unordered_map> connections; rai::tcp_endpoint endpoint (); boost::asio::ip::tcp::acceptor acceptor; rai::tcp_endpoint local; @@ -195,68 +196,68 @@ public: bool on; }; class message; -class bootstrap_server : public std::enable_shared_from_this +class bootstrap_server : public std::enable_shared_from_this { public: - bootstrap_server (std::shared_ptr , std::shared_ptr ); + bootstrap_server (std::shared_ptr, std::shared_ptr); ~bootstrap_server (); void receive (); void receive_header_action (boost::system::error_code const &, size_t); void receive_bulk_pull_action (boost::system::error_code const &, size_t); void receive_frontier_req_action (boost::system::error_code const &, size_t); void receive_bulk_push_action (); - void add_request (std::unique_ptr ); + void add_request (std::unique_ptr); void finish_request (); void run_next (); - std::array receive_buffer; - std::shared_ptr socket; - std::shared_ptr node; + std::array receive_buffer; + std::shared_ptr socket; + std::shared_ptr node; std::mutex mutex; - std::queue > requests; + std::queue> requests; }; class bulk_pull; -class bulk_pull_server : public std::enable_shared_from_this +class bulk_pull_server : public std::enable_shared_from_this { public: - bulk_pull_server (std::shared_ptr const &, std::unique_ptr ); + bulk_pull_server (std::shared_ptr const &, std::unique_ptr); void set_current_end (); - std::unique_ptr get_next (); + std::unique_ptr get_next (); void send_next (); void sent_action (boost::system::error_code const &, size_t); void send_finished (); void no_block_sent (boost::system::error_code const &, size_t); - std::shared_ptr connection; - std::unique_ptr request; - std::vector send_buffer; + std::shared_ptr connection; + std::unique_ptr request; + std::vector send_buffer; rai::block_hash current; }; -class bulk_push_server : public std::enable_shared_from_this +class bulk_push_server : public std::enable_shared_from_this { public: - bulk_push_server (std::shared_ptr const &); + bulk_push_server (std::shared_ptr const &); void receive (); void receive_block (); void received_type (); void received_block (boost::system::error_code const &, size_t); - std::array receive_buffer; - std::shared_ptr connection; + std::array receive_buffer; + std::shared_ptr connection; }; class frontier_req; -class frontier_req_server : public std::enable_shared_from_this +class frontier_req_server : public std::enable_shared_from_this { public: - frontier_req_server (std::shared_ptr const &, std::unique_ptr ); + frontier_req_server (std::shared_ptr const &, std::unique_ptr); void skip_old (); void send_next (); void sent_action (boost::system::error_code const &, size_t); void send_finished (); void no_block_sent (boost::system::error_code const &, size_t); void next (); - std::shared_ptr connection; + std::shared_ptr connection; rai::account current; rai::account_info info; - std::unique_ptr request; - std::vector send_buffer; + std::unique_ptr request; + std::vector send_buffer; size_t count; }; } diff --git a/rai/node/common.cpp b/rai/node/common.cpp index 8e286cd0..6e9c47eb 100644 --- a/rai/node/common.cpp +++ b/rai/node/common.cpp @@ -1,12 +1,12 @@ #include -#include #include +#include -std::array constexpr rai::message::magic_number; +std::array constexpr rai::message::magic_number; size_t constexpr rai::message::ipv4_only_position; size_t constexpr rai::message::bootstrap_server_position; -std::bitset <16> constexpr rai::message::block_type_mask; +std::bitset<16> constexpr rai::message::block_type_mask; rai::message::message (rai::message_type type_a) : version_max (0x05), @@ -23,13 +23,13 @@ rai::message::message (bool & error_a, rai::stream & stream_a) rai::block_type rai::message::block_type () const { - return static_cast (((extensions & block_type_mask) >> 8).to_ullong ()); + return static_cast (((extensions & block_type_mask) >> 8).to_ullong ()); } void rai::message::block_type_set (rai::block_type type_a) { extensions &= ~rai::message::block_type_mask; -extensions |= std::bitset <16> (static_cast (type_a) << 8); + extensions |= std::bitset<16> (static_cast (type_a) << 8); } bool rai::message::ipv4_only () @@ -49,12 +49,12 @@ void rai::message::write_header (rai::stream & stream_a) rai::write (stream_a, version_using); rai::write (stream_a, version_min); rai::write (stream_a, type); - rai::write (stream_a, static_cast (extensions.to_ullong ())); + rai::write (stream_a, static_cast (extensions.to_ullong ())); } -bool rai::message::read_header (rai::stream & stream_a, uint8_t & version_max_a, uint8_t & version_using_a, uint8_t & version_min_a, rai::message_type & type_a, std::bitset <16> & extensions_a) +bool rai::message::read_header (rai::stream & stream_a, uint8_t & version_max_a, uint8_t & version_using_a, uint8_t & version_min_a, rai::message_type & type_a, std::bitset<16> & extensions_a) { - std::array magic_number_l; + std::array magic_number_l; auto result (rai::read (stream_a, magic_number_l)); if (!result) { @@ -104,7 +104,7 @@ void rai::message_parser::deserialize_buffer (uint8_t const * buffer_a, size_t s uint8_t version_using; uint8_t version_min; rai::message_type type; - std::bitset <16> extensions; + std::bitset<16> extensions; if (!rai::message::read_header (header_stream, version_max, version_using, version_min, type, extensions)) { switch (type) @@ -233,7 +233,7 @@ bool rai::message_parser::at_end (rai::bufferstream & stream_a) rai::keepalive::keepalive () : message (rai::message_type::keepalive) { - rai::endpoint endpoint (boost::asio::ip::address_v6 {}, 0); + rai::endpoint endpoint (boost::asio::ip::address_v6{}, 0); for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i) { *i = endpoint; @@ -264,7 +264,7 @@ bool rai::keepalive::deserialize (rai::stream & stream_a) assert (type == rai::message_type::keepalive); for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) { - std::array address; + std::array address; uint16_t port; read (stream_a, address); read (stream_a, port); @@ -273,7 +273,7 @@ bool rai::keepalive::deserialize (rai::stream & stream_a) return result; } -bool rai::keepalive::operator == (rai::keepalive const & other_a) const +bool rai::keepalive::operator== (rai::keepalive const & other_a) const { return peers == other_a.peers; } @@ -283,7 +283,7 @@ message (rai::message_type::publish) { } -rai::publish::publish (std::shared_ptr block_a) : +rai::publish::publish (std::shared_ptr block_a) : message (rai::message_type::publish), block (block_a) { @@ -315,7 +315,7 @@ void rai::publish::visit (rai::message_visitor & visitor_a) const visitor_a.publish (*this); } -bool rai::publish::operator == (rai::publish const & other_a) const +bool rai::publish::operator== (rai::publish const & other_a) const { return *block == *other_a.block; } @@ -325,7 +325,7 @@ message (rai::message_type::confirm_req) { } -rai::confirm_req::confirm_req (std::shared_ptr block_a) : +rai::confirm_req::confirm_req (std::shared_ptr block_a) : message (rai::message_type::confirm_req), block (block_a) { @@ -357,18 +357,18 @@ void rai::confirm_req::serialize (rai::stream & stream_a) block->serialize (stream_a); } -bool rai::confirm_req::operator == (rai::confirm_req const & other_a) const +bool rai::confirm_req::operator== (rai::confirm_req const & other_a) const { return *block == *other_a.block; } rai::confirm_ack::confirm_ack (bool & error_a, rai::stream & stream_a) : message (error_a, stream_a), -vote (std::make_shared (error_a, stream_a, block_type ())) +vote (std::make_shared (error_a, stream_a, block_type ())) { } -rai::confirm_ack::confirm_ack (std::shared_ptr vote_a) : +rai::confirm_ack::confirm_ack (std::shared_ptr vote_a) : message (rai::message_type::confirm_ack), vote (vote_a) { @@ -407,7 +407,7 @@ void rai::confirm_ack::serialize (rai::stream & stream_a) vote->serialize (stream_a, block_type ()); } -bool rai::confirm_ack::operator == (rai::confirm_ack const & other_a) const +bool rai::confirm_ack::operator== (rai::confirm_ack const & other_a) const { auto result (*vote == *other_a.vote); return result; @@ -457,7 +457,7 @@ void rai::frontier_req::visit (rai::message_visitor & visitor_a) const visitor_a.frontier_req (*this); } -bool rai::frontier_req::operator == (rai::frontier_req const & other_a) const +bool rai::frontier_req::operator== (rai::frontier_req const & other_a) const { return start == other_a.start && age == other_a.age && count == other_a.count; } diff --git a/rai/node/common.hpp b/rai/node/common.hpp index 880dc293..993f3f74 100644 --- a/rai/node/common.hpp +++ b/rai/node/common.hpp @@ -40,29 +40,29 @@ struct endpoint_hash { }; template <> -struct endpoint_hash <8> +struct endpoint_hash<8> { - size_t operator () (rai::endpoint const & endpoint_a) const + size_t operator() (rai::endpoint const & endpoint_a) const { return endpoint_hash_raw (endpoint_a); } }; template <> -struct endpoint_hash <4> +struct endpoint_hash<4> { - size_t operator () (rai::endpoint const & endpoint_a) const + size_t operator() (rai::endpoint const & endpoint_a) const { uint64_t big (endpoint_hash_raw (endpoint_a)); - uint32_t result (static_cast (big) ^ static_cast (big >> 32)); + uint32_t result (static_cast (big) ^ static_cast (big >> 32)); return result; } }; template <> -struct hash +struct hash { - size_t operator () (rai::endpoint const & endpoint_a) const + size_t operator() (rai::endpoint const & endpoint_a) const { - endpoint_hash ehash; + endpoint_hash ehash; return ehash (endpoint_a); } }; @@ -70,11 +70,11 @@ struct hash namespace boost { template <> -struct hash +struct hash { - size_t operator () (rai::endpoint const & endpoint_a) const + size_t operator() (rai::endpoint const & endpoint_a) const { - std::hash hash; + std::hash hash; return hash (endpoint_a); } }; @@ -102,7 +102,7 @@ public: message (bool &, rai::stream &); virtual ~message () = default; void write_header (rai::stream &); - static bool read_header (rai::stream &, uint8_t &, uint8_t &, uint8_t &, rai::message_type &, std::bitset <16> &); + static bool read_header (rai::stream &, uint8_t &, uint8_t &, uint8_t &, rai::message_type &, std::bitset<16> &); virtual void serialize (rai::stream &) = 0; virtual bool deserialize (rai::stream &) = 0; virtual void visit (rai::message_visitor &) const = 0; @@ -110,15 +110,15 @@ public: void block_type_set (rai::block_type); bool ipv4_only (); void ipv4_only_set (bool); - static std::array constexpr magic_number = rai::rai_network == rai::rai_networks::rai_test_network ? std::array ({ 'R', 'A' }) : rai::rai_network == rai::rai_networks::rai_beta_network ? std::array ({ 'R', 'B' }) : std::array ({ 'R', 'C' }); + static std::array constexpr magic_number = rai::rai_network == rai::rai_networks::rai_test_network ? std::array ({ 'R', 'A' }) : rai::rai_network == rai::rai_networks::rai_beta_network ? std::array ({ 'R', 'B' }) : std::array ({ 'R', 'C' }); uint8_t version_max; uint8_t version_using; uint8_t version_min; rai::message_type type; - std::bitset <16> extensions; + std::bitset<16> extensions; static size_t constexpr ipv4_only_position = 1; static size_t constexpr bootstrap_server_position = 2; - static std::bitset <16> constexpr block_type_mask = std::bitset <16> (0x0f00); + static std::bitset<16> constexpr block_type_mask = std::bitset<16> (0x0f00); }; class work_pool; class message_parser @@ -143,41 +143,41 @@ public: void visit (rai::message_visitor &) const override; bool deserialize (rai::stream &) override; void serialize (rai::stream &) override; - bool operator == (rai::keepalive const &) const; - std::array peers; + bool operator== (rai::keepalive const &) const; + std::array peers; }; class publish : public message { public: publish (); - publish (std::shared_ptr ); + publish (std::shared_ptr); void visit (rai::message_visitor &) const override; bool deserialize (rai::stream &) override; void serialize (rai::stream &) override; - bool operator == (rai::publish const &) const; - std::shared_ptr block; + bool operator== (rai::publish const &) const; + std::shared_ptr block; }; class confirm_req : public message { public: confirm_req (); - confirm_req (std::shared_ptr ); + confirm_req (std::shared_ptr); bool deserialize (rai::stream &) override; void serialize (rai::stream &) override; void visit (rai::message_visitor &) const override; - bool operator == (rai::confirm_req const &) const; - std::shared_ptr block; + bool operator== (rai::confirm_req const &) const; + std::shared_ptr block; }; class confirm_ack : public message { public: confirm_ack (bool &, rai::stream &); - confirm_ack (std::shared_ptr ); + confirm_ack (std::shared_ptr); bool deserialize (rai::stream &) override; void serialize (rai::stream &) override; void visit (rai::message_visitor &) const override; - bool operator == (rai::confirm_ack const &) const; - std::shared_ptr vote; + bool operator== (rai::confirm_ack const &) const; + std::shared_ptr vote; }; class frontier_req : public message { @@ -186,7 +186,7 @@ public: bool deserialize (rai::stream &) override; void serialize (rai::stream &) override; void visit (rai::message_visitor &) const override; - bool operator == (rai::frontier_req const &) const; + bool operator== (rai::frontier_req const &) const; rai::account start; uint32_t age; uint32_t count; diff --git a/rai/node/node.cpp b/rai/node/node.cpp old mode 100755 new mode 100644 index e50f8c25..57601e10 --- a/rai/node/node.cpp +++ b/rai/node/node.cpp @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include @@ -57,9 +57,8 @@ void rai::network::receive () { BOOST_LOG (node.log) << "Receiving packet"; } - std::unique_lock lock (socket_mutex); - socket.async_receive_from (boost::asio::buffer (buffer.data (), buffer.size ()), remote, [this] (boost::system::error_code const & error, size_t size_a) - { + std::unique_lock lock (socket_mutex); + socket.async_receive_from (boost::asio::buffer (buffer.data (), buffer.size ()), remote, [this](boost::system::error_code const & error, size_t size_a) { receive_action (error, size_a); }); } @@ -76,7 +75,7 @@ void rai::network::send_keepalive (rai::endpoint const & endpoint_a) assert (endpoint_a.address ().is_v6 ()); rai::keepalive message; node.peers.random_fill (message.peers); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); message.serialize (stream); @@ -86,9 +85,8 @@ void rai::network::send_keepalive (rai::endpoint const & endpoint_a) BOOST_LOG (node.log) << boost::str (boost::format ("Keepalive req sent to %1%") % endpoint_a); } ++outgoing.keepalive; - std::weak_ptr node_w (node.shared ()); - send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w, endpoint_a] (boost::system::error_code const & ec, size_t) - { + std::weak_ptr node_w (node.shared ()); + send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w, endpoint_a](boost::system::error_code const & ec, size_t) { if (auto node_l = node_w.lock ()) { if (node_l->config.logging.network_keepalive_logging ()) @@ -105,11 +103,10 @@ void rai::network::send_keepalive (rai::endpoint const & endpoint_a) void rai::node::keepalive (std::string const & address_a, uint16_t port_a) { auto node_l (shared_from_this ()); - network.resolver.async_resolve (boost::asio::ip::udp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a] (boost::system::error_code const & ec, boost::asio::ip::udp::resolver::iterator i_a) - { + network.resolver.async_resolve (boost::asio::ip::udp::resolver::query (address_a, std::to_string (port_a)), [node_l, address_a, port_a](boost::system::error_code const & ec, boost::asio::ip::udp::resolver::iterator i_a) { if (!ec) { - for (auto i (i_a), n (boost::asio::ip::udp::resolver::iterator {}); i != n; ++i) + for (auto i (i_a), n (boost::asio::ip::udp::resolver::iterator{}); i != n; ++i) { auto endpoint (i->endpoint ()); if (endpoint.address ().is_v4 ()) @@ -126,16 +123,15 @@ void rai::node::keepalive (std::string const & address_a, uint16_t port_a) }); } -void rai::network::republish (rai::block_hash const & hash_a, std::shared_ptr > buffer_a, rai::endpoint endpoint_a) +void rai::network::republish (rai::block_hash const & hash_a, std::shared_ptr> buffer_a, rai::endpoint endpoint_a) { ++outgoing.publish; if (node.config.logging.network_publish_logging ()) { BOOST_LOG (node.log) << boost::str (boost::format ("Publishing %1% to %2%") % hash_a.to_string () % endpoint_a); } - std::weak_ptr node_w (node.shared ()); - send_buffer (buffer_a->data (), buffer_a->size (), endpoint_a, [buffer_a, node_w, endpoint_a] (boost::system::error_code const & ec, size_t size) - { + std::weak_ptr node_w (node.shared ()); + send_buffer (buffer_a->data (), buffer_a->size (), endpoint_a, [buffer_a, node_w, endpoint_a](boost::system::error_code const & ec, size_t size) { if (auto node_l = node_w.lock ()) { if (node_l->config.logging.network_logging ()) @@ -149,11 +145,11 @@ void rai::network::republish (rai::block_hash const & hash_a, std::shared_ptr block_a) +void rai::network::rebroadcast_reps (std::shared_ptr block_a) { auto hash (block_a->hash ()); rai::publish message (block_a); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); message.serialize (stream); @@ -166,17 +162,16 @@ void rai::network::rebroadcast_reps (std::shared_ptr block_a) } template -bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std::shared_ptr block_a) +bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std::shared_ptr block_a) { bool result (false); if (node_a.config.enable_voting) { - node_a.wallets.foreach_representative (transaction_a, [&result, &block_a, &list_a, &node_a, &transaction_a] (rai::public_key const & pub_a, rai::raw_key const & prv_a) - { + node_a.wallets.foreach_representative (transaction_a, [&result, &block_a, &list_a, &node_a, &transaction_a](rai::public_key const & pub_a, rai::raw_key const & prv_a) { result = true; auto vote (node_a.store.vote_generate (transaction_a, pub_a, prv_a, block_a)); rai::confirm_ack confirm (vote); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); confirm.serialize (stream); @@ -191,15 +186,15 @@ bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, T & list_a, std } template <> -bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, rai::endpoint & peer_a, std::shared_ptr block_a) +bool confirm_block (MDB_txn * transaction_a, rai::node & node_a, rai::endpoint & peer_a, std::shared_ptr block_a) { - std::array endpoints; - endpoints [0] = peer_a; + std::array endpoints; + endpoints[0] = peer_a; auto result (confirm_block (transaction_a, node_a, endpoints, std::move (block_a))); return result; } -void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr block) +void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr block) { rebroadcast_reps (block); auto hash (block->hash ()); @@ -208,7 +203,7 @@ void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); message.serialize (stream); @@ -236,14 +231,14 @@ void rai::network::republish_block (MDB_txn * transaction, std::shared_ptr Y to prevent creating a lot of small-weight accounts to send out votes -void rai::network::republish_vote (std::chrono::system_clock::time_point const & last_vote, std::shared_ptr vote_a) +void rai::network::republish_vote (std::chrono::system_clock::time_point const & last_vote, std::shared_ptr vote_a) { if (last_vote < std::chrono::system_clock::now () - std::chrono::seconds (1)) { if (node.weight (vote_a->account) > rai::Mxrb_ratio * 256) { rai::confirm_ack confirm (vote_a); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); confirm.serialize (stream); @@ -257,9 +252,9 @@ void rai::network::republish_vote (std::chrono::system_clock::time_point const & } } -void rai::network::broadcast_confirm_req (std::shared_ptr block_a) +void rai::network::broadcast_confirm_req (std::shared_ptr block_a) { - auto list (node.peers.representatives (std::numeric_limits ::max ())); + auto list (node.peers.representatives (std::numeric_limits::max ())); for (auto i (list.begin ()), j (list.end ()); i != j; ++i) { node.network.send_confirm_req (i->endpoint, block_a); @@ -270,10 +265,10 @@ void rai::network::broadcast_confirm_req (std::shared_ptr block_a) } } -void rai::network::send_confirm_req (rai::endpoint const & endpoint_a, std::shared_ptr block) +void rai::network::send_confirm_req (rai::endpoint const & endpoint_a, std::shared_ptr block) { rai::confirm_req message (block); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); message.serialize (stream); @@ -282,10 +277,9 @@ void rai::network::send_confirm_req (rai::endpoint const & endpoint_a, std::shar { BOOST_LOG (node.log) << boost::str (boost::format ("Sending confirm req to %1%") % endpoint_a); } - std::weak_ptr node_w (node.shared ()); + std::weak_ptr node_w (node.shared ()); ++outgoing.confirm_req; - send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w] (boost::system::error_code const & ec, size_t size) - { + send_buffer (bytes->data (), bytes->size (), endpoint_a, [bytes, node_w](boost::system::error_code const & ec, size_t size) { if (auto node_l = node_w.lock ()) { if (node_l->config.logging.network_logging ()) @@ -303,7 +297,7 @@ template void rep_query (rai::node & node_a, T const & peers_a) { rai::transaction transaction (node_a.store.environment, nullptr, false); - std::shared_ptr block (node_a.store.block_random (transaction)); + std::shared_ptr block (node_a.store.block_random (transaction)); auto hash (block->hash ()); node_a.rep_crawler.add (hash); for (auto i (peers_a.begin ()), n (peers_a.end ()); i != n; ++i) @@ -311,9 +305,8 @@ void rep_query (rai::node & node_a, T const & peers_a) node_a.peers.rep_request (*i); node_a.network.send_confirm_req (*i, block); } - std::weak_ptr node_w (node_a.shared ()); - node_a.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [node_w, hash] () - { + std::weak_ptr node_w (node_a.shared ()); + node_a.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [node_w, hash]() { if (auto node_l = node_w.lock ()) { node_l->rep_crawler.remove (hash); @@ -324,8 +317,8 @@ void rep_query (rai::node & node_a, T const & peers_a) template <> void rep_query (rai::node & node_a, rai::endpoint const & peers_a) { - std::array peers; - peers [0] = peers_a; + std::array peers; + peers[0] = peers_a; rep_query (node_a, peers); } @@ -396,7 +389,7 @@ public: if (vote.vote->sequence - message_a.vote->sequence > 10000) { rai::confirm_ack confirm (vote.vote); - std::shared_ptr > bytes (new std::vector ); + std::shared_ptr> bytes (new std::vector); { rai::vectorstream stream (*bytes); confirm.serialize (stream); @@ -465,13 +458,13 @@ void rai::network::receive_action (boost::system::error_code const & error, size } if (on) { - node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () { receive (); }); + node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { receive (); }); } } } // Send keepalives to all the peers we've been notified of -void rai::network::merge_peers (std::array const & peers_a) +void rai::network::merge_peers (std::array const & peers_a) { for (auto i (peers_a.begin ()), j (peers_a.end ()); i != j; ++i) { @@ -482,14 +475,14 @@ void rai::network::merge_peers (std::array const & peers_a) } } -bool rai::operation::operator > (rai::operation const & other_a) const +bool rai::operation::operator> (rai::operation const & other_a) const { return wakeup > other_a.wakeup; } rai::alarm::alarm (boost::asio::io_service & service_a) : service (service_a), -thread ([this] () { run (); }) +thread ([this]() { run (); }) { } @@ -501,7 +494,7 @@ rai::alarm::~alarm () void rai::alarm::run () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); auto done (false); while (!done) { @@ -533,10 +526,10 @@ void rai::alarm::run () } } -void rai::alarm::add (std::chrono::system_clock::time_point const & wakeup_a, std::function const & operation) +void rai::alarm::add (std::chrono::system_clock::time_point const & wakeup_a, std::function const & operation) { - std::lock_guard lock (mutex); - operations.push (rai::operation ({wakeup_a, operation})); + std::lock_guard lock (mutex); + operations.push (rai::operation ({ wakeup_a, operation })); condition.notify_all (); } @@ -598,15 +591,15 @@ bool rai::logging::upgrade_json (unsigned version_a, boost::property_tree::ptree auto result (false); switch (version_a) { - case 1: - tree_a.put ("vote", vote_logging_value); - tree_a.put ("version", "2"); - result = true; - case 2: - break; - default: - throw std::runtime_error ("Unknown logging_config version"); - break; + case 1: + tree_a.put ("vote", vote_logging_value); + tree_a.put ("version", "2"); + result = true; + case 2: + break; + default: + throw std::runtime_error ("Unknown logging_config version"); + break; } return result; } @@ -616,7 +609,7 @@ bool rai::logging::deserialize_json (bool & upgraded_a, boost::property_tree::pt auto result (false); try { - auto version_l (tree_a.get_optional ("version")); + auto version_l (tree_a.get_optional ("version")); if (!version_l) { tree_a.put ("version", "1"); @@ -629,21 +622,21 @@ bool rai::logging::deserialize_json (bool & upgraded_a, boost::property_tree::pt upgraded_a = true; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); - ledger_logging_value = tree_a.get ("ledger"); - ledger_duplicate_logging_value = tree_a.get ("ledger_duplicate"); - vote_logging_value = tree_a.get ("vote"); - network_logging_value = tree_a.get ("network"); - network_message_logging_value = tree_a.get ("network_message"); - network_publish_logging_value = tree_a.get ("network_publish"); - network_packet_logging_value = tree_a.get ("network_packet"); - network_keepalive_logging_value = tree_a.get ("network_keepalive"); - node_lifetime_tracing_value = tree_a.get ("node_lifetime_tracing"); - insufficient_work_logging_value = tree_a.get ("insufficient_work"); - log_rpc_value = tree_a.get ("log_rpc"); - bulk_pull_logging_value = tree_a.get ("bulk_pull"); - work_generation_time_value = tree_a.get ("work_generation_time"); - log_to_cerr_value = tree_a.get ("log_to_cerr"); - max_size = tree_a.get ("max_size"); + ledger_logging_value = tree_a.get ("ledger"); + ledger_duplicate_logging_value = tree_a.get ("ledger_duplicate"); + vote_logging_value = tree_a.get ("vote"); + network_logging_value = tree_a.get ("network"); + network_message_logging_value = tree_a.get ("network_message"); + network_publish_logging_value = tree_a.get ("network_publish"); + network_packet_logging_value = tree_a.get ("network_packet"); + network_keepalive_logging_value = tree_a.get ("network_keepalive"); + node_lifetime_tracing_value = tree_a.get ("node_lifetime_tracing"); + insufficient_work_logging_value = tree_a.get ("insufficient_work"); + log_rpc_value = tree_a.get ("log_rpc"); + bulk_pull_logging_value = tree_a.get ("bulk_pull"); + work_generation_time_value = tree_a.get ("work_generation_time"); + log_to_cerr_value = tree_a.get ("log_to_cerr"); + max_size = tree_a.get ("max_size"); } catch (std::runtime_error const &) { @@ -750,8 +743,8 @@ bootstrap_fraction_numerator (1), receive_minimum (rai::xrb_ratio), inactive_supply (0), password_fanout (1024), -io_threads (std::max (4, std::thread::hardware_concurrency ())), -work_threads (std::max (4, std::thread::hardware_concurrency ())), +io_threads (std::max (4, std::thread::hardware_concurrency ())), +work_threads (std::max (4, std::thread::hardware_concurrency ())), enable_voting (true), bootstrap_connections (4), callback_port (0) @@ -834,70 +827,70 @@ bool rai::node_config::upgrade_json (unsigned version, boost::property_tree::ptr auto result (false); switch (version) { - case 1: - { - auto reps_l (tree_a.get_child ("preconfigured_representatives")); - boost::property_tree::ptree reps; - for (auto i (reps_l.begin ()), n (reps_l.end ()); i != n; ++i) + case 1: { - rai::uint256_union account; - account.decode_account (i->second.get ("")); - boost::property_tree::ptree entry; - entry.put ("", account.to_account ()); - reps.push_back (std::make_pair ("", entry)); + auto reps_l (tree_a.get_child ("preconfigured_representatives")); + boost::property_tree::ptree reps; + for (auto i (reps_l.begin ()), n (reps_l.end ()); i != n; ++i) + { + rai::uint256_union account; + account.decode_account (i->second.get ("")); + boost::property_tree::ptree entry; + entry.put ("", account.to_account ()); + reps.push_back (std::make_pair ("", entry)); + } + tree_a.erase ("preconfigured_representatives"); + tree_a.add_child ("preconfigured_representatives", reps); + tree_a.erase ("version"); + tree_a.put ("version", "2"); + result = true; } - tree_a.erase ("preconfigured_representatives"); - tree_a.add_child ("preconfigured_representatives", reps); - tree_a.erase ("version"); - tree_a.put ("version", "2"); - result = true; - } - case 2: - { - tree_a.put ("inactive_supply", rai::uint128_union (0).to_string_dec ()); - tree_a.put ("password_fanout", std::to_string (1024)); - tree_a.put ("io_threads", std::to_string (io_threads)); - tree_a.put ("work_threads", std::to_string (work_threads)); - tree_a.erase ("version"); - tree_a.put ("version", "3"); - result = true; - } - case 3: - tree_a.erase ("receive_minimum"); - tree_a.put ("receive_minimum", rai::xrb_ratio.convert_to ()); - tree_a.erase ("version"); - tree_a.put ("version", "4"); - result = true; - break; - case 4: - tree_a.erase ("receive_minimum"); - tree_a.put ("receive_minimum", rai::xrb_ratio.convert_to ()); - tree_a.erase ("version"); - tree_a.put ("version", "5"); - result = true; - break; - case 5: - tree_a.put ("enable_voting", enable_voting); - tree_a.erase ("packet_delay_microseconds"); - tree_a.erase ("rebroadcast_delay"); - tree_a.erase ("creation_rebroadcast"); - tree_a.erase ("version"); - tree_a.put ("version", "6"); - result = true; - break; - case 6: - tree_a.put ("bootstrap_connections", 16); - tree_a.put ("callback_address", ""); - tree_a.put ("callback_port", "0"); - tree_a.put ("callback_target", ""); - tree_a.erase ("version"); - tree_a.put ("version", "7"); - result = true; - break; - case 7: - break; - default: - throw std::runtime_error ("Unknown node_config version"); + case 2: + { + tree_a.put ("inactive_supply", rai::uint128_union (0).to_string_dec ()); + tree_a.put ("password_fanout", std::to_string (1024)); + tree_a.put ("io_threads", std::to_string (io_threads)); + tree_a.put ("work_threads", std::to_string (work_threads)); + tree_a.erase ("version"); + tree_a.put ("version", "3"); + result = true; + } + case 3: + tree_a.erase ("receive_minimum"); + tree_a.put ("receive_minimum", rai::xrb_ratio.convert_to ()); + tree_a.erase ("version"); + tree_a.put ("version", "4"); + result = true; + break; + case 4: + tree_a.erase ("receive_minimum"); + tree_a.put ("receive_minimum", rai::xrb_ratio.convert_to ()); + tree_a.erase ("version"); + tree_a.put ("version", "5"); + result = true; + break; + case 5: + tree_a.put ("enable_voting", enable_voting); + tree_a.erase ("packet_delay_microseconds"); + tree_a.erase ("rebroadcast_delay"); + tree_a.erase ("creation_rebroadcast"); + tree_a.erase ("version"); + tree_a.put ("version", "6"); + result = true; + break; + case 6: + tree_a.put ("bootstrap_connections", 16); + tree_a.put ("callback_address", ""); + tree_a.put ("callback_port", "0"); + tree_a.put ("callback_target", ""); + tree_a.erase ("version"); + tree_a.put ("version", "7"); + result = true; + break; + case 7: + break; + default: + throw std::runtime_error ("Unknown node_config version"); } return result; } @@ -907,7 +900,7 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree auto result (false); try { - auto version_l (tree_a.get_optional ("version")); + auto version_l (tree_a.get_optional ("version")); if (!version_l) { tree_a.put ("version", "1"); @@ -920,15 +913,15 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree upgraded_a = true; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); - auto peering_port_l (tree_a.get ("peering_port")); - auto bootstrap_fraction_numerator_l (tree_a.get ("bootstrap_fraction_numerator")); - auto receive_minimum_l (tree_a.get ("receive_minimum")); + auto peering_port_l (tree_a.get ("peering_port")); + auto bootstrap_fraction_numerator_l (tree_a.get ("bootstrap_fraction_numerator")); + auto receive_minimum_l (tree_a.get ("receive_minimum")); auto & logging_l (tree_a.get_child ("logging")); work_peers.clear (); auto work_peers_l (tree_a.get_child ("work_peers")); for (auto i (work_peers_l.begin ()), n (work_peers_l.end ()); i != n; ++i) { - auto work_peer (i->second.get ("")); + auto work_peer (i->second.get ("")); boost::asio::ip::address address; uint16_t port; result |= rai::parse_address_port (work_peer, address, port); @@ -941,7 +934,7 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree preconfigured_peers.clear (); for (auto i (preconfigured_peers_l.begin ()), n (preconfigured_peers_l.end ()); i != n; ++i) { - auto bootstrap_peer (i->second.get ("")); + auto bootstrap_peer (i->second.get ("")); preconfigured_peers.push_back (bootstrap_peer); } auto preconfigured_representatives_l (tree_a.get_child ("preconfigured_representatives")); @@ -949,22 +942,22 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree for (auto i (preconfigured_representatives_l.begin ()), n (preconfigured_representatives_l.end ()); i != n; ++i) { rai::account representative (0); - result = result || representative.decode_account (i->second.get ("")); + result = result || representative.decode_account (i->second.get ("")); preconfigured_representatives.push_back (representative); } if (preconfigured_representatives.empty ()) { result = true; } - auto inactive_supply_l (tree_a.get ("inactive_supply")); - auto password_fanout_l (tree_a.get ("password_fanout")); - auto io_threads_l (tree_a.get ("io_threads")); - auto work_threads_l (tree_a.get ("work_threads")); - enable_voting = tree_a.get ("enable_voting"); - auto bootstrap_connections_l (tree_a.get ("bootstrap_connections")); - callback_address = tree_a.get ("callback_address"); - auto callback_port_l (tree_a.get ("callback_port")); - callback_target = tree_a.get ("callback_target"); + auto inactive_supply_l (tree_a.get ("inactive_supply")); + auto password_fanout_l (tree_a.get ("password_fanout")); + auto io_threads_l (tree_a.get ("io_threads")); + auto work_threads_l (tree_a.get ("work_threads")); + enable_voting = tree_a.get ("enable_voting"); + auto bootstrap_connections_l (tree_a.get ("bootstrap_connections")); + callback_address = tree_a.get ("callback_address"); + auto callback_port_l (tree_a.get ("callback_port")); + callback_target = tree_a.get ("callback_target"); result |= parse_port (callback_port_l, callback_port); try { @@ -974,7 +967,7 @@ bool rai::node_config::deserialize_json (bool & upgraded_a, boost::property_tree io_threads = std::stoul (io_threads_l); work_threads = std::stoul (work_threads_l); bootstrap_connections = std::stoul (bootstrap_connections_l); - result |= peering_port > std::numeric_limits ::max (); + result |= peering_port > std::numeric_limits::max (); result |= logging.deserialize_json (upgraded_a, logging_l); result |= receive_minimum.decode_dec (receive_minimum_l); result |= inactive_supply.decode_dec (inactive_supply_l); @@ -999,7 +992,7 @@ rai::account rai::node_config::random_representative () { assert (preconfigured_representatives.size () > 0); size_t index (rai::random_pool.GenerateWord32 (0, preconfigured_representatives.size () - 1)); - auto result (preconfigured_representatives [index]); + auto result (preconfigured_representatives[index]); return result; } @@ -1008,7 +1001,7 @@ node (node_a) { } -rai::vote_result rai::vote_processor::vote (std::shared_ptr vote_a, rai::endpoint endpoint_a) +rai::vote_result rai::vote_processor::vote (std::shared_ptr vote_a, rai::endpoint endpoint_a) { rai::vote_result result; { @@ -1045,38 +1038,38 @@ rai::vote_result rai::vote_processor::vote (std::shared_ptr vote_a, void rai::rep_crawler::add (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); active.insert (hash_a); } void rai::rep_crawler::remove (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); active.erase (hash_a); } bool rai::rep_crawler::exists (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); return active.count (hash_a) != 0; } -rai::block_processor_item::block_processor_item (std::shared_ptr block_a) : +rai::block_processor_item::block_processor_item (std::shared_ptr block_a) : block_processor_item (block_a, nullptr, false) { } -rai::block_processor_item::block_processor_item (std::shared_ptr block_a, bool force_a) : +rai::block_processor_item::block_processor_item (std::shared_ptr block_a, bool force_a) : block_processor_item (block_a, nullptr, force_a) { } -rai::block_processor_item::block_processor_item (std::shared_ptr block_a, std::function )> callback_a) : +rai::block_processor_item::block_processor_item (std::shared_ptr block_a, std::function)> callback_a) : block_processor_item (block_a, callback_a, false) { } -rai::block_processor_item::block_processor_item (std::shared_ptr block_a, std::function )> callback_a, bool force_a) : +rai::block_processor_item::block_processor_item (std::shared_ptr block_a, std::function)> callback_a, bool force_a) : block (block_a), callback (callback_a), force (force_a) @@ -1097,14 +1090,14 @@ rai::block_processor::~block_processor () void rai::block_processor::stop () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); stopped = true; condition.notify_all (); } void rai::block_processor::flush () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); while (!stopped && (!blocks.empty () || !idle)) { condition.wait (lock); @@ -1113,19 +1106,19 @@ void rai::block_processor::flush () void rai::block_processor::add (rai::block_processor_item const & item_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); blocks.push_back (item_a); condition.notify_all (); } void rai::block_processor::process_blocks () { - std::unique_lock lock (mutex); + std::unique_lock lock (mutex); while (!stopped) { if (!blocks.empty ()) { - std::deque blocks_processing; + std::deque blocks_processing; std::swap (blocks, blocks_processing); lock.unlock (); process_receive_many (blocks_processing); @@ -1145,16 +1138,16 @@ void rai::block_processor::process_blocks () void rai::block_processor::process_receive_many (rai::block_processor_item const & item_a) { - std::deque blocks_processing; + std::deque blocks_processing; blocks_processing.push_back (item_a); process_receive_many (blocks_processing); } -void rai::block_processor::process_receive_many (std::deque & blocks_processing) +void rai::block_processor::process_receive_many (std::deque & blocks_processing) { while (!blocks_processing.empty ()) { - std::deque , rai::process_return>> progress; + std::deque, rai::process_return>> progress; { rai::transaction transaction (node.store.environment, nullptr, true); auto cutoff (std::chrono::system_clock::now () + rai::transaction_timeout); @@ -1192,8 +1185,8 @@ void rai::block_processor::process_receive_many (std::deque lock (node.gap_cache.mutex); - node.gap_cache.blocks.get <1> ().erase (hash); + std::lock_guard lock (node.gap_cache.mutex); + node.gap_cache.blocks.get<1> ().erase (hash); break; } default: @@ -1208,7 +1201,7 @@ void rai::block_processor::process_receive_many (std::deque block_a) +rai::process_return rai::block_processor::process_receive_one (MDB_txn * transaction_a, std::shared_ptr block_a) { rai::process_return result; result = node.ledger.process (transaction_a, *block_a); @@ -1348,35 +1341,29 @@ port_mapping (*this), vote_processor (*this), warmed_up (0), block_processor (*this), -block_processor_thread ([this] () { this->block_processor.process_blocks (); }) +block_processor_thread ([this]() { this->block_processor.process_blocks (); }) { - wallets.observer = [this] (rai::account const & account_a, bool active) - { + wallets.observer = [this](rai::account const & account_a, bool active) { observers.wallet (account_a, active); }; - peers.peer_observer = [this] (rai::endpoint const & endpoint_a) - { + peers.peer_observer = [this](rai::endpoint const & endpoint_a) { observers.endpoint (endpoint_a); }; - peers.disconnect_observer = [this] () - { + peers.disconnect_observer = [this]() { observers.disconnect (); }; - observers.blocks.add ([this] (std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a) - { + observers.blocks.add ([this](std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a) { if (this->block_arrival.recent (block_a->hash ())) { rai::transaction transaction (store.environment, nullptr, true); active.start (transaction, block_a); } }); - observers.blocks.add ([this] (std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a) - { + observers.blocks.add ([this](std::shared_ptr block_a, rai::account const & account_a, rai::amount const & amount_a) { if (this->block_arrival.recent (block_a->hash ())) { auto node_l (shared_from_this ()); - background ([node_l, block_a, account_a, amount_a] () - { + background ([node_l, block_a, account_a, amount_a]() { if (!node_l->config.callback_address.empty ()) { boost::property_tree::ptree event; @@ -1389,50 +1376,46 @@ block_processor_thread ([this] () { this->block_processor.process_blocks (); }) std::stringstream ostream; boost::property_tree::write_json (ostream, event); ostream.flush (); - auto body (std::make_shared (ostream.str ())); + auto body (std::make_shared (ostream.str ())); auto address (node_l->config.callback_address); auto port (node_l->config.callback_port); - auto target (std::make_shared (node_l->config.callback_target)); - auto resolver (std::make_shared (node_l->service)); - resolver->async_resolve (boost::asio::ip::tcp::resolver::query (address, std::to_string (port)), [node_l, address, port, target, body, resolver] (boost::system::error_code const & ec, boost::asio::ip::tcp::resolver::iterator i_a) - { + auto target (std::make_shared (node_l->config.callback_target)); + auto resolver (std::make_shared (node_l->service)); + resolver->async_resolve (boost::asio::ip::tcp::resolver::query (address, std::to_string (port)), [node_l, address, port, target, body, resolver](boost::system::error_code const & ec, boost::asio::ip::tcp::resolver::iterator i_a) { if (!ec) { - for (auto i (i_a), n (boost::asio::ip::tcp::resolver::iterator {}); i != n; ++i) + for (auto i (i_a), n (boost::asio::ip::tcp::resolver::iterator{}); i != n; ++i) { - auto sock (std::make_shared (node_l->service)); - sock->async_connect (i->endpoint(), [node_l, target, body, sock, address, port] (boost::system::error_code const & ec) - { + auto sock (std::make_shared (node_l->service)); + sock->async_connect (i->endpoint (), [node_l, target, body, sock, address, port](boost::system::error_code const & ec) { if (!ec) { - auto req (std::make_shared > ()); + auto req (std::make_shared> ()); req->method (boost::beast::http::verb::post); req->target (*target); req->version (11); - req->insert(boost::beast::http::field::host, address); - req->insert(boost::beast::http::field::content_type, "application/json"); - req->body() = *body; + req->insert (boost::beast::http::field::host, address); + req->insert (boost::beast::http::field::content_type, "application/json"); + req->body () = *body; //req->prepare (*req); //boost::beast::http::prepare(req); - req->prepare_payload(); - boost::beast::http::async_write (*sock, *req, [node_l, sock, address, port, req] (boost::system::error_code const & ec, size_t bytes_transferred) - { + req->prepare_payload (); + boost::beast::http::async_write (*sock, *req, [node_l, sock, address, port, req](boost::system::error_code const & ec, size_t bytes_transferred) { if (!ec) { - auto sb (std::make_shared ()); - auto resp (std::make_shared > ()); - boost::beast::http::async_read (*sock, *sb, *resp, [node_l, sb, resp, sock, address, port] (boost::system::error_code const & ec, size_t bytes_transferred) - { + auto sb (std::make_shared ()); + auto resp (std::make_shared> ()); + boost::beast::http::async_read (*sock, *sb, *resp, [node_l, sb, resp, sock, address, port](boost::system::error_code const & ec, size_t bytes_transferred) { if (!ec) { - if (resp->result() == boost::beast::http::status::ok) + if (resp->result () == boost::beast::http::status::ok) { } else { if (node_l->config.logging.callback_logging ()) { - BOOST_LOG (node_l->log) << boost::str (boost::format ("Callback to %1%:%2% failed with status: %3%") % address % port % resp->result()); + BOOST_LOG (node_l->log) << boost::str (boost::format ("Callback to %1%:%2% failed with status: %3%") % address % port % resp->result ()); } } } @@ -1476,21 +1459,17 @@ block_processor_thread ([this] () { this->block_processor.process_blocks (); }) }); } }); - observers.endpoint.add ([this] (rai::endpoint const & endpoint_a) - { + observers.endpoint.add ([this](rai::endpoint const & endpoint_a) { this->network.send_keepalive (endpoint_a); rep_query (*this, endpoint_a); }); - observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) - { + observers.vote.add ([this](std::shared_ptr vote_a, rai::endpoint const &) { active.vote (vote_a); }); - observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const &) - { + observers.vote.add ([this](std::shared_ptr vote_a, rai::endpoint const &) { this->gap_cache.vote (vote_a); }); - observers.vote.add ([this] (std::shared_ptr vote_a, rai::endpoint const & endpoint_a) - { + observers.vote.add ([this](std::shared_ptr vote_a, rai::endpoint const & endpoint_a) { if (this->rep_crawler.exists (vote_a->block->hash ())) { auto weight_l (weight (vote_a->account)); @@ -1525,7 +1504,7 @@ rai::node::~node () { BOOST_LOG (log) << "Destructing node"; } - stop(); + stop (); } void rai::node::send_keepalive (rai::endpoint const & endpoint_a) @@ -1544,35 +1523,34 @@ node (node_a) { } -void rai::gap_cache::add (MDB_txn * transaction_a, std::shared_ptr block_a) +void rai::gap_cache::add (MDB_txn * transaction_a, std::shared_ptr block_a) { auto hash (block_a->hash ()); - std::lock_guard lock (mutex); - auto existing (blocks.get <1>().find (hash)); - if (existing != blocks.get <1> ().end ()) + std::lock_guard lock (mutex); + auto existing (blocks.get<1> ().find (hash)); + if (existing != blocks.get<1> ().end ()) { - blocks.get <1> ().modify (existing, [] (rai::gap_information & info) - { + blocks.get<1> ().modify (existing, [](rai::gap_information & info) { info.arrival = std::chrono::system_clock::now (); }); } else { - blocks.insert ({std::chrono::system_clock::now (), hash, std::unique_ptr (new rai::votes (block_a))}); + blocks.insert ({ std::chrono::system_clock::now (), hash, std::unique_ptr (new rai::votes (block_a)) }); if (blocks.size () > max) { - blocks.get <0> ().erase (blocks.get <0> ().begin ()); + blocks.get<0> ().erase (blocks.get<0> ().begin ()); } } } -void rai::gap_cache::vote (std::shared_ptr vote_a) +void rai::gap_cache::vote (std::shared_ptr vote_a) { rai::transaction transaction (node.store.environment, nullptr, false); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto hash (vote_a->block->hash ()); - auto existing (blocks.get <1> ().find (hash)); - if (existing != blocks.get <1> ().end ()) + auto existing (blocks.get<1> ().find (hash)); + if (existing != blocks.get<1> ().end ()) { existing->votes->vote (vote_a); auto winner (node.ledger.winner (transaction, *existing->votes)); @@ -1580,8 +1558,7 @@ void rai::gap_cache::vote (std::shared_ptr vote_a) { auto node_l (node.shared ()); auto now (std::chrono::system_clock::now ()); - node.alarm.add (rai::rai_network == rai::rai_networks::rai_test_network ? now + std::chrono::milliseconds (5) : now + std::chrono::seconds (5), [node_l, hash] () - { + node.alarm.add (rai::rai_network == rai::rai_networks::rai_test_network ? now + std::chrono::milliseconds (5) : now + std::chrono::seconds (5), [node_l, hash]() { rai::transaction transaction (node_l->store.environment, nullptr, false); if (!node_l->store.block_exists (transaction, hash)) { @@ -1605,14 +1582,14 @@ rai::uint128_t rai::gap_cache::bootstrap_threshold (MDB_txn * transaction_a) void rai::gap_cache::purge_old () { auto cutoff (std::chrono::system_clock::now () - std::chrono::seconds (10)); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto done (false); while (!done && !blocks.empty ()) { - auto first (blocks.get <1> ().begin ()); + auto first (blocks.get<1> ().begin ()); if (first->arrival < cutoff) { - blocks.get <1> ().erase (first); + blocks.get<1> ().erase (first); } else { @@ -1621,16 +1598,15 @@ void rai::gap_cache::purge_old () } } -void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared_ptr > bytes_a, rai::endpoint const & endpoint_a) +void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared_ptr> bytes_a, rai::endpoint const & endpoint_a) { if (node.config.logging.network_publish_logging ()) { BOOST_LOG (node.log) << boost::str (boost::format ("Sending confirm_ack for block %1% to %2% sequence %3%") % confirm_a.vote->block->hash ().to_string () % endpoint_a % std::to_string (confirm_a.vote->sequence)); } - std::weak_ptr node_w (node.shared ()); + std::weak_ptr node_w (node.shared ()); ++outgoing.confirm_ack; - node.network.send_buffer (bytes_a->data (), bytes_a->size (), endpoint_a, [bytes_a, node_w, endpoint_a] (boost::system::error_code const & ec, size_t size_a) - { + node.network.send_buffer (bytes_a->data (), bytes_a->size (), endpoint_a, [bytes_a, node_w, endpoint_a](boost::system::error_code const & ec, size_t size_a) { if (auto node_l = node_w.lock ()) { if (node_l->config.logging.network_logging ()) @@ -1644,7 +1620,7 @@ void rai::network::confirm_send (rai::confirm_ack const & confirm_a, std::shared }); } -void rai::node::process_active (std::shared_ptr incoming) +void rai::node::process_active (std::shared_ptr incoming) { block_arrival.add (incoming->hash ()); block_processor.add (incoming); @@ -1658,10 +1634,10 @@ rai::process_return rai::node::process (rai::block const & block_a) } // Simulating with sqrt_broadcast_simulate shows we only need to broadcast to sqrt(total_peers) random peers in order to successfully publish to everyone with high probability -std::vector rai::peer_container::list_sqrt () +std::vector rai::peer_container::list_sqrt () { auto peers (random_set (2 * size_sqrt ())); - std::vector result; + std::vector result; result.reserve (peers.size ()); for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i) { @@ -1670,10 +1646,10 @@ std::vector rai::peer_container::list_sqrt () return result; } -std::vector rai::peer_container::list () +std::vector rai::peer_container::list () { - std::vector result; - std::lock_guard lock (mutex); + std::vector result; + std::lock_guard lock (mutex); result.reserve (peers.size ()); for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) { @@ -1683,13 +1659,13 @@ std::vector rai::peer_container::list () return result; } -std::map rai::peer_container::list_version () +std::map rai::peer_container::list_version () { - std::map result; - std::lock_guard lock (mutex); + std::map result; + std::lock_guard lock (mutex); for (auto i (peers.begin ()), j (peers.end ()); i != j; ++i) { - result.insert (std::pair (i->endpoint, i->network_version)); + result.insert (std::pair (i->endpoint, i->network_version)); } return result; } @@ -1697,15 +1673,14 @@ std::map rai::peer_container::list_version () rai::endpoint rai::peer_container::bootstrap_peer () { rai::endpoint result (boost::asio::ip::address_v6::any (), 0); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); ; - for (auto i (peers.get <4> ().begin ()), n (peers.get <4> ().end ()); i != n;) + for (auto i (peers.get<4> ().begin ()), n (peers.get<4> ().end ()); i != n;) { if (i->network_version >= 0x5) { result = i->endpoint; - peers.get <4> ().modify (i, [] (rai::peer_information & peer_a) - { + peers.get<4> ().modify (i, [](rai::peer_information & peer_a) { peer_a.last_bootstrap_attempt = std::chrono::system_clock::now (); }); i = n; @@ -1723,7 +1698,7 @@ bool rai::parse_port (std::string const & string_a, uint16_t & port_a) bool result; size_t converted; port_a = std::stoul (string_a, &converted); - result = converted != string_a.size () || converted > std::numeric_limits ::max (); + result = converted != string_a.size () || converted > std::numeric_limits::max (); return result; } @@ -1827,7 +1802,7 @@ void rai::node::stop () } } -void rai::node::keepalive_preconfigured (std::vector const & peers_a) +void rai::node::keepalive_preconfigured (std::vector const & peers_a) { for (auto i (peers_a.begin ()), n (peers_a.end ()); i != n; ++i) { @@ -1847,15 +1822,15 @@ rai::uint128_t rai::node::balance (rai::account const & account_a) return ledger.account_balance (transaction, account_a); } -std::unique_ptr rai::node::block (rai::block_hash const & hash_a) +std::unique_ptr rai::node::block (rai::block_hash const & hash_a) { rai::transaction transaction (store.environment, nullptr, false); return store.block_get (transaction, hash_a); } -std::pair rai::node::balance_pending (rai::account const & account_a) +std::pair rai::node::balance_pending (rai::account const & account_a) { - std::pair result; + std::pair result; rai::transaction transaction (store.environment, nullptr, false); result.first = ledger.account_balance (transaction, account_a); result.second = ledger.account_pending (transaction, account_a); @@ -1888,9 +1863,8 @@ void rai::node::ongoing_keepalive () { network.send_keepalive (i->endpoint); } - std::weak_ptr node_w (shared_from_this ()); - alarm.add (std::chrono::system_clock::now () + period, [node_w] () - { + std::weak_ptr node_w (shared_from_this ()); + alarm.add (std::chrono::system_clock::now () + period, [node_w]() { if (auto node_l = node_w.lock ()) { node_l->ongoing_keepalive (); @@ -1905,9 +1879,8 @@ void rai::node::ongoing_rep_crawl () rep_query (*this, peers_l); if (network.on) { - std::weak_ptr node_w (shared_from_this ()); - alarm.add (now + period, [node_w] () - { + std::weak_ptr node_w (shared_from_this ()); + alarm.add (now + period, [node_w]() { if (auto node_l = node_w.lock ()) { node_l->ongoing_rep_crawl (); @@ -1929,9 +1902,8 @@ void rai::node::ongoing_bootstrap () } } bootstrap_initiator.bootstrap (); - std::weak_ptr node_w (shared_from_this ()); - alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (next_wakeup), [node_w] () - { + std::weak_ptr node_w (shared_from_this ()); + alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (next_wakeup), [node_w]() { if (auto node_l = node_w.lock ()) { node_l->ongoing_bootstrap (); @@ -1945,9 +1917,8 @@ void rai::node::ongoing_store_flush () rai::transaction transaction (store.environment, nullptr, true); store.flush (transaction); } - std::weak_ptr node_w (shared_from_this ()); - alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [node_w] () - { + std::weak_ptr node_w (shared_from_this ()); + alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [node_w]() { if (auto node_l = node_w.lock ()) { node_l->ongoing_store_flush (); @@ -1965,8 +1936,7 @@ void rai::node::backup_wallet () i->second->store.write_backup (transaction, backup_path / (i->first.to_string () + ".json")); } auto this_l (shared ()); - alarm.add (std::chrono::system_clock::now () + backup_interval, [this_l] () - { + alarm.add (std::chrono::system_clock::now () + backup_interval, [this_l]() { this_l->backup_wallet (); }); } @@ -1979,228 +1949,222 @@ int rai::node::price (rai::uint128_t const & balance_a, int amount_a) for (auto i (0); i < amount_a; ++i) { balance_l -= rai::Gxrb_ratio; - auto balance_scaled ((balance_l / rai::Mxrb_ratio).convert_to ()); + auto balance_scaled ((balance_l / rai::Mxrb_ratio).convert_to ()); auto units (balance_scaled / 1000.0); auto unit_price (((free_cutoff - units) / free_cutoff) * price_max); result += std::min (std::max (0.0, unit_price), price_max); } - return static_cast (result * 100.0); + return static_cast (result * 100.0); } -namespace { +namespace +{ class work_request { public: -work_request (boost::asio::io_service & service_a, boost::asio::ip::address address_a, uint16_t port_a) : -address (address_a), -port (port_a), -socket (service_a) -{ -} -boost::asio::ip::address address; -uint16_t port; -boost::beast::flat_buffer buffer; -boost::beast::http::response response; -boost::asio::ip::tcp::socket socket; + work_request (boost::asio::io_service & service_a, boost::asio::ip::address address_a, uint16_t port_a) : + address (address_a), + port (port_a), + socket (service_a) + { + } + boost::asio::ip::address address; + uint16_t port; + boost::beast::flat_buffer buffer; + boost::beast::http::response response; + boost::asio::ip::tcp::socket socket; }; -class distributed_work : public std::enable_shared_from_this +class distributed_work : public std::enable_shared_from_this { public: -distributed_work (std::shared_ptr const & node_a, rai::block_hash const & root_a, std::function callback_a) : -callback (callback_a), -node (node_a), -root (root_a) -{ - completed.clear (); - for (auto & i : node_a->config.work_peers) + distributed_work (std::shared_ptr const & node_a, rai::block_hash const & root_a, std::function callback_a) : + callback (callback_a), + node (node_a), + root (root_a) { - outstanding [i.first] = i.second; - } -} -void start () -{ - if (!outstanding.empty ()) - { - auto this_l (shared_from_this ()); - std::lock_guard lock (mutex); - for (auto const & i: outstanding) + completed.clear (); + for (auto & i : node_a->config.work_peers) { - auto host (i.first); - auto service (i.second); - node->background ([this_l, host, service] () + outstanding[i.first] = i.second; + } + } + void start () + { + if (!outstanding.empty ()) + { + auto this_l (shared_from_this ()); + std::lock_guard lock (mutex); + for (auto const & i : outstanding) { - auto connection (std::make_shared (this_l->node->service, host, service)); - connection->socket.async_connect (rai::tcp_endpoint (host, service), [this_l, connection] (boost::system::error_code const & ec) - { - if (!ec) - { - std::string request_string; + auto host (i.first); + auto service (i.second); + node->background ([this_l, host, service]() { + auto connection (std::make_shared (this_l->node->service, host, service)); + connection->socket.async_connect (rai::tcp_endpoint (host, service), [this_l, connection](boost::system::error_code const & ec) { + if (!ec) { - boost::property_tree::ptree request; - request.put ("action", "work_generate"); - request.put ("hash", this_l->root.to_string ()); - std::stringstream ostream; - boost::property_tree::write_json (ostream, request); - request_string = ostream.str (); - } - auto request (std::make_shared > ()); - request->method (boost::beast::http::verb::post); - request->target ("/"); - request->version (11); - request->body() = request_string; - request->prepare_payload (); - boost::beast::http::async_write (connection->socket, *request, [this_l, connection, request] (boost::system::error_code const & ec, size_t bytes_transferred) - { - if (!ec) + std::string request_string; { - boost::beast::http::async_read (connection->socket, connection->buffer, connection->response, [this_l, connection] (boost::system::error_code const & ec, size_t bytes_transferred) + boost::property_tree::ptree request; + request.put ("action", "work_generate"); + request.put ("hash", this_l->root.to_string ()); + std::stringstream ostream; + boost::property_tree::write_json (ostream, request); + request_string = ostream.str (); + } + auto request (std::make_shared> ()); + request->method (boost::beast::http::verb::post); + request->target ("/"); + request->version (11); + request->body () = request_string; + request->prepare_payload (); + boost::beast::http::async_write (connection->socket, *request, [this_l, connection, request](boost::system::error_code const & ec, size_t bytes_transferred) { + if (!ec) { - if (!ec) - { - if (connection->response.result() == boost::beast::http::status::ok) + boost::beast::http::async_read (connection->socket, connection->buffer, connection->response, [this_l, connection](boost::system::error_code const & ec, size_t bytes_transferred) { + if (!ec) { - this_l->success (connection->response.body(), connection->address); + if (connection->response.result () == boost::beast::http::status::ok) + { + this_l->success (connection->response.body (), connection->address); + } + else + { + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Work peer %1% responded with an error %2%") % connection->address % connection->port); + this_l->failure (connection->address); + } } else { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Work peer %1% responded with an error %2%") % connection->address % connection->port); + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to read from work_peer %1% %2%") % connection->address % connection->port); this_l->failure (connection->address); } - } - else - { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to read from work_peer %1% %2%") % connection->address % connection->port); - this_l->failure (connection->address); - } - }); - } - else - { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to write to work_peer %1% %2%") % connection->address % connection->port); - this_l->failure (connection->address); - } - }); - } - else - { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to connect to work_peer %1% %2%") % connection->address % connection->port); - this_l->failure (connection->address); - } + }); + } + else + { + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to write to work_peer %1% %2%") % connection->address % connection->port); + this_l->failure (connection->address); + } + }); + } + else + { + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("Unable to connect to work_peer %1% %2%") % connection->address % connection->port); + this_l->failure (connection->address); + } + }); }); - }); - } - } - else - { - handle_failure (true); - } -} -void stop () -{ - auto this_l (shared_from_this ()); - std::lock_guard lock (mutex); - for (auto const & i: outstanding) - { - auto host (i.first); - auto service (i.second); - node->background ([this_l, host, service] () - { - std::string request_string; - { - boost::property_tree::ptree request; - request.put ("action", "work_cancel"); - request.put ("hash", this_l->root.to_string ()); - std::stringstream ostream; - boost::property_tree::write_json (ostream, request); - request_string = ostream.str (); - } - boost::beast::http::request request; - request.method (boost::beast::http::verb::post); - request.target ("/"); - request.version (11); - request.body() = request_string; - request.prepare_payload(); - auto socket (std::make_shared (this_l->node->service)); - boost::beast::http::async_write (*socket, request, [socket] (boost::system::error_code const & ec, size_t bytes_transferred) - { - }); - }); - } - outstanding.clear (); -} -void success (std::string const & body_a, boost::asio::ip::address const & address) -{ - auto last (remove (address)); - std::stringstream istream (body_a); - try - { - boost::property_tree::ptree result; - boost::property_tree::read_json (istream, result); - auto work_text (result.get ("work")); - uint64_t work; - if (!rai::from_string_hex (work_text, work)) - { - if (!rai::work_validate (root, work)) - { - set_once (work); - stop (); - } - else - { - BOOST_LOG (node->log) << boost::str (boost::format ("Incorrect work response from %1% for root %2% value %3%") % address % root.to_string () % work_text); - handle_failure (last); } } else { - BOOST_LOG (node->log) << boost::str (boost::format ("Work response from %1% wasn't a number %2%") % address % work_text); + handle_failure (true); + } + } + void stop () + { + auto this_l (shared_from_this ()); + std::lock_guard lock (mutex); + for (auto const & i : outstanding) + { + auto host (i.first); + auto service (i.second); + node->background ([this_l, host, service]() { + std::string request_string; + { + boost::property_tree::ptree request; + request.put ("action", "work_cancel"); + request.put ("hash", this_l->root.to_string ()); + std::stringstream ostream; + boost::property_tree::write_json (ostream, request); + request_string = ostream.str (); + } + boost::beast::http::request request; + request.method (boost::beast::http::verb::post); + request.target ("/"); + request.version (11); + request.body () = request_string; + request.prepare_payload (); + auto socket (std::make_shared (this_l->node->service)); + boost::beast::http::async_write (*socket, request, [socket](boost::system::error_code const & ec, size_t bytes_transferred) { + }); + }); + } + outstanding.clear (); + } + void success (std::string const & body_a, boost::asio::ip::address const & address) + { + auto last (remove (address)); + std::stringstream istream (body_a); + try + { + boost::property_tree::ptree result; + boost::property_tree::read_json (istream, result); + auto work_text (result.get ("work")); + uint64_t work; + if (!rai::from_string_hex (work_text, work)) + { + if (!rai::work_validate (root, work)) + { + set_once (work); + stop (); + } + else + { + BOOST_LOG (node->log) << boost::str (boost::format ("Incorrect work response from %1% for root %2% value %3%") % address % root.to_string () % work_text); + handle_failure (last); + } + } + else + { + BOOST_LOG (node->log) << boost::str (boost::format ("Work response from %1% wasn't a number %2%") % address % work_text); + handle_failure (last); + } + } + catch (...) + { + BOOST_LOG (node->log) << boost::str (boost::format ("Work response from %1% wasn't parsable %2%") % address % body_a); handle_failure (last); } } - catch (...) - { - BOOST_LOG (node->log) << boost::str (boost::format ("Work response from %1% wasn't parsable %2%") % address % body_a); - handle_failure (last); - } -} -void set_once (uint64_t work_a) -{ - if (!completed.test_and_set ()) - { - callback (work_a); - } -} -void failure (boost::asio::ip::address const & address) -{ - auto last (remove (address)); - handle_failure (last); -} -void handle_failure (bool last) -{ - if (last) + void set_once (uint64_t work_a) { if (!completed.test_and_set ()) { - auto callback_l (callback); - node->work.generate (root, [callback_l] (boost::optional const & work_a) - { - callback_l (work_a.value ()); - }); + callback (work_a); } } -} -bool remove (boost::asio::ip::address const & address) -{ - std::lock_guard lock (mutex); - outstanding.erase (address); - return outstanding.empty (); -} -std::function callback; -std::shared_ptr node; -rai::block_hash root; -std::mutex mutex; -std::map outstanding; -std::atomic_flag completed; + void failure (boost::asio::ip::address const & address) + { + auto last (remove (address)); + handle_failure (last); + } + void handle_failure (bool last) + { + if (last) + { + if (!completed.test_and_set ()) + { + auto callback_l (callback); + node->work.generate (root, [callback_l](boost::optional const & work_a) { + callback_l (work_a.value ()); + }); + } + } + } + bool remove (boost::asio::ip::address const & address) + { + std::lock_guard lock (mutex); + outstanding.erase (address); + return outstanding.empty (); + } + std::function callback; + std::shared_ptr node; + rai::block_hash root; + std::mutex mutex; + std::map outstanding; + std::atomic_flag completed; }; } @@ -2209,17 +2173,16 @@ void rai::node::generate_work (rai::block & block_a) block_a.block_work_set (generate_work (block_a.root ())); } -void rai::node::generate_work (rai::uint256_union const & hash_a, std::function callback_a) +void rai::node::generate_work (rai::uint256_union const & hash_a, std::function callback_a) { - auto work_generation (std::make_shared (shared (), hash_a, callback_a)); + auto work_generation (std::make_shared (shared (), hash_a, callback_a)); work_generation->start (); } uint64_t rai::node::generate_work (rai::uint256_union const & hash_a) { - std::promise promise; - generate_work (hash_a, [&promise] (uint64_t work_a) - { + std::promise promise; + generate_work (hash_a, [&promise](uint64_t work_a) { promise.set_value (work_a); }); return promise.get_future ().get (); @@ -2227,7 +2190,6 @@ uint64_t rai::node::generate_work (rai::uint256_union const & hash_a) void rai::node::add_initial_peers () { - } namespace @@ -2235,7 +2197,7 @@ namespace class confirmed_visitor : public rai::block_visitor { public: - confirmed_visitor (rai::node & node_a, std::shared_ptr block_a) : + confirmed_visitor (rai::node & node_a, std::shared_ptr block_a) : node (node_a), block (block_a) { @@ -2257,7 +2219,7 @@ public: auto node_l (node.shared ()); auto amount (pending.amount.number ()); assert (block.get () == &block_a); - wallet->receive_async (block, representative, amount, [] (std::shared_ptr ) {}); + wallet->receive_async (block, representative, amount, [](std::shared_ptr) {}); } else { @@ -2279,11 +2241,11 @@ public: { } rai::node & node; - std::shared_ptr block; + std::shared_ptr block; }; } -void rai::node::process_confirmed (std::shared_ptr confirmed_a) +void rai::node::process_confirmed (std::shared_ptr confirmed_a) { confirmed_visitor visitor (*this, confirmed_a); confirmed_a->visit (visitor); @@ -2308,27 +2270,27 @@ rai::endpoint rai::network::endpoint () void rai::block_arrival::add (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto now (std::chrono::system_clock::now ()); - arrival.insert (rai::block_arrival_info {now, hash_a}); + arrival.insert (rai::block_arrival_info{ now, hash_a }); } bool rai::block_arrival::recent (rai::block_hash const & hash_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto now (std::chrono::system_clock::now ()); while (!arrival.empty () && arrival.begin ()->arrival + std::chrono::seconds (60) < now) { arrival.erase (arrival.begin ()); } - return arrival.get <1> ().find (hash_a) != arrival.get <1> ().end (); + return arrival.get<1> ().find (hash_a) != arrival.get<1> ().end (); } -std::unordered_set rai::peer_container::random_set (size_t count_a) +std::unordered_set rai::peer_container::random_set (size_t count_a) { - std::unordered_set result; + std::unordered_set result; result.reserve (count_a); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); // Stop trying to fill result with random samples after this many attempts auto random_cutoff (count_a * 2); auto peers_size (peers.size ()); @@ -2339,22 +2301,22 @@ std::unordered_set rai::peer_container::random_set (size_t count for (auto i (0); i < random_cutoff && result.size () < count_a; ++i) { auto index (random_pool.GenerateWord32 (0, peers_size - 1)); - result.insert (peers.get <3> () [index].endpoint); + result.insert (peers.get<3> ()[index].endpoint); } } // Fill the remainder with most recent contact - for (auto i (peers.get <1> ().begin ()), n (peers.get <1> ().end ()); i != n && result.size () < count_a; ++i) + for (auto i (peers.get<1> ().begin ()), n (peers.get<1> ().end ()); i != n && result.size () < count_a; ++i) { result.insert (i->endpoint); } return result; } -void rai::peer_container::random_fill (std::array & target_a) +void rai::peer_container::random_fill (std::array & target_a) { auto peers (random_set (target_a.size ())); assert (peers.size () <= target_a.size ()); - auto endpoint (rai::endpoint (boost::asio::ip::address_v6 {}, 0)); + auto endpoint (rai::endpoint (boost::asio::ip::address_v6{}, 0)); assert (endpoint.address ().is_v6 ()); std::fill (target_a.begin (), target_a.end (), endpoint); auto j (target_a.begin ()); @@ -2367,12 +2329,12 @@ void rai::peer_container::random_fill (std::array & target_a) } // Request a list of the top known representatives -std::vector rai::peer_container::representatives (size_t count_a) +std::vector rai::peer_container::representatives (size_t count_a) { - std::vector result; + std::vector result; result.reserve (std::min (count_a, size_t (16))); - std::lock_guard lock (mutex); - for (auto i (peers.get <6> ().begin ()), n (peers.get <6> ().end ()); i != n && result.size () < count_a; ++i) + std::lock_guard lock (mutex); + for (auto i (peers.get<6> ().begin ()), n (peers.get<6> ().end ()); i != n && result.size () < count_a; ++i) { if (!i->rep_weight.is_zero ()) { @@ -2382,23 +2344,23 @@ std::vector rai::peer_container::representatives (size_t return result; } -std::vector rai::peer_container::purge_list (std::chrono::system_clock::time_point const & cutoff) +std::vector rai::peer_container::purge_list (std::chrono::system_clock::time_point const & cutoff) { - std::vector result; + std::vector result; { - std::lock_guard lock (mutex); - auto pivot (peers.get <1> ().lower_bound (cutoff)); - result.assign (pivot, peers.get <1> ().end ()); + std::lock_guard lock (mutex); + auto pivot (peers.get<1> ().lower_bound (cutoff)); + result.assign (pivot, peers.get<1> ().end ()); // Remove peers that haven't been heard from past the cutoff - peers.get <1> ().erase (peers.get <1> ().begin (), pivot); + peers.get<1> ().erase (peers.get<1> ().begin (), pivot); for (auto i (peers.begin ()), n (peers.end ()); i != n; ++i) { - peers.modify (i, [] (rai::peer_information & info) {info.last_attempt = std::chrono::system_clock::now ();}); + peers.modify (i, [](rai::peer_information & info) { info.last_attempt = std::chrono::system_clock::now (); }); } // Remove keepalive attempt tracking for attempts older than cutoff - auto attempts_pivot (attempts.get <1> ().lower_bound (cutoff)); - attempts.get <1> ().erase (attempts.get <1> ().begin (), attempts_pivot); + auto attempts_pivot (attempts.get<1> ().lower_bound (cutoff)); + attempts.get<1> ().erase (attempts.get<1> ().begin (), attempts_pivot); } if (result.empty ()) { @@ -2407,13 +2369,13 @@ std::vector rai::peer_container::purge_list (std::chrono return result; } -std::vector rai::peer_container::rep_crawl () +std::vector rai::peer_container::rep_crawl () { - std::vector result; + std::vector result; result.reserve (8); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto count (0); - for (auto i (peers.get <5> ().begin ()), n (peers.get <5> ().end ()); i != n && count < 8; ++i, ++count) + for (auto i (peers.get<5> ().begin ()), n (peers.get<5> ().end ()); i != n && count < 8; ++i, ++count) { result.push_back (i->endpoint); }; @@ -2422,7 +2384,7 @@ std::vector rai::peer_container::rep_crawl () size_t rai::peer_container::size () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); return peers.size (); } @@ -2458,12 +2420,11 @@ bool rai::peer_container::not_a_peer (rai::endpoint const & endpoint_a) bool rai::peer_container::rep_response (rai::endpoint const & endpoint_a, rai::amount const & weight_a) { auto updated (false); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (peers.find (endpoint_a)); if (existing != peers.end ()) { - peers.modify (existing, [weight_a, &updated] (rai::peer_information & info) - { + peers.modify (existing, [weight_a, &updated](rai::peer_information & info) { info.last_rep_response = std::chrono::system_clock::now (); if (info.rep_weight < weight_a) { @@ -2477,12 +2438,11 @@ bool rai::peer_container::rep_response (rai::endpoint const & endpoint_a, rai::a void rai::peer_container::rep_request (rai::endpoint const & endpoint_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (peers.find (endpoint_a)); if (existing != peers.end ()) { - peers.modify (existing, [] (rai::peer_information & info) - { + peers.modify (existing, [](rai::peer_information & info) { info.last_rep_request = std::chrono::system_clock::now (); }); } @@ -2495,10 +2455,10 @@ bool rai::peer_container::reachout (rai::endpoint const & endpoint_a) result |= not_a_peer (endpoint_a); // Don't keepalive to nodes that already sent us something result |= known_peer (endpoint_a); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (attempts.find (endpoint_a)); result |= existing != attempts.end (); - attempts.insert ({endpoint_a, std::chrono::system_clock::now ()}); + attempts.insert ({ endpoint_a, std::chrono::system_clock::now () }); return result; } @@ -2508,12 +2468,11 @@ bool rai::peer_container::insert (rai::endpoint const & endpoint_a, unsigned ver auto result (not_a_peer (endpoint_a)); if (!result) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (peers.find (endpoint_a)); if (existing != peers.end ()) { - peers.modify (existing, [] (rai::peer_information & info) - { + peers.modify (existing, [](rai::peer_information & info) { info.last_contact = std::chrono::system_clock::now (); }); result = true; @@ -2531,7 +2490,8 @@ bool rai::peer_container::insert (rai::endpoint const & endpoint_a, unsigned ver return result; } -namespace { +namespace +{ boost::asio::ip::address_v6 mapped_from_v4_bytes (unsigned long address_a) { return boost::asio::ip::address_v6::v4_mapped (boost::asio::ip::address_v4 (address_a)); @@ -2635,8 +2595,8 @@ rep_weight (0) rai::peer_container::peer_container (rai::endpoint const & self_a) : self (self_a), -peer_observer ([] (rai::endpoint const &) {}), -disconnect_observer ([] () {}) +peer_observer ([](rai::endpoint const &) {}), +disconnect_observer ([]() {}) { } @@ -2651,7 +2611,7 @@ void rai::peer_container::contacted (rai::endpoint const & endpoint_a, unsigned insert (endpoint_l, version_a); } -std::ostream & operator << (std::ostream & stream_a, std::chrono::system_clock::time_point const & time_a) +std::ostream & operator<< (std::ostream & stream_a, std::chrono::system_clock::time_point const & time_a) { time_t last_contact (std::chrono::system_clock::to_time_t (time_a)); std::string string (ctime (&last_contact)); @@ -2660,15 +2620,14 @@ std::ostream & operator << (std::ostream & stream_a, std::chrono::system_clock:: return stream_a; } -void rai::network::send_buffer (uint8_t const * data_a, size_t size_a, rai::endpoint const & endpoint_a, std::function callback_a) +void rai::network::send_buffer (uint8_t const * data_a, size_t size_a, rai::endpoint const & endpoint_a, std::function callback_a) { - std::unique_lock lock (socket_mutex); + std::unique_lock lock (socket_mutex); if (node.config.logging.network_packet_logging ()) { BOOST_LOG (node.log) << "Sending packet"; } - socket.async_send_to (boost::asio::buffer (data_a, size_a), endpoint_a, [this, callback_a] (boost::system::error_code const & ec, size_t size_a) - { + socket.async_send_to (boost::asio::buffer (data_a, size_a), endpoint_a, [this, callback_a](boost::system::error_code const & ec, size_t size_a) { callback_a (ec, size_a); if (this->node.config.logging.network_packet_logging ()) { @@ -2687,17 +2646,17 @@ uint64_t rai::block_store::now () bool rai::peer_container::known_peer (rai::endpoint const & endpoint_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (peers.find (endpoint_a)); return existing != peers.end (); } -std::shared_ptr rai::node::shared () +std::shared_ptr rai::node::shared () { return shared_from_this (); } -rai::election::election (MDB_txn * transaction_a, rai::node & node_a, std::shared_ptr block_a, std::function )> const & confirmation_action_a) : +rai::election::election (MDB_txn * transaction_a, rai::node & node_a, std::shared_ptr block_a, std::function)> const & confirmation_action_a) : confirmation_action (confirmation_action_a), votes (block_a), node (node_a), @@ -2711,8 +2670,7 @@ last_winner (block_a) void rai::election::compute_rep_votes (MDB_txn * transaction_a) { - node.wallets.foreach_representative (transaction_a, [this, transaction_a] (rai::public_key const & pub_a, rai::raw_key const & prv_a) - { + node.wallets.foreach_representative (transaction_a, [this, transaction_a](rai::public_key const & pub_a, rai::raw_key const & prv_a) { auto vote (this->node.store.vote_generate (transaction_a, pub_a, prv_a, last_winner)); this->votes.vote (vote); }); @@ -2753,8 +2711,7 @@ void rai::election::confirm_once (MDB_txn * transaction_a) if (winner->first > minimum_threshold (transaction_a, node.ledger)) { auto node_l (node.shared ()); - node.background ([node_l, block_l] () - { + node.background ([node_l, block_l]() { node_l->block_processor.process_receive_many (rai::block_processor_item (block_l, true)); }); last_winner = block_l; @@ -2767,8 +2724,7 @@ void rai::election::confirm_once (MDB_txn * transaction_a) auto winner_l (last_winner); auto node_l (node.shared ()); auto confirmation_action_l (confirmation_action); - node.background ([winner_l, confirmation_action_l, node_l] () - { + node.background ([winner_l, confirmation_action_l, node_l]() { node_l->process_confirmed (winner_l); confirmation_action_l (winner_l); }); @@ -2805,7 +2761,7 @@ void rai::election::confirm_cutoff (MDB_txn * transaction_a) confirm_once (transaction_a); } -void rai::election::vote (std::shared_ptr vote_a) +void rai::election::vote (std::shared_ptr vote_a) { node.network.republish_vote (last_vote, vote_a); last_vote = std::chrono::system_clock::now (); @@ -2817,9 +2773,9 @@ void rai::election::vote (std::shared_ptr vote_a) void rai::active_transactions::announce_votes () { - std::vector inactive; + std::vector inactive; rai::transaction transaction (node.store.environment, nullptr, true); - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); size_t announcements (0); { auto i (roots.begin ()); @@ -2828,7 +2784,7 @@ void rai::active_transactions::announce_votes () for (; i != n && announcements < announcements_per_interval; ++i) { auto election_l (i->election); - node.background ([election_l] () { election_l->broadcast_winner (); } ); + node.background ([election_l]() { election_l->broadcast_winner (); }); if (i->announcements >= contigious_announcements - 1) { // These blocks have reached the confirmation interval for forks @@ -2839,8 +2795,7 @@ void rai::active_transactions::announce_votes () else { unsigned announcements; - roots.modify (i, [&announcements] (rai::conflict_info & info_a) - { + roots.modify (i, [&announcements](rai::conflict_info & info_a) { announcements = ++info_a.announcements; }); // If more than one full announcement interval has passed and no one has voted on this block, we need to synchronize @@ -2856,8 +2811,7 @@ void rai::active_transactions::announce_votes () for (; i != n; ++i) { // Reset announcement count for conflicts above announcement cutoff - roots.modify (i, [] (rai::conflict_info & info_a) - { + roots.modify (i, [](rai::conflict_info & info_a) { info_a.announcements = 0; }); } @@ -2869,34 +2823,34 @@ void rai::active_transactions::announce_votes () } auto now (std::chrono::system_clock::now ()); auto node_l (node.shared ()); - node.alarm.add (now + std::chrono::milliseconds (announce_interval_ms), [node_l] () {node_l->active.announce_votes ();}); + node.alarm.add (now + std::chrono::milliseconds (announce_interval_ms), [node_l]() { node_l->active.announce_votes (); }); } void rai::active_transactions::stop () { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); roots.clear (); } -bool rai::active_transactions::start (MDB_txn * transaction_a, std::shared_ptr block_a, std::function )> const & confirmation_action_a) +bool rai::active_transactions::start (MDB_txn * transaction_a, std::shared_ptr block_a, std::function)> const & confirmation_action_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto root (block_a->root ()); auto existing (roots.find (root)); if (existing == roots.end ()) { - auto election (std::make_shared (transaction_a, node, block_a, confirmation_action_a)); - roots.insert (rai::conflict_info {root, election, 0}); + auto election (std::make_shared (transaction_a, node, block_a, confirmation_action_a)); + roots.insert (rai::conflict_info{ root, election, 0 }); } return existing != roots.end (); } // Validate a vote and apply it to the current election if one exists -void rai::active_transactions::vote (std::shared_ptr vote_a) +void rai::active_transactions::vote (std::shared_ptr vote_a) { - std::shared_ptr election; + std::shared_ptr election; { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto root (vote_a->block->root ()); auto existing (roots.find (root)); if (existing != roots.end ()) @@ -2912,7 +2866,7 @@ void rai::active_transactions::vote (std::shared_ptr vote_a) bool rai::active_transactions::active (rai::block const & block_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); return roots.find (block_a.root ()) != roots.end (); } @@ -2931,8 +2885,7 @@ rai::thread_runner::thread_runner (boost::asio::io_service & service_a, unsigned { for (auto i (0); i < service_threads_a; ++i) { - threads.push_back (std::thread ([&service_a] () - { + threads.push_back (std::thread ([&service_a]() { try { service_a.run (); @@ -2952,7 +2905,7 @@ rai::thread_runner::~thread_runner () void rai::thread_runner::join () { - for (auto &i : threads) + for (auto & i : threads) { if (i.joinable ()) { @@ -2963,30 +2916,7 @@ void rai::thread_runner::join () void rai::add_node_options (boost::program_options::options_description & description_a) { - description_a.add_options () - ("account_create", "Insert next deterministic key in to ") - ("account_get", "Get account number for the ") - ("account_key", "Get the public key for ") - ("data_path", boost::program_options::value (), "Use the supplied path as the data directory") - ("diagnostics", "Run internal diagnostics") - ("key_create", "Generates a adhoc random keypair and prints it to stdout") - ("key_expand", "Derive public key and account number from ") - ("wallet_add_adhoc", "Insert in to ") - ("wallet_create", "Creates a new wallet and prints the ID") - ("wallet_change_seed", "Changes seed for to ") - ("wallet_decrypt_unsafe", "Decrypts using , !!THIS WILL PRINT YOUR PRIVATE KEY TO STDOUT!!") - ("wallet_destroy", "Destroys and all keys it contains") - ("wallet_import", "Imports keys in using in to ") - ("wallet_list", "Dumps wallet IDs and public keys") - ("wallet_remove", "Remove from ") - ("wallet_representative_get", "Prints default representative for ") - ("wallet_representative_set", "Set as default representative for ") - ("vote_dump", "Dump most recent votes from representatives") - ("account", boost::program_options::value (), "Defines for other commands") - ("file", boost::program_options::value (), "Defines for other commands") - ("key", boost::program_options::value (), "Defines the for other commands, hex") - ("password", boost::program_options::value (), "Defines for other commands") - ("wallet", boost::program_options::value (), "Defines for other commands"); + description_a.add_options () ("account_create", "Insert next deterministic key in to ") ("account_get", "Get account number for the ") ("account_key", "Get the public key for ") ("data_path", boost::program_options::value (), "Use the supplied path as the data directory") ("diagnostics", "Run internal diagnostics") ("key_create", "Generates a adhoc random keypair and prints it to stdout") ("key_expand", "Derive public key and account number from ") ("wallet_add_adhoc", "Insert in to ") ("wallet_create", "Creates a new wallet and prints the ID") ("wallet_change_seed", "Changes seed for to ") ("wallet_decrypt_unsafe", "Decrypts using , !!THIS WILL PRINT YOUR PRIVATE KEY TO STDOUT!!") ("wallet_destroy", "Destroys and all keys it contains") ("wallet_import", "Imports keys in using in to ") ("wallet_list", "Dumps wallet IDs and public keys") ("wallet_remove", "Remove from ") ("wallet_representative_get", "Prints default representative for ") ("wallet_representative_set", "Set as default representative for ") ("vote_dump", "Dump most recent votes from representatives") ("account", boost::program_options::value (), "Defines for other commands") ("file", boost::program_options::value (), "Defines for other commands") ("key", boost::program_options::value (), "Defines the for other commands, hex") ("password", boost::program_options::value (), "Defines for other commands") ("wallet", boost::program_options::value (), "Defines for other commands"); } bool rai::handle_node_options (boost::program_options::variables_map & vm) @@ -2997,12 +2927,12 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("wallet") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { std::string password; if (vm.count ("password") > 0) { - password = vm ["password"].as (); + password = vm["password"].as (); } inactive_node node; auto wallet (node.node->wallets.open (wallet_id)); @@ -3043,7 +2973,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("key") == 1) { rai::uint256_union pub; - pub.decode_hex (vm ["key"].as ()); + pub.decode_hex (vm["key"].as ()); std::cout << "Account: " << pub.to_account () << std::endl; } else @@ -3057,7 +2987,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("account") == 1) { rai::uint256_union account; - account.decode_account (vm ["account"].as ()); + account.decode_account (vm["account"].as ()); std::cout << "Hex: " << account.to_string () << std::endl; } else @@ -3097,17 +3027,21 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) else if (vm.count ("key_create")) { rai::keypair pair; - std::cout << "Private: " << pair.prv.data.to_string () << std::endl << "Public: " << pair.pub.to_string () << std::endl << "Account: " << pair.pub.to_account () << std::endl; + std::cout << "Private: " << pair.prv.data.to_string () << std::endl + << "Public: " << pair.pub.to_string () << std::endl + << "Account: " << pair.pub.to_account () << std::endl; } else if (vm.count ("key_expand")) { if (vm.count ("key") == 1) { rai::uint256_union prv; - prv.decode_hex (vm ["key"].as ()); + prv.decode_hex (vm["key"].as ()); rai::uint256_union pub; ed25519_publickey (prv.bytes.data (), pub.bytes.data ()); - std::cout << "Private: " << prv.to_string () << std::endl << "Public: " << pub.to_string () << std::endl << "Account: " << pub.to_account () << std::endl; + std::cout << "Private: " << prv.to_string () << std::endl + << "Public: " << pub.to_string () << std::endl + << "Account: " << pub.to_account () << std::endl; } else { @@ -3120,12 +3054,12 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("wallet") == 1 && vm.count ("key") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { std::string password; if (vm.count ("password") > 0) { - password = vm ["password"].as (); + password = vm["password"].as (); } inactive_node node; auto wallet (node.node->wallets.open (wallet_id)); @@ -3134,7 +3068,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (!wallet->enter_password (password)) { rai::raw_key key; - if (!key.data.decode_hex (vm ["key"].as ())) + if (!key.data.decode_hex (vm["key"].as ())) { rai::transaction transaction (wallet->store.environment, nullptr, true); wallet->store.insert_adhoc (transaction, key); @@ -3174,12 +3108,12 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("wallet") == 1 && vm.count ("key") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { std::string password; if (vm.count ("password") > 0) { - password = vm ["password"].as (); + password = vm["password"].as (); } inactive_node node; auto wallet (node.node->wallets.open (wallet_id)); @@ -3188,7 +3122,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (!wallet->enter_password (password)) { rai::raw_key key; - if (!key.data.decode_hex (vm ["key"].as ())) + if (!key.data.decode_hex (vm["key"].as ())) { rai::transaction transaction (wallet->store.environment, nullptr, true); wallet->store.seed_set (transaction, key); @@ -3238,10 +3172,10 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) std::string password; if (vm.count ("password") == 1) { - password = vm ["password"].as (); + password = vm["password"].as (); } rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { inactive_node node; auto existing (node.node->wallets.items.find (wallet_id)); @@ -3291,7 +3225,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("wallet") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { inactive_node node; if (node.node->wallets.items.find (wallet_id) != node.node->wallets.items.end ()) @@ -3320,7 +3254,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { if (vm.count ("file") == 1) { - std::string filename (vm ["file"].as ()); + std::string filename (vm["file"].as ()); std::ifstream stream; stream.open (filename.c_str ()); if (!stream.fail ()) @@ -3330,12 +3264,12 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) std::string password; if (vm.count ("password") == 1) { - password = vm ["password"].as (); + password = vm["password"].as (); } if (vm.count ("wallet") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { inactive_node node; auto existing (node.node->wallets.items.find (wallet_id)); @@ -3400,13 +3334,13 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) { inactive_node node; rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { auto wallet (node.node->wallets.items.find (wallet_id)); if (wallet != node.node->wallets.items.end ()) { rai::account account_id; - if (!account_id.decode_account (vm ["account"].as ())) + if (!account_id.decode_account (vm["account"].as ())) { rai::transaction transaction (wallet->second->store.environment, nullptr, true); auto account (wallet->second->store.find (transaction, account_id)); @@ -3449,7 +3383,7 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("wallet") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { inactive_node node; auto wallet (node.node->wallets.items.find (wallet_id)); @@ -3484,10 +3418,10 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) if (vm.count ("account") == 1) { rai::uint256_union wallet_id; - if (!wallet_id.decode_hex (vm ["wallet"].as ())) + if (!wallet_id.decode_hex (vm["wallet"].as ())) { rai::account account; - if (!account.decode_account (vm ["account"].as ())) + if (!account.decode_account (vm["account"].as ())) { inactive_node node; auto wallet (node.node->wallets.items.find (wallet_id)); @@ -3533,8 +3467,8 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) for (auto i (node.node->store.vote_begin (transaction)), n (node.node->store.vote_end ()); i != n; ++i) { bool error (false); - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); - auto vote (std::make_shared (error, stream)); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); + auto vote (std::make_shared (error, stream)); assert (!error); std::cerr << boost::str (boost::format ("%1%\n") % vote->to_json ()); } @@ -3548,13 +3482,13 @@ bool rai::handle_node_options (boost::program_options::variables_map & vm) rai::inactive_node::inactive_node () : path (rai::working_path ()), -service (boost::make_shared ()), +service (boost::make_shared ()), alarm (*service), work (1, nullptr) { boost::filesystem::create_directories (path); logging.init (path); - node = std::make_shared (init, *service, 24000, path, alarm, logging, work); + node = std::make_shared (init, *service, 24000, path, alarm, logging, work); } rai::inactive_node::~inactive_node () @@ -3565,12 +3499,12 @@ rai::inactive_node::~inactive_node () rai::port_mapping::port_mapping (rai::node & node_a) : node (node_a), devices (nullptr), -protocols ({{{ "TCP", 0, boost::asio::ip::address_v4::any (), 0 }, { "UDP", 0, boost::asio::ip::address_v4::any (), 0 }}}), +protocols ({ { { "TCP", 0, boost::asio::ip::address_v4::any (), 0 }, { "UDP", 0, boost::asio::ip::address_v4::any (), 0 } } }), check_count (0), on (false) { - urls = {0}; - data = {{0}}; + urls = { 0 }; + data = { { 0 } }; } void rai::port_mapping::start () @@ -3582,11 +3516,11 @@ void rai::port_mapping::refresh_devices () { if (rai::rai_network != rai::rai_networks::rai_test_network) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); int discover_error = 0; freeUPNPDevlist (devices); devices = upnpDiscover (2000, nullptr, nullptr, UPNP_LOCAL_PORT_ANY, false, 2, &discover_error); - std::array local_address; + std::array local_address; local_address.fill (0); auto igd_error (UPNP_GetValidIGD (devices, &urls, &data, local_address.data (), sizeof (local_address))); if (igd_error == 1 || igd_error == 2) @@ -3609,13 +3543,13 @@ void rai::port_mapping::refresh_mapping () { if (rai::rai_network != rai::rai_networks::rai_test_network) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto node_port (std::to_string (node.network.endpoint ().port ())); - + // Intentionally omitted: we don't map the RPC port because, unless RPC authentication was added, this would almost always be a security risk - for (auto & protocol: protocols) + for (auto & protocol : protocols) { - std::array actual_external_port; + std::array actual_external_port; actual_external_port.fill (0); auto add_port_mapping_error (UPNP_AddAnyPortMapping (urls.controlURL, data.first.servicetype, node_port.c_str (), node_port.c_str (), address.to_string ().c_str (), nullptr, protocol.name, nullptr, std::to_string (mapping_timeout).c_str (), actual_external_port.data ())); if (check_count % 15 == 0) @@ -3640,13 +3574,13 @@ int rai::port_mapping::check_mapping () if (rai::rai_network != rai::rai_networks::rai_test_network) { // Long discovery time and fast setup/teardown make this impractical for testing - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto node_port (std::to_string (node.network.endpoint ().port ())); - for (auto & protocol: protocols) + for (auto & protocol : protocols) { - std::array int_client; - std::array int_port; - std::array remaining_mapping_duration; + std::array int_client; + std::array int_port; + std::array remaining_mapping_duration; remaining_mapping_duration.fill (0); auto verify_port_mapping_error (UPNP_GetSpecificPortMappingEntry (urls.controlURL, data.first.servicetype, node_port.c_str (), protocol.name, nullptr, int_client.data (), int_port.data (), nullptr, nullptr, remaining_mapping_duration.data ())); if (verify_port_mapping_error == UPNPCOMMAND_SUCCESS) @@ -3658,7 +3592,7 @@ int rai::port_mapping::check_mapping () protocol.remaining = 0; } result = std::min (result, protocol.remaining); - std::array external_address; + std::array external_address; external_address.fill (0); auto external_ip_error (UPNP_GetExternalIPAddress (urls.controlURL, data.first.servicetype, external_address.data ())); if (external_ip_error == UPNPCOMMAND_SUCCESS) @@ -3704,8 +3638,7 @@ void rai::port_mapping::check_mapping_loop () if (on) { auto node_l (node.shared ()); - node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (wait_duration), [node_l] () - { + node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (wait_duration), [node_l]() { node_l->port_mapping.check_mapping_loop (); }); } @@ -3714,8 +3647,8 @@ void rai::port_mapping::check_mapping_loop () void rai::port_mapping::stop () { on = false; - std::lock_guard lock (mutex); - for (auto & protocol: protocols) + std::lock_guard lock (mutex); + for (auto & protocol : protocols) { if (protocol.external_port != 0) { diff --git a/rai/node/node.hpp b/rai/node/node.hpp index 90e75831..32fecb03 100644 --- a/rai/node/node.hpp +++ b/rai/node/node.hpp @@ -4,46 +4,47 @@ #include #include -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include +#include #include #include -#include -#include #include #include +#include #include -#include +#include #include -std::ostream & operator << (std::ostream &, std::chrono::system_clock::time_point const &); +std::ostream & operator<< (std::ostream &, std::chrono::system_clock::time_point const &); namespace boost { namespace program_options { -class options_description; -class variables_map; + class options_description; + class variables_map; } } namespace rai { class node; -class election : public std::enable_shared_from_this +class election : public std::enable_shared_from_this { - std::function )> confirmation_action; + std::function)> confirmation_action; void confirm_once (MDB_txn *); + public: - election (MDB_txn *, rai::node &, std::shared_ptr , std::function )> const &); - void vote (std::shared_ptr ); + election (MDB_txn *, rai::node &, std::shared_ptr, std::function)> const &); + void vote (std::shared_ptr); // Check if we have vote quorum bool have_quorum (MDB_txn *); // Tell the network our view of the winner @@ -59,14 +60,14 @@ public: rai::votes votes; rai::node & node; std::chrono::system_clock::time_point last_vote; - std::shared_ptr last_winner; + std::shared_ptr last_winner; std::atomic_flag confirmed; }; class conflict_info { public: rai::block_hash root; - std::shared_ptr election; + std::shared_ptr election; // Number of announcements in a row for this fork unsigned announcements; }; @@ -78,20 +79,17 @@ public: active_transactions (rai::node &); // Start an election for a block // Call action with confirmed block, may be different than what we started with - bool start (MDB_txn *, std::shared_ptr , std::function )> const & = [] (std::shared_ptr ) {}); - void vote (std::shared_ptr ); + bool start (MDB_txn *, std::shared_ptr, std::function)> const & = [](std::shared_ptr) {}); + void vote (std::shared_ptr); // Is the root of this block in the roots container bool active (rai::block const &); void announce_votes (); void stop (); - boost::multi_index_container - < - rai::conflict_info, - boost::multi_index::indexed_by - < - boost::multi_index::ordered_unique > - > - > roots; + boost::multi_index_container< + rai::conflict_info, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique>>> + roots; rai::node & node; std::mutex mutex; // Maximum number of conflicts to vote on per interval, lowest root hash first @@ -103,21 +101,21 @@ public: class operation { public: - bool operator > (rai::operation const &) const; + bool operator> (rai::operation const &) const; std::chrono::system_clock::time_point wakeup; - std::function function; + std::function function; }; class alarm { public: alarm (boost::asio::io_service &); ~alarm (); - void add (std::chrono::system_clock::time_point const &, std::function const &); + void add (std::chrono::system_clock::time_point const &, std::function const &); void run (); boost::asio::io_service & service; std::mutex mutex; std::condition_variable condition; - std::priority_queue , std::greater > operations; + std::priority_queue, std::greater> operations; std::thread thread; }; class gap_information @@ -125,25 +123,22 @@ class gap_information public: std::chrono::system_clock::time_point arrival; rai::block_hash hash; - std::unique_ptr votes; + std::unique_ptr votes; }; class gap_cache { public: gap_cache (rai::node &); - void add (MDB_txn *, std::shared_ptr ); - void vote (std::shared_ptr ); + void add (MDB_txn *, std::shared_ptr); + void vote (std::shared_ptr); rai::uint128_t bootstrap_threshold (MDB_txn *); void purge_old (); - boost::multi_index_container - < - rai::gap_information, - boost::multi_index::indexed_by - < - boost::multi_index::ordered_non_unique >, - boost::multi_index::hashed_unique > - > - > blocks; + boost::multi_index_container< + rai::gap_information, + boost::multi_index::indexed_by< + boost::multi_index::ordered_non_unique>, + boost::multi_index::hashed_unique>>> + blocks; size_t const max = 256; std::mutex mutex; rai::node & node; @@ -181,20 +176,20 @@ public: bool known_peer (rai::endpoint const &); // Notify of peer we received from bool insert (rai::endpoint const &, unsigned); - std::unordered_set random_set (size_t); - void random_fill (std::array &); + std::unordered_set random_set (size_t); + void random_fill (std::array &); // Request a list of the top known representatives - std::vector representatives (size_t); + std::vector representatives (size_t); // List of all peers - std::vector list (); - std::map list_version (); + std::vector list (); + std::map list_version (); // A list of random peers with size the square root of total peer count - std::vector list_sqrt (); + std::vector list_sqrt (); // Get the next peer for attempting bootstrap rai::endpoint bootstrap_peer (); // Purge any peer where last_contact < time_point and return what was left - std::vector purge_list (std::chrono::system_clock::time_point const &); - std::vector rep_crawl (); + std::vector purge_list (std::chrono::system_clock::time_point const &); + std::vector rep_crawl (); bool rep_response (rai::endpoint const &, rai::amount const &); void rep_request (rai::endpoint const &); // Should we reach out to this endpoint with a keepalive message @@ -204,32 +199,26 @@ public: bool empty (); std::mutex mutex; rai::endpoint self; - boost::multi_index_container - < - peer_information, - boost::multi_index::indexed_by - < - boost::multi_index::hashed_unique >, - boost::multi_index::ordered_non_unique >, - boost::multi_index::ordered_non_unique , std::greater >, - boost::multi_index::random_access <>, - boost::multi_index::ordered_non_unique >, - boost::multi_index::ordered_non_unique >, - boost::multi_index::ordered_non_unique , std::greater > - > - > peers; - boost::multi_index_container - < - peer_attempt, - boost::multi_index::indexed_by - < - boost::multi_index::hashed_unique >, - boost::multi_index::ordered_non_unique > - > - > attempts; + boost::multi_index_container< + peer_information, + boost::multi_index::indexed_by< + boost::multi_index::hashed_unique>, + boost::multi_index::ordered_non_unique>, + boost::multi_index::ordered_non_unique, std::greater>, + boost::multi_index::random_access<>, + boost::multi_index::ordered_non_unique>, + boost::multi_index::ordered_non_unique>, + boost::multi_index::ordered_non_unique, std::greater>>> + peers; + boost::multi_index_container< + peer_attempt, + boost::multi_index::indexed_by< + boost::multi_index::hashed_unique>, + boost::multi_index::ordered_non_unique>>> + attempts; // Called when a new peer is observed - std::function peer_observer; - std::function disconnect_observer; + std::function peer_observer; + std::function disconnect_observer; // Number of peers to crawl for being a rep every period static size_t constexpr peers_per_crawl = 8; }; @@ -239,7 +228,7 @@ public: uint8_t const * data; size_t size; rai::endpoint endpoint; - std::function callback; + std::function callback; }; class mapping_protocol { @@ -272,7 +261,7 @@ public: static int constexpr mapping_timeout = rai::rai_network == rai::rai_networks::rai_test_network ? 53 : 3593; static int constexpr check_timeout = rai::rai_network == rai::rai_networks::rai_test_network ? 17 : 53; boost::asio::ip::address_v4 address; - std::array protocols; + std::array protocols; uint64_t check_count; bool on; }; @@ -280,10 +269,10 @@ class message_statistics { public: message_statistics (); - std::atomic keepalive; - std::atomic publish; - std::atomic confirm_req; - std::atomic confirm_ack; + std::atomic keepalive; + std::atomic publish; + std::atomic confirm_req; + std::atomic confirm_ack; }; class block_arrival_info { @@ -298,15 +287,12 @@ class block_arrival public: void add (rai::block_hash const &); bool recent (rai::block_hash const &); - boost::multi_index_container - < - rai::block_arrival_info, - boost::multi_index::indexed_by - < - boost::multi_index::ordered_non_unique >, - boost::multi_index::hashed_unique > - > - > arrival; + boost::multi_index_container< + rai::block_arrival_info, + boost::multi_index::indexed_by< + boost::multi_index::ordered_non_unique>, + boost::multi_index::hashed_unique>>> + arrival; std::mutex mutex; }; class network @@ -317,20 +303,20 @@ public: void stop (); void receive_action (boost::system::error_code const &, size_t); void rpc_action (boost::system::error_code const &, size_t); - void rebroadcast_reps (std::shared_ptr ); - void republish_vote (std::chrono::system_clock::time_point const &, std::shared_ptr ); - void republish_block (MDB_txn *, std::shared_ptr ); - void republish (rai::block_hash const &, std::shared_ptr >, rai::endpoint); - void publish_broadcast (std::vector &, std::unique_ptr ); - void confirm_send (rai::confirm_ack const &, std::shared_ptr >, rai::endpoint const &); - void merge_peers (std::array const &); + void rebroadcast_reps (std::shared_ptr); + void republish_vote (std::chrono::system_clock::time_point const &, std::shared_ptr); + void republish_block (MDB_txn *, std::shared_ptr); + void republish (rai::block_hash const &, std::shared_ptr>, rai::endpoint); + void publish_broadcast (std::vector &, std::unique_ptr); + void confirm_send (rai::confirm_ack const &, std::shared_ptr>, rai::endpoint const &); + void merge_peers (std::array const &); void send_keepalive (rai::endpoint const &); - void broadcast_confirm_req (std::shared_ptr ); - void send_confirm_req (rai::endpoint const &, std::shared_ptr ); - void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function ); + void broadcast_confirm_req (std::shared_ptr); + void send_confirm_req (rai::endpoint const &, std::shared_ptr); + void send_buffer (uint8_t const *, size_t, rai::endpoint const &, std::function); rai::endpoint endpoint (); rai::endpoint remote; - std::array buffer; + std::array buffer; boost::asio::ip::udp::socket socket; std::mutex socket_mutex; boost::asio::ip::udp::resolver resolver; @@ -366,7 +352,7 @@ public: bool work_generation_time () const; bool log_to_cerr () const; void init (boost::filesystem::path const &); - + bool ledger_logging_value; bool ledger_duplicate_logging_value; bool vote_logging_value; @@ -403,9 +389,9 @@ public: rai::account random_representative (); uint16_t peering_port; rai::logging logging; - std::vector > work_peers; - std::vector preconfigured_peers; - std::vector preconfigured_representatives; + std::vector> work_peers; + std::vector preconfigured_peers; + std::vector preconfigured_representatives; unsigned bootstrap_fraction_numerator; rai::amount receive_minimum; rai::amount inactive_supply; @@ -424,18 +410,18 @@ public: class node_observers { public: - rai::observer_set , rai::account const &, rai::amount const &> blocks; - rai::observer_set wallet; - rai::observer_set , rai::endpoint const &> vote; - rai::observer_set endpoint; - rai::observer_set <> disconnect; - rai::observer_set <> started; + rai::observer_set, rai::account const &, rai::amount const &> blocks; + rai::observer_set wallet; + rai::observer_set, rai::endpoint const &> vote; + rai::observer_set endpoint; + rai::observer_set<> disconnect; + rai::observer_set<> started; }; class vote_processor { public: vote_processor (rai::node &); - rai::vote_result vote (std::shared_ptr , rai::endpoint); + rai::vote_result vote (std::shared_ptr, rai::endpoint); rai::node & node; }; // The network is crawled for representatives by ocassionally sending a unicast confirm_req for a specific block and watching to see if it's acknowledged with a vote. @@ -446,17 +432,17 @@ public: void remove (rai::block_hash const &); bool exists (rai::block_hash const &); std::mutex mutex; - std::unordered_set active; + std::unordered_set active; }; class block_processor_item { public: - block_processor_item (std::shared_ptr ); - block_processor_item (std::shared_ptr , bool); - block_processor_item (std::shared_ptr , std::function )>); - block_processor_item (std::shared_ptr , std::function )>, bool); - std::shared_ptr block; - std::function )> callback; + block_processor_item (std::shared_ptr); + block_processor_item (std::shared_ptr, bool); + block_processor_item (std::shared_ptr, std::function)>); + block_processor_item (std::shared_ptr, std::function)>, bool); + std::shared_ptr block; + std::function)> callback; bool force; }; // Processing blocks is a potentially long IO operation @@ -470,18 +456,19 @@ public: void flush (); void add (rai::block_processor_item const &); void process_receive_many (rai::block_processor_item const &); - void process_receive_many (std::deque &); - rai::process_return process_receive_one (MDB_txn *, std::shared_ptr ); + void process_receive_many (std::deque &); + rai::process_return process_receive_one (MDB_txn *, std::shared_ptr); void process_blocks (); + private: bool stopped; bool idle; - std::deque blocks; + std::deque blocks; std::mutex mutex; std::condition_variable condition; rai::node & node; }; -class node : public std::enable_shared_from_this +class node : public std::enable_shared_from_this { public: node (rai::node_init &, boost::asio::io_service &, uint16_t, boost::filesystem::path const &, rai::alarm &, rai::logging const &, rai::work_pool &); @@ -496,17 +483,17 @@ public: void keepalive (std::string const &, uint16_t); void start (); void stop (); - std::shared_ptr shared (); + std::shared_ptr shared (); int store_version (); - void process_confirmed (std::shared_ptr ); + void process_confirmed (std::shared_ptr); void process_message (rai::message &, rai::endpoint const &); - void process_active (std::shared_ptr ); + void process_active (std::shared_ptr); rai::process_return process (rai::block const &); - void keepalive_preconfigured (std::vector const &); + void keepalive_preconfigured (std::vector const &); rai::block_hash latest (rai::account const &); rai::uint128_t balance (rai::account const &); - std::unique_ptr block (rai::block_hash const &); - std::pair balance_pending (rai::account const &); + std::unique_ptr block (rai::block_hash const &); + std::pair balance_pending (rai::account const &); rai::uint128_t weight (rai::account const &); rai::account representative (rai::account const &); void ongoing_keepalive (); @@ -517,7 +504,7 @@ public: int price (rai::uint128_t const &, int); void generate_work (rai::block &); uint64_t generate_work (rai::uint256_union const &); - void generate_work (rai::uint256_union const &, std::function ); + void generate_work (rai::uint256_union const &, std::function); void add_initial_peers (); boost::asio::io_service & service; rai::node_config config; @@ -554,7 +541,7 @@ public: thread_runner (boost::asio::io_service &, unsigned); ~thread_runner (); void join (); - std::vector threads; + std::vector threads; }; void add_node_options (boost::program_options::options_description &); bool handle_node_options (boost::program_options::variables_map &); @@ -564,11 +551,11 @@ public: inactive_node (); ~inactive_node (); boost::filesystem::path path; - boost::shared_ptr service; + boost::shared_ptr service; rai::alarm alarm; rai::logging logging; rai::node_init init; rai::work_pool work; - std::shared_ptr node; + std::shared_ptr node; }; } diff --git a/rai/node/openclwork.cpp b/rai/node/openclwork.cpp index b3259f2b..6cb1c525 100644 --- a/rai/node/openclwork.cpp +++ b/rai/node/openclwork.cpp @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include #include +#include +#include +#include +#include namespace { @@ -394,15 +394,15 @@ rai::opencl_environment::opencl_environment (bool & error_a) { cl_uint platformIdCount = 0; clGetPlatformIDs (0, nullptr, &platformIdCount); - std::vector platformIds (platformIdCount); - clGetPlatformIDs (platformIdCount, platformIds.data(), nullptr); + std::vector platformIds (platformIdCount); + clGetPlatformIDs (platformIdCount, platformIds.data (), nullptr); for (auto i (platformIds.begin ()), n (platformIds.end ()); i != n; ++i) { rai::opencl_platform platform; platform.platform = *i; cl_uint deviceIdCount = 0; clGetDeviceIDs (*i, CL_DEVICE_TYPE_ALL, 0, nullptr, &deviceIdCount); - std::vector deviceIds (deviceIdCount); + std::vector deviceIds (deviceIdCount); clGetDeviceIDs (*i, CL_DEVICE_TYPE_ALL, deviceIdCount, deviceIds.data (), nullptr); for (auto j (deviceIds.begin ()), m (deviceIds.end ()); j != m; ++j) { @@ -416,72 +416,72 @@ void rai::opencl_environment::dump (std::ostream & stream) { auto index (0); auto device_count (0); - for (auto & i: platforms) + for (auto & i : platforms) { device_count += i.devices.size (); } stream << boost::str (boost::format ("OpenCL found %1% platforms and %2% devices\n") % platforms.size () % device_count); for (auto i (platforms.begin ()), n (platforms.end ()); i != n; ++i, ++index) { - std::vector queries = {CL_PLATFORM_PROFILE, CL_PLATFORM_VERSION, CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, CL_PLATFORM_EXTENSIONS}; + std::vector queries = { CL_PLATFORM_PROFILE, CL_PLATFORM_VERSION, CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, CL_PLATFORM_EXTENSIONS }; stream << "Platform: " << index << std::endl; for (auto j (queries.begin ()), m (queries.end ()); j != m; ++j) { size_t platformInfoCount = 0; - clGetPlatformInfo(i->platform, *j, 0, nullptr, &platformInfoCount); - std::vector info (platformInfoCount); - clGetPlatformInfo(i->platform, *j, info.size (), info.data (), nullptr); + clGetPlatformInfo (i->platform, *j, 0, nullptr, &platformInfoCount); + std::vector info (platformInfoCount); + clGetPlatformInfo (i->platform, *j, info.size (), info.data (), nullptr); stream << info.data () << std::endl; } for (auto j (i->devices.begin ()), m (i->devices.end ()); j != m; ++j) { - std::vector queries = {CL_DEVICE_NAME, CL_DEVICE_VENDOR, CL_DEVICE_PROFILE}; + std::vector queries = { CL_DEVICE_NAME, CL_DEVICE_VENDOR, CL_DEVICE_PROFILE }; stream << "Device: " << j - i->devices.begin () << std::endl; for (auto k (queries.begin ()), o (queries.end ()); k != o; ++k) { size_t platformInfoCount = 0; - clGetDeviceInfo(*j, *k, 0, nullptr, &platformInfoCount); - std::vector info (platformInfoCount); - clGetDeviceInfo(*j, *k, info.size (), info.data (), nullptr); + clGetDeviceInfo (*j, *k, 0, nullptr, &platformInfoCount); + std::vector info (platformInfoCount); + clGetDeviceInfo (*j, *k, info.size (), info.data (), nullptr); stream << '\t' << info.data () << std::endl; } size_t deviceTypeCount = 0; - clGetDeviceInfo(*j, CL_DEVICE_TYPE, 0, nullptr, &deviceTypeCount); - std::vector deviceTypeInfo (deviceTypeCount); - clGetDeviceInfo(*j, CL_DEVICE_TYPE, deviceTypeCount, deviceTypeInfo.data (), 0); + clGetDeviceInfo (*j, CL_DEVICE_TYPE, 0, nullptr, &deviceTypeCount); + std::vector deviceTypeInfo (deviceTypeCount); + clGetDeviceInfo (*j, CL_DEVICE_TYPE, deviceTypeCount, deviceTypeInfo.data (), 0); std::string device_type_string; - switch (deviceTypeInfo [0]) + switch (deviceTypeInfo[0]) { case CL_DEVICE_TYPE_ACCELERATOR: - device_type_string = "ACCELERATOR"; - break; + device_type_string = "ACCELERATOR"; + break; case CL_DEVICE_TYPE_CPU: - device_type_string = "CPU"; - break; + device_type_string = "CPU"; + break; case CL_DEVICE_TYPE_CUSTOM: - device_type_string = "CUSTOM"; - break; + device_type_string = "CUSTOM"; + break; case CL_DEVICE_TYPE_DEFAULT: - device_type_string = "DEFAULT"; - break; + device_type_string = "DEFAULT"; + break; case CL_DEVICE_TYPE_GPU: - device_type_string = "GPU"; - break; - default: - device_type_string = "Unknown"; - break; + device_type_string = "GPU"; + break; + default: + device_type_string = "Unknown"; + break; } stream << '\t' << device_type_string << std::endl; size_t compilerAvailableCount = 0; - clGetDeviceInfo(*j, CL_DEVICE_COMPILER_AVAILABLE, 0, nullptr, &compilerAvailableCount); - std::vector compilerAvailableInfo (compilerAvailableCount); - clGetDeviceInfo(*j, CL_DEVICE_COMPILER_AVAILABLE, compilerAvailableCount, compilerAvailableInfo.data (), 0); - stream << '\t' << "Compiler available: " << (compilerAvailableInfo [0] ? "true" : "false") << std::endl; + clGetDeviceInfo (*j, CL_DEVICE_COMPILER_AVAILABLE, 0, nullptr, &compilerAvailableCount); + std::vector compilerAvailableInfo (compilerAvailableCount); + clGetDeviceInfo (*j, CL_DEVICE_COMPILER_AVAILABLE, compilerAvailableCount, compilerAvailableInfo.data (), 0); + stream << '\t' << "Compiler available: " << (compilerAvailableInfo[0] ? "true" : "false") << std::endl; size_t computeUnitsAvailableCount = 0; - clGetDeviceInfo(*j, CL_DEVICE_MAX_COMPUTE_UNITS, 0, nullptr, &computeUnitsAvailableCount); - std::vector computeUnitsAvailableInfo (computeUnitsAvailableCount); - clGetDeviceInfo(*j, CL_DEVICE_MAX_COMPUTE_UNITS, computeUnitsAvailableCount, computeUnitsAvailableInfo.data (), 0); - uint64_t computeUnits (computeUnitsAvailableInfo [0] | (computeUnitsAvailableInfo [1] << 8) | (computeUnitsAvailableInfo [2] << 16) | (computeUnitsAvailableInfo [3] << 24)); + clGetDeviceInfo (*j, CL_DEVICE_MAX_COMPUTE_UNITS, 0, nullptr, &computeUnitsAvailableCount); + std::vector computeUnitsAvailableInfo (computeUnitsAvailableCount); + clGetDeviceInfo (*j, CL_DEVICE_MAX_COMPUTE_UNITS, computeUnitsAvailableCount, computeUnitsAvailableInfo.data (), 0); + uint64_t computeUnits (computeUnitsAvailableInfo[0] | (computeUnitsAvailableInfo[1] << 8) | (computeUnitsAvailableInfo[2] << 16) | (computeUnitsAvailableInfo[3] << 24)); stream << '\t' << "Compute units available: " << computeUnits << std::endl; } } @@ -513,9 +513,9 @@ bool rai::opencl_config::deserialize_json (boost::property_tree::ptree const & t auto result (false); try { - auto platform_l (tree_a.get ("platform")); - auto device_l (tree_a.get ("device")); - auto threads_l (tree_a.get ("threads")); + auto platform_l (tree_a.get ("platform")); + auto device_l (tree_a.get ("device")); + auto threads_l (tree_a.get ("threads")); try { platform = std::stoull (platform_l); @@ -548,15 +548,14 @@ logging (logging_a) error_a |= config.platform >= environment_a.platforms.size (); if (!error_a) { - auto & platform (environment_a.platforms [config.platform]); + auto & platform (environment_a.platforms[config.platform]); error_a |= config.device >= platform.devices.size (); if (!error_a) { - rai::random_pool.GenerateBlock (reinterpret_cast (rand.s.data ()), rand.s.size () * sizeof (decltype (rand.s)::value_type)); - std::array selected_devices; - selected_devices [0] = platform.devices [config.device]; - cl_context_properties contextProperties [] = - { + rai::random_pool.GenerateBlock (reinterpret_cast (rand.s.data ()), rand.s.size () * sizeof (decltype (rand.s)::value_type)); + std::array selected_devices; + selected_devices[0] = platform.devices[config.device]; + cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, reinterpret_cast (platform.platform), 0, 0 @@ -567,7 +566,7 @@ logging (logging_a) if (!error_a) { cl_int queue_error (0); - queue = clCreateCommandQueue (context, selected_devices [0], 0, &queue_error); + queue = clCreateCommandQueue (context, selected_devices[0], 0, &queue_error); error_a |= queue_error != CL_SUCCESS; if (!error_a) { @@ -594,7 +593,7 @@ logging (logging_a) error_a |= program_error != CL_SUCCESS; if (!error_a) { - auto clBuildProgramError (clBuildProgram(program, selected_devices.size(), selected_devices.data(), "-D __APPLE__", nullptr, nullptr)); + auto clBuildProgramError (clBuildProgram (program, selected_devices.size (), selected_devices.data (), "-D __APPLE__", nullptr, nullptr)); error_a |= clBuildProgramError != CL_SUCCESS; if (!error_a) { @@ -643,7 +642,7 @@ logging (logging_a) { size_t log_size (0); clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, 0, nullptr, &log_size); - std::vector log (log_size); + std::vector log (log_size); clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, log.size (), log.data (), nullptr); BOOST_LOG (logging.log) << log.data (); } @@ -706,13 +705,13 @@ rai::opencl_work::~opencl_work () } } -boost::optional rai::opencl_work::generate_work (rai::uint256_union const & root_a) +boost::optional rai::opencl_work::generate_work (rai::uint256_union const & root_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); bool error (false); uint64_t result (0); unsigned thread_count (config.threads); - size_t work_size [] = { thread_count, 0, 0 }; + size_t work_size[] = { thread_count, 0, 0 }; while (rai::work_validate (root_a, result) && !error) { result = rand.next (); @@ -725,7 +724,7 @@ boost::optional rai::opencl_work::generate_work (rai::uint256_union c cl_int enqueue_error = clEnqueueNDRangeKernel (queue, kernel, 1, nullptr, work_size, nullptr, 0, nullptr, nullptr); if (enqueue_error == CL_SUCCESS) { - cl_int read_error1 = clEnqueueReadBuffer(queue, result_buffer, false, 0, sizeof (uint64_t), &result, 0, nullptr, nullptr); + cl_int read_error1 = clEnqueueReadBuffer (queue, result_buffer, false, 0, sizeof (uint64_t), &result, 0, nullptr, nullptr); if (read_error1 == CL_SUCCESS) { cl_int finishError = clFinish (queue); @@ -762,7 +761,7 @@ boost::optional rai::opencl_work::generate_work (rai::uint256_union c BOOST_LOG (logging.log) << boost::str (boost::format ("Error writing attempt %1%") % write_error1); } } - boost::optional value; + boost::optional value; if (!error) { value = result; @@ -770,9 +769,9 @@ boost::optional rai::opencl_work::generate_work (rai::uint256_union c return value; } -std::unique_ptr rai::opencl_work::create (bool create_a, rai::opencl_config const & config_a, rai::logging & logging_a) +std::unique_ptr rai::opencl_work::create (bool create_a, rai::opencl_config const & config_a, rai::logging & logging_a) { - std::unique_ptr result; + std::unique_ptr result; if (create_a) { auto error (false); diff --git a/rai/node/openclwork.hpp b/rai/node/openclwork.hpp index b7cc42db..0e766397 100644 --- a/rai/node/openclwork.hpp +++ b/rai/node/openclwork.hpp @@ -23,14 +23,14 @@ class opencl_platform { public: cl_platform_id platform; - std::vector devices; + std::vector devices; }; class opencl_environment { public: opencl_environment (bool &); void dump (std::ostream & stream); - std::vector platforms; + std::vector platforms; }; union uint256_union; class work_pool; @@ -51,7 +51,7 @@ public: opencl_work (bool &, rai::opencl_config const &, rai::opencl_environment &, rai::logging &); ~opencl_work (); boost::optional generate_work (rai::uint256_union const &); - static std::unique_ptr create (bool, rai::opencl_config const &, rai::logging &); + static std::unique_ptr create (bool, rai::opencl_config const &, rai::logging &); rai::opencl_config const & config; std::mutex mutex; cl_context context; diff --git a/rai/node/rpc.cpp b/rai/node/rpc.cpp old mode 100755 new mode 100644 index 2c0f71d9..ac213bdb --- a/rai/node/rpc.cpp +++ b/rai/node/rpc.cpp @@ -39,15 +39,15 @@ bool rai::rpc_config::deserialize_json (boost::property_tree::ptree const & tree auto result (false); try { - auto address_l (tree_a.get ("address")); - auto port_l (tree_a.get ("port")); - enable_control = tree_a.get ("enable_control"); - auto frontier_request_limit_l (tree_a.get ("frontier_request_limit")); - auto chain_request_limit_l (tree_a.get ("chain_request_limit")); + auto address_l (tree_a.get ("address")); + auto port_l (tree_a.get ("port")); + enable_control = tree_a.get ("enable_control"); + auto frontier_request_limit_l (tree_a.get ("frontier_request_limit")); + auto chain_request_limit_l (tree_a.get ("chain_request_limit")); try { port = std::stoul (port_l); - result = port > std::numeric_limits ::max (); + result = port > std::numeric_limits::max (); frontier_request_limit = std::stoull (frontier_request_limit_l); chain_request_limit = std::stoull (chain_request_limit_l); } @@ -82,22 +82,20 @@ node (node_a) acceptor.bind (endpoint, ec); if (ec) { - BOOST_LOG (node.log) << boost::str (boost::format ("Error while binding for RPC on port %1%: %2%") % endpoint.port() % ec.message ()); - throw std::runtime_error (ec.message()); + BOOST_LOG (node.log) << boost::str (boost::format ("Error while binding for RPC on port %1%: %2%") % endpoint.port () % ec.message ()); + throw std::runtime_error (ec.message ()); } acceptor.listen (); - node_a.observers.blocks.add ([this] (std::shared_ptr block_a, rai::account const & account_a, rai::amount const &) - { + node_a.observers.blocks.add ([this](std::shared_ptr block_a, rai::account const & account_a, rai::amount const &) { observer_action (account_a); }); } void rai::rpc::start () { - auto connection (std::make_shared (node, *this)); - acceptor.async_accept (connection->socket, [this, connection] (boost::system::error_code const & ec) - { + auto connection (std::make_shared (node, *this)); + acceptor.async_accept (connection->socket, [this, connection](boost::system::error_code const & ec) { if (!ec) { start (); @@ -115,7 +113,7 @@ void rai::rpc::stop () acceptor.close (); } -rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::function const & response_a) : +rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::function const & response_a) : body (body_a), node (node_a), rpc (rpc_a), @@ -125,9 +123,9 @@ response (response_a) void rai::rpc::observer_action (rai::account const & account_a) { - std::shared_ptr observer; + std::shared_ptr observer; { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto existing (payment_observers.find (account_a)); if (existing != payment_observers.end ()) { @@ -142,7 +140,7 @@ void rai::rpc::observer_action (rai::account const & account_a) namespace { -void error_response (std::function response_a, std::string const & message_a) +void error_response (std::function response_a, std::string const & message_a) { boost::property_tree::ptree response_l; response_l.put ("error", message_a); @@ -173,15 +171,15 @@ bool decode_unsigned (std::string const & text, uint64_t & number) void rai::rpc_handler::account_balance () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) { auto balance (node.balance_pending (account)); boost::property_tree::ptree response_l; - response_l.put ("balance", balance.first.convert_to ()); - response_l.put ("pending", balance.second.convert_to ()); + response_l.put ("balance", balance.first.convert_to ()); + response_l.put ("pending", balance.second.convert_to ()); response (response_l); } else @@ -192,7 +190,7 @@ void rai::rpc_handler::account_balance () void rai::rpc_handler::account_block_count () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) @@ -220,7 +218,7 @@ void rai::rpc_handler::account_create () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -229,7 +227,7 @@ void rai::rpc_handler::account_create () if (existing != node.wallets.items.end ()) { bool generate_work (true); - boost::optional work (request.get_optional ("work")); + boost::optional work (request.get_optional ("work")); if (work.is_initialized ()) { generate_work = work.get (); @@ -264,7 +262,7 @@ void rai::rpc_handler::account_create () void rai::rpc_handler::account_get () { - std::string key_text (request.get ("key")); + std::string key_text (request.get ("key")); rai::uint256_union pub; auto error (pub.decode_hex (key_text)); if (!error) @@ -281,25 +279,25 @@ void rai::rpc_handler::account_get () void rai::rpc_handler::account_info () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) { bool representative (false); - boost::optional representative_optional (request.get_optional ("representative")); + boost::optional representative_optional (request.get_optional ("representative")); if (representative_optional.is_initialized ()) { representative = representative_optional.get (); } bool weight (false); - boost::optional weight_optional (request.get_optional ("weight")); + boost::optional weight_optional (request.get_optional ("weight")); if (weight_optional.is_initialized ()) { weight = weight_optional.get (); } bool pending (false); - boost::optional pending_optional (request.get_optional ("pending")); + boost::optional pending_optional (request.get_optional ("pending")); if (pending_optional.is_initialized ()) { pending = pending_optional.get (); @@ -326,12 +324,12 @@ void rai::rpc_handler::account_info () if (weight) { auto account_weight (node.ledger.weight (transaction, account)); - response_l.put ("weight", account_weight.convert_to ()); + response_l.put ("weight", account_weight.convert_to ()); } if (pending) { auto account_pending (node.ledger.account_pending (transaction, account)); - response_l.put ("pending", account_pending.convert_to ()); + response_l.put ("pending", account_pending.convert_to ()); } response (response_l); } @@ -348,7 +346,7 @@ void rai::rpc_handler::account_info () void rai::rpc_handler::account_key () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -365,7 +363,7 @@ void rai::rpc_handler::account_key () void rai::rpc_handler::account_list () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -400,8 +398,8 @@ void rai::rpc_handler::account_move () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); - std::string source_text (request.get ("source")); + std::string wallet_text (request.get ("wallet")); + std::string source_text (request.get ("source")); auto accounts_text (request.get_child ("accounts")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); @@ -419,11 +417,11 @@ void rai::rpc_handler::account_move () if (existing != node.wallets.items.end ()) { auto source (existing->second); - std::vector accounts; + std::vector accounts; for (auto i (accounts_text.begin ()), n (accounts_text.end ()); i != n; ++i) { rai::public_key account; - account.decode_hex (i->second.get ("")); + account.decode_hex (i->second.get ("")); accounts.push_back (account); } rai::transaction transaction (node.store.environment, nullptr, true); @@ -462,8 +460,8 @@ void rai::rpc_handler::account_remove () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); - std::string account_text (request.get ("account")); + std::string wallet_text (request.get ("wallet")); + std::string account_text (request.get ("account")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -520,7 +518,7 @@ void rai::rpc_handler::account_remove () void rai::rpc_handler::account_representative () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -551,7 +549,7 @@ void rai::rpc_handler::account_representative_set () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -560,18 +558,18 @@ void rai::rpc_handler::account_representative_set () if (existing != node.wallets.items.end ()) { auto wallet (existing->second); - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) { - std::string representative_text (request.get ("representative")); + std::string representative_text (request.get ("representative")); rai::account representative; auto error (representative.decode_account (representative_text)); if (!error) { uint64_t work (0); - boost::optional work_text (request.get_optional ("work")); + boost::optional work_text (request.get_optional ("work")); if (work_text.is_initialized ()) { auto work_error (rai::from_string_hex (work_text.get (), work)); @@ -601,8 +599,7 @@ void rai::rpc_handler::account_representative_set () } } auto response_a (response); - wallet->change_async (account, representative, [response_a] (std::shared_ptr block) - { + wallet->change_async (account, representative, [response_a](std::shared_ptr block) { rai::block_hash hash (0); if (block != nullptr) { @@ -611,7 +608,8 @@ void rai::rpc_handler::account_representative_set () boost::property_tree::ptree response_l; response_l.put ("block", hash.to_string ()); response_a (response_l); - }, work == 0); + }, + work == 0); } } else @@ -629,14 +627,14 @@ void rai::rpc_handler::account_representative_set () void rai::rpc_handler::account_weight () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) { auto balance (node.weight (account)); boost::property_tree::ptree response_l; - response_l.put ("weight", balance.convert_to ()); + response_l.put ("weight", balance.convert_to ()); response (response_l); } else @@ -649,7 +647,7 @@ void rai::rpc_handler::accounts_balances () { boost::property_tree::ptree response_l; boost::property_tree::ptree balances; - for (auto &accounts : request.get_child ("accounts")) + for (auto & accounts : request.get_child ("accounts")) { std::string account_text = accounts.second.data (); rai::uint256_union account; @@ -658,8 +656,8 @@ void rai::rpc_handler::accounts_balances () { boost::property_tree::ptree entry; auto balance (node.balance_pending (account)); - entry.put ("balance", balance.first.convert_to ()); - entry.put ("pending", balance.second.convert_to ()); + entry.put ("balance", balance.first.convert_to ()); + entry.put ("pending", balance.second.convert_to ()); balances.push_back (std::make_pair (account.to_account (), entry)); } else @@ -675,13 +673,13 @@ void rai::rpc_handler::accounts_create () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) { uint64_t count; - std::string count_text (request.get ("count")); + std::string count_text (request.get ("count")); auto count_error (decode_unsigned (count_text, count)); if (!count_error && count != 0) { @@ -689,14 +687,14 @@ void rai::rpc_handler::accounts_create () if (existing != node.wallets.items.end ()) { bool generate_work (true); - boost::optional work (request.get_optional ("work")); + boost::optional work (request.get_optional ("work")); if (work.is_initialized ()) { generate_work = work.get (); } boost::property_tree::ptree response_l; boost::property_tree::ptree accounts; - for (auto i(0); accounts.size ()< count; ++i) + for (auto i (0); accounts.size () < count; ++i) { rai::account new_key (existing->second->deterministic_insert (generate_work)); if (!new_key.is_zero ()) @@ -735,7 +733,7 @@ void rai::rpc_handler::accounts_frontiers () boost::property_tree::ptree response_l; boost::property_tree::ptree frontiers; rai::transaction transaction (node.store.environment, nullptr, false); - for (auto &accounts : request.get_child("accounts")) + for (auto & accounts : request.get_child ("accounts")) { std::string account_text = accounts.second.data (); rai::uint256_union account; @@ -759,10 +757,10 @@ void rai::rpc_handler::accounts_frontiers () void rai::rpc_handler::accounts_pending () { - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); rai::uint128_union threshold (0); bool source (false); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -771,7 +769,7 @@ void rai::rpc_handler::accounts_pending () error_response (response, "Invalid count limit"); } } - boost::optional threshold_text (request.get_optional ("threshold")); + boost::optional threshold_text (request.get_optional ("threshold")); if (threshold_text.is_initialized ()) { auto error_threshold (threshold.decode_dec (threshold_text.get ())); @@ -780,7 +778,7 @@ void rai::rpc_handler::accounts_pending () error_response (response, "Bad threshold number"); } } - boost::optional source_optional (request.get_optional ("source")); + boost::optional source_optional (request.get_optional ("source")); if (source_optional.is_initialized ()) { source = source_optional.get (); @@ -788,7 +786,7 @@ void rai::rpc_handler::accounts_pending () boost::property_tree::ptree response_l; boost::property_tree::ptree pending; rai::transaction transaction (node.store.environment, nullptr, false); - for (auto &accounts : request.get_child("accounts")) + for (auto & accounts : request.get_child ("accounts")) { std::string account_text = accounts.second.data (); rai::uint256_union account; @@ -813,13 +811,13 @@ void rai::rpc_handler::accounts_pending () if (source) { boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().convert_to ()); + pending_tree.put ("amount", info.amount.number ().convert_to ()); pending_tree.put ("source", info.source.to_account ()); peers_l.add_child (key.hash.to_string (), pending_tree); } else { - peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); } } } @@ -843,13 +841,13 @@ void rai::rpc_handler::available_supply () auto burned_balance ((node.balance_pending (rai::account (0))).second); // Burning 0 account auto available (rai::genesis_amount - genesis_balance - landing_balance - faucet_balance - burned_balance); boost::property_tree::ptree response_l; - response_l.put ("available", available.convert_to ()); + response_l.put ("available", available.convert_to ()); response (response_l); } void rai::rpc_handler::block () { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -877,13 +875,13 @@ void rai::rpc_handler::block () void rai::rpc_handler::blocks () { - std::vector hashes; + std::vector hashes; boost::property_tree::ptree response_l; boost::property_tree::ptree blocks; rai::transaction transaction (node.store.environment, nullptr, false); - for (boost::property_tree::ptree::value_type &hashes : request.get_child("hashes")) + for (boost::property_tree::ptree::value_type & hashes : request.get_child ("hashes")) { - std::string hash_text = hashes.second.data(); + std::string hash_text = hashes.second.data (); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -912,24 +910,24 @@ void rai::rpc_handler::blocks () void rai::rpc_handler::blocks_info () { bool pending (false); - boost::optional pending_optional (request.get_optional ("pending")); + boost::optional pending_optional (request.get_optional ("pending")); if (pending_optional.is_initialized ()) { pending = pending_optional.get (); } bool source (false); - boost::optional source_optional (request.get_optional ("source")); + boost::optional source_optional (request.get_optional ("source")); if (source_optional.is_initialized ()) { source = source_optional.get (); } - std::vector hashes; + std::vector hashes; boost::property_tree::ptree response_l; boost::property_tree::ptree blocks; rai::transaction transaction (node.store.environment, nullptr, false); - for (boost::property_tree::ptree::value_type &hashes : request.get_child("hashes")) + for (boost::property_tree::ptree::value_type & hashes : request.get_child ("hashes")) { - std::string hash_text = hashes.second.data(); + std::string hash_text = hashes.second.data (); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -941,13 +939,13 @@ void rai::rpc_handler::blocks_info () auto account (node.ledger.account (transaction, hash)); entry.put ("block_account", account.to_account ()); auto amount (node.ledger.amount (transaction, hash)); - entry.put ("amount", amount.convert_to ()); + entry.put ("amount", amount.convert_to ()); std::string contents; block->serialize_json (contents); entry.put ("contents", contents); if (pending) { - auto block_l (dynamic_cast (block.get ())); + auto block_l (dynamic_cast (block.get ())); bool exists (false); if (block_l != nullptr) { @@ -959,13 +957,14 @@ void rai::rpc_handler::blocks_info () if (source) { rai::block_hash source_hash (block->source ()); - std::unique_ptr block_a (node.store.block_get (transaction, source_hash)); + std::unique_ptr block_a (node.store.block_get (transaction, source_hash)); if (block_a != nullptr) { auto source_account (node.ledger.account (transaction, source_hash)); entry.put ("source_account", source_account.to_account ()); } - else { + else + { entry.put ("source_account", "0"); } } @@ -987,7 +986,7 @@ void rai::rpc_handler::blocks_info () void rai::rpc_handler::block_account () { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::block_hash hash; if (!hash.decode_hex (hash_text)) { @@ -1031,14 +1030,13 @@ void rai::rpc_handler::block_count_type () response (response_l); } - void rai::rpc_handler::block_create () { if (rpc.config.enable_control) { - std::string type (request.get ("type")); + std::string type (request.get ("type")); rai::uint256_union wallet (0); - boost::optional wallet_text (request.get_optional ("wallet")); + boost::optional wallet_text (request.get_optional ("wallet")); if (wallet_text.is_initialized ()) { auto error (wallet.decode_hex (wallet_text.get ())); @@ -1048,7 +1046,7 @@ void rai::rpc_handler::block_create () } } rai::uint256_union account (0); - boost::optional account_text (request.get_optional ("account")); + boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { auto error_account (account.decode_account (account_text.get ())); @@ -1058,7 +1056,7 @@ void rai::rpc_handler::block_create () } } rai::uint256_union representative (0); - boost::optional representative_text (request.get_optional ("representative")); + boost::optional representative_text (request.get_optional ("representative")); if (representative_text.is_initialized ()) { auto error_representative (representative.decode_account (representative_text.get ())); @@ -1068,7 +1066,7 @@ void rai::rpc_handler::block_create () } } rai::uint256_union destination (0); - boost::optional destination_text (request.get_optional ("destination")); + boost::optional destination_text (request.get_optional ("destination")); if (destination_text.is_initialized ()) { auto error_destination (destination.decode_account (destination_text.get ())); @@ -1078,7 +1076,7 @@ void rai::rpc_handler::block_create () } } rai::block_hash source (0); - boost::optional source_text (request.get_optional ("source")); + boost::optional source_text (request.get_optional ("source")); if (source_text.is_initialized ()) { auto error_source (source.decode_hex (source_text.get ())); @@ -1088,7 +1086,7 @@ void rai::rpc_handler::block_create () } } rai::uint128_union amount (0); - boost::optional amount_text (request.get_optional ("amount")); + boost::optional amount_text (request.get_optional ("amount")); if (amount_text.is_initialized ()) { auto error_amount (amount.decode_dec (amount_text.get ())); @@ -1098,7 +1096,7 @@ void rai::rpc_handler::block_create () } } uint64_t work (0); - boost::optional work_text (request.get_optional ("work")); + boost::optional work_text (request.get_optional ("work")); if (work_text.is_initialized ()) { auto work_error (rai::from_string_hex (work_text.get (), work)); @@ -1142,7 +1140,7 @@ void rai::rpc_handler::block_create () error_response (response, "Wallet not found"); } } - boost::optional key_text (request.get_optional ("key")); + boost::optional key_text (request.get_optional ("key")); if (key_text.is_initialized ()) { auto error_key (prv.data.decode_hex (key_text.get ())); @@ -1151,7 +1149,7 @@ void rai::rpc_handler::block_create () error_response (response, "Bad private key"); } } - boost::optional previous_text (request.get_optional ("previous")); + boost::optional previous_text (request.get_optional ("previous")); if (previous_text.is_initialized ()) { auto error_previous (previous.decode_hex (previous_text.get ())); @@ -1160,7 +1158,7 @@ void rai::rpc_handler::block_create () error_response (response, "Invalid previous hash"); } } - boost::optional balance_text (request.get_optional ("balance")); + boost::optional balance_text (request.get_optional ("balance")); if (balance_text.is_initialized ()) { auto error_balance (balance.decode_dec (balance_text.get ())); @@ -1282,8 +1280,8 @@ void rai::rpc_handler::block_create () void rai::rpc_handler::successors () { - std::string block_text (request.get ("block")); - std::string count_text (request.get ("count")); + std::string block_text (request.get ("block")); + std::string count_text (request.get ("count")); rai::block_hash block; if (!block.decode_hex (block_text)) { @@ -1324,8 +1322,8 @@ void rai::rpc_handler::successors () void rai::rpc_handler::bootstrap () { - std::string address_text = request.get ("address"); - std::string port_text = request.get ("port"); + std::string address_text = request.get ("address"); + std::string port_text = request.get ("port"); boost::system::error_code ec; auto address (boost::asio::ip::address_v6::from_string (address_text, ec)); if (!ec) @@ -1359,8 +1357,8 @@ void rai::rpc_handler::bootstrap_any () void rai::rpc_handler::chain () { - std::string block_text (request.get ("block")); - std::string count_text (request.get ("count")); + std::string block_text (request.get ("block")); + std::string count_text (request.get ("count")); rai::block_hash block; if (!block.decode_hex (block_text)) { @@ -1401,7 +1399,7 @@ void rai::rpc_handler::chain () void rai::rpc_handler::delegators () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -1414,7 +1412,8 @@ void rai::rpc_handler::delegators () rai::account_info info (i->second); auto block (node.store.block_get (transaction, info.rep_block)); assert (block != nullptr); - if (block->representative() == account) { + if (block->representative () == account) + { std::string balance; rai::uint128_union (info.balance).encode_dec (balance); delegators.put (rai::account (i->first.uint256 ()).to_account (), balance); @@ -1431,7 +1430,7 @@ void rai::rpc_handler::delegators () void rai::rpc_handler::delegators_count () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -1443,7 +1442,8 @@ void rai::rpc_handler::delegators_count () rai::account_info info (i->second); auto block (node.store.block_get (transaction, info.rep_block)); assert (block != nullptr); - if (block->representative() == account) { + if (block->representative () == account) + { ++count; } } @@ -1459,8 +1459,8 @@ void rai::rpc_handler::delegators_count () void rai::rpc_handler::deterministic_key () { - std::string seed_text (request.get ("seed")); - std::string index_text (request.get ("index")); + std::string seed_text (request.get ("seed")); + std::string index_text (request.get ("index")); rai::raw_key seed; auto error (seed.data.decode_hex (seed_text)); if (!error) @@ -1473,7 +1473,7 @@ void rai::rpc_handler::deterministic_key () blake2b_state hash; blake2b_init (&hash, prv.bytes.size ()); blake2b_update (&hash, seed.data.bytes.data (), seed.data.bytes.size ()); - blake2b_update (&hash, reinterpret_cast (&index.dwords [7]), sizeof (uint32_t)); + blake2b_update (&hash, reinterpret_cast (&index.dwords[7]), sizeof (uint32_t)); blake2b_final (&hash, prv.bytes.data (), prv.bytes.size ()); boost::property_tree::ptree response_l; rai::uint256_union pub; @@ -1496,8 +1496,8 @@ void rai::rpc_handler::deterministic_key () void rai::rpc_handler::frontiers () { - std::string account_text (request.get ("account")); - std::string count_text (request.get ("count")); + std::string account_text (request.get ("account")); + std::string count_text (request.get ("count")); rai::account start; if (!start.decode_account (account_text)) { @@ -1551,7 +1551,7 @@ public: tree.put ("type", "send"); auto account (block_a.hashables.destination.to_account ()); tree.put ("account", account); - auto amount (handler.node.ledger.amount (transaction, hash).convert_to ()); + auto amount (handler.node.ledger.amount (transaction, hash).convert_to ()); tree.put ("amount", amount); } void receive_block (rai::receive_block const & block_a) @@ -1559,7 +1559,7 @@ public: tree.put ("type", "receive"); auto account (handler.node.ledger.account (transaction, block_a.hashables.source).to_account ()); tree.put ("account", account); - auto amount (handler.node.ledger.amount (transaction, hash).convert_to ()); + auto amount (handler.node.ledger.amount (transaction, hash).convert_to ()); tree.put ("amount", amount); } void open_block (rai::open_block const & block_a) @@ -1569,12 +1569,12 @@ public: if (block_a.hashables.source != rai::genesis_account) { tree.put ("account", handler.node.ledger.account (transaction, block_a.hashables.source).to_account ()); - tree.put ("amount", handler.node.ledger.amount (transaction, hash).convert_to ()); + tree.put ("amount", handler.node.ledger.amount (transaction, hash).convert_to ()); } else { tree.put ("account", rai::genesis_account.to_account ()); - tree.put ("amount", rai::genesis_amount.convert_to ()); + tree.put ("amount", rai::genesis_amount.convert_to ()); } } void change_block (rai::change_block const &) @@ -1590,8 +1590,8 @@ public: void rai::rpc_handler::history () { - std::string hash_text (request.get ("hash")); - std::string count_text (request.get ("count")); + std::string hash_text (request.get ("hash")); + std::string count_text (request.get ("count")); rai::block_hash hash; if (!hash.decode_hex (hash_text)) { @@ -1632,8 +1632,8 @@ void rai::rpc_handler::history () void rai::rpc_handler::account_history () { - std::string account_text (request.get ("account")); - std::string count_text (request.get ("count")); + std::string account_text (request.get ("account")); + std::string count_text (request.get ("count")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) @@ -1678,8 +1678,8 @@ void rai::rpc_handler::keepalive () { if (rpc.config.enable_control) { - std::string address_text (request.get ("address")); - std::string port_text (request.get ("port")); + std::string address_text (request.get ("address")); + std::string port_text (request.get ("port")); uint16_t port; if (!rai::parse_port (port_text, port)) { @@ -1710,7 +1710,7 @@ void rai::rpc_handler::key_create () void rai::rpc_handler::key_expand () { - std::string key_text (request.get ("key")); + std::string key_text (request.get ("key")); rai::uint256_union prv; auto error (prv.decode_hex (key_text)); if (!error) @@ -1734,9 +1734,9 @@ void rai::rpc_handler::ledger () if (rpc.config.enable_control) { rai::account start (0); - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); bool sorting (false); - boost::optional account_text (request.get_optional ("account")); + boost::optional account_text (request.get_optional ("account")); if (account_text.is_initialized ()) { auto error (start.decode_account (account_text.get ())); @@ -1745,7 +1745,7 @@ void rai::rpc_handler::ledger () error_response (response, "Invalid starting account"); } } - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error_count (decode_unsigned (count_text.get (), count)); @@ -1754,25 +1754,25 @@ void rai::rpc_handler::ledger () error_response (response, "Invalid count limit"); } } - boost::optional sorting_optional (request.get_optional ("sorting")); + boost::optional sorting_optional (request.get_optional ("sorting")); if (sorting_optional.is_initialized ()) { sorting = sorting_optional.get (); } bool representative (false); - boost::optional representative_optional (request.get_optional ("representative")); + boost::optional representative_optional (request.get_optional ("representative")); if (representative_optional.is_initialized ()) { representative = representative_optional.get (); } bool weight (false); - boost::optional weight_optional (request.get_optional ("weight")); + boost::optional weight_optional (request.get_optional ("weight")); if (weight_optional.is_initialized ()) { weight = weight_optional.get (); } bool pending (false); - boost::optional pending_optional (request.get_optional ("pending")); + boost::optional pending_optional (request.get_optional ("pending")); if (pending_optional.is_initialized ()) { pending = pending_optional.get (); @@ -1805,19 +1805,19 @@ void rai::rpc_handler::ledger () if (weight) { auto account_weight (node.ledger.weight (transaction, account)); - response_l.put ("weight", account_weight.convert_to ()); + response_l.put ("weight", account_weight.convert_to ()); } if (pending) { auto account_pending (node.ledger.account_pending (transaction, account)); - response_l.put ("pending", account_pending.convert_to ()); + response_l.put ("pending", account_pending.convert_to ()); } accounts.push_back (std::make_pair (account.to_account (), response_l)); } } else // Sorting { - std::vector > ledger_l; + std::vector> ledger_l; for (auto i (node.store.latest_begin (transaction, start)), n (node.store.latest_end ()); i != n; ++i) { rai::uint128_union balance (rai::account_info (i->second).balance); @@ -1847,12 +1847,12 @@ void rai::rpc_handler::ledger () if (weight) { auto account_weight (node.ledger.weight (transaction, account)); - response_l.put ("weight", account_weight.convert_to ()); + response_l.put ("weight", account_weight.convert_to ()); } if (pending) { auto account_pending (node.ledger.account_pending (transaction, account)); - response_l.put ("pending", account_pending.convert_to ()); + response_l.put ("pending", account_pending.convert_to ()); } accounts.push_back (std::make_pair (account.to_account (), response_l)); } @@ -1868,13 +1868,13 @@ void rai::rpc_handler::ledger () void rai::rpc_handler::mrai_from_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { auto result (amount.number () / rai::Mxrb_ratio); boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -1885,7 +1885,7 @@ void rai::rpc_handler::mrai_from_raw () void rai::rpc_handler::mrai_to_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { @@ -1893,7 +1893,7 @@ void rai::rpc_handler::mrai_to_raw () if (result > amount.number ()) { boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -1909,13 +1909,13 @@ void rai::rpc_handler::mrai_to_raw () void rai::rpc_handler::krai_from_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { auto result (amount.number () / rai::kxrb_ratio); boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -1926,7 +1926,7 @@ void rai::rpc_handler::krai_from_raw () void rai::rpc_handler::krai_to_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { @@ -1934,7 +1934,7 @@ void rai::rpc_handler::krai_to_raw () if (result > amount.number ()) { boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -1952,7 +1952,7 @@ void rai::rpc_handler::password_change () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -1962,7 +1962,7 @@ void rai::rpc_handler::password_change () { rai::transaction transaction (node.store.environment, nullptr, true); boost::property_tree::ptree response_l; - std::string password_text (request.get ("password")); + std::string password_text (request.get ("password")); auto error (existing->second->store.rekey (transaction, password_text)); response_l.put ("changed", error ? "0" : "1"); response (response_l); @@ -1985,7 +1985,7 @@ void rai::rpc_handler::password_change () void rai::rpc_handler::password_enter () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -1994,7 +1994,7 @@ void rai::rpc_handler::password_enter () if (existing != node.wallets.items.end ()) { boost::property_tree::ptree response_l; - std::string password_text (request.get ("password")); + std::string password_text (request.get ("password")); auto error (existing->second->enter_password (password_text)); response_l.put ("valid", error ? "0" : "1"); response (response_l); @@ -2012,7 +2012,7 @@ void rai::rpc_handler::password_enter () void rai::rpc_handler::password_valid (bool wallet_locked = false) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -2027,7 +2027,7 @@ void rai::rpc_handler::password_valid (bool wallet_locked = false) { response_l.put ("valid", valid ? "1" : "0"); } - else + else { response_l.put ("locked", valid ? "0" : "1"); } @@ -2061,14 +2061,14 @@ void rai::rpc_handler::peers () void rai::rpc_handler::pending () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; - if (!account.decode_account(account_text)) + if (!account.decode_account (account_text)) { - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); rai::uint128_union threshold (0); bool source (false); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -2077,7 +2077,7 @@ void rai::rpc_handler::pending () error_response (response, "Invalid count limit"); } } - boost::optional threshold_text (request.get_optional ("threshold")); + boost::optional threshold_text (request.get_optional ("threshold")); if (threshold_text.is_initialized ()) { auto error_threshold (threshold.decode_dec (threshold_text.get ())); @@ -2086,7 +2086,7 @@ void rai::rpc_handler::pending () error_response (response, "Bad threshold number"); } } - boost::optional source_optional (request.get_optional ("source")); + boost::optional source_optional (request.get_optional ("source")); if (source_optional.is_initialized ()) { source = source_optional.get (); @@ -2096,7 +2096,7 @@ void rai::rpc_handler::pending () { rai::transaction transaction (node.store.environment, nullptr, false); rai::account end (account.number () + 1); - for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (node.store.pending_begin (transaction, rai::pending_key (end, 0))); i != n && peers_l.size ()< count; ++i) + for (auto i (node.store.pending_begin (transaction, rai::pending_key (account, 0))), n (node.store.pending_begin (transaction, rai::pending_key (end, 0))); i != n && peers_l.size () < count; ++i) { rai::pending_key key (i->first); if (threshold.is_zero () && !source) @@ -2113,13 +2113,13 @@ void rai::rpc_handler::pending () if (source) { boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().convert_to ()); + pending_tree.put ("amount", info.amount.number ().convert_to ()); pending_tree.put ("source", info.source.to_account ()); peers_l.add_child (key.hash.to_string (), pending_tree); } else { - peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); } } } @@ -2136,7 +2136,7 @@ void rai::rpc_handler::pending () void rai::rpc_handler::pending_exists () { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -2145,7 +2145,7 @@ void rai::rpc_handler::pending_exists () auto block (node.store.block_get (transaction, hash)); if (block != nullptr) { - auto block_l (dynamic_cast (block.get ())); + auto block_l (dynamic_cast (block.get ())); auto exists (false); if (block_l != nullptr) { @@ -2169,7 +2169,7 @@ void rai::rpc_handler::pending_exists () void rai::rpc_handler::payment_begin () { - std::string id_text (request.get ("wallet")); + std::string id_text (request.get ("wallet")); rai::uint256_union id; if (!id.decode_hex (id_text)) { @@ -2177,7 +2177,7 @@ void rai::rpc_handler::payment_begin () if (existing != node.wallets.items.end ()) { rai::transaction transaction (node.store.environment, nullptr, true); - std::shared_ptr wallet (existing->second); + std::shared_ptr wallet (existing->second); if (wallet->store.valid_password (transaction)) { rai::account account (0); @@ -2237,7 +2237,7 @@ void rai::rpc_handler::payment_begin () void rai::rpc_handler::payment_init () { - std::string id_text (request.get ("wallet")); + std::string id_text (request.get ("wallet")); rai::uint256_union id; if (!id.decode_hex (id_text)) { @@ -2275,8 +2275,8 @@ void rai::rpc_handler::payment_init () void rai::rpc_handler::payment_end () { - std::string id_text (request.get ("wallet")); - std::string account_text (request.get ("account")); + std::string id_text (request.get ("wallet")); + std::string account_text (request.get ("account")); rai::uint256_union id; if (!id.decode_hex (id_text)) { @@ -2325,9 +2325,9 @@ void rai::rpc_handler::payment_end () void rai::rpc_handler::payment_wait () { - std::string account_text (request.get ("account")); - std::string amount_text (request.get ("amount")); - std::string timeout_text (request.get ("timeout")); + std::string account_text (request.get ("account")); + std::string amount_text (request.get ("amount")); + std::string timeout_text (request.get ("timeout")); rai::uint256_union account; if (!account.decode_account (account_text)) { @@ -2338,11 +2338,11 @@ void rai::rpc_handler::payment_wait () if (!decode_unsigned (timeout_text, timeout)) { { - auto observer (std::make_shared (response, rpc, account, amount)); + auto observer (std::make_shared (response, rpc, account, amount)); observer->start (timeout); - std::lock_guard lock (rpc.mutex); + std::lock_guard lock (rpc.mutex); assert (rpc.payment_observers.find (account) == rpc.payment_observers.end ()); - rpc.payment_observers [account] = observer; + rpc.payment_observers[account] = observer; } rpc.observer_action (account); } @@ -2364,7 +2364,7 @@ void rai::rpc_handler::payment_wait () void rai::rpc_handler::process () { - std::string block_text (request.get ("block")); + std::string block_text (request.get ("block")); boost::property_tree::ptree block_l; std::stringstream block_stream (block_text); boost::property_tree::read_json (block_stream, block_l); @@ -2376,7 +2376,7 @@ void rai::rpc_handler::process () auto hash (block->hash ()); node.block_arrival.add (hash); rai::process_return result; - std::shared_ptr block_a (std::move (block)); + std::shared_ptr block_a (std::move (block)); { rai::transaction transaction (node.store.environment, nullptr, true); result = node.block_processor.process_receive_one (transaction, block_a); @@ -2456,13 +2456,13 @@ void rai::rpc_handler::process () void rai::rpc_handler::rai_from_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { auto result (amount.number () / rai::xrb_ratio); boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -2473,7 +2473,7 @@ void rai::rpc_handler::rai_from_raw () void rai::rpc_handler::rai_to_raw () { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { @@ -2481,7 +2481,7 @@ void rai::rpc_handler::rai_to_raw () if (result > amount.number ()) { boost::property_tree::ptree response_l; - response_l.put ("amount", result.convert_to ()); + response_l.put ("amount", result.convert_to ()); response (response_l); } else @@ -2499,7 +2499,7 @@ void rai::rpc_handler::receive () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -2507,7 +2507,7 @@ void rai::rpc_handler::receive () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -2516,7 +2516,7 @@ void rai::rpc_handler::receive () auto account_check (existing->second->store.find (transaction, account)); if (account_check != existing->second->store.end ()) { - std::string hash_text (request.get ("block")); + std::string hash_text (request.get ("block")); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -2527,7 +2527,7 @@ void rai::rpc_handler::receive () if (node.store.pending_exists (transaction, rai::pending_key (account, hash))) { uint64_t work (0); - boost::optional work_text (request.get_optional ("work")); + boost::optional work_text (request.get_optional ("work")); if (work_text.is_initialized ()) { auto work_error (rai::from_string_hex (work_text.get (), work)); @@ -2559,8 +2559,7 @@ void rai::rpc_handler::receive () } } auto response_a (response); - existing->second->receive_async (std::move (block), account, rai::genesis_amount, [response_a] (std::shared_ptr block_a) - { + existing->second->receive_async (std::move (block), account, rai::genesis_amount, [response_a](std::shared_ptr block_a) { rai::uint256_union hash_a (0); if (block_a != nullptr) { @@ -2569,7 +2568,8 @@ void rai::rpc_handler::receive () boost::property_tree::ptree response_l; response_l.put ("block", hash_a.to_string ()); response_a (response_l); - }, work == 0); + }, + work == 0); } else { @@ -2630,7 +2630,7 @@ void rai::rpc_handler::receive_minimum_set () { if (rpc.config.enable_control) { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::uint128_union amount; if (!amount.decode_dec (amount_text)) { @@ -2652,9 +2652,9 @@ void rai::rpc_handler::receive_minimum_set () void rai::rpc_handler::representatives () { - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); bool sorting (false); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -2663,7 +2663,7 @@ void rai::rpc_handler::representatives () error_response (response, "Invalid count limit"); } } - boost::optional sorting_optional (request.get_optional ("sorting")); + boost::optional sorting_optional (request.get_optional ("sorting")); if (sorting_optional.is_initialized ()) { sorting = sorting_optional.get (); @@ -2675,17 +2675,17 @@ void rai::rpc_handler::representatives () { for (auto i (node.store.representation_begin (transaction)), n (node.store.representation_end ()); i != n && representatives.size () < count; ++i) { - rai::account account(i->first.uint256 ()); + rai::account account (i->first.uint256 ()); auto amount (node.store.representation_get (transaction, account)); - representatives.put (account.to_account (), amount.convert_to ()); + representatives.put (account.to_account (), amount.convert_to ()); } } else // Sorting { - std::vector > representation; + std::vector> representation; for (auto i (node.store.representation_begin (transaction)), n (node.store.representation_end ()); i != n; ++i) { - rai::account account(i->first.uint256 ()); + rai::account account (i->first.uint256 ()); auto amount (node.store.representation_get (transaction, account)); representation.push_back (std::make_pair (amount, account.to_account ())); } @@ -2693,7 +2693,7 @@ void rai::rpc_handler::representatives () std::reverse (representation.begin (), representation.end ()); for (auto i (representation.begin ()), n (representation.end ()); i != n && representatives.size () < count; ++i) { - representatives.put (i->second, (i->first).number ().convert_to ()); + representatives.put (i->second, (i->first).number ().convert_to ()); } } response_l.add_child ("representatives", representatives); @@ -2705,7 +2705,7 @@ void rai::rpc_handler::republish () uint64_t count (1024U); uint64_t sources (0); uint64_t destinations (0); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -2714,7 +2714,7 @@ void rai::rpc_handler::republish () error_response (response, "Invalid count limit"); } } - boost::optional sources_text (request.get_optional ("sources")); + boost::optional sources_text (request.get_optional ("sources")); if (sources_text.is_initialized ()) { auto sources_error (decode_unsigned (sources_text.get (), sources)); @@ -2723,7 +2723,7 @@ void rai::rpc_handler::republish () error_response (response, "Invalid sources number"); } } - boost::optional destinations_text (request.get_optional ("destinations")); + boost::optional destinations_text (request.get_optional ("destinations")); if (destinations_text.is_initialized ()) { auto destinations_error (decode_unsigned (destinations_text.get (), destinations)); @@ -2732,7 +2732,7 @@ void rai::rpc_handler::republish () error_response (response, "Invalid destinations number"); } } - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -2749,8 +2749,8 @@ void rai::rpc_handler::republish () if (sources != 0) // Republish source chain { rai::block_hash source (block->source ()); - std::unique_ptr block_a (node.store.block_get (transaction, source)); - std::vector hashes; + std::unique_ptr block_a (node.store.block_get (transaction, source)); + std::vector hashes; while (block_a != nullptr && hashes.size () < sources) { hashes.push_back (source); @@ -2774,7 +2774,7 @@ void rai::rpc_handler::republish () if (destinations != 0) // Republish destination chain { auto block_b (node.store.block_get (transaction, hash)); - auto block_s (dynamic_cast (block_b.get ())); + auto block_s (dynamic_cast (block_b.get ())); if (block_s != nullptr) { auto destination (block_s->hashables.destination); @@ -2782,9 +2782,9 @@ void rai::rpc_handler::republish () if (!exists) { rai::block_hash previous (node.ledger.latest (transaction, destination)); - std::unique_ptr block_d (node.store.block_get (transaction, previous)); + std::unique_ptr block_d (node.store.block_get (transaction, previous)); rai::block_hash source; - std::vector hashes; + std::vector hashes; while (block_d != nullptr && hash != source) { hashes.push_back (previous); @@ -2795,7 +2795,7 @@ void rai::rpc_handler::republish () std::reverse (hashes.begin (), hashes.end ()); if (hashes.size () > destinations) { - hashes.resize(destinations); + hashes.resize (destinations); } for (auto & hash_l : hashes) { @@ -2829,7 +2829,7 @@ void rai::rpc_handler::search_pending () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -2873,7 +2873,7 @@ void rai::rpc_handler::send () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -2881,23 +2881,23 @@ void rai::rpc_handler::send () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - std::string source_text (request.get ("source")); + std::string source_text (request.get ("source")); rai::account source; auto error (source.decode_account (source_text)); if (!error) { - std::string destination_text (request.get ("destination")); + std::string destination_text (request.get ("destination")); rai::account destination; auto error (destination.decode_account (destination_text)); if (!error) { - std::string amount_text (request.get ("amount")); + std::string amount_text (request.get ("amount")); rai::amount amount; auto error (amount.decode_dec (amount_text)); if (!error) { uint64_t work (0); - boost::optional work_text (request.get_optional ("work")); + boost::optional work_text (request.get_optional ("work")); if (work_text.is_initialized ()) { auto work_error (rai::from_string_hex (work_text.get (), work)); @@ -2912,7 +2912,7 @@ void rai::rpc_handler::send () rai::account_info info; if (!node.store.account_get (transaction, source, info)) { - balance = (info.balance).number(); + balance = (info.balance).number (); } else { @@ -2934,8 +2934,7 @@ void rai::rpc_handler::send () { auto rpc_l (shared_from_this ()); auto response_a (response); - existing->second->send_async (source, destination, amount.number (), [response_a] (std::shared_ptr block_a) - { + existing->second->send_async (source, destination, amount.number (), [response_a](std::shared_ptr block_a) { rai::uint256_union hash (0); if (block_a != nullptr) { @@ -2944,7 +2943,8 @@ void rai::rpc_handler::send () boost::property_tree::ptree response_l; response_l.put ("block", hash.to_string ()); response_a (response_l); - }, work == 0); + }, + work == 0); } else { @@ -3000,8 +3000,8 @@ void rai::rpc_handler::stop () void rai::rpc_handler::unchecked () { - uint64_t count (std::numeric_limits ::max ()); - boost::optional count_text (request.get_optional ("count")); + uint64_t count (std::numeric_limits::max ()); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -3015,11 +3015,11 @@ void rai::rpc_handler::unchecked () rai::transaction transaction (node.store.environment, nullptr, false); for (auto i (node.store.unchecked_begin (transaction)), n (node.store.unchecked_end ()); i != n && unchecked.size () < count; ++i) { - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); auto block (rai::deserialize_block (stream)); std::string contents; block->serialize_json (contents); - unchecked.put(block->hash ().to_string (), contents); + unchecked.put (block->hash ().to_string (), contents); } response_l.add_child ("blocks", unchecked); response (response_l); @@ -3043,7 +3043,7 @@ void rai::rpc_handler::unchecked_clear () void rai::rpc_handler::unchecked_get () { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::uint256_union hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -3052,7 +3052,7 @@ void rai::rpc_handler::unchecked_get () rai::transaction transaction (node.store.environment, nullptr, false); for (auto i (node.store.unchecked_begin (transaction)), n (node.store.unchecked_end ()); i != n; ++i) { - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); auto block (rai::deserialize_block (stream)); if (block->hash () == hash) { @@ -3079,9 +3079,9 @@ void rai::rpc_handler::unchecked_get () void rai::rpc_handler::unchecked_keys () { - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); rai::uint256_union key (0); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -3090,7 +3090,7 @@ void rai::rpc_handler::unchecked_keys () error_response (response, "Invalid count limit"); } } - boost::optional hash_text (request.get_optional ("key")); + boost::optional hash_text (request.get_optional ("key")); if (hash_text.is_initialized ()) { auto error_hash (key.decode_hex (hash_text.get ())); @@ -3105,7 +3105,7 @@ void rai::rpc_handler::unchecked_keys () for (auto i (node.store.unchecked_begin (transaction, key)), n (node.store.unchecked_end ()); i != n && unchecked.size () < count; ++i) { boost::property_tree::ptree entry; - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); auto block (rai::deserialize_block (stream)); std::string contents; block->serialize_json (contents); @@ -3129,7 +3129,7 @@ void rai::rpc_handler::version () void rai::rpc_handler::validate_account_number () { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::uint256_union account; auto error (account.decode_account (account_text)); boost::property_tree::ptree response_l; @@ -3141,8 +3141,8 @@ void rai::rpc_handler::wallet_add () { if (rpc.config.enable_control) { - std::string key_text (request.get ("key")); - std::string wallet_text (request.get ("wallet")); + std::string key_text (request.get ("key")); + std::string wallet_text (request.get ("wallet")); rai::raw_key key; auto error (key.data.decode_hex (key_text)); if (!error) @@ -3155,7 +3155,7 @@ void rai::rpc_handler::wallet_add () if (existing != node.wallets.items.end ()) { bool generate_work (true); - boost::optional work (request.get_optional ("work")); + boost::optional work (request.get_optional ("work")); if (work.is_initialized ()) { generate_work = work.get (); @@ -3195,7 +3195,7 @@ void rai::rpc_handler::wallet_add () void rai::rpc_handler::wallet_balance_total () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3208,13 +3208,13 @@ void rai::rpc_handler::wallet_balance_total () rai::transaction transaction (node.store.environment, nullptr, false); for (auto i (existing->second->store.begin (transaction)), n (existing->second->store.end ()); i != n; ++i) { - rai::account account(i->first.uint256 ()); + rai::account account (i->first.uint256 ()); balance = balance + node.ledger.account_balance (transaction, account); pending = pending + node.ledger.account_pending (transaction, account); } boost::property_tree::ptree response_l; - response_l.put ("balance", balance.convert_to ()); - response_l.put ("pending", pending.convert_to ()); + response_l.put ("balance", balance.convert_to ()); + response_l.put ("pending", pending.convert_to ()); response (response_l); } else @@ -3230,13 +3230,13 @@ void rai::rpc_handler::wallet_balance_total () void rai::rpc_handler::wallet_balances () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) { rai::uint128_union threshold (0); - boost::optional threshold_text (request.get_optional ("threshold")); + boost::optional threshold_text (request.get_optional ("threshold")); if (threshold_text.is_initialized ()) { auto error_threshold (threshold.decode_dec (threshold_text.get ())); @@ -3253,14 +3253,14 @@ void rai::rpc_handler::wallet_balances () rai::transaction transaction (node.store.environment, nullptr, false); for (auto i (existing->second->store.begin (transaction)), n (existing->second->store.end ()); i != n; ++i) { - rai::account account(i->first.uint256 ()); + rai::account account (i->first.uint256 ()); rai::uint128_t balance = node.ledger.account_balance (transaction, account); if (threshold.is_zero ()) { boost::property_tree::ptree entry; rai::uint128_t pending = node.ledger.account_pending (transaction, account); - entry.put ("balance", balance.convert_to ()); - entry.put ("pending", pending.convert_to ()); + entry.put ("balance", balance.convert_to ()); + entry.put ("pending", pending.convert_to ()); balances.push_back (std::make_pair (account.to_account (), entry)); } else @@ -3269,8 +3269,8 @@ void rai::rpc_handler::wallet_balances () { boost::property_tree::ptree entry; rai::uint128_t pending = node.ledger.account_pending (transaction, account); - entry.put ("balance", balance.convert_to ()); - entry.put ("pending", pending.convert_to ()); + entry.put ("balance", balance.convert_to ()); + entry.put ("pending", pending.convert_to ()); balances.push_back (std::make_pair (account.to_account (), entry)); } } @@ -3293,8 +3293,8 @@ void rai::rpc_handler::wallet_change_seed () { if (rpc.config.enable_control) { - std::string seed_text (request.get ("seed")); - std::string wallet_text (request.get ("wallet")); + std::string seed_text (request.get ("seed")); + std::string wallet_text (request.get ("wallet")); rai::raw_key seed; auto error (seed.data.decode_hex (seed_text)); if (!error) @@ -3342,8 +3342,8 @@ void rai::rpc_handler::wallet_change_seed () void rai::rpc_handler::wallet_contains () { - std::string account_text (request.get ("account")); - std::string wallet_text (request.get ("wallet")); + std::string account_text (request.get ("account")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union account; auto error (account.decode_account (account_text)); if (!error) @@ -3397,7 +3397,7 @@ void rai::rpc_handler::wallet_destroy () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3427,7 +3427,7 @@ void rai::rpc_handler::wallet_destroy () void rai::rpc_handler::wallet_export () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3455,7 +3455,7 @@ void rai::rpc_handler::wallet_export () void rai::rpc_handler::wallet_frontiers () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3491,7 +3491,7 @@ void rai::rpc_handler::wallet_frontiers () void rai::rpc_handler::wallet_key_valid () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3520,7 +3520,7 @@ void rai::rpc_handler::wallet_lock () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3553,7 +3553,7 @@ void rai::rpc_handler::wallet_lock () void rai::rpc_handler::wallet_pending () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3561,10 +3561,10 @@ void rai::rpc_handler::wallet_pending () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - uint64_t count (std::numeric_limits ::max ()); + uint64_t count (std::numeric_limits::max ()); rai::uint128_union threshold (0); bool source (false); - boost::optional count_text (request.get_optional ("count")); + boost::optional count_text (request.get_optional ("count")); if (count_text.is_initialized ()) { auto error (decode_unsigned (count_text.get (), count)); @@ -3573,7 +3573,7 @@ void rai::rpc_handler::wallet_pending () error_response (response, "Invalid count limit"); } } - boost::optional threshold_text (request.get_optional ("threshold")); + boost::optional threshold_text (request.get_optional ("threshold")); if (threshold_text.is_initialized ()) { auto error_threshold (threshold.decode_dec (threshold_text.get ())); @@ -3582,7 +3582,7 @@ void rai::rpc_handler::wallet_pending () error_response (response, "Bad threshold number"); } } - boost::optional source_optional (request.get_optional ("source")); + boost::optional source_optional (request.get_optional ("source")); if (source_optional.is_initialized ()) { source = source_optional.get (); @@ -3595,7 +3595,7 @@ void rai::rpc_handler::wallet_pending () rai::account account (i->first.uint256 ()); boost::property_tree::ptree peers_l; rai::account end (account.number () + 1); - for (auto ii (node.store.pending_begin (transaction, rai::pending_key (account, 0))), nn (node.store.pending_begin (transaction, rai::pending_key (end, 0))); ii != nn && peers_l.size ()< count; ++ii) + for (auto ii (node.store.pending_begin (transaction, rai::pending_key (account, 0))), nn (node.store.pending_begin (transaction, rai::pending_key (end, 0))); ii != nn && peers_l.size () < count; ++ii) { rai::pending_key key (ii->first); if (threshold.is_zero () && !source) @@ -3612,13 +3612,13 @@ void rai::rpc_handler::wallet_pending () if (source) { boost::property_tree::ptree pending_tree; - pending_tree.put ("amount", info.amount.number ().convert_to ()); + pending_tree.put ("amount", info.amount.number ().convert_to ()); pending_tree.put ("source", info.source.to_account ()); peers_l.add_child (key.hash.to_string (), pending_tree); } else { - peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); + peers_l.put (key.hash.to_string (), info.amount.number ().convert_to ()); } } } @@ -3644,7 +3644,7 @@ void rai::rpc_handler::wallet_pending () void rai::rpc_handler::wallet_representative () { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3672,7 +3672,7 @@ void rai::rpc_handler::wallet_representative_set () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3680,7 +3680,7 @@ void rai::rpc_handler::wallet_representative_set () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - std::string representative_text (request.get ("representative")); + std::string representative_text (request.get ("representative")); rai::account representative; auto error (representative.decode_account (representative_text)); if (!error) @@ -3716,7 +3716,7 @@ void rai::rpc_handler::wallet_republish () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3725,7 +3725,7 @@ void rai::rpc_handler::wallet_republish () if (existing != node.wallets.items.end ()) { uint64_t count; - std::string count_text (request.get ("count")); + std::string count_text (request.get ("count")); auto error (decode_unsigned (count_text, count)); if (!error) { @@ -3736,19 +3736,20 @@ void rai::rpc_handler::wallet_republish () { rai::account account (i->first.uint256 ()); auto latest (node.ledger.latest (transaction, account)); - std::unique_ptr block; - std::vector hashes; + std::unique_ptr block; + std::vector hashes; while (!latest.is_zero () && hashes.size () < count) { hashes.push_back (latest); block = node.store.block_get (transaction, latest); latest = block->previous (); } - std::reverse (hashes.begin (), hashes.end ()); + std::reverse (hashes.begin (), hashes.end ()); for (auto & hash : hashes) { block = node.store.block_get (transaction, hash); - node.network.republish_block (transaction, std::move (block));; + node.network.republish_block (transaction, std::move (block)); + ; boost::property_tree::ptree entry; entry.put ("", hash.to_string ()); blocks.push_back (std::make_pair ("", entry)); @@ -3782,7 +3783,7 @@ void rai::rpc_handler::wallet_work_get () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3823,14 +3824,13 @@ void rai::rpc_handler::work_generate () { if (rpc.config.enable_control) { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::block_hash hash; auto error (hash.decode_hex (hash_text)); if (!error) { auto rpc_l (shared_from_this ()); - node.work.generate (hash, [rpc_l] (boost::optional const & work_a) - { + node.work.generate (hash, [rpc_l](boost::optional const & work_a) { if (work_a) { boost::property_tree::ptree response_l; @@ -3858,7 +3858,7 @@ void rai::rpc_handler::work_cancel () { if (rpc.config.enable_control) { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::block_hash hash; auto error (hash.decode_hex (hash_text)); if (!error) @@ -3882,7 +3882,7 @@ void rai::rpc_handler::work_get () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3890,7 +3890,7 @@ void rai::rpc_handler::work_get () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -3935,7 +3935,7 @@ void rai::rpc_handler::work_set () { if (rpc.config.enable_control) { - std::string wallet_text (request.get ("wallet")); + std::string wallet_text (request.get ("wallet")); rai::uint256_union wallet; auto error (wallet.decode_hex (wallet_text)); if (!error) @@ -3943,7 +3943,7 @@ void rai::rpc_handler::work_set () auto existing (node.wallets.items.find (wallet)); if (existing != node.wallets.items.end ()) { - std::string account_text (request.get ("account")); + std::string account_text (request.get ("account")); rai::account account; auto error (account.decode_account (account_text)); if (!error) @@ -3952,7 +3952,7 @@ void rai::rpc_handler::work_set () auto account_check (existing->second->store.find (transaction, account)); if (account_check != existing->second->store.end ()) { - std::string work_text (request.get ("work")); + std::string work_text (request.get ("work")); uint64_t work; auto work_error (rai::from_string_hex (work_text, work)); if (!work_error) @@ -3995,12 +3995,12 @@ void rai::rpc_handler::work_set () void rai::rpc_handler::work_validate () { - std::string hash_text (request.get ("hash")); + std::string hash_text (request.get ("hash")); rai::block_hash hash; auto error (hash.decode_hex (hash_text)); if (!error) { - std::string work_text (request.get ("work")); + std::string work_text (request.get ("work")); uint64_t work; auto work_error (rai::from_string_hex (work_text, work)); if (!work_error) @@ -4025,8 +4025,8 @@ void rai::rpc_handler::work_peer_add () { if (rpc.config.enable_control) { - std::string address_text = request.get ("address"); - std::string port_text = request.get ("port"); + std::string address_text = request.get ("address"); + std::string port_text = request.get ("port"); boost::system::error_code ec; auto address (boost::asio::ip::address_v6::from_string (address_text, ec)); if (!ec) @@ -4048,7 +4048,7 @@ void rai::rpc_handler::work_peer_add () { error_response (response, "Invalid address"); } - } + } else { error_response (response, "RPC control is disabled"); @@ -4101,16 +4101,13 @@ socket (node_a.service) void rai::rpc_connection::parse_connection () { auto this_l (shared_from_this ()); - boost::beast::http::async_read (socket, buffer, request, [this_l] (boost::system::error_code const & ec, size_t bytes_transferred) - { + boost::beast::http::async_read (socket, buffer, request, [this_l](boost::system::error_code const & ec, size_t bytes_transferred) { if (!ec) { - this_l->node->background ([this_l] () - { + this_l->node->background ([this_l]() { auto start (std::chrono::system_clock::now ()); - auto version (this_l->request.version()); - auto response_handler ([this_l, version, start] (boost::property_tree::ptree const & tree_a) - { + auto version (this_l->request.version ()); + auto response_handler ([this_l, version, start](boost::property_tree::ptree const & tree_a) { std::stringstream ostream; boost::property_tree::write_json (ostream, tree_a); ostream.flush (); @@ -4118,22 +4115,21 @@ void rai::rpc_connection::parse_connection () this_l->res.set ("Content-Type", "application/json"); this_l->res.set ("Access-Control-Allow-Origin", "*"); this_l->res.set ("Access-Control-Allow-Headers", "Accept, Accept-Language, Content-Language, Content-Type"); - this_l->res.result(boost::beast::http::status::ok); - this_l->res.body() = body; + this_l->res.result (boost::beast::http::status::ok); + this_l->res.body () = body; this_l->res.version (version); - this_l->res.prepare_payload(); + this_l->res.prepare_payload (); //boost::beast::http::prepare (this_l->res); - boost::beast::http::async_write (this_l->socket, this_l->res, [this_l] (boost::system::error_code const & ec, size_t bytes_transferred) - { + boost::beast::http::async_write (this_l->socket, this_l->res, [this_l](boost::system::error_code const & ec, size_t bytes_transferred) { }); if (this_l->node->config.logging.log_rpc ()) { - BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::system_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ()))); + BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast (std::chrono::system_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast (this_l.get ()))); } }); if (this_l->request.method () == boost::beast::http::verb::post) { - auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body(), response_handler)); + auto handler (std::make_shared (*this_l->node, this_l->rpc, this_l->request.body (), response_handler)); handler->process_request (); } else @@ -4161,7 +4157,7 @@ void rai::rpc_handler::process_request () { std::stringstream istream (body); boost::property_tree::read_json (istream, request); - std::string action (request.get ("action")); + std::string action (request.get ("action")); if (action == "password_enter") { password_enter (); @@ -4587,7 +4583,7 @@ void rai::rpc_handler::process_request () } } -rai::payment_observer::payment_observer (std::function const & response_a, rai::rpc & rpc_a, rai::account const & account_a, rai::amount const & amount_a) : +rai::payment_observer::payment_observer (std::function const & response_a, rai::rpc & rpc_a, rai::account const & account_a, rai::amount const & amount_a) : rpc (rpc_a), account (account_a), amount (amount_a), @@ -4599,8 +4595,7 @@ response (response_a) void rai::payment_observer::start (uint64_t timeout) { auto this_l (shared_from_this ()); - rpc.node.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (timeout), [this_l] () - { + rpc.node.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (timeout), [this_l]() { this_l->complete (rai::payment_status::nothing); }); } @@ -4624,7 +4619,7 @@ void rai::payment_observer::complete (rai::payment_status status) { if (rpc.node.config.logging.log_rpc ()) { - BOOST_LOG (rpc.node.log) << boost::str (boost::format ("Exiting payment_observer for account %1% status %2%") % account.to_account () % static_cast (status)); + BOOST_LOG (rpc.node.log) << boost::str (boost::format ("Exiting payment_observer for account %1% status %2%") % account.to_account () % static_cast (status)); } switch (status) { @@ -4648,7 +4643,7 @@ void rai::payment_observer::complete (rai::payment_status status) break; } } - std::lock_guard lock (rpc.mutex); + std::lock_guard lock (rpc.mutex); assert (rpc.payment_observers.find (account) != rpc.payment_observers.end ()); rpc.payment_observers.erase (account); } diff --git a/rai/node/rpc.hpp b/rai/node/rpc.hpp index 3b2bbf35..b17e51ce 100644 --- a/rai/node/rpc.hpp +++ b/rai/node/rpc.hpp @@ -50,28 +50,28 @@ public: void observer_action (rai::account const &); boost::asio::ip::tcp::acceptor acceptor; std::mutex mutex; - std::unordered_map > payment_observers; + std::unordered_map> payment_observers; rai::rpc_config config; rai::node & node; bool on; static uint16_t const rpc_port = rai::rai_network == rai::rai_networks::rai_live_network ? 7076 : 55000; }; -class rpc_connection : public std::enable_shared_from_this +class rpc_connection : public std::enable_shared_from_this { public: rpc_connection (rai::node &, rai::rpc &); void parse_connection (); - std::shared_ptr node; + std::shared_ptr node; rai::rpc & rpc; boost::asio::ip::tcp::socket socket; boost::beast::flat_buffer buffer; - boost::beast::http::request request; - boost::beast::http::response res; + boost::beast::http::request request; + boost::beast::http::response res; }; -class payment_observer : public std::enable_shared_from_this +class payment_observer : public std::enable_shared_from_this { public: - payment_observer (std::function const &, rai::rpc &, rai::account const &, rai::amount const &); + payment_observer (std::function const &, rai::rpc &, rai::account const &, rai::amount const &); ~payment_observer (); void start (uint64_t); void observe (); @@ -82,13 +82,13 @@ public: rai::rpc & rpc; rai::account account; rai::amount amount; - std::function response; + std::function response; std::atomic_flag completed; }; -class rpc_handler : public std::enable_shared_from_this +class rpc_handler : public std::enable_shared_from_this { public: - rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function const &); + rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function const &); void process_request (); void account_balance (); void account_block_count (); @@ -189,6 +189,6 @@ public: rai::node & node; rai::rpc & rpc; boost::property_tree::ptree request; - std::function response; + std::function response; }; } diff --git a/rai/node/testing.cpp b/rai/node/testing.cpp index 5f1c1b85..c0d6eb6d 100644 --- a/rai/node/testing.cpp +++ b/rai/node/testing.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include rai::system::system (uint16_t port_a, size_t count_a) : alarm (service), @@ -13,7 +13,7 @@ work (1, nullptr) { rai::node_init init; rai::node_config config (port_a + i, logging); - auto node (std::make_shared (init, service, rai::unique_path (), alarm, config, work)); + auto node (std::make_shared (init, service, rai::unique_path (), alarm, config, work)); assert (!init.error ()); node->start (); rai::uint256_union wallet; @@ -28,14 +28,15 @@ work (1, nullptr) auto starting2 ((*j)->peers.size ()); auto new2 (starting2); (*j)->network.send_keepalive ((*i)->network.endpoint ()); - do { + do + { poll (); new1 = (*i)->peers.size (); new2 = (*j)->peers.size (); } while (new1 == starting1 || new2 == starting2); } auto iterations1 (0); - while (std::any_of (nodes.begin (), nodes.end (), [] (std::shared_ptr const & node_a) {return node_a->bootstrap_initiator.in_progress ();})) + while (std::any_of (nodes.begin (), nodes.end (), [](std::shared_ptr const & node_a) { return node_a->bootstrap_initiator.in_progress (); })) { poll (); ++iterations1; @@ -45,18 +46,18 @@ work (1, nullptr) rai::system::~system () { - for (auto & i: nodes) + for (auto & i : nodes) { i->stop (); } } -std::shared_ptr rai::system::wallet (size_t index_a) +std::shared_ptr rai::system::wallet (size_t index_a) { assert (nodes.size () > index_a); - auto size (nodes [index_a]->wallets.items.size ()); + auto size (nodes[index_a]->wallets.items.size ()); assert (size == 1); - return nodes [index_a]->wallets.items.begin ()->second; + return nodes[index_a]->wallets.items.begin ()->second; } rai::account rai::system::account (MDB_txn * transaction_a, size_t index_a) @@ -78,13 +79,12 @@ void rai::system::poll () } } - namespace { -class traffic_generator : public std::enable_shared_from_this +class traffic_generator : public std::enable_shared_from_this { public: - traffic_generator (uint32_t count_a, uint32_t wait_a, std::shared_ptr node_a, rai::system & system_a) : + traffic_generator (uint32_t count_a, uint32_t wait_a, std::shared_ptr node_a, rai::system & system_a) : count (count_a), wait (wait_a), node (node_a), @@ -99,13 +99,13 @@ public: if (count_l > 0) { auto this_l (shared_from_this ()); - node->alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (wait), [this_l] () {this_l->run ();}); + node->alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (wait), [this_l]() { this_l->run (); }); } } - std::vector accounts; + std::vector accounts; uint32_t count; uint32_t wait; - std::shared_ptr node; + std::shared_ptr node; rai::system & system; }; } @@ -122,11 +122,11 @@ void rai::system::generate_usage_traffic (uint32_t count_a, uint32_t wait_a, siz { assert (nodes.size () > index_a); assert (count_a > 0); - auto generate (std::make_shared (count_a, wait_a, nodes [index_a], *this)); + auto generate (std::make_shared (count_a, wait_a, nodes[index_a], *this)); generate->run (); } -void rai::system::generate_rollback (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_rollback (rai::node & node_a, std::vector & accounts_a) { rai::block_hash current (node_a.latest (get_random_account (accounts_a))); rai::block_hash target (current); @@ -144,7 +144,7 @@ void rai::system::generate_rollback (rai::node & node_a, std::vector previous (); } - auto open (dynamic_cast (block2.get())); + auto open (dynamic_cast (block2.get ())); if (open != nullptr) { if (!node_a.ledger.block_exists (open->hashables.source)) @@ -161,7 +161,7 @@ void rai::system::generate_rollback (rai::node & node_a, std::vector send_block; + std::shared_ptr send_block; { rai::transaction transaction (node_a.store.environment, nullptr, false); rai::uint256_union random_block; @@ -172,18 +172,18 @@ void rai::system::generate_receive (rai::node & node_a) rai::pending_key send_hash (i->first); rai::pending_info info (i->second); auto block (node_a.store.block_get (transaction, send_hash.hash)); - assert (dynamic_cast (block.get ()) != nullptr); - send_block.reset (static_cast (block.release ())); + assert (dynamic_cast (block.get ()) != nullptr); + send_block.reset (static_cast (block.release ())); } } if (send_block != nullptr) { auto receive_error (wallet (0)->receive_sync (std::move (send_block), rai::genesis_account, std::numeric_limits::max ())); - (void) receive_error; + (void)receive_error; } } -void rai::system::generate_activity (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_activity (rai::node & node_a, std::vector & accounts_a) { auto what (random_pool.GenerateByte ()); if (what < 0x10) @@ -212,25 +212,25 @@ void rai::system::generate_activity (rai::node & node_a, std::vector & accounts_a) +rai::account rai::system::get_random_account (std::vector & accounts_a) { auto index (random_pool.GenerateWord32 (0, accounts_a.size () - 1)); - auto result (accounts_a [index]); + auto result (accounts_a[index]); return result; } rai::uint128_t rai::system::get_random_amount (MDB_txn * transaction_a, rai::node & node_a, rai::account const & account_a) { rai::uint128_t balance (node_a.ledger.account_balance (transaction_a, account_a)); - std::string balance_text (balance.convert_to ()); + std::string balance_text (balance.convert_to ()); rai::uint128_union random_amount; random_pool.GenerateBlock (random_amount.bytes.data (), sizeof (random_amount.bytes)); - auto result (((rai::uint256_t {random_amount.number ()} * balance) / rai::uint256_t {std::numeric_limits ::max ()}).convert_to ()); - std::string text (result.convert_to ()); + auto result (((rai::uint256_t{ random_amount.number () } * balance) / rai::uint256_t{ std::numeric_limits::max () }).convert_to ()); + std::string text (result.convert_to ()); return result; } -void rai::system::generate_send_existing (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_send_existing (rai::node & node_a, std::vector & accounts_a) { rai::uint128_t amount; rai::account destination; @@ -256,7 +256,7 @@ void rai::system::generate_send_existing (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_change_known (rai::node & node_a, std::vector & accounts_a) { rai::account source (get_random_account (accounts_a)); if (!node_a.latest (source).is_zero ()) @@ -267,7 +267,7 @@ void rai::system::generate_change_known (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_change_unknown (rai::node & node_a, std::vector & accounts_a) { rai::account source (get_random_account (accounts_a)); if (!node_a.latest (source).is_zero ()) @@ -279,7 +279,7 @@ void rai::system::generate_change_unknown (rai::node & node_a, std::vector & accounts_a) +void rai::system::generate_send_new (rai::node & node_a, std::vector & accounts_a) { assert (node_a.wallets.items.size () == 1); rai::uint128_t amount; @@ -300,7 +300,7 @@ void rai::system::generate_send_new (rai::node & node_a, std::vector accounts; + std::vector accounts; wallet (0)->insert_adhoc (rai::test_genesis_key.prv); accounts.push_back (rai::test_genesis_key.pub); auto previous (std::chrono::system_clock::now ()); @@ -309,7 +309,7 @@ void rai::system::generate_mass_activity (uint32_t count_a, rai::node & node_a) if ((i & 0xfff) == 0) { auto now (std::chrono::system_clock::now ()); - auto us (std::chrono::duration_cast (now - previous).count ()); + auto us (std::chrono::duration_cast (now - previous).count ()); std::cerr << boost::str (boost::format ("Mass activity iteration %1% us %2% us/t %3%\n") % i % us % (us / 256)); previous = now; } @@ -350,10 +350,10 @@ bool rai::landing_store::deserialize (std::istream & stream_a) { boost::property_tree::ptree tree; boost::property_tree::read_json (stream_a, tree); - auto source_l (tree.get ("source")); - auto destination_l (tree.get ("destination")); - auto start_l (tree.get ("start")); - auto last_l (tree.get ("last")); + auto source_l (tree.get ("source")); + auto destination_l (tree.get ("destination")); + auto start_l (tree.get ("start")); + auto last_l (tree.get ("last")); result = source.decode_account (source_l); if (!result) { @@ -386,12 +386,12 @@ void rai::landing_store::serialize (std::ostream & stream_a) const boost::property_tree::write_json (stream_a, tree); } -bool rai::landing_store::operator == (rai::landing_store const & other_a) const +bool rai::landing_store::operator== (rai::landing_store const & other_a) const { return source == other_a.source && destination == other_a.destination && start == other_a.start && last == other_a.last; } -rai::landing::landing (rai::node & node_a, std::shared_ptr wallet_a, rai::landing_store & store_a, boost::filesystem::path const & path_a) : +rai::landing::landing (rai::node & node_a, std::shared_ptr wallet_a, rai::landing_store & store_a, boost::filesystem::path const & path_a) : path (path_a), store (store_a), wallet (wallet_a), @@ -464,7 +464,7 @@ rai::uint128_t rai::landing::distribution_amount (uint64_t interval) uint64_t rai::landing::seconds_since_epoch () { - return std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()).count (); + return std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()).count (); } void rai::landing::distribute_one () @@ -492,9 +492,8 @@ void rai::landing::distribute_ongoing () { distribute_one (); BOOST_LOG (node.log) << "Waiting for next distribution cycle"; - node.alarm.add (std::chrono::system_clock::now () + sleep_seconds, [this] () {distribute_ongoing ();}); + node.alarm.add (std::chrono::system_clock::now () + sleep_seconds, [this]() { distribute_ongoing (); }); } - std::chrono::seconds constexpr rai::landing::distribution_interval; std::chrono::seconds constexpr rai::landing::sleep_seconds; diff --git a/rai/node/testing.hpp b/rai/node/testing.hpp index 236024c9..d1f09efd 100644 --- a/rai/node/testing.hpp +++ b/rai/node/testing.hpp @@ -9,25 +9,25 @@ class system public: system (uint16_t, size_t); ~system (); - void generate_activity (rai::node &, std::vector &); + void generate_activity (rai::node &, std::vector &); void generate_mass_activity (uint32_t, rai::node &); void generate_usage_traffic (uint32_t, uint32_t, size_t); void generate_usage_traffic (uint32_t, uint32_t); - rai::account get_random_account (std::vector &); + rai::account get_random_account (std::vector &); rai::uint128_t get_random_amount (MDB_txn *, rai::node &, rai::account const &); - void generate_rollback (rai::node &, std::vector &); - void generate_change_known (rai::node &, std::vector &); - void generate_change_unknown (rai::node &, std::vector &); + void generate_rollback (rai::node &, std::vector &); + void generate_change_known (rai::node &, std::vector &); + void generate_change_unknown (rai::node &, std::vector &); void generate_receive (rai::node &); - void generate_send_new (rai::node &, std::vector &); - void generate_send_existing (rai::node &, std::vector &); - std::shared_ptr wallet (size_t); + void generate_send_new (rai::node &, std::vector &); + void generate_send_existing (rai::node &, std::vector &); + std::shared_ptr wallet (size_t); rai::account account (MDB_txn *, size_t); void poll (); void stop (); boost::asio::io_service service; rai::alarm alarm; - std::vector > nodes; + std::vector> nodes; rai::logging logging; rai::work_pool work; }; @@ -43,12 +43,12 @@ public: uint64_t last; bool deserialize (std::istream &); void serialize (std::ostream &) const; - bool operator == (rai::landing_store const &) const; + bool operator== (rai::landing_store const &) const; }; class landing { public: - landing (rai::node &, std::shared_ptr , rai::landing_store &, boost::filesystem::path const &); + landing (rai::node &, std::shared_ptr, rai::landing_store &, boost::filesystem::path const &); void write_store (); rai::uint128_t distribution_amount (uint64_t); uint64_t seconds_since_epoch (); @@ -56,7 +56,7 @@ public: void distribute_ongoing (); boost::filesystem::path path; rai::landing_store & store; - std::shared_ptr wallet; + std::shared_ptr wallet; rai::node & node; static int constexpr interval_exponent = 10; static std::chrono::seconds constexpr distribution_interval = std::chrono::seconds (1 << interval_exponent); // 1024 seconds diff --git a/rai/node/utility.cpp b/rai/node/utility.cpp index 72bda59b..10895fa5 100644 --- a/rai/node/utility.cpp +++ b/rai/node/utility.cpp @@ -58,7 +58,7 @@ rai::mdb_env::operator MDB_env * () const } rai::mdb_val::mdb_val () : -value ({0, nullptr}) +value ({ 0, nullptr }) { } @@ -68,17 +68,17 @@ value (value_a) } rai::mdb_val::mdb_val (size_t size_a, void * data_a) : -value ({size_a, data_a}) +value ({ size_a, data_a }) { } rai::mdb_val::mdb_val (rai::uint128_union const & val_a) : -mdb_val (sizeof (val_a), const_cast (&val_a)) +mdb_val (sizeof (val_a), const_cast (&val_a)) { } rai::mdb_val::mdb_val (rai::uint256_union const & val_a) : -mdb_val (sizeof (val_a), const_cast (&val_a)) +mdb_val (sizeof (val_a), const_cast (&val_a)) { } @@ -96,14 +96,14 @@ rai::uint256_union rai::mdb_val::uint256 () const { rai::uint256_union result; assert (size () == sizeof (result)); - std::copy (reinterpret_cast (data ()), reinterpret_cast (data ()) + sizeof (result), result.bytes.data ()); + std::copy (reinterpret_cast (data ()), reinterpret_cast (data ()) + sizeof (result), result.bytes.data ()); return result; } rai::mdb_val::operator MDB_val * () const { // Allow passing a temporary to a non-c++ function which doesn't have constness - return const_cast (&value); + return const_cast (&value); }; rai::mdb_val::operator MDB_val const & () const diff --git a/rai/node/utility.hpp b/rai/node/utility.hpp old mode 100755 new mode 100644 index 70d1c6e5..50eab6f1 --- a/rai/node/utility.hpp +++ b/rai/node/utility.hpp @@ -5,9 +5,9 @@ #include #include +#include #include #include -#include #include #include @@ -20,8 +20,8 @@ namespace rai { -using bufferstream = boost::iostreams::stream_buffer >; -using vectorstream = boost::iostreams::stream_buffer >>; +using bufferstream = boost::iostreams::stream_buffer>; +using vectorstream = boost::iostreams::stream_buffer>>; // OS-specific way of finding a path to a home directory. boost::filesystem::path working_path (); // Get a unique path within the home directory, used for testing @@ -43,7 +43,7 @@ bool fetch_object (T & object, std::iostream & stream_a) catch (std::runtime_error const &) { auto pos (stream_a.tellg ()); - if (pos != std::streampos(0)) + if (pos != std::streampos (0)) { error = true; } @@ -71,7 +71,7 @@ bool fetch_object (T & object, boost::filesystem::path const & path_a, std::fstr catch (std::runtime_error const &) { auto pos (stream_a.tellg ()); - if (pos != std::streampos(0)) + if (pos != std::streampos (0)) { error = true; } diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index dd8cc1c7..f6cf0c67 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -6,8 +6,8 @@ #include -#include #include +#include #include @@ -30,7 +30,7 @@ void rai::wallet_store::wallet_key (rai::raw_key & prv_a, MDB_txn * transaction_ rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::wallet_key_special)); rai::raw_key password_l; password.value (password_l); - prv_a.decrypt (value.key, password_l, salt (transaction_a).owords [0]); + prv_a.decrypt (value.key, password_l, salt (transaction_a).owords[0]); } void rai::wallet_store::seed (rai::raw_key & prv_a, MDB_txn * transaction_a) @@ -38,7 +38,7 @@ void rai::wallet_store::seed (rai::raw_key & prv_a, MDB_txn * transaction_a) rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::seed_special)); rai::raw_key password_l; wallet_key (password_l, transaction_a); - prv_a.decrypt (value.key, password_l, salt (transaction_a).owords [0]); + prv_a.decrypt (value.key, password_l, salt (transaction_a).owords[0]); } void rai::wallet_store::seed_set (MDB_txn * transaction_a, rai::raw_key const & prv_a) @@ -46,7 +46,7 @@ void rai::wallet_store::seed_set (MDB_txn * transaction_a, rai::raw_key const & rai::raw_key password_l; wallet_key (password_l, transaction_a); rai::uint256_union ciphertext; - ciphertext.encrypt (prv_a, password_l, salt (transaction_a).owords [0]); + ciphertext.encrypt (prv_a, password_l, salt (transaction_a).owords[0]); entry_put_raw (transaction_a, rai::wallet_store::seed_special, rai::wallet_value (ciphertext, 0)); deterministic_clear (transaction_a); } @@ -84,7 +84,7 @@ void rai::wallet_store::deterministic_key (rai::raw_key & prv_a, MDB_txn * trans uint32_t rai::wallet_store::deterministic_index_get (MDB_txn * transaction_a) { rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::deterministic_index_special)); - return value.key.number ().convert_to (); + return value.key.number ().convert_to (); } void rai::wallet_store::deterministic_index_set (MDB_txn * transaction_a, uint32_t index_a) @@ -101,18 +101,18 @@ void rai::wallet_store::deterministic_clear (MDB_txn * transaction_a) { switch (key_type (rai::wallet_value (i->second))) { - case rai::key_type::deterministic: - { - rai::uint256_union key (i->first.uint256 ()); - erase (transaction_a, key); - i = begin (transaction_a, key); - break; - } - default: - { - ++i; - break; - } + case rai::key_type::deterministic: + { + rai::uint256_union key (i->first.uint256 ()); + erase (transaction_a, key); + i = begin (transaction_a, key); + break; + } + default: + { + ++i; + break; + } } } deterministic_index_set (transaction_a, 0); @@ -125,7 +125,7 @@ bool rai::wallet_store::valid_password (MDB_txn * transaction_a) rai::raw_key wallet_key_l; wallet_key (wallet_key_l, transaction_a); rai::uint256_union check_l; - check_l.encrypt (zero, wallet_key_l, salt (transaction_a).owords [0]); + check_l.encrypt (zero, wallet_key_l, salt (transaction_a).owords[0]); return check (transaction_a) == check_l; } @@ -162,7 +162,7 @@ bool rai::wallet_store::rekey (MDB_txn * transaction_a, std::string const & pass password.value (password_l); password.value_set (password_new); rai::uint256_union encrypted; - encrypted.encrypt (wallet_key_l, password_new, salt (transaction_a).owords [0]); + encrypted.encrypt (wallet_key_l, password_new, salt (transaction_a).owords[0]); entry_put_raw (transaction_a, rai::wallet_store::wallet_key_special, rai::wallet_value (encrypted, 0)); } else @@ -180,10 +180,10 @@ void rai::wallet_store::derive_key (rai::raw_key & prv_a, MDB_txn * transaction_ rai::fan::fan (rai::uint256_union const & key, size_t count_a) { - std::unique_ptr first (new rai::uint256_union (key)); + std::unique_ptr first (new rai::uint256_union (key)); for (auto i (1); i < count_a; ++i) { - std::unique_ptr entry (new rai::uint256_union); + std::unique_ptr entry (new rai::uint256_union); random_pool.GenerateBlock (entry->bytes.data (), entry->bytes.size ()); *first ^= *entry; values.push_back (std::move (entry)); @@ -193,7 +193,7 @@ rai::fan::fan (rai::uint256_union const & key, size_t count_a) void rai::fan::value (rai::raw_key & prv_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); value_get (prv_a); } @@ -201,7 +201,7 @@ void rai::fan::value_get (rai::raw_key & prv_a) { assert (!mutex.try_lock ()); prv_a.data.clear (); - for (auto & i: values) + for (auto & i : values) { prv_a.data ^= *i; } @@ -209,18 +209,18 @@ void rai::fan::value_get (rai::raw_key & prv_a) void rai::fan::value_set (rai::raw_key const & value_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); rai::raw_key value_l; value_get (value_l); - *(values [0]) ^= value_l.data; - *(values [0]) ^= value_a.data; + *(values[0]) ^= value_l.data; + *(values[0]) ^= value_a.data; } rai::wallet_value::wallet_value (rai::mdb_val const & val_a) { assert (val_a.size () == sizeof (*this)); - std::copy (reinterpret_cast (val_a.data ()), reinterpret_cast (val_a.data ()) + sizeof (key), key.chars.begin ()); - std::copy (reinterpret_cast (val_a.data ()) + sizeof (key), reinterpret_cast (val_a.data ()) + sizeof (key) + sizeof (work), reinterpret_cast (&work)); + std::copy (reinterpret_cast (val_a.data ()), reinterpret_cast (val_a.data ()) + sizeof (key), key.chars.begin ()); + std::copy (reinterpret_cast (val_a.data ()) + sizeof (key), reinterpret_cast (val_a.data ()) + sizeof (key) + sizeof (work), reinterpret_cast (&work)); } rai::wallet_value::wallet_value (rai::uint256_union const & key_a, uint64_t work_a) : @@ -232,7 +232,7 @@ work (work_a) rai::mdb_val rai::wallet_value::val () const { static_assert (sizeof (*this) == sizeof (key) + sizeof (work), "Class not packed"); - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } unsigned const rai::wallet_store::version_1 (1); @@ -283,7 +283,7 @@ environment (transaction_a.environment) if (!init_a) { rai::uint256_union value; - init_a = value.decode_hex (wallet_l.get (i->first)); + init_a = value.decode_hex (wallet_l.get (i->first)); if (!init_a) { entry_put_raw (transaction_a, key, rai::wallet_value (value, 0)); @@ -299,12 +299,12 @@ environment (transaction_a.environment) } } init_a |= mdb_get (transaction_a, handle, rai::mdb_val (version_special), &junk) != 0; - init_a |= mdb_get (transaction_a, handle, rai::mdb_val (wallet_key_special), & junk) != 0; + init_a |= mdb_get (transaction_a, handle, rai::mdb_val (wallet_key_special), &junk) != 0; init_a |= mdb_get (transaction_a, handle, rai::mdb_val (salt_special), &junk) != 0; init_a |= mdb_get (transaction_a, handle, rai::mdb_val (check_special), &junk) != 0; init_a |= mdb_get (transaction_a, handle, rai::mdb_val (representative_special), &junk) != 0; rai::raw_key key; - key.data.clear(); + key.data.clear (); password.value_set (key); } } @@ -337,10 +337,10 @@ environment (transaction_a.environment) zero.data.clear (); // Wallet key is encrypted by the user's password rai::uint256_union encrypted; - encrypted.encrypt (wallet_key, zero, salt_l.owords [0]); + encrypted.encrypt (wallet_key, zero, salt_l.owords[0]); entry_put_raw (transaction_a, rai::wallet_store::wallet_key_special, rai::wallet_value (encrypted, 0)); rai::uint256_union check; - check.encrypt (zero, wallet_key, salt_l.owords [0]); + check.encrypt (zero, wallet_key, salt_l.owords[0]); entry_put_raw (transaction_a, rai::wallet_store::check_special, rai::wallet_value (check, 0)); entry_put_raw (transaction_a, rai::wallet_store::representative_special, rai::wallet_value (representative_a, 0)); rai::raw_key seed; @@ -351,9 +351,9 @@ environment (transaction_a.environment) } } -std::vector rai::wallet_store::accounts (MDB_txn * transaction_a) +std::vector rai::wallet_store::accounts (MDB_txn * transaction_a) { - std::vector result; + std::vector result; for (auto i (begin (transaction_a)), n (end ()); i != n; ++i) { rai::account account (i->first.uint256 ()); @@ -393,7 +393,7 @@ rai::public_key rai::wallet_store::insert_adhoc (MDB_txn * transaction_a, rai::r rai::raw_key password_l; wallet_key (password_l, transaction_a); rai::uint256_union ciphertext; - ciphertext.encrypt (prv, password_l, salt (transaction_a).owords [0]); + ciphertext.encrypt (prv, password_l, salt (transaction_a).owords[0]); entry_put_raw (transaction_a, pub, rai::wallet_value (ciphertext, 0)); return pub; } @@ -431,14 +431,14 @@ rai::key_type rai::wallet_store::key_type (rai::wallet_value const & value_a) { auto number (value_a.key.number ()); rai::key_type result; - auto text (number.convert_to ()); - if (number > std::numeric_limits ::max ()) + auto text (number.convert_to ()); + if (number > std::numeric_limits::max ()) { result = rai::key_type::adhoc; } else { - if ((number >> 32).convert_to () == 1) + if ((number >> 32).convert_to () == 1) { result = rai::key_type::deterministic; } @@ -460,27 +460,27 @@ bool rai::wallet_store::fetch (MDB_txn * transaction_a, rai::public_key const & { switch (key_type (value)) { - case rai::key_type::deterministic: - { - rai::raw_key seed_l; - seed (seed_l, transaction_a); - uint32_t index (value.key.number ().convert_to ()); - deterministic_key (prv, transaction_a, index); - break; - } - case rai::key_type::adhoc: - { - // Ad-hoc keys - rai::raw_key password_l; - wallet_key (password_l, transaction_a); - prv.decrypt (value.key, password_l, salt (transaction_a).owords [0]); - break; - } - default: - { - result = true; - break; - } + case rai::key_type::deterministic: + { + rai::raw_key seed_l; + seed (seed_l, transaction_a); + uint32_t index (value.key.number ().convert_to ()); + deterministic_key (prv, transaction_a, index); + break; + } + case rai::key_type::adhoc: + { + // Ad-hoc keys + rai::raw_key password_l; + wallet_key (password_l, transaction_a); + prv.decrypt (value.key, password_l, salt (transaction_a).owords[0]); + break; + } + default: + { + result = true; + break; + } } } else @@ -533,7 +533,7 @@ void rai::wallet_store::write_backup (MDB_txn * transaction_a, boost::filesystem } } -bool rai::wallet_store::move (MDB_txn * transaction_a, rai::wallet_store & other_a, std::vector const & keys) +bool rai::wallet_store::move (MDB_txn * transaction_a, rai::wallet_store & other_a, std::vector const & keys) { assert (valid_password (transaction_a)); assert (other_a.valid_password (transaction_a)); @@ -598,7 +598,7 @@ unsigned rai::wallet_store::version (MDB_txn * transaction_a) { rai::wallet_value value (entry_get_raw (transaction_a, rai::wallet_store::version_special)); auto entry (value.key); - auto result (static_cast (entry.bytes [31])); + auto result (static_cast (entry.bytes[31])); return result; } @@ -616,10 +616,10 @@ void rai::wallet_store::upgrade_v1_v2 () rai::wallet_value value (entry_get_raw (transaction, rai::wallet_store::wallet_key_special)); rai::raw_key kdf; kdf.data.clear (); - zero_password.decrypt (value.key, kdf, salt (transaction).owords [0]); + zero_password.decrypt (value.key, kdf, salt (transaction).owords[0]); derive_key (kdf, transaction, ""); rai::raw_key empty_password; - empty_password.decrypt (value.key, kdf, salt (transaction).owords [0]); + empty_password.decrypt (value.key, kdf, salt (transaction).owords[0]); for (auto i (begin (transaction)), n (end ()); i != n; ++i) { rai::public_key key (i->first.uint256 ()); @@ -628,7 +628,7 @@ void rai::wallet_store::upgrade_v1_v2 () { // Key failed to decrypt despite valid password rai::wallet_value data (entry_get_raw (transaction, key)); - prv.decrypt (data.key, zero_password, salt (transaction).owords [0]); + prv.decrypt (data.key, zero_password, salt (transaction).owords[0]); rai::public_key compare; ed25519_publickey (prv.data.bytes.data (), compare.bytes.data ()); if (compare == key) @@ -640,7 +640,7 @@ void rai::wallet_store::upgrade_v1_v2 () { // Also try the empty password rai::wallet_value data (entry_get_raw (transaction, key)); - prv.decrypt (data.key, empty_password, salt (transaction).owords [0]); + prv.decrypt (data.key, empty_password, salt (transaction).owords[0]); rai::public_key compare; ed25519_publickey (prv.data.bytes.data (), compare.bytes.data ()); if (compare == key) @@ -667,20 +667,21 @@ void rai::wallet_store::upgrade_v2_v3 () void rai::kdf::phs (rai::raw_key & result_a, std::string const & password_a, rai::uint256_union const & salt_a) { - std::lock_guard lock (mutex); + std::lock_guard lock (mutex); auto success (argon2_hash (1, rai::wallet_store::kdf_work, 1, password_a.data (), password_a.size (), salt_a.bytes.data (), salt_a.bytes.size (), result_a.data.bytes.data (), result_a.data.bytes.size (), NULL, 0, Argon2_d, 0x10)); - assert (success == 0); (void) success; + assert (success == 0); + (void)success; } rai::wallet::wallet (bool & init_a, rai::transaction & transaction_a, rai::node & node_a, std::string const & wallet_a) : -lock_observer ([](bool, bool){}), +lock_observer ([](bool, bool) {}), store (init_a, node_a.wallets.kdf, transaction_a, node_a.config.random_representative (), node_a.config.password_fanout, wallet_a), node (node_a) { } rai::wallet::wallet (bool & init_a, rai::transaction & transaction_a, rai::node & node_a, std::string const & wallet_a, std::string const & json) : -lock_observer ([](bool, bool){}), +lock_observer ([](bool, bool) {}), store (init_a, node_a.wallets.kdf, transaction_a, node_a.config.random_representative (), node_a.config.password_fanout, wallet_a, json), node (node_a) { @@ -716,12 +717,11 @@ bool rai::wallet::enter_password (std::string const & password_a) if (!result) { auto this_l (shared_from_this ()); - node.background([this_l] () - { + node.background ([this_l]() { this_l->search_pending (); }); } - lock_observer (result, password_a.empty()); + lock_observer (result, password_a.empty ()); return result; } @@ -776,7 +776,7 @@ bool rai::wallet::exists (rai::public_key const & account_a) bool rai::wallet::import (std::string const & json_a, std::string const & password_a) { auto error (false); - std::unique_ptr temp; + std::unique_ptr temp; { rai::transaction transaction (store.environment, nullptr, true); rai::uint256_union id; @@ -811,16 +811,17 @@ void rai::wallet_store::destroy (MDB_txn * transaction_a) namespace { -bool check_ownership (rai::wallets & wallets_a, rai::account const & account_a) { - std::lock_guard lock (wallets_a.action_mutex); +bool check_ownership (rai::wallets & wallets_a, rai::account const & account_a) +{ + std::lock_guard lock (wallets_a.action_mutex); return wallets_a.current_actions.find (account_a) == wallets_a.current_actions.end (); } } -std::shared_ptr rai::wallet::receive_action (rai::send_block const & send_a, rai::account const & representative_a, rai::uint128_union const & amount_a, bool generate_work_a) +std::shared_ptr rai::wallet::receive_action (rai::send_block const & send_a, rai::account const & representative_a, rai::uint128_union const & amount_a, bool generate_work_a) { auto hash (send_a.hash ()); - std::shared_ptr block; + std::shared_ptr block; if (node.config.receive_minimum.number () <= amount_a.number ()) { rai::transaction transaction (node.ledger.store.environment, nullptr, false); @@ -866,8 +867,7 @@ std::shared_ptr rai::wallet::receive_action (rai::send_block const auto hash (block->hash ()); auto this_l (shared_from_this ()); auto source (send_a.hashables.destination); - node.wallets.queue_wallet_action (source, rai::wallets::generate_priority, [this_l, source, hash] - { + node.wallets.queue_wallet_action (source, rai::wallets::generate_priority, [this_l, source, hash] { this_l->work_generate (source, hash); }); } @@ -875,9 +875,9 @@ std::shared_ptr rai::wallet::receive_action (rai::send_block const return block; } -std::shared_ptr rai::wallet::change_action (rai::account const & source_a, rai::account const & representative_a, bool generate_work_a) +std::shared_ptr rai::wallet::change_action (rai::account const & source_a, rai::account const & representative_a, bool generate_work_a) { - std::shared_ptr block; + std::shared_ptr block; { rai::transaction transaction (store.environment, nullptr, false); if (store.valid_password (transaction)) @@ -907,8 +907,7 @@ std::shared_ptr rai::wallet::change_action (rai::account const & so { auto hash (block->hash ()); auto this_l (shared_from_this ()); - node.wallets.queue_wallet_action (source_a, rai::wallets::generate_priority, [this_l, source_a, hash] - { + node.wallets.queue_wallet_action (source_a, rai::wallets::generate_priority, [this_l, source_a, hash] { this_l->work_generate (source_a, hash); }); } @@ -916,9 +915,9 @@ std::shared_ptr rai::wallet::change_action (rai::account const & so return block; } -std::shared_ptr rai::wallet::send_action (rai::account const & source_a, rai::account const & account_a, rai::uint128_t const & amount_a, bool generate_work_a) +std::shared_ptr rai::wallet::send_action (rai::account const & source_a, rai::account const & account_a, rai::uint128_t const & amount_a, bool generate_work_a) { - std::shared_ptr block; + std::shared_ptr block; { rai::transaction transaction (store.environment, nullptr, false); if (store.valid_password (transaction)) @@ -952,8 +951,7 @@ std::shared_ptr rai::wallet::send_action (rai::account const & sour { auto hash (block->hash ()); auto this_l (shared_from_this ()); - node.wallets.queue_wallet_action (source_a, rai::wallets::generate_priority, [this_l, source_a, hash] - { + node.wallets.queue_wallet_action (source_a, rai::wallets::generate_priority, [this_l, source_a, hash] { this_l->work_generate (source_a, hash); }); } @@ -963,61 +961,57 @@ std::shared_ptr rai::wallet::send_action (rai::account const & sour bool rai::wallet::change_sync (rai::account const & source_a, rai::account const & representative_a) { - std::promise result; - change_async (source_a, representative_a, [this, source_a, representative_a, &result] (std::shared_ptr block_a) - { + std::promise result; + change_async (source_a, representative_a, [this, source_a, representative_a, &result](std::shared_ptr block_a) { result.set_value (block_a == nullptr); - }, true); + }, + true); return result.get_future ().get (); } -void rai::wallet::change_async (rai::account const & source_a, rai::account const & representative_a, std::function )> const & action_a, bool generate_work_a) +void rai::wallet::change_async (rai::account const & source_a, rai::account const & representative_a, std::function)> const & action_a, bool generate_work_a) { - node.wallets.queue_wallet_action (source_a, rai::wallets::high_priority, [this, source_a, representative_a, action_a, generate_work_a] () - { + node.wallets.queue_wallet_action (source_a, rai::wallets::high_priority, [this, source_a, representative_a, action_a, generate_work_a]() { assert (!check_ownership (node.wallets, source_a)); auto block (change_action (source_a, representative_a, generate_work_a)); action_a (block); }); } -bool rai::wallet::receive_sync (std::shared_ptr block_a, rai::account const & representative_a, rai::uint128_t const & amount_a) +bool rai::wallet::receive_sync (std::shared_ptr block_a, rai::account const & representative_a, rai::uint128_t const & amount_a) { - std::promise result; - receive_async (block_a, representative_a, amount_a, [&result] (std::shared_ptr block_a) - { + std::promise result; + receive_async (block_a, representative_a, amount_a, [&result](std::shared_ptr block_a) { result.set_value (block_a == nullptr); - }, true); + }, + true); return result.get_future ().get (); } -void rai::wallet::receive_async (std::shared_ptr block_a, rai::account const & representative_a, rai::uint128_t const & amount_a, std::function )> const & action_a, bool generate_work_a) +void rai::wallet::receive_async (std::shared_ptr block_a, rai::account const & representative_a, rai::uint128_t const & amount_a, std::function)> const & action_a, bool generate_work_a) { - assert (dynamic_cast (block_a.get ()) != nullptr); - node.wallets.queue_wallet_action (static_cast (block_a.get ())->hashables.destination, amount_a, [this, block_a, representative_a, amount_a, action_a, generate_work_a] () - { - assert (!check_ownership (node.wallets, static_cast (block_a.get ())->hashables.destination)); - auto block (receive_action (*static_cast (block_a.get ()), representative_a, amount_a, generate_work_a)); + assert (dynamic_cast (block_a.get ()) != nullptr); + node.wallets.queue_wallet_action (static_cast (block_a.get ())->hashables.destination, amount_a, [this, block_a, representative_a, amount_a, action_a, generate_work_a]() { + assert (!check_ownership (node.wallets, static_cast (block_a.get ())->hashables.destination)); + auto block (receive_action (*static_cast (block_a.get ()), representative_a, amount_a, generate_work_a)); action_a (block); }); } rai::block_hash rai::wallet::send_sync (rai::account const & source_a, rai::account const & account_a, rai::uint128_t const & amount_a) { - std::promise result; - send_async (source_a, account_a, amount_a, [&result] (std::shared_ptr block_a) - { + std::promise result; + send_async (source_a, account_a, amount_a, [&result](std::shared_ptr block_a) { result.set_value (block_a->hash ()); - }, true); + }, + true); return result.get_future ().get (); } -void rai::wallet::send_async (rai::account const & source_a, rai::account const & account_a, rai::uint128_t const & amount_a, std::function )> const & action_a, bool generate_work_a) +void rai::wallet::send_async (rai::account const & source_a, rai::account const & account_a, rai::uint128_t const & amount_a, std::function)> const & action_a, bool generate_work_a) { - node.background ([this, source_a, account_a, amount_a, action_a, generate_work_a] () - { - this->node.wallets.queue_wallet_action (source_a, rai::wallets::high_priority, [this, source_a, account_a, amount_a, action_a, generate_work_a] () - { + node.background ([this, source_a, account_a, amount_a, action_a, generate_work_a]() { + this->node.wallets.queue_wallet_action (source_a, rai::wallets::high_priority, [this, source_a, account_a, amount_a, action_a, generate_work_a]() { assert (!check_ownership (node.wallets, source_a)); auto block (send_action (source_a, account_a, amount_a, generate_work_a)); action_a (block); @@ -1071,7 +1065,7 @@ void rai::wallet::work_ensure (MDB_txn * transaction_a, rai::account const & acc if (rai::work_validate (root, work)) { auto this_l (shared_from_this ()); - node.background ([this_l, account_a, root] () { + node.background ([this_l, account_a, root]() { this_l->work_generate (account_a, root); }); } @@ -1079,10 +1073,10 @@ void rai::wallet::work_ensure (MDB_txn * transaction_a, rai::account const & acc namespace { -class search_action : public std::enable_shared_from_this +class search_action : public std::enable_shared_from_this { public: - search_action (std::shared_ptr const & wallet_a, MDB_txn * transaction_a) : + search_action (std::shared_ptr const & wallet_a, MDB_txn * transaction_a) : wallet (wallet_a) { for (auto i (wallet_a->store.begin (transaction_a)), n (wallet_a->store.end ()); i != n; ++i) @@ -1094,7 +1088,7 @@ public: { BOOST_LOG (wallet->node.log) << "Beginning pending block search"; rai::transaction transaction (wallet->node.store.environment, nullptr, false); - std::unordered_set already_searched; + std::unordered_set already_searched; for (auto i (wallet->node.store.pending_begin (transaction)), n (wallet->node.store.pending_end ()); i != n; ++i) { rai::pending_key key (i->first); @@ -1113,12 +1107,10 @@ public: if (already_searched.find (account) == already_searched.end ()) { auto this_l (shared_from_this ()); - std::shared_ptr block_l (wallet->node.store.block_get (transaction, info.head)); - wallet->node.background ([this_l, account, block_l] - { + std::shared_ptr block_l (wallet->node.store.block_get (transaction, info.head)); + wallet->node.background ([this_l, account, block_l] { rai::transaction transaction (this_l->wallet->node.store.environment, nullptr, true); - this_l->wallet->node.active.start (transaction, block_l, [this_l, account] (std::shared_ptr ) - { + this_l->wallet->node.active.start (transaction, block_l, [this_l, account](std::shared_ptr) { // If there were any forks for this account they've been rolled back and we can receive anything remaining from this account this_l->receive_all (account); }); @@ -1151,17 +1143,17 @@ public: if (wallet->store.valid_password (transaction)) { rai::pending_key key (i->first); - std::shared_ptr block (wallet->node.store.block_get (transaction, key.hash)); + std::shared_ptr block (wallet->node.store.block_get (transaction, key.hash)); auto wallet_l (wallet); auto amount (pending.amount.number ()); BOOST_LOG (wallet_l->node.log) << boost::str (boost::format ("Receiving block: %1%") % block->hash ().to_string ()); - wallet_l->receive_async (block, representative, amount, [wallet_l, block] (std::shared_ptr block_a) - { + wallet_l->receive_async (block, representative, amount, [wallet_l, block](std::shared_ptr block_a) { if (block_a == nullptr) { BOOST_LOG (wallet_l->node.log) << boost::str (boost::format ("Error receiving block %1%") % block->hash ().to_string ()); } - }, true); + }, + true); } else { @@ -1171,8 +1163,8 @@ public: } } } - std::unordered_set keys; - std::shared_ptr wallet; + std::unordered_set keys; + std::shared_ptr wallet; }; } @@ -1182,9 +1174,8 @@ bool rai::wallet::search_pending () auto result (!store.valid_password (transaction)); if (!result) { - auto search (std::make_shared (shared_from_this (), transaction)); - node.background ([search] () - { + auto search (std::make_shared (shared_from_this (), transaction)); + node.background ([search]() { search->run (); }); } @@ -1210,7 +1201,7 @@ void rai::wallet::work_generate (rai::account const & account_a, rai::block_hash auto work (node.generate_work (root_a)); if (node.config.logging.work_generation_time ()) { - BOOST_LOG (node.log) << "Work generation complete: " << (std::chrono::duration_cast (std::chrono::system_clock::now () - begin).count ()) << " us"; + BOOST_LOG (node.log) << "Work generation complete: " << (std::chrono::duration_cast (std::chrono::system_clock::now () - begin).count ()) << " us"; } rai::transaction transaction (store.environment, nullptr, true); if (store.exists (transaction, account_a)) @@ -1220,7 +1211,7 @@ void rai::wallet::work_generate (rai::account const & account_a, rai::block_hash } rai::wallets::wallets (bool & error_a, rai::node & node_a) : -observer ([] (rai::account const &, bool) {}), +observer ([](rai::account const &, bool) {}), node (node_a) { if (!error_a) @@ -1230,21 +1221,20 @@ node (node_a) assert (status == 0); std::string beginning (rai::uint256_union (0).to_string ()); std::string end ((rai::uint256_union (rai::uint256_t (0) - rai::uint256_t (1))).to_string ()); - for (rai::store_iterator i (transaction, handle, rai::mdb_val (beginning.size (), const_cast (beginning.c_str ()))), n (transaction, handle, rai::mdb_val (end.size (), const_cast (end.c_str ()))); i != n; ++i) + for (rai::store_iterator i (transaction, handle, rai::mdb_val (beginning.size (), const_cast (beginning.c_str ()))), n (transaction, handle, rai::mdb_val (end.size (), const_cast (end.c_str ()))); i != n; ++i) { rai::uint256_union id; - std::string text (reinterpret_cast (i->first.data ()), i->first.size ()); + std::string text (reinterpret_cast (i->first.data ()), i->first.size ()); auto error (id.decode_hex (text)); assert (!error); assert (items.find (id) == items.end ()); - auto wallet (std::make_shared (error, transaction, node_a, text)); + auto wallet (std::make_shared (error, transaction, node_a, text)); if (!error) { - node_a.background ([wallet] () - { + node_a.background ([wallet]() { wallet->enter_initial_password (); }); - items [id] = wallet; + items[id] = wallet; } else { @@ -1254,9 +1244,9 @@ node (node_a) } } -std::shared_ptr rai::wallets::open (rai::uint256_union const & id_a) +std::shared_ptr rai::wallets::open (rai::uint256_union const & id_a) { - std::shared_ptr result; + std::shared_ptr result; auto existing (items.find (id_a)); if (existing != items.end ()) { @@ -1265,21 +1255,20 @@ std::shared_ptr rai::wallets::open (rai::uint256_union const & id_ return result; } -std::shared_ptr rai::wallets::create (rai::uint256_union const & id_a) +std::shared_ptr rai::wallets::create (rai::uint256_union const & id_a) { assert (items.find (id_a) == items.end ()); - std::shared_ptr result; + std::shared_ptr result; bool error; { rai::transaction transaction (node.store.environment, nullptr, true); - result = std::make_shared (error, transaction, node, id_a.to_string ()); - items [id_a] = result; + result = std::make_shared (error, transaction, node, id_a.to_string ()); + items[id_a] = result; result = result; } if (!error) { - node.background ([result] () - { + node.background ([result]() { result->enter_initial_password (); }); } @@ -1301,7 +1290,7 @@ bool rai::wallets::search_pending (rai::uint256_union const & wallet_a) void rai::wallets::search_pending_all () { - for (auto i: items) + for (auto i : items) { i.second->search_pending (); } @@ -1320,7 +1309,7 @@ void rai::wallets::destroy (rai::uint256_union const & id_a) void rai::wallets::do_wallet_actions (rai::account const & account_a) { observer (account_a, true); - std::unique_lock lock (node.wallets.action_mutex); + std::unique_lock lock (node.wallets.action_mutex); auto existing (node.wallets.pending_actions.find (account_a)); while (existing != node.wallets.pending_actions.end ()) { @@ -1329,7 +1318,8 @@ void rai::wallets::do_wallet_actions (rai::account const & account_a) { node.wallets.pending_actions.erase (existing); auto erased (node.wallets.current_actions.erase (account_a)); - assert (erased == 1); (void) erased; + assert (erased == 1); + (void)erased; } else { @@ -1345,21 +1335,20 @@ void rai::wallets::do_wallet_actions (rai::account const & account_a) observer (account_a, false); } -void rai::wallets::queue_wallet_action (rai::account const & account_a, rai::uint128_t const & amount_a, std::function const & action_a) +void rai::wallets::queue_wallet_action (rai::account const & account_a, rai::uint128_t const & amount_a, std::function const & action_a) { - std::lock_guard lock (action_mutex); - pending_actions [account_a].insert (decltype (pending_actions)::mapped_type::value_type (amount_a, std::move (action_a))); + std::lock_guard lock (action_mutex); + pending_actions[account_a].insert (decltype (pending_actions)::mapped_type::value_type (amount_a, std::move (action_a))); if (current_actions.insert (account_a).second) { auto node_l (node.shared ()); - node.background ([node_l, account_a] () - { + node.background ([node_l, account_a]() { node_l->wallets.do_wallet_actions (account_a); }); } } -void rai::wallets::foreach_representative (MDB_txn * transaction_a, std::function const & action_a) +void rai::wallets::foreach_representative (MDB_txn * transaction_a, std::function const & action_a) { for (auto i (items.begin ()), n (items.end ()); i != n; ++i) { @@ -1400,8 +1389,8 @@ bool rai::wallets::exists (MDB_txn * transaction_a, rai::public_key const & acco return result; } -rai::uint128_t const rai::wallets::generate_priority = std::numeric_limits ::max (); -rai::uint128_t const rai::wallets::high_priority = std::numeric_limits ::max () - 1; +rai::uint128_t const rai::wallets::generate_priority = std::numeric_limits::max (); +rai::uint128_t const rai::wallets::high_priority = std::numeric_limits::max () - 1; rai::store_iterator rai::wallet_store::begin (MDB_txn * transaction_a) { diff --git a/rai/node/wallet.hpp b/rai/node/wallet.hpp index cb32b3c1..02820780 100644 --- a/rai/node/wallet.hpp +++ b/rai/node/wallet.hpp @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include #include #include @@ -18,7 +18,8 @@ public: fan (rai::uint256_union const &, size_t); void value (rai::raw_key &); void value_set (rai::raw_key const &); - std::vector > values; + std::vector> values; + private: std::mutex mutex; void value_get (rai::raw_key &); @@ -52,7 +53,7 @@ class wallet_store public: wallet_store (bool &, rai::kdf &, rai::transaction &, rai::account, unsigned, std::string const &); wallet_store (bool &, rai::kdf &, rai::transaction &, rai::account, unsigned, std::string const &, std::string const &); - std::vector accounts (MDB_txn *); + std::vector accounts (MDB_txn *); void initialize (MDB_txn *, bool &, std::string const &); rai::uint256_union check (MDB_txn *); bool rekey (MDB_txn *, std::string const &); @@ -85,7 +86,7 @@ public: void derive_key (rai::raw_key &, MDB_txn *, std::string const &); void serialize_json (MDB_txn *, std::string &); void write_backup (MDB_txn *, boost::filesystem::path const &); - bool move (MDB_txn *, rai::wallet_store &, std::vector const &); + bool move (MDB_txn *, rai::wallet_store &, std::vector const &); bool import (MDB_txn *, rai::wallet_store &); bool work_get (MDB_txn *, rai::public_key const &, uint64_t &); void work_put (MDB_txn *, rai::public_key const &, uint64_t); @@ -115,12 +116,12 @@ public: }; class node; // A wallet is a set of account keys encrypted by a common encryption key -class wallet : public std::enable_shared_from_this +class wallet : public std::enable_shared_from_this { public: - std::shared_ptr change_action (rai::account const &, rai::account const &, bool = true); - std::shared_ptr receive_action (rai::send_block const &, rai::account const &, rai::uint128_union const &, bool = true); - std::shared_ptr send_action (rai::account const &, rai::account const &, rai::uint128_t const &, bool = true); + std::shared_ptr change_action (rai::account const &, rai::account const &, bool = true); + std::shared_ptr receive_action (rai::send_block const &, rai::account const &, rai::uint128_union const &, bool = true); + std::shared_ptr send_action (rai::account const &, rai::account const &, rai::uint128_t const &, bool = true); wallet (bool &, rai::transaction &, rai::node &, std::string const &); wallet (bool &, rai::transaction &, rai::node &, std::string const &, std::string const &); void enter_initial_password (); @@ -134,19 +135,19 @@ public: bool import (std::string const &, std::string const &); void serialize (std::string &); bool change_sync (rai::account const &, rai::account const &); - void change_async (rai::account const &, rai::account const &, std::function )> const &, bool = true); - bool receive_sync (std::shared_ptr , rai::account const &, rai::uint128_t const &); - void receive_async (std::shared_ptr , rai::account const &, rai::uint128_t const &, std::function )> const &, bool = true); + void change_async (rai::account const &, rai::account const &, std::function)> const &, bool = true); + bool receive_sync (std::shared_ptr, rai::account const &, rai::uint128_t const &); + void receive_async (std::shared_ptr, rai::account const &, rai::uint128_t const &, std::function)> const &, bool = true); rai::block_hash send_sync (rai::account const &, rai::account const &, rai::uint128_t const &); - void send_async (rai::account const &, rai::account const &, rai::uint128_t const &, std::function )> const &, bool = true); + void send_async (rai::account const &, rai::account const &, rai::uint128_t const &, std::function)> const &, bool = true); void work_generate (rai::account const &, rai::block_hash const &); void work_update (MDB_txn *, rai::account const &, rai::block_hash const &, uint64_t); uint64_t work_fetch (MDB_txn *, rai::account const &, rai::block_hash const &); void work_ensure (MDB_txn *, rai::account const &); bool search_pending (); void init_free_accounts (MDB_txn *); - std::unordered_set free_accounts; - std::function lock_observer; + std::unordered_set free_accounts; + std::function lock_observer; rai::wallet_store store; rai::node & node; }; @@ -155,19 +156,19 @@ class wallets { public: wallets (bool &, rai::node &); - std::shared_ptr open (rai::uint256_union const &); - std::shared_ptr create (rai::uint256_union const &); + std::shared_ptr open (rai::uint256_union const &); + std::shared_ptr create (rai::uint256_union const &); bool search_pending (rai::uint256_union const &); void search_pending_all (); void destroy (rai::uint256_union const &); void do_wallet_actions (rai::account const &); - void queue_wallet_action (rai::account const &, rai::uint128_t const &, std::function const &); - void foreach_representative (MDB_txn *, std::function const &); + void queue_wallet_action (rai::account const &, rai::uint128_t const &, std::function const &); + void foreach_representative (MDB_txn *, std::function const &); bool exists (MDB_txn *, rai::public_key const &); - std::function observer; - std::unordered_map > items; - std::unordered_map , std::greater >> pending_actions; - std::unordered_set current_actions; + std::function observer; + std::unordered_map> items; + std::unordered_map, std::greater>> pending_actions; + std::unordered_set current_actions; std::mutex action_mutex; rai::kdf kdf; MDB_dbi handle; diff --git a/rai/node/xorshift.hpp b/rai/node/xorshift.hpp index 84217140..ce3d5544 100644 --- a/rai/node/xorshift.hpp +++ b/rai/node/xorshift.hpp @@ -6,23 +6,23 @@ namespace rai class xorshift1024star { public: - xorshift1024star (): + xorshift1024star () : p (0) { } - std::array s; + std::array s; unsigned p; uint64_t next () { auto p_l (p); auto pn ((p_l + 1) & 15); p = pn; - uint64_t s0 = s[ p_l ]; - uint64_t s1 = s[ pn ]; + uint64_t s0 = s[p_l]; + uint64_t s1 = s[pn]; s1 ^= s1 << 31; // a s1 ^= s1 >> 11; // b s0 ^= s0 >> 30; // c - return ( s[ pn ] = s0 ^ s1 ) * 1181783497276652981LL; + return (s[pn] = s0 ^ s1) * 1181783497276652981LL; } }; } diff --git a/rai/plat/linux/priority.cpp b/rai/plat/linux/priority.cpp index c5ba5a29..56ba2ddf 100644 --- a/rai/plat/linux/priority.cpp +++ b/rai/plat/linux/priority.cpp @@ -11,6 +11,6 @@ void rai::work_thread_reprioritize () { policy = SCHED_BATCH; auto result (pthread_setschedparam (handle, policy, &sched)); - (void) result; + (void)result; } } diff --git a/rai/plat/posix/openclapi.cpp b/rai/plat/posix/openclapi.cpp index 915a6b9c..689f82fc 100644 --- a/rai/plat/posix/openclapi.cpp +++ b/rai/plat/posix/openclapi.cpp @@ -12,25 +12,25 @@ public: opencl_library = dlopen ("libOpenCL.so", RTLD_NOW); if (opencl_library != nullptr) { - clGetPlatformIDs = reinterpret_cast (dlsym(opencl_library, "clGetPlatformIDs")); - clGetPlatformInfo = reinterpret_cast (dlsym(opencl_library, "clGetPlatformInfo")); - clGetDeviceIDs = reinterpret_cast (dlsym(opencl_library, "clGetDeviceIDs")); - clGetDeviceInfo = reinterpret_cast (dlsym(opencl_library, "clGetDeviceInfo")); - clCreateContext = reinterpret_cast (dlsym(opencl_library, "clCreateContext")); - clCreateCommandQueue = reinterpret_cast (dlsym(opencl_library, "clCreateCommandQueue")); - clCreateBuffer = reinterpret_cast (dlsym(opencl_library, "clCreateBuffer")); - clCreateProgramWithSource = reinterpret_cast (dlsym(opencl_library, "clCreateProgramWithSource")); - clBuildProgram = reinterpret_cast (dlsym(opencl_library, "clBuildProgram")); - clGetProgramBuildInfo = reinterpret_cast (dlsym(opencl_library, "clGetProgramBuildInfo")); - clCreateKernel = reinterpret_cast (dlsym(opencl_library, "clCreateKernel")); - clSetKernelArg = reinterpret_cast (dlsym(opencl_library, "clSetKernelArg")); - clReleaseKernel = reinterpret_cast (dlsym(opencl_library, "clReleaseKernel")); - clReleaseProgram = reinterpret_cast (dlsym(opencl_library, "clReleaseProgram")); - clReleaseContext = reinterpret_cast (dlsym(opencl_library, "clReleaseContext")); - clEnqueueWriteBuffer = reinterpret_cast (dlsym(opencl_library, "clEnqueueWriteBuffer")); - clEnqueueNDRangeKernel = reinterpret_cast (dlsym(opencl_library, "clEnqueueNDRangeKernel")); - clEnqueueReadBuffer = reinterpret_cast (dlsym(opencl_library, "clEnqueueReadBuffer")); - clFinish = reinterpret_cast (dlsym(opencl_library, "clFinish")); + clGetPlatformIDs = reinterpret_cast (dlsym (opencl_library, "clGetPlatformIDs")); + clGetPlatformInfo = reinterpret_cast (dlsym (opencl_library, "clGetPlatformInfo")); + clGetDeviceIDs = reinterpret_cast (dlsym (opencl_library, "clGetDeviceIDs")); + clGetDeviceInfo = reinterpret_cast (dlsym (opencl_library, "clGetDeviceInfo")); + clCreateContext = reinterpret_cast (dlsym (opencl_library, "clCreateContext")); + clCreateCommandQueue = reinterpret_cast (dlsym (opencl_library, "clCreateCommandQueue")); + clCreateBuffer = reinterpret_cast (dlsym (opencl_library, "clCreateBuffer")); + clCreateProgramWithSource = reinterpret_cast (dlsym (opencl_library, "clCreateProgramWithSource")); + clBuildProgram = reinterpret_cast (dlsym (opencl_library, "clBuildProgram")); + clGetProgramBuildInfo = reinterpret_cast (dlsym (opencl_library, "clGetProgramBuildInfo")); + clCreateKernel = reinterpret_cast (dlsym (opencl_library, "clCreateKernel")); + clSetKernelArg = reinterpret_cast (dlsym (opencl_library, "clSetKernelArg")); + clReleaseKernel = reinterpret_cast (dlsym (opencl_library, "clReleaseKernel")); + clReleaseProgram = reinterpret_cast (dlsym (opencl_library, "clReleaseProgram")); + clReleaseContext = reinterpret_cast (dlsym (opencl_library, "clReleaseContext")); + clEnqueueWriteBuffer = reinterpret_cast (dlsym (opencl_library, "clEnqueueWriteBuffer")); + clEnqueueNDRangeKernel = reinterpret_cast (dlsym (opencl_library, "clEnqueueNDRangeKernel")); + clEnqueueReadBuffer = reinterpret_cast (dlsym (opencl_library, "clEnqueueReadBuffer")); + clFinish = reinterpret_cast (dlsym (opencl_library, "clFinish")); } } ~opencl_initializer () @@ -41,25 +41,25 @@ public: } } void * opencl_library; - cl_int (* clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); - cl_int (* clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); - cl_int (* clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); - cl_int (* clGetDeviceInfo) (cl_device_id, cl_device_info, size_t, void *, size_t *); - cl_context (* clCreateContext) (cl_context_properties const *, cl_uint, cl_device_id const *, void (*)(const char *, const void *, size_t, void *), void *, cl_int *); - cl_command_queue (* clCreateCommandQueue) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); - cl_mem (* clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); - cl_program (* clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); - cl_int (* clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void (*)(cl_program, void *), void *); - cl_int(*clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); - cl_kernel (* clCreateKernel) (cl_program, char const *, cl_int *); - cl_int (* clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); - cl_int (* clReleaseKernel) (cl_kernel); - cl_int (* clReleaseProgram) (cl_program); - cl_int (* clReleaseContext) (cl_context); - cl_int (* clEnqueueWriteBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void const *, cl_uint, cl_event const *, cl_event *); - cl_int (* clEnqueueNDRangeKernel) (cl_command_queue, cl_kernel, cl_uint, size_t const *, size_t const *, size_t const *, cl_uint, cl_event const *, cl_event *); - cl_int (* clEnqueueReadBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, cl_event const *, cl_event *); - cl_int (* clFinish) (cl_command_queue); + cl_int (*clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); + cl_int (*clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); + cl_int (*clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); + cl_int (*clGetDeviceInfo) (cl_device_id, cl_device_info, size_t, void *, size_t *); + cl_context (*clCreateContext) (cl_context_properties const *, cl_uint, cl_device_id const *, void (*) (const char *, const void *, size_t, void *), void *, cl_int *); + cl_command_queue (*clCreateCommandQueue) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); + cl_mem (*clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); + cl_program (*clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); + cl_int (*clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void (*) (cl_program, void *), void *); + cl_int (*clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); + cl_kernel (*clCreateKernel) (cl_program, char const *, cl_int *); + cl_int (*clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); + cl_int (*clReleaseKernel) (cl_kernel); + cl_int (*clReleaseProgram) (cl_program); + cl_int (*clReleaseContext) (cl_context); + cl_int (*clEnqueueWriteBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void const *, cl_uint, cl_event const *, cl_event *); + cl_int (*clEnqueueNDRangeKernel) (cl_command_queue, cl_kernel, cl_uint, size_t const *, size_t const *, size_t const *, cl_uint, cl_event const *, cl_event *); + cl_int (*clEnqueueReadBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, cl_event const *, cl_event *); + cl_int (*clFinish) (cl_command_queue); static opencl_initializer initializer; }; } @@ -99,7 +99,7 @@ cl_int clGetDeviceInfo (cl_device_id device, cl_device_info param_name, size_t p return opencl_initializer::initializer.clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret); } -cl_context clCreateContext (cl_context_properties const * properties, cl_uint num_devices, cl_device_id const * devices, void (* pfn_notify)(const char *, const void *, size_t, void *), void * user_data, cl_int * errcode_ret) +cl_context clCreateContext (cl_context_properties const * properties, cl_uint num_devices, cl_device_id const * devices, void (*pfn_notify) (const char *, const void *, size_t, void *), void * user_data, cl_int * errcode_ret) { return opencl_initializer::initializer.clCreateContext (properties, num_devices, devices, pfn_notify, user_data, errcode_ret); } @@ -119,14 +119,14 @@ cl_program clCreateProgramWithSource (cl_context context, cl_uint count, char co return opencl_initializer::initializer.clCreateProgramWithSource (context, count, strings, lengths, errcode_ret); } -cl_int clBuildProgram (cl_program program, cl_uint num_devices, cl_device_id const * device_list, char const * options, void (*pfn_notify) (cl_program , void *), void * user_data) +cl_int clBuildProgram (cl_program program, cl_uint num_devices, cl_device_id const * device_list, char const * options, void (*pfn_notify) (cl_program, void *), void * user_data) { return opencl_initializer::initializer.clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); } -cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +cl_int clGetProgramBuildInfo (cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { - return opencl_initializer::initializer.clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret); + return opencl_initializer::initializer.clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret); } cl_kernel clCreateKernel (cl_program program, char const * kernel_name, cl_int * errcode_ret) @@ -154,7 +154,7 @@ cl_int clReleaseContext (cl_context context) return opencl_initializer::initializer.clReleaseContext (context); } -cl_int clEnqueueWriteBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, void const * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list,cl_event * event) +cl_int clEnqueueWriteBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, void const * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) { return opencl_initializer::initializer.clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); } @@ -164,7 +164,7 @@ cl_int clEnqueueNDRangeKernel (cl_command_queue command_queue, cl_kernel kernel, return opencl_initializer::initializer.clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); } -cl_int clEnqueueReadBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event *event) +cl_int clEnqueueReadBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) { return opencl_initializer::initializer.clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); } diff --git a/rai/plat/posix/working.cpp b/rai/plat/posix/working.cpp index 4e134cea..28984239 100644 --- a/rai/plat/posix/working.cpp +++ b/rai/plat/posix/working.cpp @@ -1,7 +1,7 @@ #include -#include #include +#include namespace rai { diff --git a/rai/plat/windows/icon.cpp b/rai/plat/windows/icon.cpp index 36262559..ac340266 100644 --- a/rai/plat/windows/icon.cpp +++ b/rai/plat/windows/icon.cpp @@ -6,7 +6,7 @@ void rai::set_application_icon (QApplication & application_a) { - HICON hIcon = static_cast (LoadImage (GetModuleHandle (nullptr), MAKEINTRESOURCE (1), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT)); + HICON hIcon = static_cast (LoadImage (GetModuleHandle (nullptr), MAKEINTRESOURCE (1), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT)); application_a.setWindowIcon (QIcon (QtWin::fromHICON (hIcon))); DestroyIcon (hIcon); } \ No newline at end of file diff --git a/rai/plat/windows/openclapi.cpp b/rai/plat/windows/openclapi.cpp index 182c76f9..e43ea0ec 100644 --- a/rai/plat/windows/openclapi.cpp +++ b/rai/plat/windows/openclapi.cpp @@ -4,74 +4,74 @@ namespace { - class opencl_initializer +class opencl_initializer +{ +public: + opencl_initializer () { - public: - opencl_initializer() + opencl_library = LoadLibrary ("OpenCL.dll"); + if (opencl_library != nullptr) { - opencl_library = LoadLibrary("OpenCL.dll"); - if (opencl_library != nullptr) - { - clGetPlatformIDs = reinterpret_cast (GetProcAddress(opencl_library, "clGetPlatformIDs")); - clGetPlatformInfo = reinterpret_cast (GetProcAddress(opencl_library, "clGetPlatformInfo")); - clGetDeviceIDs = reinterpret_cast (GetProcAddress(opencl_library, "clGetDeviceIDs")); - clGetDeviceInfo = reinterpret_cast (GetProcAddress(opencl_library, "clGetDeviceInfo")); - clCreateContext = reinterpret_cast (GetProcAddress(opencl_library, "clCreateContext")); - clCreateCommandQueue = reinterpret_cast (GetProcAddress(opencl_library, "clCreateCommandQueue")); - clCreateBuffer = reinterpret_cast (GetProcAddress(opencl_library, "clCreateBuffer")); - clCreateProgramWithSource = reinterpret_cast (GetProcAddress(opencl_library, "clCreateProgramWithSource")); - clBuildProgram = reinterpret_cast (GetProcAddress(opencl_library, "clBuildProgram")); - clGetProgramBuildInfo = reinterpret_cast (GetProcAddress(opencl_library, "clGetProgramBuildInfo")); - clCreateKernel = reinterpret_cast (GetProcAddress(opencl_library, "clCreateKernel")); - clSetKernelArg = reinterpret_cast (GetProcAddress(opencl_library, "clSetKernelArg")); - clReleaseKernel = reinterpret_cast (GetProcAddress(opencl_library, "clReleaseKernel")); - clReleaseProgram = reinterpret_cast (GetProcAddress(opencl_library, "clReleaseProgram")); - clReleaseContext = reinterpret_cast (GetProcAddress(opencl_library, "clReleaseContext")); - clEnqueueWriteBuffer = reinterpret_cast (GetProcAddress(opencl_library, "clEnqueueWriteBuffer")); - clEnqueueNDRangeKernel = reinterpret_cast (GetProcAddress(opencl_library, "clEnqueueNDRangeKernel")); - clEnqueueReadBuffer = reinterpret_cast (GetProcAddress(opencl_library, "clEnqueueReadBuffer")); - clFinish = reinterpret_cast (GetProcAddress(opencl_library, "clFinish")); - } + clGetPlatformIDs = reinterpret_cast (GetProcAddress (opencl_library, "clGetPlatformIDs")); + clGetPlatformInfo = reinterpret_cast (GetProcAddress (opencl_library, "clGetPlatformInfo")); + clGetDeviceIDs = reinterpret_cast (GetProcAddress (opencl_library, "clGetDeviceIDs")); + clGetDeviceInfo = reinterpret_cast (GetProcAddress (opencl_library, "clGetDeviceInfo")); + clCreateContext = reinterpret_cast (GetProcAddress (opencl_library, "clCreateContext")); + clCreateCommandQueue = reinterpret_cast (GetProcAddress (opencl_library, "clCreateCommandQueue")); + clCreateBuffer = reinterpret_cast (GetProcAddress (opencl_library, "clCreateBuffer")); + clCreateProgramWithSource = reinterpret_cast (GetProcAddress (opencl_library, "clCreateProgramWithSource")); + clBuildProgram = reinterpret_cast (GetProcAddress (opencl_library, "clBuildProgram")); + clGetProgramBuildInfo = reinterpret_cast (GetProcAddress (opencl_library, "clGetProgramBuildInfo")); + clCreateKernel = reinterpret_cast (GetProcAddress (opencl_library, "clCreateKernel")); + clSetKernelArg = reinterpret_cast (GetProcAddress (opencl_library, "clSetKernelArg")); + clReleaseKernel = reinterpret_cast (GetProcAddress (opencl_library, "clReleaseKernel")); + clReleaseProgram = reinterpret_cast (GetProcAddress (opencl_library, "clReleaseProgram")); + clReleaseContext = reinterpret_cast (GetProcAddress (opencl_library, "clReleaseContext")); + clEnqueueWriteBuffer = reinterpret_cast (GetProcAddress (opencl_library, "clEnqueueWriteBuffer")); + clEnqueueNDRangeKernel = reinterpret_cast (GetProcAddress (opencl_library, "clEnqueueNDRangeKernel")); + clEnqueueReadBuffer = reinterpret_cast (GetProcAddress (opencl_library, "clEnqueueReadBuffer")); + clFinish = reinterpret_cast (GetProcAddress (opencl_library, "clFinish")); } - ~opencl_initializer() + } + ~opencl_initializer () + { + if (opencl_library != nullptr) { - if (opencl_library != nullptr) - { - FreeLibrary(opencl_library); - } + FreeLibrary (opencl_library); } - HMODULE opencl_library; - cl_int(CL_API_CALL *clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); - cl_int(CL_API_CALL *clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); - cl_int(CL_API_CALL *clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); - cl_int(CL_API_CALL *clGetDeviceInfo) (cl_device_id, cl_device_info, size_t, void *, size_t *); - cl_context(CL_API_CALL *clCreateContext) (cl_context_properties const *, cl_uint, cl_device_id const *, void(CL_CALLBACK*)(const char *, const void *, size_t, void *), void *, cl_int *); - cl_command_queue(CL_API_CALL *clCreateCommandQueue) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); - cl_mem(CL_API_CALL *clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); - cl_program(CL_API_CALL *clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); - cl_int(CL_API_CALL *clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void(CL_CALLBACK*)(cl_program, void *), void *); - cl_int (CL_API_CALL *clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); - cl_kernel(CL_API_CALL *clCreateKernel) (cl_program, char const *, cl_int *); - cl_int(CL_API_CALL *clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); - cl_int(CL_API_CALL *clReleaseKernel) (cl_kernel); - cl_int(CL_API_CALL *clReleaseProgram) (cl_program); - cl_int(CL_API_CALL *clReleaseContext) (cl_context); - cl_int(CL_API_CALL *clEnqueueWriteBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void const *, cl_uint, cl_event const *, cl_event *); - cl_int(CL_API_CALL *clEnqueueNDRangeKernel) (cl_command_queue, cl_kernel, cl_uint, size_t const *, size_t const *, size_t const *, cl_uint, cl_event const *, cl_event *); - cl_int(CL_API_CALL *clEnqueueReadBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, cl_event const *, cl_event *); - cl_int(CL_API_CALL *clFinish) (cl_command_queue); - static opencl_initializer initializer; - }; + } + HMODULE opencl_library; + cl_int (CL_API_CALL * clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); + cl_int (CL_API_CALL * clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); + cl_int (CL_API_CALL * clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); + cl_int (CL_API_CALL * clGetDeviceInfo) (cl_device_id, cl_device_info, size_t, void *, size_t *); + cl_context (CL_API_CALL * clCreateContext) (cl_context_properties const *, cl_uint, cl_device_id const *, void(CL_CALLBACK *) (const char *, const void *, size_t, void *), void *, cl_int *); + cl_command_queue (CL_API_CALL * clCreateCommandQueue) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); + cl_mem (CL_API_CALL * clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); + cl_program (CL_API_CALL * clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); + cl_int (CL_API_CALL * clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void(CL_CALLBACK *) (cl_program, void *), void *); + cl_int (CL_API_CALL * clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); + cl_kernel (CL_API_CALL * clCreateKernel) (cl_program, char const *, cl_int *); + cl_int (CL_API_CALL * clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); + cl_int (CL_API_CALL * clReleaseKernel) (cl_kernel); + cl_int (CL_API_CALL * clReleaseProgram) (cl_program); + cl_int (CL_API_CALL * clReleaseContext) (cl_context); + cl_int (CL_API_CALL * clEnqueueWriteBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void const *, cl_uint, cl_event const *, cl_event *); + cl_int (CL_API_CALL * clEnqueueNDRangeKernel) (cl_command_queue, cl_kernel, cl_uint, size_t const *, size_t const *, size_t const *, cl_uint, cl_event const *, cl_event *); + cl_int (CL_API_CALL * clEnqueueReadBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, cl_event const *, cl_event *); + cl_int (CL_API_CALL * clFinish) (cl_command_queue); + static opencl_initializer initializer; +}; } opencl_initializer opencl_initializer::initializer; -cl_int CL_API_CALL clGetPlatformIDs(cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms) +cl_int CL_API_CALL clGetPlatformIDs (cl_uint num_entries, cl_platform_id * platforms, cl_uint * num_platforms) { cl_int result; if (opencl_initializer::initializer.opencl_library != nullptr) { - result = opencl_initializer::initializer.clGetPlatformIDs(num_entries, platforms, num_platforms); + result = opencl_initializer::initializer.clGetPlatformIDs (num_entries, platforms, num_platforms); } else { @@ -84,92 +84,92 @@ cl_int CL_API_CALL clGetPlatformIDs(cl_uint num_entries, cl_platform_id * platfo return result; } -cl_int CL_API_CALL clGetPlatformInfo(cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +cl_int CL_API_CALL clGetPlatformInfo (cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { - return opencl_initializer::initializer.clGetPlatformInfo(platform, param_name, param_value_size, param_value, param_value_size_ret); + return opencl_initializer::initializer.clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret); } -cl_int CL_API_CALL clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id * devices, cl_uint * num_devices) +cl_int CL_API_CALL clGetDeviceIDs (cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id * devices, cl_uint * num_devices) { - return opencl_initializer::initializer.clGetDeviceIDs(platform, device_type, num_entries, devices, num_devices); + return opencl_initializer::initializer.clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices); } -cl_int CL_API_CALL clGetDeviceInfo(cl_device_id device, cl_device_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +cl_int CL_API_CALL clGetDeviceInfo (cl_device_id device, cl_device_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { - return opencl_initializer::initializer.clGetDeviceInfo(device, param_name, param_value_size, param_value, param_value_size_ret); + return opencl_initializer::initializer.clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret); } -cl_context CL_API_CALL clCreateContext(cl_context_properties const * properties, cl_uint num_devices, cl_device_id const * devices, void(CL_CALLBACK *pfn_notify)(const char *, const void *, size_t, void *), void * user_data, cl_int * errcode_ret) +cl_context CL_API_CALL clCreateContext (cl_context_properties const * properties, cl_uint num_devices, cl_device_id const * devices, void(CL_CALLBACK * pfn_notify) (const char *, const void *, size_t, void *), void * user_data, cl_int * errcode_ret) { - return opencl_initializer::initializer.clCreateContext(properties, num_devices, devices, pfn_notify, user_data, errcode_ret); + return opencl_initializer::initializer.clCreateContext (properties, num_devices, devices, pfn_notify, user_data, errcode_ret); } -cl_command_queue CL_API_CALL clCreateCommandQueue(cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int * errcode_ret) +cl_command_queue CL_API_CALL clCreateCommandQueue (cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_int * errcode_ret) { - return opencl_initializer::initializer.clCreateCommandQueue(context, device, properties, errcode_ret); + return opencl_initializer::initializer.clCreateCommandQueue (context, device, properties, errcode_ret); } -cl_mem CL_API_CALL clCreateBuffer(cl_context context, cl_mem_flags flags, size_t size, void * host_ptr, cl_int * errcode_ret) +cl_mem CL_API_CALL clCreateBuffer (cl_context context, cl_mem_flags flags, size_t size, void * host_ptr, cl_int * errcode_ret) { - return opencl_initializer::initializer.clCreateBuffer(context, flags, size, host_ptr, errcode_ret); + return opencl_initializer::initializer.clCreateBuffer (context, flags, size, host_ptr, errcode_ret); } -cl_program CL_API_CALL clCreateProgramWithSource(cl_context context, cl_uint count, char const ** strings, size_t const * lengths, cl_int * errcode_ret) +cl_program CL_API_CALL clCreateProgramWithSource (cl_context context, cl_uint count, char const ** strings, size_t const * lengths, cl_int * errcode_ret) { - return opencl_initializer::initializer.clCreateProgramWithSource(context, count, strings, lengths, errcode_ret); + return opencl_initializer::initializer.clCreateProgramWithSource (context, count, strings, lengths, errcode_ret); } -cl_int CL_API_CALL clBuildProgram(cl_program program, cl_uint num_devices, cl_device_id const * device_list, char const * options, void(CL_CALLBACK *pfn_notify) (cl_program, void *), void * user_data) +cl_int CL_API_CALL clBuildProgram (cl_program program, cl_uint num_devices, cl_device_id const * device_list, char const * options, void(CL_CALLBACK * pfn_notify) (cl_program, void *), void * user_data) { - return opencl_initializer::initializer.clBuildProgram(program, num_devices, device_list, options, pfn_notify, user_data); + return opencl_initializer::initializer.clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); } -cl_int CL_API_CALL clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +cl_int CL_API_CALL clGetProgramBuildInfo (cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) { - return opencl_initializer::initializer.clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret); + return opencl_initializer::initializer.clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret); } -cl_kernel CL_API_CALL clCreateKernel(cl_program program, char const * kernel_name, cl_int * errcode_ret) +cl_kernel CL_API_CALL clCreateKernel (cl_program program, char const * kernel_name, cl_int * errcode_ret) { - return opencl_initializer::initializer.clCreateKernel(program, kernel_name, errcode_ret); + return opencl_initializer::initializer.clCreateKernel (program, kernel_name, errcode_ret); } -cl_int CL_API_CALL clSetKernelArg(cl_kernel kernel, cl_uint arg_index, size_t arg_size, void const * arg_value) +cl_int CL_API_CALL clSetKernelArg (cl_kernel kernel, cl_uint arg_index, size_t arg_size, void const * arg_value) { - return opencl_initializer::initializer.clSetKernelArg(kernel, arg_index, arg_size, arg_value); + return opencl_initializer::initializer.clSetKernelArg (kernel, arg_index, arg_size, arg_value); } -cl_int CL_API_CALL clReleaseKernel(cl_kernel kernel) +cl_int CL_API_CALL clReleaseKernel (cl_kernel kernel) { - return opencl_initializer::initializer.clReleaseKernel(kernel); + return opencl_initializer::initializer.clReleaseKernel (kernel); } -cl_int CL_API_CALL clReleaseProgram(cl_program program) +cl_int CL_API_CALL clReleaseProgram (cl_program program) { - return opencl_initializer::initializer.clReleaseProgram(program); + return opencl_initializer::initializer.clReleaseProgram (program); } -cl_int CL_API_CALL clReleaseContext(cl_context context) +cl_int CL_API_CALL clReleaseContext (cl_context context) { - return opencl_initializer::initializer.clReleaseContext(context); + return opencl_initializer::initializer.clReleaseContext (context); } -cl_int CL_API_CALL clEnqueueWriteBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, void const * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) +cl_int CL_API_CALL clEnqueueWriteBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t size, void const * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) { - return opencl_initializer::initializer.clEnqueueWriteBuffer(command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); + return opencl_initializer::initializer.clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); } -cl_int CL_API_CALL clEnqueueNDRangeKernel(cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, size_t const * global_work_offset, size_t const * global_work_size, size_t const * local_work_size, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) +cl_int CL_API_CALL clEnqueueNDRangeKernel (cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, size_t const * global_work_offset, size_t const * global_work_size, size_t const * local_work_size, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) { - return opencl_initializer::initializer.clEnqueueNDRangeKernel(command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); + return opencl_initializer::initializer.clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); } -cl_int CL_API_CALL clEnqueueReadBuffer(cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event *event) +cl_int CL_API_CALL clEnqueueReadBuffer (cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t size, void * ptr, cl_uint num_events_in_wait_list, cl_event const * event_wait_list, cl_event * event) { - return opencl_initializer::initializer.clEnqueueReadBuffer(command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); + return opencl_initializer::initializer.clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, size, ptr, num_events_in_wait_list, event_wait_list, event); } -cl_int CL_API_CALL clFinish(cl_command_queue command_queue) +cl_int CL_API_CALL clFinish (cl_command_queue command_queue) { - return opencl_initializer::initializer.clFinish(command_queue); + return opencl_initializer::initializer.clFinish (command_queue); } diff --git a/rai/plat/windows/priority.cpp b/rai/plat/windows/priority.cpp index 305193b8..140cdf32 100644 --- a/rai/plat/windows/priority.cpp +++ b/rai/plat/windows/priority.cpp @@ -4,5 +4,5 @@ void rai::work_thread_reprioritize () { - auto SUCCESS (SetThreadPriority (GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN)); + auto SUCCESS (SetThreadPriority (GetCurrentThread (), THREAD_MODE_BACKGROUND_BEGIN)); } diff --git a/rai/plat/windows/working.cpp b/rai/plat/windows/working.cpp index 8bb9e7f4..810ec269 100644 --- a/rai/plat/windows/working.cpp +++ b/rai/plat/windows/working.cpp @@ -8,7 +8,7 @@ boost::filesystem::path app_path () { boost::filesystem::path result; WCHAR path[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path))) + if (SUCCEEDED (SHGetFolderPathW (NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path))) { result = boost::filesystem::path (path); } diff --git a/rai/qt/qt.cpp b/rai/qt/qt.cpp old mode 100755 new mode 100644 index 0cd8f2ae..708a5920 --- a/rai/qt/qt.cpp +++ b/rai/qt/qt.cpp @@ -42,12 +42,12 @@ void show_button_success (QPushButton & button) bool rai_qt::eventloop_processor::event (QEvent * event_a) { - assert(dynamic_cast (event_a) != nullptr); - static_cast (event_a)->action (); + assert (dynamic_cast (event_a) != nullptr); + static_cast (event_a)->action (); return true; } -rai_qt::eventloop_event::eventloop_event (std::function const & action_a) : +rai_qt::eventloop_event::eventloop_event (std::function const & action_a) : QEvent (QEvent::Type::User), action (action_a) { @@ -68,22 +68,22 @@ balance_layout (new QHBoxLayout), balance_label (new QLabel), wallet (wallet_a) { - your_account_label->setStyleSheet("font-weight: bold;"); + your_account_label->setStyleSheet ("font-weight: bold;"); version = new QLabel (boost::str (boost::format ("Version %1%.%2%") % RAIBLOCKS_VERSION_MAJOR % RAIBLOCKS_VERSION_MINOR).c_str ()); self_layout->addWidget (your_account_label); self_layout->addStretch (); self_layout->addWidget (version); self_layout->setContentsMargins (0, 0, 0, 0); self_window->setLayout (self_layout); - account_text->setReadOnly(true); - account_text->setStyleSheet("QLineEdit{ background: #ddd; }"); + account_text->setReadOnly (true); + account_text->setStyleSheet ("QLineEdit{ background: #ddd; }"); account_layout->addWidget (account_text, 9); account_layout->addWidget (copy_button, 1); account_layout->setContentsMargins (0, 0, 0, 0); account_window->setLayout (account_layout); layout->addWidget (self_window); layout->addWidget (account_window); - balance_label->setStyleSheet("font-weight: bold;"); + balance_label->setStyleSheet ("font-weight: bold;"); balance_layout->addWidget (balance_label); balance_layout->addStretch (); balance_layout->setContentsMargins (0, 0, 0, 0); @@ -92,13 +92,11 @@ wallet (wallet_a) layout->setContentsMargins (5, 5, 5, 5); window->setLayout (layout); - QObject::connect (copy_button, &QPushButton::clicked, [this] () - { + QObject::connect (copy_button, &QPushButton::clicked, [this]() { this->wallet.application.clipboard ()->setText (QString (this->wallet.account.to_account ().c_str ())); - copy_button->setText("Copied!"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (2), [this] () - { - copy_button->setText("Copy"); + copy_button->setText ("Copied!"); + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (2), [this]() { + copy_button->setText ("Copy"); }); }); } @@ -138,7 +136,7 @@ wallet (wallet_a) view->setModel (model); view->verticalHeader ()->hide (); view->setContextMenuPolicy (Qt::ContextMenuPolicy::CustomContextMenu); - view->horizontalHeader()->setStretchLastSection(true); + view->horizontalHeader ()->setStretchLastSection (true); layout->addWidget (wallet_balance_label); layout->addWidget (view); layout->addWidget (use_account); @@ -150,18 +148,16 @@ wallet (wallet_a) layout->addWidget (account_key_button); layout->addWidget (back); window->setLayout (layout); - QObject::connect (use_account, &QPushButton::released, [this] () - { + QObject::connect (use_account, &QPushButton::released, [this]() { auto selection (view->selectionModel ()->selection ().indexes ()); if (selection.size () == 1) { - auto error (this->wallet.account.decode_account (model->item (selection [0].row (), 1)->text ().toStdString ())); + auto error (this->wallet.account.decode_account (model->item (selection[0].row (), 1)->text ().toStdString ())); assert (!error); this->wallet.refresh (); } }); - QObject::connect (account_key_button, &QPushButton::released, [this] () - { + QObject::connect (account_key_button, &QPushButton::released, [this]() { QString key_text_wide (account_key_line->text ()); std::string key_text (key_text_wide.toLocal8Bit ()); rai::raw_key key; @@ -179,12 +175,10 @@ wallet (wallet_a) show_line_error (*account_key_line); } }); - QObject::connect (back, &QPushButton::clicked, [this] () - { + QObject::connect (back, &QPushButton::clicked, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (create_account, &QPushButton::released, [this] () - { + QObject::connect (create_account, &QPushButton::released, [this]() { rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); if (this->wallet.wallet_m->store.valid_password (transaction)) { @@ -192,8 +186,7 @@ wallet (wallet_a) show_button_success (*create_account); create_account->setText ("New account was created"); refresh (); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*create_account); create_account->setText ("Create account"); }); @@ -202,19 +195,16 @@ wallet (wallet_a) { show_button_error (*create_account); create_account->setText ("Wallet is locked, unlock it to create account"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*create_account); create_account->setText ("Create account"); }); } }); - QObject::connect (import_wallet, &QPushButton::released, [this] () - { + QObject::connect (import_wallet, &QPushButton::released, [this]() { this->wallet.push_main_stack (this->wallet.import.window); }); - QObject::connect (backup_seed, &QPushButton::released, [this] () - { + QObject::connect (backup_seed, &QPushButton::released, [this]() { rai::raw_key seed; rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, false); if (this->wallet.wallet_m->store.valid_password (transaction)) @@ -223,8 +213,7 @@ wallet (wallet_a) this->wallet.application.clipboard ()->setText (QString (seed.data.to_string ().c_str ())); show_button_success (*backup_seed); backup_seed->setText ("Seed was copied to clipboard"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*backup_seed); backup_seed->setText ("Copy wallet seed to clipboard"); }); @@ -234,8 +223,7 @@ wallet (wallet_a) this->wallet.application.clipboard ()->setText (""); show_button_error (*backup_seed); backup_seed->setText ("Wallet is locked, unlock it to enable the backup"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*backup_seed); backup_seed->setText ("Copy wallet seed to clipboard"); }); @@ -244,7 +232,6 @@ wallet (wallet_a) refresh_wallet_balance (); } - void rai_qt::accounts::refresh_wallet_balance () { rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, false); @@ -262,10 +249,8 @@ void rai_qt::accounts::refresh_wallet_balance () final_text += "\nWallet pending: " + wallet.format_balance (pending); } wallet_balance_label->setText (QString (final_text.c_str ())); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (60), [this] () - { - this->wallet.application.postEvent (&this->wallet.processor, new eventloop_event ([this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (60), [this]() { + this->wallet.application.postEvent (&this->wallet.processor, new eventloop_event ([this]() { refresh_wallet_balance (); })); }); @@ -283,21 +268,21 @@ void rai_qt::accounts::refresh () bool display (true); switch (wallet.wallet_m->store.key_type (i->second)) { - case rai::key_type::adhoc: - { - brush.setColor ("red"); - display = !balance_amount.is_zero (); - break; - } - default: - { - brush.setColor ("black"); - break; - } + case rai::key_type::adhoc: + { + brush.setColor ("red"); + display = !balance_amount.is_zero (); + break; + } + default: + { + brush.setColor ("black"); + break; + } } if (display) { - QList items; + QList items; std::string balance = wallet.format_balance (balance_amount); items.push_back (new QStandardItem (balance.c_str ())); auto account (new QStandardItem (QString (key.to_account ().c_str ()))); @@ -340,8 +325,7 @@ wallet (wallet_a) layout->addStretch (); layout->addWidget (back); window->setLayout (layout); - QObject::connect (perform, &QPushButton::released, [this] () - { + QObject::connect (perform, &QPushButton::released, [this]() { std::ifstream stream; stream.open (filename->text ().toStdString ().c_str ()); if (!stream.fail ()) @@ -366,12 +350,10 @@ wallet (wallet_a) show_line_error (*filename); } }); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (import_seed, &QPushButton::released, [this] () - { + QObject::connect (import_seed, &QPushButton::released, [this]() { if (clear_line->text ().toStdString () == "clear keys") { show_line_ok (*clear_line); @@ -391,8 +373,7 @@ wallet (wallet_a) show_line_error (*seed); show_button_error (*import_seed); import_seed->setText ("Wallet is locked, unlock it to enable the import"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (10), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (10), [this]() { show_line_ok (*seed); show_button_ok (*import_seed); import_seed->setText ("Import seed"); @@ -429,8 +410,7 @@ wallet (wallet_a) show_button_success (*import_seed); import_seed->setText ("Successful import of seed"); this->wallet.refresh (); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*import_seed); import_seed->setText ("Import seed"); }); @@ -448,8 +428,7 @@ wallet (wallet_a) { import_seed->setText ("Incorrect seed. Only HEX characters allowed"); } - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*import_seed); import_seed->setText ("Import seed"); }); @@ -460,8 +439,7 @@ wallet (wallet_a) show_line_error (*clear_line); show_button_error (*import_seed); import_seed->setText ("Type words 'clear keys'"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*import_seed); import_seed->setText ("Import seed"); }); @@ -481,7 +459,7 @@ tx_count (new QSpinBox), ledger (ledger_a), account (account_a), wallet (wallet_a) -{/* +{ /* tx_count->setRange (1, 256); tx_layout->addWidget (tx_label); tx_layout->addWidget (tx_count); @@ -494,15 +472,14 @@ wallet (wallet_a) view->setModel (model); view->setEditTriggers (QAbstractItemView::NoEditTriggers); view->verticalHeader ()->hide (); - view->horizontalHeader()->setStretchLastSection(true); -// layout->addWidget (tx_window); + view->horizontalHeader ()->setStretchLastSection (true); + // layout->addWidget (tx_window); layout->addWidget (view); layout->setContentsMargins (0, 0, 0, 0); window->setLayout (layout); tx_count->setValue (32); } - namespace { class short_text_visitor : public rai::block_visitor @@ -561,13 +538,13 @@ void rai_qt::history::refresh () short_text_visitor visitor (transaction, ledger); for (auto i (0), n (tx_count->value ()); i < n && !hash.is_zero (); ++i) { - QList items; + QList items; auto block (ledger.store.block_get (transaction, hash)); assert (block != nullptr); block->visit (visitor); items.push_back (new QStandardItem (QString (visitor.type.c_str ()))); items.push_back (new QStandardItem (QString (visitor.account.to_account ().c_str ()))); - items.push_back (new QStandardItem (QString (wallet.format_balance (visitor.amount).c_str()))); + items.push_back (new QStandardItem (QString (wallet.format_balance (visitor.amount).c_str ()))); items.push_back (new QStandardItem (QString (hash.to_string ().c_str ()))); hash = block->previous (); model->appendRow (items); @@ -599,12 +576,10 @@ wallet (wallet_a) layout->addStretch (); layout->addWidget (back); window->setLayout (layout); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (retrieve, &QPushButton::released, [this] () - { + QObject::connect (retrieve, &QPushButton::released, [this]() { rai::block_hash hash_l; if (!hash_l.decode_hex (hash->text ().toStdString ())) { @@ -628,8 +603,7 @@ wallet (wallet_a) block->setPlainText ("Bad block hash"); } }); - QObject::connect (rebroadcast, &QPushButton::released, [this] () - { + QObject::connect (rebroadcast, &QPushButton::released, [this]() { rai::block_hash block; auto error (block.decode_hex (hash->text ().toStdString ())); if (!error) @@ -638,8 +612,7 @@ wallet (wallet_a) if (this->wallet.node.store.block_exists (transaction, block)) { rebroadcast->setEnabled (false); - this->wallet.node.background ([this, block] () - { + this->wallet.node.background ([this, block]() { rebroadcast_action (block); }); } @@ -660,8 +633,7 @@ void rai_qt::block_viewer::rebroadcast_action (rai::uint256_union const & hash_a if (!successor.is_zero ()) { done = false; - wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (1), [this, successor] () - { + wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (1), [this, successor]() { rebroadcast_action (successor); }); } @@ -697,12 +669,10 @@ wallet (wallet_a) layout->addWidget (history.window); layout->addWidget (back); window->setLayout (layout); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (refresh, &QPushButton::released, [this] () - { + QObject::connect (refresh, &QPushButton::released, [this]() { account.clear (); if (!account.decode_account (account_line->text ().toStdString ())) { @@ -735,7 +705,8 @@ wallet (wallet_a) void rai_qt::status::erase (rai_qt::status_types status_a) { assert (status_a != rai_qt::status_types::nominal); - auto erased (active.erase (status_a)); (void)erased; + auto erased (active.erase (status_a)); + (void)erased; set_text (); } @@ -837,7 +808,7 @@ std::string rai_qt::status::color () return result; } -rai_qt::wallet::wallet (QApplication & application_a, rai_qt::eventloop_processor & processor_a, rai::node & node_a, std::shared_ptr wallet_a, rai::account & account_a) : +rai_qt::wallet::wallet (QApplication & application_a, rai_qt::eventloop_processor & processor_a, rai::node & node_a, std::shared_ptr wallet_a, rai::account & account_a) : rendering_ratio (rai::Mxrb_ratio), node (node_a), wallet_m (wallet_a), @@ -890,7 +861,7 @@ active_status (*this) send_blocks_layout->addWidget (send_blocks_back); send_blocks_layout->setContentsMargins (0, 0, 0, 0); send_blocks_window->setLayout (send_blocks_layout); - + entry_window_layout->addWidget (account_history_label); entry_window_layout->addWidget (history.window); entry_window_layout->addWidget (send_blocks); @@ -902,11 +873,11 @@ active_status (*this) entry_window->setLayout (entry_window_layout); main_stack->addWidget (entry_window); - status->setContentsMargins(5, 5, 5, 5); + status->setContentsMargins (5, 5, 5, 5); status->setAlignment (Qt::AlignHCenter); separator->setFrameShape (QFrame::HLine); separator->setFrameShadow (QFrame::Sunken); - + client_layout->addWidget (status); client_layout->addWidget (self.window); client_layout->addWidget (separator); @@ -915,7 +886,7 @@ active_status (*this) client_layout->setContentsMargins (0, 0, 0, 0); client_window->setLayout (client_layout); client_window->resize (320, 480); - client_window->setStyleSheet("\ + client_window->setStyleSheet ("\ QLineEdit { padding: 3px; } \ "); refresh (); @@ -923,30 +894,26 @@ active_status (*this) void rai_qt::wallet::start () { - std::weak_ptr this_w (shared_from_this ()); - QObject::connect (settings_button, &QPushButton::released, [this_w] () - { + std::weak_ptr this_w (shared_from_this ()); + QObject::connect (settings_button, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { this_l->settings.activate (); } }); - QObject::connect (accounts_button, &QPushButton::released, [this_w] () - { + QObject::connect (accounts_button, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { this_l->push_main_stack (this_l->accounts.window); } }); - QObject::connect (show_advanced, &QPushButton::released, [this_w] () - { + QObject::connect (show_advanced, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { this_l->push_main_stack (this_l->advanced.window); } }); - QObject::connect (send_blocks_send, &QPushButton::released, [this_w] () - { + QObject::connect (send_blocks_send, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { show_line_ok (*this_l->send_count); @@ -970,17 +937,14 @@ void rai_qt::wallet::start () if (this_l->wallet_m->store.valid_password (transaction)) { this_l->send_blocks_send->setEnabled (false); - this_l->node.background ([this_w, account_l, actual] () - { + this_l->node.background ([this_w, account_l, actual]() { if (auto this_l = this_w.lock ()) { - this_l->wallet_m->send_async (this_l->account, account_l, actual, [this_w] (std::shared_ptr block_a) - { + this_l->wallet_m->send_async (this_l->account, account_l, actual, [this_w](std::shared_ptr block_a) { if (auto this_l = this_w.lock ()) { auto succeeded (block_a != nullptr); - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, succeeded] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, succeeded]() { if (auto this_l = this_w.lock ()) { this_l->send_blocks_send->setEnabled (true); @@ -1005,8 +969,7 @@ void rai_qt::wallet::start () { show_button_error (*this_l->send_blocks_send); this_l->send_blocks_send->setText ("Wallet is locked, unlock it to send"); - this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { show_button_ok (*this_l->send_blocks_send); @@ -1020,8 +983,7 @@ void rai_qt::wallet::start () show_line_error (*this_l->send_count); show_button_error (*this_l->send_blocks_send); this_l->send_blocks_send->setText ("Not enough balance"); - this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { show_button_ok (*this_l->send_blocks_send); @@ -1035,8 +997,7 @@ void rai_qt::wallet::start () show_line_error (*this_l->send_account); show_button_error (*this_l->send_blocks_send); this_l->send_blocks_send->setText ("Bad destination account"); - this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { show_button_ok (*this_l->send_blocks_send); @@ -1050,8 +1011,7 @@ void rai_qt::wallet::start () show_line_error (*this_l->send_count); show_button_error (*this_l->send_blocks_send); this_l->send_blocks_send->setText ("Amount too big"); - this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { show_line_ok (*this_l->send_account); @@ -1066,8 +1026,7 @@ void rai_qt::wallet::start () show_line_error (*this_l->send_count); show_button_error (*this_l->send_blocks_send); this_l->send_blocks_send->setText ("Bad amount number"); - this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w] () - { + this_l->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this_w]() { if (auto this_l = this_w.lock ()) { show_button_ok (*this_l->send_blocks_send); @@ -1077,26 +1036,22 @@ void rai_qt::wallet::start () } } }); - QObject::connect (send_blocks_back, &QPushButton::released, [this_w] () - { + QObject::connect (send_blocks_back, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { this_l->pop_main_stack (); } }); - QObject::connect (send_blocks, &QPushButton::released, [this_w] () - { + QObject::connect (send_blocks, &QPushButton::released, [this_w]() { if (auto this_l = this_w.lock ()) { this_l->push_main_stack (this_l->send_blocks_window); } }); - node.observers.blocks.add ([this_w] (std::shared_ptr , rai::account const & account_a, rai::amount const &) - { + node.observers.blocks.add ([this_w](std::shared_ptr, rai::account const & account_a, rai::amount const &) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, account_a] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, account_a]() { if (auto this_l = this_w.lock ()) { if (this_l->wallet_m->exists (account_a)) @@ -1112,12 +1067,10 @@ void rai_qt::wallet::start () })); } }); - node.observers.wallet.add ([this_w] (rai::account const & account_a, bool active_a) - { + node.observers.wallet.add ([this_w](rai::account const & account_a, bool active_a) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, account_a, active_a] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, account_a, active_a]() { if (auto this_l = this_w.lock ()) { if (this_l->account == account_a) @@ -1135,12 +1088,10 @@ void rai_qt::wallet::start () })); } }); - node.observers.endpoint.add ([this_w] (rai::endpoint const &) - { + node.observers.endpoint.add ([this_w](rai::endpoint const &) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w]() { if (auto this_l = this_w.lock ()) { this_l->update_connected (); @@ -1148,12 +1099,10 @@ void rai_qt::wallet::start () })); } }); - node.observers.disconnect.add ([this_w] () - { + node.observers.disconnect.add ([this_w]() { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w]() { if (auto this_l = this_w.lock ()) { this_l->update_connected (); @@ -1161,12 +1110,10 @@ void rai_qt::wallet::start () })); } }); - node.bootstrap_initiator.add_observer ([this_w] (bool active_a) - { + node.bootstrap_initiator.add_observer ([this_w](bool active_a) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, active_a] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, active_a]() { if (auto this_l = this_w.lock ()) { if (active_a) @@ -1181,12 +1128,10 @@ void rai_qt::wallet::start () })); } }); - node.work.work_observers.add ([this_w] (bool working) - { + node.work.work_observers.add ([this_w](bool working) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, working] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, working]() { if (auto this_l = this_w.lock ()) { if (working) @@ -1201,12 +1146,10 @@ void rai_qt::wallet::start () })); } }); - wallet_m->lock_observer = [this_w] (bool invalid, bool vulnerable) - { + wallet_m->lock_observer = [this_w](bool invalid, bool vulnerable) { if (auto this_l = this_w.lock ()) { - this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, invalid, vulnerable] () - { + this_l->application.postEvent (&this_l->processor, new eventloop_event ([this_w, invalid, vulnerable]() { if (auto this_l = this_w.lock ()) { this_l->settings.update_locked (invalid, vulnerable); @@ -1245,16 +1188,14 @@ void rai_qt::wallet::update_connected () void rai_qt::wallet::empty_password () { - this->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (3), [this] () - { + this->node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (3), [this]() { wallet_m->enter_password (std::string ("")); }); } void rai_qt::wallet::change_rendering_ratio (rai::uint128_t const & rendering_ratio_a) { - application.postEvent (&processor, new eventloop_event ([this, rendering_ratio_a] () - { + application.postEvent (&processor, new eventloop_event ([this, rendering_ratio_a]() { this->rendering_ratio = rendering_ratio_a; this->refresh (); })); @@ -1264,9 +1205,12 @@ std::string rai_qt::wallet::format_balance (rai::uint128_t const & balance) cons { auto balance_str = rai::amount (balance).format_balance (rendering_ratio, 2, true, std::locale ("")); auto unit = std::string ("XRB"); - if (rendering_ratio == rai::kxrb_ratio) { + if (rendering_ratio == rai::kxrb_ratio) + { unit = std::string ("kxrb"); - } else if (rendering_ratio == rai::xrb_ratio) { + } + else if (rendering_ratio == rai::xrb_ratio) + { unit = std::string ("xrb"); } return balance_str + " " + unit; @@ -1300,10 +1244,10 @@ change_rep (new QPushButton ("Change representative")), back (new QPushButton ("Back")), wallet (wallet_a) { - password->setPlaceholderText("Password"); + password->setPlaceholderText ("Password"); password->setEchoMode (QLineEdit::EchoMode::Password); layout->addWidget (password); - layout->addWidget(lock_toggle); + layout->addWidget (lock_toggle); sep1->setFrameShape (QFrame::HLine); sep1->setFrameShadow (QFrame::Sunken); layout->addWidget (sep1); @@ -1318,7 +1262,7 @@ wallet (wallet_a) sep2->setFrameShadow (QFrame::Sunken); layout->addWidget (sep2); layout->addWidget (representative); - current_representative->setTextInteractionFlags(Qt::TextSelectableByMouse); + current_representative->setTextInteractionFlags (Qt::TextSelectableByMouse); layout->addWidget (current_representative); new_representative->setPlaceholderText (rai::zero_key.pub.to_account ().c_str ()); layout->addWidget (new_representative); @@ -1326,12 +1270,11 @@ wallet (wallet_a) layout->addStretch (); layout->addWidget (back); window->setLayout (layout); - QObject::connect (change, &QPushButton::released, [this] () - { + QObject::connect (change, &QPushButton::released, [this]() { rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); if (this->wallet.wallet_m->store.valid_password (transaction)) { - if (new_password->text ().isEmpty()) + if (new_password->text ().isEmpty ()) { new_password->clear (); new_password->setPlaceholderText ("Empty Password - try again: New password"); @@ -1349,8 +1292,7 @@ wallet (wallet_a) show_button_success (*change); change->setText ("Password was changed"); update_locked (false, false); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*change); change->setText ("Set/Change password"); }); @@ -1366,15 +1308,13 @@ wallet (wallet_a) { show_button_error (*change); change->setText ("Wallet is locked, unlock it"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*change); change->setText ("Set/Change password"); }); } }); - QObject::connect (change_rep, &QPushButton::released, [this] () - { + QObject::connect (change_rep, &QPushButton::released, [this]() { rai::account representative_l; if (!representative_l.decode_account (new_representative->text ().toStdString ())) { @@ -1392,8 +1332,7 @@ wallet (wallet_a) change_rep->setText ("Represenative was changed"); current_representative->setText (QString (representative_l.to_account_split ().c_str ())); new_representative->clear (); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*change_rep); change_rep->setText ("Change representative"); }); @@ -1402,8 +1341,7 @@ wallet (wallet_a) { show_button_error (*change_rep); change_rep->setText ("Wallet is locked, unlock it"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_button_ok (*change_rep); change_rep->setText ("Change representative"); }); @@ -1414,58 +1352,54 @@ wallet (wallet_a) show_line_error (*new_representative); show_button_error (*change_rep); change_rep->setText ("Invalid account"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_line_ok (*new_representative); show_button_ok (*change_rep); change_rep->setText ("Change representative"); }); } }); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { assert (this->wallet.main_stack->currentWidget () == window); this->wallet.pop_main_stack (); }); - QObject::connect (lock_toggle, &QPushButton::released, [this] () - { + QObject::connect (lock_toggle, &QPushButton::released, [this]() { rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); - if (this->wallet.wallet_m->store.valid_password (transaction)) + if (this->wallet.wallet_m->store.valid_password (transaction)) { // lock wallet rai::raw_key empty; empty.data.clear (); this->wallet.wallet_m->store.password.value_set (empty); - update_locked (true, true); + update_locked (true, true); lock_toggle->setText ("Unlock"); - password->setEnabled(1); - } + password->setEnabled (1); + } else { // try to unlock wallet if (!this->wallet.wallet_m->enter_password (std::string (password->text ().toLocal8Bit ()))) { password->clear (); - lock_toggle->setText("Lock"); - password->setDisabled(1); + lock_toggle->setText ("Lock"); + password->setDisabled (1); } else { show_line_error (*password); show_button_error (*lock_toggle); lock_toggle->setText ("Invalid password"); - this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this] () - { + this->wallet.node.alarm.add (std::chrono::system_clock::now () + std::chrono::seconds (5), [this]() { show_line_ok (*password); show_button_ok (*lock_toggle); // if wallet is still not unlocked by now, change button text rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); - if (! this->wallet.wallet_m->store.valid_password (transaction)) + if (!this->wallet.wallet_m->store.valid_password (transaction)) { lock_toggle->setText ("Unlock"); } - + }); } } @@ -1473,10 +1407,10 @@ wallet (wallet_a) // initial state for lock toggle button rai::transaction transaction (this->wallet.wallet_m->store.environment, nullptr, true); - if (this->wallet.wallet_m->store.valid_password (transaction)) + if (this->wallet.wallet_m->store.valid_password (transaction)) { - lock_toggle->setText("Lock"); - password->setDisabled(1); + lock_toggle->setText ("Lock"); + password->setDisabled (1); } representative->setToolTip ("In the infrequent case where the network needs to make a global decision,\nyour wallet software performs a balance-weighted vote to determine\nthe outcome. Since not everyone can remain online and perform this duty,\nyour wallet names a representative that can vote with, but cannot spend,\nyour balance."); @@ -1568,33 +1502,33 @@ wallet (wallet_a) ratio_group->setId (mrai, 0); ratio_group->setId (krai, 1); ratio_group->setId (rai, 2); - scale_layout->addWidget(scale_label); - scale_layout->addWidget(mrai); - scale_layout->addWidget(krai); - scale_layout->addWidget(rai); - scale_window->setLayout(scale_layout); - + scale_layout->addWidget (scale_label); + scale_layout->addWidget (mrai); + scale_layout->addWidget (krai); + scale_layout->addWidget (rai); + scale_window->setLayout (scale_layout); + ledger_model->setHorizontalHeaderItem (0, new QStandardItem ("Account")); ledger_model->setHorizontalHeaderItem (1, new QStandardItem ("Balance")); ledger_model->setHorizontalHeaderItem (2, new QStandardItem ("Block")); ledger_view->setModel (ledger_model); ledger_view->setEditTriggers (QAbstractItemView::NoEditTriggers); ledger_view->verticalHeader ()->hide (); - ledger_view->horizontalHeader()->setStretchLastSection(true); + ledger_view->horizontalHeader ()->setStretchLastSection (true); ledger_layout->addWidget (ledger_view); ledger_layout->addWidget (ledger_refresh); ledger_layout->addWidget (ledger_back); ledger_layout->setContentsMargins (0, 0, 0, 0); ledger_window->setLayout (ledger_layout); - + peers_model->setHorizontalHeaderItem (0, new QStandardItem ("IPv6 address:port")); peers_model->setHorizontalHeaderItem (1, new QStandardItem ("Net version")); peers_view->setEditTriggers (QAbstractItemView::NoEditTriggers); peers_view->verticalHeader ()->hide (); peers_view->setModel (peers_model); - peers_view->setColumnWidth(0, 220); - peers_view->setSortingEnabled(true); - peers_view->horizontalHeader()->setStretchLastSection(true); + peers_view->setColumnWidth (0, 220); + peers_view->setSortingEnabled (true); + peers_view->horizontalHeader ()->setStretchLastSection (true); peers_layout->addWidget (peers_view); peers_layout->addWidget (bootstrap_label); peers_layout->addWidget (bootstrap_line); @@ -1618,52 +1552,43 @@ wallet (wallet_a) layout->addWidget (back); window->setLayout (layout); - QObject::connect (mrai, &QRadioButton::toggled, [this] () - { + QObject::connect (mrai, &QRadioButton::toggled, [this]() { if (mrai->isChecked ()) { this->wallet.change_rendering_ratio (rai::Mxrb_ratio); } - }); - QObject::connect (krai, &QRadioButton::toggled, [this] () - { + }); + QObject::connect (krai, &QRadioButton::toggled, [this]() { if (krai->isChecked ()) { this->wallet.change_rendering_ratio (rai::kxrb_ratio); } - }); - QObject::connect (rai, &QRadioButton::toggled, [this] () - { + }); + QObject::connect (rai, &QRadioButton::toggled, [this]() { if (rai->isChecked ()) { this->wallet.change_rendering_ratio (rai::xrb_ratio); } }); mrai->click (); - QObject::connect (wallet_refresh, &QPushButton::released, [this] () - { + QObject::connect (wallet_refresh, &QPushButton::released, [this]() { this->wallet.accounts.refresh (); this->wallet.accounts.refresh_wallet_balance (); }); - QObject::connect (show_peers, &QPushButton::released, [this] () - { + QObject::connect (show_peers, &QPushButton::released, [this]() { refresh_peers (); this->wallet.push_main_stack (peers_window); }); - QObject::connect (show_ledger, &QPushButton::released, [this] () - { + QObject::connect (show_ledger, &QPushButton::released, [this]() { this->wallet.push_main_stack (ledger_window); }); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (peers_back, &QPushButton::released, [this] () - { + QObject::connect (peers_back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (peers_bootstrap, &QPushButton::released, [this] () - { + QObject::connect (peers_bootstrap, &QPushButton::released, [this]() { rai::endpoint endpoint; auto error (rai::parse_endpoint (bootstrap_line->text ().toStdString (), endpoint)); if (!error) @@ -1677,40 +1602,31 @@ wallet (wallet_a) show_line_error (*bootstrap_line); } }); - QObject::connect (peers_refresh, &QPushButton::released, [this] () - { + QObject::connect (peers_refresh, &QPushButton::released, [this]() { refresh_peers (); }); - QObject::connect (ledger_refresh, &QPushButton::released, [this] () - { + QObject::connect (ledger_refresh, &QPushButton::released, [this]() { refresh_ledger (); }); - QObject::connect (ledger_back, &QPushButton::released, [this] () - { + QObject::connect (ledger_back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); - QObject::connect (search_for_receivables, &QPushButton::released, [this] () - { + QObject::connect (search_for_receivables, &QPushButton::released, [this]() { this->wallet.wallet_m->search_pending (); }); - QObject::connect (bootstrap, &QPushButton::released, [this] () - { + QObject::connect (bootstrap, &QPushButton::released, [this]() { this->wallet.node.bootstrap_initiator.bootstrap (); }); - QObject::connect (create_block, &QPushButton::released, [this] () - { + QObject::connect (create_block, &QPushButton::released, [this]() { this->wallet.push_main_stack (this->wallet.block_creation.window); }); - QObject::connect (enter_block, &QPushButton::released, [this] () - { + QObject::connect (enter_block, &QPushButton::released, [this]() { this->wallet.push_main_stack (this->wallet.block_entry.window); }); - QObject::connect (block_viewer, &QPushButton::released, [this] () - { + QObject::connect (block_viewer, &QPushButton::released, [this]() { this->wallet.push_main_stack (this->wallet.block_viewer.window); }); - QObject::connect (account_viewer, &QPushButton::released, [this] () - { + QObject::connect (account_viewer, &QPushButton::released, [this]() { this->wallet.push_main_stack (this->wallet.account_viewer.window); }); bootstrap->setToolTip ("Multi-connection bootstrap to random peers"); @@ -1729,8 +1645,8 @@ void rai_qt::advanced_actions::refresh_peers () endpoint << i->first.address ().to_string (); endpoint << ':'; endpoint << i->first.port (); - QString qendpoint (endpoint.str().c_str ()); - QList items; + QString qendpoint (endpoint.str ().c_str ()); + QList items; items.push_back (new QStandardItem (qendpoint)); items.push_back (new QStandardItem (QString (std::to_string (i->second).c_str ()))); peers_model->appendRow (items); @@ -1743,7 +1659,7 @@ void rai_qt::advanced_actions::refresh_ledger () rai::transaction transaction (wallet.node.store.environment, nullptr, false); for (auto i (wallet.node.ledger.store.latest_begin (transaction)), j (wallet.node.ledger.store.latest_end ()); i != j; ++i) { - QList items; + QList items; items.push_back (new QStandardItem (QString (rai::block_hash (i->first.uint256 ()).to_account ().c_str ()))); rai::account_info info (i->second); std::string balance; @@ -1770,8 +1686,7 @@ wallet (wallet_a) layout->addWidget (process); layout->addWidget (back); window->setLayout (layout); - QObject::connect (process, &QPushButton::released, [this] () - { + QObject::connect (process, &QPushButton::released, [this]() { auto string (block->toPlainText ().toStdString ()); try { @@ -1797,8 +1712,7 @@ wallet (wallet_a) this->status->setText ("Unable to parse block"); } }); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); } @@ -1836,12 +1750,12 @@ wallet (wallet_a) group->setId (receive, 1); group->setId (change, 2); group->setId (open, 3); - + button_layout->addWidget (send); button_layout->addWidget (receive); button_layout->addWidget (open); button_layout->addWidget (change); - + layout->addLayout (button_layout); layout->addWidget (account_label); layout->addWidget (account); @@ -1858,40 +1772,35 @@ wallet (wallet_a) layout->addWidget (create); layout->addWidget (back); window->setLayout (layout); - QObject::connect (send, &QRadioButton::toggled, [this] () - { + QObject::connect (send, &QRadioButton::toggled, [this]() { if (send->isChecked ()) { deactivate_all (); activate_send (); } }); - QObject::connect (receive, &QRadioButton::toggled, [this] () - { + QObject::connect (receive, &QRadioButton::toggled, [this]() { if (receive->isChecked ()) { deactivate_all (); activate_receive (); } }); - QObject::connect (open, &QRadioButton::toggled, [this] () - { + QObject::connect (open, &QRadioButton::toggled, [this]() { if (open->isChecked ()) { deactivate_all (); activate_open (); } }); - QObject::connect (change, &QRadioButton::toggled, [this] () - { + QObject::connect (change, &QRadioButton::toggled, [this]() { if (change->isChecked ()) { deactivate_all (); activate_change (); } }); - QObject::connect (create, &QPushButton::released, [this] () - { + QObject::connect (create, &QPushButton::released, [this]() { switch (group->checkedId ()) { case 0: @@ -1911,8 +1820,7 @@ wallet (wallet_a) break; } }); - QObject::connect (back, &QPushButton::released, [this] () - { + QObject::connect (back, &QPushButton::released, [this]() { this->wallet.pop_main_stack (); }); send->click (); @@ -2036,7 +1944,7 @@ void rai_qt::block_creation::create_receive () auto block_l (wallet.node.store.block_get (transaction, source_l)); if (block_l != nullptr) { - auto send_block (dynamic_cast (block_l.get ())); + auto send_block (dynamic_cast (block_l.get ())); if (send_block != nullptr) { rai::pending_key pending_key (send_block->hashables.destination, source_l); @@ -2079,13 +1987,13 @@ void rai_qt::block_creation::create_receive () else { show_label_error (*status); - status->setText("Source is not a send block"); + status->setText ("Source is not a send block"); } } else { show_label_error (*status); - status->setText("Source block not found"); + status->setText ("Source block not found"); } } else @@ -2160,7 +2068,7 @@ void rai_qt::block_creation::create_open () auto block_l (wallet.node.store.block_get (transaction, source_l)); if (block_l != nullptr) { - auto send_block (dynamic_cast (block_l.get ())); + auto send_block (dynamic_cast (block_l.get ())); if (send_block != nullptr) { rai::pending_key pending_key (send_block->hashables.destination, source_l); @@ -2203,13 +2111,13 @@ void rai_qt::block_creation::create_open () else { show_label_error (*status); - status->setText("Source is not a send block"); + status->setText ("Source is not a send block"); } } else { show_label_error (*status); - status->setText("Source block not found"); + status->setText ("Source block not found"); } } else diff --git a/rai/qt/qt.hpp b/rai/qt/qt.hpp index 54c26b75..e44076b6 100644 --- a/rai/qt/qt.hpp +++ b/rai/qt/qt.hpp @@ -9,326 +9,328 @@ #include #include -namespace rai_qt { - class wallet; - class eventloop_processor : public QObject - { - public: - bool event (QEvent *) override; - }; - class eventloop_event : public QEvent - { - public: - eventloop_event (std::function const &); - std::function action; - }; - class settings - { - public: - settings (rai_qt::wallet &); - void refresh_representative (); - void activate (); - void update_locked (bool, bool); - QWidget * window; - QVBoxLayout * layout; - QLineEdit * password; - QPushButton * lock_toggle; - QFrame * sep1; - QLineEdit * new_password; - QLineEdit * retype_password; - QPushButton * change; - QFrame * sep2; - QLabel * representative; - QLabel * current_representative; - QLineEdit * new_representative; - QPushButton * change_rep; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class advanced_actions - { - public: - advanced_actions (rai_qt::wallet &); - QWidget * window; - QVBoxLayout * layout; - QPushButton * show_ledger; - QPushButton * show_peers; - QPushButton * search_for_receivables; - QPushButton * bootstrap; - QPushButton * wallet_refresh; - QPushButton * create_block; - QPushButton * enter_block; - QPushButton * block_viewer; - QPushButton * account_viewer; - QWidget * scale_window; - QHBoxLayout * scale_layout; - QLabel * scale_label; - QButtonGroup * ratio_group; - QRadioButton * mrai; - QRadioButton * krai; - QRadioButton * rai; - QPushButton * back; +namespace rai_qt +{ +class wallet; +class eventloop_processor : public QObject +{ +public: + bool event (QEvent *) override; +}; +class eventloop_event : public QEvent +{ +public: + eventloop_event (std::function const &); + std::function action; +}; +class settings +{ +public: + settings (rai_qt::wallet &); + void refresh_representative (); + void activate (); + void update_locked (bool, bool); + QWidget * window; + QVBoxLayout * layout; + QLineEdit * password; + QPushButton * lock_toggle; + QFrame * sep1; + QLineEdit * new_password; + QLineEdit * retype_password; + QPushButton * change; + QFrame * sep2; + QLabel * representative; + QLabel * current_representative; + QLineEdit * new_representative; + QPushButton * change_rep; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class advanced_actions +{ +public: + advanced_actions (rai_qt::wallet &); + QWidget * window; + QVBoxLayout * layout; + QPushButton * show_ledger; + QPushButton * show_peers; + QPushButton * search_for_receivables; + QPushButton * bootstrap; + QPushButton * wallet_refresh; + QPushButton * create_block; + QPushButton * enter_block; + QPushButton * block_viewer; + QPushButton * account_viewer; + QWidget * scale_window; + QHBoxLayout * scale_layout; + QLabel * scale_label; + QButtonGroup * ratio_group; + QRadioButton * mrai; + QRadioButton * krai; + QRadioButton * rai; + QPushButton * back; - QWidget * ledger_window; - QVBoxLayout * ledger_layout; - QStandardItemModel * ledger_model; - QTableView * ledger_view; - QPushButton * ledger_refresh; - QPushButton * ledger_back; + QWidget * ledger_window; + QVBoxLayout * ledger_layout; + QStandardItemModel * ledger_model; + QTableView * ledger_view; + QPushButton * ledger_refresh; + QPushButton * ledger_back; - QWidget * peers_window; - QVBoxLayout * peers_layout; - QStandardItemModel * peers_model; - QTableView * peers_view; - QLabel * bootstrap_label; - QLineEdit * bootstrap_line; - QPushButton * peers_bootstrap; - QPushButton * peers_refresh; - QPushButton * peers_back; - - rai_qt::wallet & wallet; - private: - void refresh_ledger (); - void refresh_peers (); - }; - class block_entry - { - public: - block_entry (rai_qt::wallet &); - QWidget * window; - QVBoxLayout * layout; - QPlainTextEdit * block; - QLabel * status; - QPushButton * process; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class block_creation - { - public: - block_creation (rai_qt::wallet &); - void deactivate_all (); - void activate_send (); - void activate_receive (); - void activate_change (); - void activate_open (); - void create_send (); - void create_receive (); - void create_change (); - void create_open (); - QWidget * window; - QVBoxLayout * layout; - QButtonGroup * group; - QHBoxLayout * button_layout; - QRadioButton * send; - QRadioButton * receive; - QRadioButton * change; - QRadioButton * open; - QLabel * account_label; - QLineEdit * account; - QLabel * source_label; - QLineEdit * source; - QLabel * amount_label; - QLineEdit * amount; - QLabel * destination_label; - QLineEdit * destination; - QLabel * representative_label; - QLineEdit * representative; - QPlainTextEdit * block; - QLabel * status; - QPushButton * create; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class self_pane - { - public: - self_pane (rai_qt::wallet &, rai::account const &); - void refresh_balance (); - QWidget * window; - QVBoxLayout * layout; - QHBoxLayout * self_layout; - QWidget * self_window; - QLabel * your_account_label; - QLabel * version; - QWidget * account_window; - QHBoxLayout * account_layout; - QLineEdit * account_text; - QPushButton * copy_button; - QWidget * balance_window; - QHBoxLayout * balance_layout; - QLabel * balance_label; - rai_qt::wallet & wallet; - }; - class accounts - { - public: - accounts (rai_qt::wallet &); - void refresh (); - void refresh_wallet_balance (); - QLabel * wallet_balance_label; - QWidget * window; - QVBoxLayout * layout; - QStandardItemModel * model; - QTableView * view; - QPushButton * use_account; - QPushButton * create_account; - QPushButton * import_wallet; - QPushButton * backup_seed; - QFrame * separator; - QLineEdit * account_key_line; - QPushButton * account_key_button; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class import - { - public: - import (rai_qt::wallet &); - QWidget * window; - QVBoxLayout * layout; - QLabel * seed_label; - QLineEdit * seed; - QLabel * clear_label; - QLineEdit * clear_line; - QPushButton * import_seed; - QFrame * separator; - QLabel * filename_label; - QLineEdit * filename; - QLabel * password_label; - QLineEdit * password; - QPushButton * perform; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class history - { - public: - history (rai::ledger &, rai::account const &, rai_qt::wallet &); - void refresh (); - QWidget * window; - QVBoxLayout * layout; - QStandardItemModel * model; - QTableView * view; - QWidget * tx_window; - QHBoxLayout * tx_layout; - QLabel * tx_label; - QSpinBox * tx_count; - rai::ledger & ledger; - rai::account const & account; - rai_qt::wallet & wallet; - }; - class block_viewer - { - public: - block_viewer (rai_qt::wallet &); - void rebroadcast_action (rai::uint256_union const &); - QWidget * window; - QVBoxLayout * layout; - QLabel * hash_label; - QLineEdit * hash; - QLabel * block_label; - QPlainTextEdit * block; - QLabel * successor_label; - QLineEdit * successor; - QPushButton * retrieve; - QPushButton * rebroadcast; - QPushButton * back; - rai_qt::wallet & wallet; - }; - class account_viewer - { - public: - account_viewer (rai_qt::wallet &); - QWidget * window; - QVBoxLayout * layout; - QLabel * account_label; - QLineEdit * account_line; - QPushButton * refresh; - QWidget * balance_window; - QHBoxLayout * balance_layout; - QLabel * balance_label; - rai_qt::history history; - QPushButton * back; - rai::account account; - rai_qt::wallet & wallet; - }; - enum class status_types - { - not_a_status, - disconnected, - working, - locked, - vulnerable, - active, - synchronizing, - nominal - }; - class status - { - public: - status (rai_qt::wallet &); - void erase (rai_qt::status_types); - void insert (rai_qt::status_types); - void set_text (); - std::string text (); - std::string color (); - std::set active; - rai_qt::wallet & wallet; - }; - class wallet : public std::enable_shared_from_this - { - public: - wallet (QApplication &, rai_qt::eventloop_processor &, rai::node &, std::shared_ptr , rai::account &); - void start (); - void refresh (); - void update_connected (); - void empty_password (); - void change_rendering_ratio (rai::uint128_t const &); - std::string format_balance (rai::uint128_t const &) const; - rai::uint128_t rendering_ratio; - rai::node & node; - std::shared_ptr wallet_m; - rai::account & account; - rai_qt::eventloop_processor & processor; - rai_qt::history history; - rai_qt::accounts accounts; - rai_qt::self_pane self; - rai_qt::settings settings; - rai_qt::advanced_actions advanced; - rai_qt::block_creation block_creation; - rai_qt::block_entry block_entry; - rai_qt::block_viewer block_viewer; - rai_qt::account_viewer account_viewer; - rai_qt::import import; - - QApplication & application; - QLabel * status; - QStackedWidget * main_stack; - - QWidget * client_window; - QVBoxLayout * client_layout; - - QWidget * entry_window; - QVBoxLayout * entry_window_layout; - QFrame * separator; - QLabel * account_history_label; - QPushButton * send_blocks; - QPushButton * settings_button; - QPushButton * accounts_button; - QPushButton * show_advanced; - - QWidget * send_blocks_window; - QVBoxLayout * send_blocks_layout; - QLabel * send_account_label; - QLineEdit * send_account; - QLabel * send_count_label; - QLineEdit * send_count; - QPushButton * send_blocks_send; - QPushButton * send_blocks_back; - - rai_qt::status active_status; - void pop_main_stack (); - void push_main_stack (QWidget *); - }; + QWidget * peers_window; + QVBoxLayout * peers_layout; + QStandardItemModel * peers_model; + QTableView * peers_view; + QLabel * bootstrap_label; + QLineEdit * bootstrap_line; + QPushButton * peers_bootstrap; + QPushButton * peers_refresh; + QPushButton * peers_back; + + rai_qt::wallet & wallet; + +private: + void refresh_ledger (); + void refresh_peers (); +}; +class block_entry +{ +public: + block_entry (rai_qt::wallet &); + QWidget * window; + QVBoxLayout * layout; + QPlainTextEdit * block; + QLabel * status; + QPushButton * process; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class block_creation +{ +public: + block_creation (rai_qt::wallet &); + void deactivate_all (); + void activate_send (); + void activate_receive (); + void activate_change (); + void activate_open (); + void create_send (); + void create_receive (); + void create_change (); + void create_open (); + QWidget * window; + QVBoxLayout * layout; + QButtonGroup * group; + QHBoxLayout * button_layout; + QRadioButton * send; + QRadioButton * receive; + QRadioButton * change; + QRadioButton * open; + QLabel * account_label; + QLineEdit * account; + QLabel * source_label; + QLineEdit * source; + QLabel * amount_label; + QLineEdit * amount; + QLabel * destination_label; + QLineEdit * destination; + QLabel * representative_label; + QLineEdit * representative; + QPlainTextEdit * block; + QLabel * status; + QPushButton * create; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class self_pane +{ +public: + self_pane (rai_qt::wallet &, rai::account const &); + void refresh_balance (); + QWidget * window; + QVBoxLayout * layout; + QHBoxLayout * self_layout; + QWidget * self_window; + QLabel * your_account_label; + QLabel * version; + QWidget * account_window; + QHBoxLayout * account_layout; + QLineEdit * account_text; + QPushButton * copy_button; + QWidget * balance_window; + QHBoxLayout * balance_layout; + QLabel * balance_label; + rai_qt::wallet & wallet; +}; +class accounts +{ +public: + accounts (rai_qt::wallet &); + void refresh (); + void refresh_wallet_balance (); + QLabel * wallet_balance_label; + QWidget * window; + QVBoxLayout * layout; + QStandardItemModel * model; + QTableView * view; + QPushButton * use_account; + QPushButton * create_account; + QPushButton * import_wallet; + QPushButton * backup_seed; + QFrame * separator; + QLineEdit * account_key_line; + QPushButton * account_key_button; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class import +{ +public: + import (rai_qt::wallet &); + QWidget * window; + QVBoxLayout * layout; + QLabel * seed_label; + QLineEdit * seed; + QLabel * clear_label; + QLineEdit * clear_line; + QPushButton * import_seed; + QFrame * separator; + QLabel * filename_label; + QLineEdit * filename; + QLabel * password_label; + QLineEdit * password; + QPushButton * perform; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class history +{ +public: + history (rai::ledger &, rai::account const &, rai_qt::wallet &); + void refresh (); + QWidget * window; + QVBoxLayout * layout; + QStandardItemModel * model; + QTableView * view; + QWidget * tx_window; + QHBoxLayout * tx_layout; + QLabel * tx_label; + QSpinBox * tx_count; + rai::ledger & ledger; + rai::account const & account; + rai_qt::wallet & wallet; +}; +class block_viewer +{ +public: + block_viewer (rai_qt::wallet &); + void rebroadcast_action (rai::uint256_union const &); + QWidget * window; + QVBoxLayout * layout; + QLabel * hash_label; + QLineEdit * hash; + QLabel * block_label; + QPlainTextEdit * block; + QLabel * successor_label; + QLineEdit * successor; + QPushButton * retrieve; + QPushButton * rebroadcast; + QPushButton * back; + rai_qt::wallet & wallet; +}; +class account_viewer +{ +public: + account_viewer (rai_qt::wallet &); + QWidget * window; + QVBoxLayout * layout; + QLabel * account_label; + QLineEdit * account_line; + QPushButton * refresh; + QWidget * balance_window; + QHBoxLayout * balance_layout; + QLabel * balance_label; + rai_qt::history history; + QPushButton * back; + rai::account account; + rai_qt::wallet & wallet; +}; +enum class status_types +{ + not_a_status, + disconnected, + working, + locked, + vulnerable, + active, + synchronizing, + nominal +}; +class status +{ +public: + status (rai_qt::wallet &); + void erase (rai_qt::status_types); + void insert (rai_qt::status_types); + void set_text (); + std::string text (); + std::string color (); + std::set active; + rai_qt::wallet & wallet; +}; +class wallet : public std::enable_shared_from_this +{ +public: + wallet (QApplication &, rai_qt::eventloop_processor &, rai::node &, std::shared_ptr, rai::account &); + void start (); + void refresh (); + void update_connected (); + void empty_password (); + void change_rendering_ratio (rai::uint128_t const &); + std::string format_balance (rai::uint128_t const &) const; + rai::uint128_t rendering_ratio; + rai::node & node; + std::shared_ptr wallet_m; + rai::account & account; + rai_qt::eventloop_processor & processor; + rai_qt::history history; + rai_qt::accounts accounts; + rai_qt::self_pane self; + rai_qt::settings settings; + rai_qt::advanced_actions advanced; + rai_qt::block_creation block_creation; + rai_qt::block_entry block_entry; + rai_qt::block_viewer block_viewer; + rai_qt::account_viewer account_viewer; + rai_qt::import import; + + QApplication & application; + QLabel * status; + QStackedWidget * main_stack; + + QWidget * client_window; + QVBoxLayout * client_layout; + + QWidget * entry_window; + QVBoxLayout * entry_window_layout; + QFrame * separator; + QLabel * account_history_label; + QPushButton * send_blocks; + QPushButton * settings_button; + QPushButton * accounts_button; + QPushButton * show_advanced; + + QWidget * send_blocks_window; + QVBoxLayout * send_blocks_layout; + QLabel * send_account_label; + QLineEdit * send_account; + QLabel * send_count_label; + QLineEdit * send_count; + QPushButton * send_blocks_send; + QPushButton * send_blocks_back; + + rai_qt::status active_status; + void pop_main_stack (); + void push_main_stack (QWidget *); +}; } diff --git a/rai/qt_system/entry.cpp b/rai/qt_system/entry.cpp index ac424fd5..04eed704 100644 --- a/rai/qt_system/entry.cpp +++ b/rai/qt_system/entry.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include @@ -9,22 +9,21 @@ int main (int argc, char ** argv) rai_qt::eventloop_processor processor; static int count (16); rai::system system (24000, count); - std::unique_ptr client_tabs (new QTabWidget); - std::vector > guis; + std::unique_ptr client_tabs (new QTabWidget); + std::vector> guis; for (auto i (0); i < count; ++i) { rai::uint256_union wallet_id; rai::random_pool.GenerateBlock (wallet_id.bytes.data (), wallet_id.bytes.size ()); - auto wallet (system.nodes [i]->wallets.create (wallet_id)); + auto wallet (system.nodes[i]->wallets.create (wallet_id)); rai::keypair key; wallet->insert_adhoc (key.prv); - guis.push_back (std::unique_ptr (new rai_qt::wallet (application, processor, *system.nodes [i], wallet, key.pub))); + guis.push_back (std::unique_ptr (new rai_qt::wallet (application, processor, *system.nodes[i], wallet, key.pub))); client_tabs->addTab (guis.back ()->client_window, boost::str (boost::format ("Wallet %1%") % i).c_str ()); } client_tabs->show (); - rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads); - QObject::connect (&application, &QApplication::aboutToQuit, [&] () - { + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); + QObject::connect (&application, &QApplication::aboutToQuit, [&]() { system.stop (); }); int result; diff --git a/rai/qt_test/entry.cpp b/rai/qt_test/entry.cpp index 89183178..8d900983 100644 --- a/rai/qt_test/entry.cpp +++ b/rai/qt_test/entry.cpp @@ -4,7 +4,7 @@ QApplication * test_application = nullptr; -int main (int argc, char **argv) +int main (int argc, char ** argv) { QApplication application (argc, argv); test_application = &application; diff --git a/rai/qt_test/qt.cpp b/rai/qt_test/qt.cpp index 212d5fb0..eb75b590 100644 --- a/rai/qt_test/qt.cpp +++ b/rai/qt_test/qt.cpp @@ -1,12 +1,12 @@ #include -#include #include +#include #include -#include #include +#include extern QApplication * test_application; @@ -14,9 +14,9 @@ TEST (wallet, construction) { rai_qt::eventloop_processor processor; rai::system system (24000, 1); - auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); + auto wallet_l (system.nodes[0]->wallets.create (rai::uint256_union ())); auto key (wallet_l->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], wallet_l, key)); wallet->start (); ASSERT_EQ (key.to_account_split (), wallet->self.account_text->text ().toStdString ()); ASSERT_EQ (1, wallet->accounts.model->rowCount ()); @@ -28,13 +28,13 @@ TEST (wallet, status) { rai_qt::eventloop_processor processor; rai::system system (24000, 1); - auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); + auto wallet_l (system.nodes[0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], wallet_l, key.pub)); wallet->start (); ASSERT_EQ ("Status: Disconnected, Block: 1", wallet->status->text ().toStdString ()); - system.nodes [0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000), 0); + system.nodes[0]->peers.insert (rai::endpoint (boost::asio::ip::address_v6::loopback (), 10000), 0); ASSERT_NE ("Status: Synchronizing", wallet->status->text ().toStdString ()); auto iterations (0); while (wallet->status->text ().toStdString () != "Status: Synchronizing") @@ -44,7 +44,7 @@ TEST (wallet, status) ++iterations; ASSERT_LT (iterations, 200); } - system.nodes [0]->peers.purge_list (std::chrono::system_clock::now () + std::chrono::seconds (5)); + system.nodes[0]->peers.purge_list (std::chrono::system_clock::now () + std::chrono::seconds (5)); while (wallet->status->text ().toStdString () == "Status: Synchronizing") { test_application->processEvents (); @@ -56,22 +56,22 @@ TEST (wallet, startup_balance) { rai_qt::eventloop_processor processor; rai::system system (24000, 1); - auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); + auto wallet_l (system.nodes[0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], wallet_l, key.pub)); wallet->start (); - ASSERT_EQ ("Balance (XRB): 0", wallet->self.balance_label->text().toStdString ()); + ASSERT_EQ ("Balance (XRB): 0", wallet->self.balance_label->text ().toStdString ()); } TEST (wallet, select_account) { rai_qt::eventloop_processor processor; rai::system system (24000, 1); - auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); + auto wallet_l (system.nodes[0]->wallets.create (rai::uint256_union ())); rai::public_key key1 (wallet_l->deterministic_insert ()); rai::public_key key2 (wallet_l->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], wallet_l, key1)); wallet->start (); ASSERT_EQ (key1, wallet->account); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -89,10 +89,10 @@ TEST (wallet, main) { rai_qt::eventloop_processor processor; rai::system system (24000, 1); - auto wallet_l (system.nodes [0]->wallets.create (rai::uint256_union ())); + auto wallet_l (system.nodes[0]->wallets.create (rai::uint256_union ())); rai::keypair key; wallet_l->insert_adhoc (key.prv); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], wallet_l, key.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], wallet_l, key.pub)); wallet->start (); ASSERT_EQ (wallet->entry_window, wallet->main_stack->currentWidget ()); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); @@ -123,14 +123,14 @@ TEST (wallet, password_change) rai::account account; system.wallet (0)->insert_adhoc (rai::keypair ().prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->settings_button, Qt::LeftButton); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); rai::raw_key password1; rai::raw_key password2; system.wallet (0)->store.derive_key (password1, transaction, "1"); @@ -141,7 +141,7 @@ TEST (wallet, password_change) QTest::keyClicks (wallet->settings.retype_password, "1"); QTest::mouseClick (wallet->settings.change, Qt::LeftButton); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); rai::raw_key password1; rai::raw_key password2; system.wallet (0)->store.derive_key (password1, transaction, "1"); @@ -159,10 +159,10 @@ TEST (client, password_nochange) rai::account account; system.wallet (0)->insert_adhoc (rai::keypair ().prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->settings_button, Qt::LeftButton); auto iterations (0); @@ -176,7 +176,7 @@ TEST (client, password_nochange) system.wallet (0)->store.password.value (password); } { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); rai::raw_key password1; system.wallet (0)->store.derive_key (password1, transaction, ""); rai::raw_key password2; @@ -187,7 +187,7 @@ TEST (client, password_nochange) QTest::keyClicks (wallet->settings.retype_password, "2"); QTest::mouseClick (wallet->settings.change, Qt::LeftButton); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); rai::raw_key password1; system.wallet (0)->store.derive_key (password1, transaction, ""); rai::raw_key password2; @@ -205,29 +205,29 @@ TEST (wallet, enter_password) rai::account account; system.wallet (0)->insert_adhoc (rai::keypair ().prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.password)); ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.lock_toggle)); ASSERT_NE (-1, wallet->settings.layout->indexOf (wallet->settings.back)); QTest::mouseClick (wallet->settings_button, Qt::LeftButton); - test_application->processEvents(); + test_application->processEvents (); ASSERT_EQ ("Status: Wallet password empty", wallet->status->text ().toStdString ()); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); ASSERT_FALSE (system.wallet (0)->store.rekey (transaction, "abc")); } QTest::mouseClick (wallet->settings_button, Qt::LeftButton); QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton); - test_application->processEvents(); + test_application->processEvents (); ASSERT_EQ ("Status: Wallet locked", wallet->status->text ().toStdString ()); wallet->settings.new_password->setText (""); QTest::keyClicks (wallet->settings.password, "abc"); QTest::mouseClick (wallet->settings.lock_toggle, Qt::LeftButton); - test_application->processEvents(); + test_application->processEvents (); ASSERT_EQ ("Status: Running", wallet->status->text ().toStdString ()); ASSERT_EQ ("", wallet->settings.password->text ()); } @@ -239,7 +239,7 @@ TEST (wallet, send) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); rai::public_key key1 (system.wallet (1)->insert_adhoc (rai::keypair ().prv)); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); QTest::keyClicks (wallet->send_account, key1.to_account ().c_str ()); @@ -272,7 +272,7 @@ TEST (wallet, send_locked) rai::keypair key1; system.wallet (0)->enter_password ("0"); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->send_blocks, Qt::LeftButton); QTest::keyClicks (wallet->send_account, key1.pub.to_account ().c_str ()); @@ -293,13 +293,13 @@ TEST (wallet, process_block) rai_qt::eventloop_processor processor; rai::system system (24000, 1); rai::account account; - rai::block_hash latest (system.nodes [0]->latest (rai::genesis_account)); + rai::block_hash latest (system.nodes[0]->latest (rai::genesis_account)); system.wallet (0)->insert_adhoc (rai::keypair ().prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); ASSERT_EQ ("Process", wallet->block_entry.process->text ()); ASSERT_EQ ("Back", wallet->block_entry.back->text ()); @@ -318,8 +318,8 @@ TEST (wallet, process_block) auto block_json (boost::str (boost::format ("{\"type\": \"send\", \"previous\": \"%1%\", \"balance\": \"%2%\", \"destination\": \"%3%\", \"work\": \"%4%\", \"signature\": \"%5%\"}") % previous % balance % send.hashables.destination.to_account () % rai::to_string_hex (send.work) % signature)); QTest::keyClicks (wallet->block_entry.block, block_json.c_str ()); QTest::mouseClick (wallet->block_entry.process, Qt::LeftButton); - ASSERT_EQ (send.hash (), system.nodes [0]->latest (rai::genesis_account)); - QTest::mouseClick(wallet->block_entry.back, Qt::LeftButton); + ASSERT_EQ (send.hash (), system.nodes[0]->latest (rai::genesis_account)); + QTest::mouseClick (wallet->block_entry.back, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); } @@ -331,7 +331,7 @@ TEST (wallet, create_send) system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->insert_adhoc (key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -349,8 +349,8 @@ TEST (wallet, create_send) bool error; rai::send_block send (error, tree1); ASSERT_FALSE (error); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (send).code); - ASSERT_EQ (rai::process_result::old, system.nodes [0]->process (send).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (send).code); + ASSERT_EQ (rai::process_result::old, system.nodes[0]->process (send).code); } TEST (wallet, create_open_receive) @@ -360,13 +360,13 @@ TEST (wallet, create_open_receive) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 100); - rai::block_hash latest1 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest1 (system.nodes[0]->latest (rai::test_genesis_key.pub)); system.wallet (0)->send_action (rai::test_genesis_key.pub, key.pub, 100); - rai::block_hash latest2 (system.nodes [0]->latest (rai::test_genesis_key.pub)); + rai::block_hash latest2 (system.nodes[0]->latest (rai::test_genesis_key.pub)); ASSERT_NE (latest1, latest2); system.wallet (0)->insert_adhoc (key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -383,8 +383,8 @@ TEST (wallet, create_open_receive) bool error; rai::open_block open (error, tree1); ASSERT_FALSE (error); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (open).code); - ASSERT_EQ (rai::process_result::old, system.nodes [0]->process (open).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (open).code); + ASSERT_EQ (rai::process_result::old, system.nodes[0]->process (open).code); wallet->block_creation.block->clear (); wallet->block_creation.source->clear (); QTest::mouseClick (wallet->block_creation.receive, Qt::LeftButton); @@ -398,8 +398,8 @@ TEST (wallet, create_open_receive) bool error2; rai::receive_block receive (error2, tree2); ASSERT_FALSE (error2); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (receive).code); - ASSERT_EQ (rai::process_result::old, system.nodes [0]->process (receive).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (receive).code); + ASSERT_EQ (rai::process_result::old, system.nodes[0]->process (receive).code); } TEST (wallet, create_change) @@ -409,7 +409,7 @@ TEST (wallet, create_change) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); wallet->client_window->show (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); @@ -426,8 +426,8 @@ TEST (wallet, create_change) bool error (false); rai::change_block change (error, tree1); ASSERT_FALSE (error); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->process (change).code); - ASSERT_EQ (rai::process_result::old, system.nodes [0]->process (change).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->process (change).code); + ASSERT_EQ (rai::process_result::old, system.nodes[0]->process (change).code); } TEST (history, short_text) @@ -439,10 +439,10 @@ TEST (history, short_text) system.wallet (0)->insert_adhoc (key.prv); rai::account account; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); rai::block_store store (init, rai::unique_path ()); ASSERT_TRUE (!init); rai::genesis genesis; @@ -471,15 +471,15 @@ TEST (wallet, startup_work) system.wallet (0)->insert_adhoc (key.prv); rai::account account; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); uint64_t work1; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); ASSERT_TRUE (wallet->wallet_m->store.work_get (transaction, rai::test_genesis_key.pub, work1)); } QTest::mouseClick (wallet->accounts_button, Qt::LeftButton); @@ -492,7 +492,7 @@ TEST (wallet, startup_work) system.poll (); ++iterations1; ASSERT_LT (iterations1, 200); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); again = wallet->wallet_m->store.work_get (transaction, rai::test_genesis_key.pub, work1); } } @@ -505,16 +505,16 @@ TEST (wallet, block_viewer) system.wallet (0)->insert_adhoc (key.prv); rai::account account; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); account = system.account (transaction, 0); } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_NE (-1, wallet->advanced.layout->indexOf (wallet->advanced.block_viewer)); QTest::mouseClick (wallet->advanced.block_viewer, Qt::LeftButton); ASSERT_EQ (wallet->block_viewer.window, wallet->main_stack->currentWidget ()); - rai::block_hash latest (system.nodes [0]->latest (rai::genesis_account)); + rai::block_hash latest (system.nodes[0]->latest (rai::genesis_account)); QTest::keyClicks (wallet->block_viewer.hash, latest.to_string ().c_str ()); QTest::mouseClick (wallet->block_viewer.retrieve, Qt::LeftButton); ASSERT_FALSE (wallet->block_viewer.block->toPlainText ().toStdString ().empty ()); @@ -531,7 +531,7 @@ TEST (wallet, import) rai::keypair key2; system.wallet (0)->insert_adhoc (key1.prv); { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); system.wallet (0)->store.serialize_json (transaction, json); } system.wallet (1)->insert_adhoc (key2.prv); @@ -541,7 +541,7 @@ TEST (wallet, import) stream.open (path.string ().c_str ()); stream << json; } - auto wallet (std::make_shared (*test_application, processor, *system.nodes [1], system.wallet (1), key2.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[1], system.wallet (1), key2.pub)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -564,13 +564,13 @@ TEST (wallet, republish) rai::keypair key; rai::block_hash hash; { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); - rai::send_block block (system.nodes [0]->ledger.latest (transaction, rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); + rai::send_block block (system.nodes[0]->ledger.latest (transaction, rai::test_genesis_key.pub), key.pub, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0); hash = block.hash (); - ASSERT_EQ (rai::process_result::progress, system.nodes [0]->ledger.process (transaction, block).code); + ASSERT_EQ (rai::process_result::progress, system.nodes[0]->ledger.process (transaction, block).code); } auto account (rai::test_genesis_key.pub); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), account)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), account)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -578,9 +578,9 @@ TEST (wallet, republish) ASSERT_EQ (wallet->block_viewer.window, wallet->main_stack->currentWidget ()); QTest::keyClicks (wallet->block_viewer.hash, hash.to_string ().c_str ()); QTest::mouseClick (wallet->block_viewer.rebroadcast, Qt::LeftButton); - ASSERT_FALSE (system.nodes [1]->balance (rai::test_genesis_key.pub).is_zero ()); + ASSERT_FALSE (system.nodes[1]->balance (rai::test_genesis_key.pub).is_zero ()); int iterations (0); - while (system.nodes [1]->balance (rai::test_genesis_key.pub).is_zero ()) + while (system.nodes[1]->balance (rai::test_genesis_key.pub).is_zero ()) { ++iterations; ASSERT_LT (iterations, 200); @@ -594,7 +594,7 @@ TEST (wallet, ignore_empty_adhoc) rai::system system (24000, 1); rai::keypair key1; system.wallet (0)->insert_adhoc (key1.prv); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1.pub)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), key1.pub)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -622,7 +622,7 @@ TEST (wallet, change_seed) rai::raw_key seed3; system.wallet (0)->store.seed (seed3, rai::transaction (system.wallet (0)->store.environment, nullptr, false)); auto wallet_key (key1); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), wallet_key)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), wallet_key)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -664,7 +664,7 @@ TEST (wallet, seed_work_generation) rai_qt::eventloop_processor processor; rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -688,7 +688,7 @@ TEST (wallet, seed_work_generation) ++iterations; ASSERT_LT (iterations, 200); } - ASSERT_FALSE (rai::work_validate (system.nodes [0]->ledger.latest_root (rai::transaction (system.wallet (0)->store.environment, nullptr, false), key1), work)); + ASSERT_FALSE (rai::work_validate (system.nodes[0]->ledger.latest_root (rai::transaction (system.wallet (0)->store.environment, nullptr, false), key1), work)); } TEST (wallet, backup_seed) @@ -696,7 +696,7 @@ TEST (wallet, backup_seed) rai_qt::eventloop_processor processor; rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -714,7 +714,7 @@ TEST (wallet, import_locked) rai::system system (24000, 1); auto key1 (system.wallet (0)->deterministic_insert ()); system.wallet (0)->store.rekey (rai::transaction (system.wallet (0)->store.environment, nullptr, true), "1"); - auto wallet (std::make_shared (*test_application, processor, *system.nodes [0], system.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system.nodes[0], system.wallet (0), key1)); wallet->start (); QTest::mouseClick (wallet->show_advanced, Qt::LeftButton); ASSERT_EQ (wallet->advanced.window, wallet->main_stack->currentWidget ()); @@ -742,22 +742,22 @@ TEST (wallet, synchronizing) rai::system system0 (24000, 1); rai::system system1 (24001, 1); auto key1 (system0.wallet (0)->deterministic_insert ()); - auto wallet (std::make_shared (*test_application, processor, *system0.nodes [0], system0.wallet (0), key1)); + auto wallet (std::make_shared (*test_application, processor, *system0.nodes[0], system0.wallet (0), key1)); wallet->start (); { - rai::transaction transaction (system1.nodes [0]->store.environment, nullptr, true); - auto latest (system1.nodes [0]->ledger.latest (transaction, rai::genesis_account)); + rai::transaction transaction (system1.nodes[0]->store.environment, nullptr, true); + auto latest (system1.nodes[0]->ledger.latest (transaction, rai::genesis_account)); rai::send_block send (latest, key1, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, system1.work.generate (latest)); - system1.nodes [0]->ledger.process (transaction, send); + system1.nodes[0]->ledger.process (transaction, send); } ASSERT_EQ (0, wallet->active_status.active.count (rai_qt::status_types::synchronizing)); - system0.nodes [0]->bootstrap_initiator.bootstrap (system1.nodes [0]->network.endpoint ()); + system0.nodes[0]->bootstrap_initiator.bootstrap (system1.nodes[0]->network.endpoint ()); auto iterations0 (0); while (wallet->active_status.active.count (rai_qt::status_types::synchronizing) == 0) { system0.poll (); system1.poll (); - test_application->processEvents(); + test_application->processEvents (); ++iterations0; ASSERT_GT (200, iterations0); } @@ -766,7 +766,7 @@ TEST (wallet, synchronizing) { system0.poll (); system1.poll (); - test_application->processEvents(); + test_application->processEvents (); ++iterations1; ASSERT_GT (200, iterations1); } diff --git a/rai/rai_node/daemon.cpp b/rai/rai_node/daemon.cpp index 6f34531f..1b7b0c74 100644 --- a/rai/rai_node/daemon.cpp +++ b/rai/rai_node/daemon.cpp @@ -1,9 +1,9 @@ #include -#include #include -#include #include +#include +#include rai_daemon::daemon_config::daemon_config (boost::filesystem::path const & application_path_a) : rpc_enable (false), @@ -34,19 +34,19 @@ bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::prop { if (!tree_a.empty ()) { - auto version_l (tree_a.get_optional ("version")); + auto version_l (tree_a.get_optional ("version")); if (!version_l) { tree_a.put ("version", "1"); version_l = "1"; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); - rpc_enable = tree_a.get ("rpc_enable"); + rpc_enable = tree_a.get ("rpc_enable"); auto rpc_l (tree_a.get_child ("rpc")); error |= rpc.deserialize_json (rpc_l); auto & node_l (tree_a.get_child ("node")); error |= node.deserialize_json (upgraded_a, node_l); - opencl_enable = tree_a.get ("opencl_enable"); + opencl_enable = tree_a.get ("opencl_enable"); auto & opencl_l (tree_a.get_child ("opencl")); error |= opencl.deserialize_json (opencl_l); } @@ -63,33 +63,32 @@ bool rai_daemon::daemon_config::deserialize_json (bool & upgraded_a, boost::prop return error; } - bool rai_daemon::daemon_config::upgrade_json (unsigned version_a, boost::property_tree::ptree & tree_a) { auto result (false); switch (version_a) { - case 1: - { - auto opencl_enable_l (tree_a.get_optional ("opencl_enable")); - if (!opencl_enable_l) + case 1: { - tree_a.put ("opencl_enable", "false"); + auto opencl_enable_l (tree_a.get_optional ("opencl_enable")); + if (!opencl_enable_l) + { + tree_a.put ("opencl_enable", "false"); + } + auto opencl_l (tree_a.get_child_optional ("opencl")); + if (!opencl_l) + { + boost::property_tree::ptree opencl_l; + opencl.serialize_json (opencl_l); + tree_a.put_child ("opencl", opencl_l); + } + tree_a.put ("version", "2"); + result = true; } - auto opencl_l (tree_a.get_child_optional ("opencl")); - if (!opencl_l) - { - boost::property_tree::ptree opencl_l; - opencl.serialize_json (opencl_l); - tree_a.put_child ("opencl", opencl_l); - } - tree_a.put ("version", "2"); - result = true; - } - case 2: - break; - default: - throw std::runtime_error ("Unknown daemon_config version"); + case 2: + break; + default: + throw std::runtime_error ("Unknown daemon_config version"); } return result; } @@ -100,7 +99,7 @@ void rai_daemon::daemon::run (boost::filesystem::path const & data_path) rai_daemon::daemon_config config (data_path); auto config_path ((data_path / "config.json")); std::fstream config_file; - std::unique_ptr runner; + std::unique_ptr runner; auto error (rai::fetch_object (config, config_path, config_file)); if (!error) { @@ -108,15 +107,15 @@ void rai_daemon::daemon::run (boost::filesystem::path const & data_path) config_file.close (); boost::asio::io_service service; auto opencl (rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging)); - rai::work_pool opencl_work (config.node.work_threads, opencl ? [&opencl] (rai::uint256_union const & root_a) - { + rai::work_pool opencl_work (config.node.work_threads, opencl ? [&opencl](rai::uint256_union const & root_a) { return opencl->generate_work (root_a); - } : std::function (rai::uint256_union const &)> (nullptr)); + } + : std::function (rai::uint256_union const &)> (nullptr)); rai::alarm alarm (service); rai::node_init init; try { - auto node (std::make_shared (init, service, data_path, alarm, config.node, opencl_work)); + auto node (std::make_shared (init, service, data_path, alarm, config.node, opencl_work)); if (!init.error ()) { node->start (); @@ -133,9 +132,9 @@ void rai_daemon::daemon::run (boost::filesystem::path const & data_path) std::cerr << "Error initializing node\n"; } } - catch(const std::runtime_error& e) + catch (const std::runtime_error & e) { - std::cerr << "Error while running node (" << e.what() << ")\n"; + std::cerr << "Error while running node (" << e.what () << ")\n"; } } else diff --git a/rai/rai_node/daemon.hpp b/rai/rai_node/daemon.hpp index b8ce102e..89384ab5 100644 --- a/rai/rai_node/daemon.hpp +++ b/rai/rai_node/daemon.hpp @@ -3,22 +3,22 @@ namespace rai_daemon { - class daemon - { - public: - void run (boost::filesystem::path const &); - }; - class daemon_config - { - public: - daemon_config (boost::filesystem::path const &); - bool deserialize_json (bool &, boost::property_tree::ptree &); - void serialize_json (boost::property_tree::ptree &); - bool upgrade_json (unsigned, boost::property_tree::ptree &); - bool rpc_enable; - rai::rpc_config rpc; - rai::node_config node; - bool opencl_enable; - rai::opencl_config opencl; - }; +class daemon +{ +public: + void run (boost::filesystem::path const &); +}; +class daemon_config +{ +public: + daemon_config (boost::filesystem::path const &); + bool deserialize_json (bool &, boost::property_tree::ptree &); + void serialize_json (boost::property_tree::ptree &); + bool upgrade_json (unsigned, boost::property_tree::ptree &); + bool rpc_enable; + rai::rpc_config rpc; + rai::node_config node; + bool opencl_enable; + rai::opencl_config opencl; +}; } diff --git a/rai/rai_node/entry.cpp b/rai/rai_node/entry.cpp index 69851a4b..4777c571 100644 --- a/rai/rai_node/entry.cpp +++ b/rai/rai_node/entry.cpp @@ -4,45 +4,47 @@ #include -#include #include +#include class xorshift128 { public: - uint64_t s[ 2 ]; - - uint64_t next(void) { - uint64_t s1 = s[ 0 ]; - const uint64_t s0 = s[ 1 ]; - s[ 0 ] = s0; + uint64_t s[2]; + + uint64_t next (void) + { + uint64_t s1 = s[0]; + const uint64_t s0 = s[1]; + s[0] = s0; s1 ^= s1 << 23; // a - return ( s[ 1 ] = ( s1 ^ s0 ^ ( s1 >> 17 ) ^ ( s0 >> 26 ) ) ) + s0; // b, c + return (s[1] = (s1 ^ s0 ^ (s1 >> 17) ^ (s0 >> 26))) + s0; // b, c } }; class xorshift1024 { public: - uint64_t s[ 16 ]; + uint64_t s[16]; int p; - - uint64_t next(void) { - uint64_t s0 = s[ p ]; - uint64_t s1 = s[ p = ( p + 1 ) & 15 ]; + + uint64_t next (void) + { + uint64_t s0 = s[p]; + uint64_t s1 = s[p = (p + 1) & 15]; s1 ^= s1 << 31; // a s1 ^= s1 >> 11; // b s0 ^= s0 >> 30; // c - return ( s[ p ] = s0 ^ s1 ) * 1181783497276652981LL; + return (s[p] = s0 ^ s1) * 1181783497276652981LL; } }; void fill_128_reference (void * data) { xorshift128 rng; - rng.s [0] = 1; - rng.s [1] = 0; - for (auto i (reinterpret_cast (data)), n (reinterpret_cast (data) + 1024 * 1024); i != n; ++i) + rng.s[0] = 1; + rng.s[1] = 0; + for (auto i (reinterpret_cast (data)), n (reinterpret_cast (data) + 1024 * 1024); i != n; ++i) { *i = rng.next (); } @@ -67,12 +69,12 @@ void fill_1024_reference (void * data) { xorshift1024 rng; rng.p = 0; - rng.s [0] = 1; + rng.s[0] = 1; for (auto i (0u); i < 16; ++i) { - rng.s [i] = 0; + rng.s[i] = 0; } - for (auto i (reinterpret_cast (data)), n (reinterpret_cast (data) + 1024 * 1024); i != n; ++i) + for (auto i (reinterpret_cast (data)), n (reinterpret_cast (data) + 1024 * 1024); i != n; ++i) { *i = rng.next (); } @@ -109,26 +111,9 @@ int main (int argc, char * const * argv) { boost::program_options::options_description description ("Command line options"); rai::add_node_options (description); - description.add_options () - ("help", "Print out options") - ("daemon", "Start node daemon") - ("debug_block_count", "Display the number of block") - ("debug_bootstrap_generate", "Generate bootstrap sequence of blocks") - ("debug_dump_representatives", "List representatives and weights") - ("debug_frontier_count", "Display the number of accounts") - ("debug_mass_activity", "Generates fake debug activity") - ("debug_profile_generate", "Profile work generation") - ("debug_opencl", "OpenCL work generation") - ("debug_profile_verify", "Profile work verification") - ("debug_profile_kdf", "Profile kdf function") - ("debug_verify_profile", "Profile signature verification") - ("debug_profile_sign", "Profile signature generation") - ("debug_xorshift_profile", "Profile xorshift algorithms") - ("platform", boost::program_options::value (), "Defines the for OpenCL commands") - ("device", boost::program_options::value (), "Defines for OpenCL command") - ("threads", boost::program_options::value (), "Defines count for OpenCL command"); + description.add_options () ("help", "Print out options") ("daemon", "Start node daemon") ("debug_block_count", "Display the number of block") ("debug_bootstrap_generate", "Generate bootstrap sequence of blocks") ("debug_dump_representatives", "List representatives and weights") ("debug_frontier_count", "Display the number of accounts") ("debug_mass_activity", "Generates fake debug activity") ("debug_profile_generate", "Profile work generation") ("debug_opencl", "OpenCL work generation") ("debug_profile_verify", "Profile work verification") ("debug_profile_kdf", "Profile kdf function") ("debug_verify_profile", "Profile signature verification") ("debug_profile_sign", "Profile signature generation") ("debug_xorshift_profile", "Profile xorshift algorithms") ("platform", boost::program_options::value (), "Defines the for OpenCL commands") ("device", boost::program_options::value (), "Defines for OpenCL command") ("threads", boost::program_options::value (), "Defines count for OpenCL command"); boost::program_options::variables_map vm; - boost::program_options::store (boost::program_options::parse_command_line(argc, argv, description), vm); + boost::program_options::store (boost::program_options::parse_command_line (argc, argv, description), vm); boost::program_options::notify (vm); int result (0); if (!rai::handle_node_options (vm)) @@ -139,7 +124,7 @@ int main (int argc, char * const * argv) boost::filesystem::path data_path; if (vm.count ("data_path")) { - data_path = boost::filesystem::path (vm ["data_path"].as ()); + data_path = boost::filesystem::path (vm["data_path"].as ()); } else { @@ -159,19 +144,25 @@ int main (int argc, char * const * argv) if (vm.count ("key") == 1) { rai::uint256_union key; - if (!key.decode_hex (vm ["key"].as ())) + if (!key.decode_hex (vm["key"].as ())) { rai::keypair genesis (key.to_string ()); - rai::work_pool work (std::numeric_limits ::max (), nullptr); - std::cout << "Genesis: " << genesis.prv.data.to_string () << std::endl << "Public: " << genesis.pub.to_string () << std::endl << "Account: " << genesis.pub.to_account () << std::endl; + rai::work_pool work (std::numeric_limits::max (), nullptr); + std::cout << "Genesis: " << genesis.prv.data.to_string () << std::endl + << "Public: " << genesis.pub.to_string () << std::endl + << "Account: " << genesis.pub.to_account () << std::endl; rai::keypair landing; - std::cout << "Landing: " << landing.prv.data.to_string () << std::endl << "Public: " << landing.pub.to_string () << std::endl << "Account: " << landing.pub.to_account () << std::endl; + std::cout << "Landing: " << landing.prv.data.to_string () << std::endl + << "Public: " << landing.pub.to_string () << std::endl + << "Account: " << landing.pub.to_account () << std::endl; for (auto i (0); i != 32; ++i) { rai::keypair rep; - std::cout << "Rep" << i << ": " << rep.prv.data.to_string () << std::endl << "Public: " << rep.pub.to_string () << std::endl << "Account: " << rep.pub.to_account () << std::endl; + std::cout << "Rep" << i << ": " << rep.prv.data.to_string () << std::endl + << "Public: " << rep.pub.to_string () << std::endl + << "Account: " << rep.pub.to_account () << std::endl; } - rai::uint128_t balance (std::numeric_limits ::max ()); + rai::uint128_t balance (std::numeric_limits::max ()); rai::open_block genesis_block (genesis.pub, genesis.pub, genesis.pub, genesis.prv, genesis.pub, work.generate (genesis.pub)); std::cout << genesis_block.to_json (); rai::block_hash previous (genesis_block.hash ()); @@ -207,27 +198,27 @@ int main (int argc, char * const * argv) rai::inactive_node node; rai::transaction transaction (node.node->store.environment, nullptr, false); rai::uint128_t total; - for (auto i(node.node->store.representation_begin(transaction)), n(node.node->store.representation_end()); i != n; ++i) + for (auto i (node.node->store.representation_begin (transaction)), n (node.node->store.representation_end ()); i != n; ++i) { rai::account account (i->first.uint256 ()); - auto amount (node.node->store.representation_get(transaction, account)); + auto amount (node.node->store.representation_get (transaction, account)); total += amount; - std::cout << boost::str(boost::format("%1% %2% %3%\n") % account.to_account () % amount.convert_to () % total.convert_to ()); + std::cout << boost::str (boost::format ("%1% %2% %3%\n") % account.to_account () % amount.convert_to () % total.convert_to ()); } - std::map calculated; + std::map calculated; for (auto i (node.node->store.latest_begin (transaction)), n (node.node->store.latest_end ()); i != n; ++i) { rai::account account (i->first.uint256 ()); rai::account_info info (i->second); rai::block_hash rep_block (node.node->ledger.representative_calculated (transaction, info.head)); - std::unique_ptr block (node.node->store.block_get (transaction, rep_block)); - calculated [block->representative()] += info.balance.number(); + std::unique_ptr block (node.node->store.block_get (transaction, rep_block)); + calculated[block->representative ()] += info.balance.number (); } total = 0; for (auto i (calculated.begin ()), n (calculated.end ()); i != n; ++i) { total += i->second; - std::cout << boost::str(boost::format("%1% %2% %3%\n") % i->first.to_account () % i->second.convert_to () % total.convert_to ()); + std::cout << boost::str (boost::format ("%1% %2% %3%\n") % i->first.to_account () % i->second.convert_to () % total.convert_to ()); } } else if (vm.count ("debug_frontier_count")) @@ -240,7 +231,7 @@ int main (int argc, char * const * argv) { rai::system system (24000, 1); size_t count (1000000); - system.generate_mass_activity (count, *system.nodes [0]); + system.generate_mass_activity (count, *system.nodes[0]); } else if (vm.count ("debug_profile_kdf")) { @@ -252,21 +243,21 @@ int main (int argc, char * const * argv) auto begin1 (std::chrono::high_resolution_clock::now ()); auto success (argon2_hash (1, rai::wallet_store::kdf_work, 1, password.data (), password.size (), salt.bytes.data (), salt.bytes.size (), result.bytes.data (), result.bytes.size (), NULL, 0, Argon2_d, 0x10)); auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("Derivation time: %1%us\n") % std::chrono::duration_cast (end1 - begin1).count ()); + std::cerr << boost::str (boost::format ("Derivation time: %1%us\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } else if (vm.count ("debug_profile_generate")) { - rai::work_pool work (std::numeric_limits ::max (), nullptr); + rai::work_pool work (std::numeric_limits::max (), nullptr); rai::change_block block (0, 0, rai::keypair ().prv, 0, 0); std::cerr << "Starting generation profiling\n"; for (uint64_t i (0); true; ++i) { - block.hashables.previous.qwords [0] += 1; + block.hashables.previous.qwords[0] += 1; auto begin1 (std::chrono::high_resolution_clock::now ()); block.block_work_set (work.generate (block.root ())); auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); + std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } else if (vm.count ("debug_opencl")) @@ -278,10 +269,12 @@ int main (int argc, char * const * argv) unsigned short platform (0); if (vm.count ("platform") == 1) { - try { - platform = boost::lexical_cast (vm ["platform"].as ()); + try + { + platform = boost::lexical_cast (vm["platform"].as ()); } - catch (boost::bad_lexical_cast & e ) { + catch (boost::bad_lexical_cast & e) + { std::cerr << "Invalid platform id\n"; result = -1; } @@ -289,10 +282,12 @@ int main (int argc, char * const * argv) unsigned short device (0); if (vm.count ("device") == 1) { - try { - device = boost::lexical_cast (vm ["device"].as ()); + try + { + device = boost::lexical_cast (vm["device"].as ()); } - catch (boost::bad_lexical_cast & e ) { + catch (boost::bad_lexical_cast & e) + { std::cerr << "Invalid device id\n"; result = -1; } @@ -300,10 +295,12 @@ int main (int argc, char * const * argv) unsigned threads (1024 * 1024); if (vm.count ("threads") == 1) { - try { - threads = boost::lexical_cast (vm ["threads"].as ()); + try + { + threads = boost::lexical_cast (vm["threads"].as ()); } - catch (boost::bad_lexical_cast & e ) { + catch (boost::bad_lexical_cast & e) + { std::cerr << "Invalid threads count\n"; result = -1; } @@ -317,31 +314,33 @@ int main (int argc, char * const * argv) if (!error) { rai::logging logging; - auto opencl (rai::opencl_work::create (true, {platform, device, threads}, logging)); - rai::work_pool work_pool (std::numeric_limits ::max (), opencl ? [&opencl] (rai::uint256_union const & root_a) - { + auto opencl (rai::opencl_work::create (true, { platform, device, threads }, logging)); + rai::work_pool work_pool (std::numeric_limits::max (), opencl ? [&opencl](rai::uint256_union const & root_a) { return opencl->generate_work (root_a); - } : std::function (rai::uint256_union const &)> (nullptr)); + } + : std::function (rai::uint256_union const &)> (nullptr)); rai::change_block block (0, 0, rai::keypair ().prv, 0, 0); std::cerr << boost::str (boost::format ("Starting OpenCL generation profiling. Platform: %1%. Device: %2%. Threads: %3%\n") % platform % device % threads); for (uint64_t i (0); true; ++i) { - block.hashables.previous.qwords [0] += 1; + block.hashables.previous.qwords[0] += 1; auto begin1 (std::chrono::high_resolution_clock::now ()); block.block_work_set (work_pool.generate (block.root ())); auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); + std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } else { - std::cout << "Not available device id\n" << std::endl; + std::cout << "Not available device id\n" + << std::endl; result = -1; } } else { - std::cout << "Not available platform id\n" << std::endl; + std::cout << "Not available platform id\n" + << std::endl; result = -1; } } @@ -354,21 +353,21 @@ int main (int argc, char * const * argv) } else if (vm.count ("debug_profile_verify")) { - rai::work_pool work (std::numeric_limits ::max (), nullptr); + rai::work_pool work (std::numeric_limits::max (), nullptr); rai::change_block block (0, 0, rai::keypair ().prv, 0, 0); std::cerr << "Starting verification profiling\n"; for (uint64_t i (0); true; ++i) { - block.hashables.previous.qwords [0] += 1; + block.hashables.previous.qwords[0] += 1; auto begin1 (std::chrono::high_resolution_clock::now ()); for (uint64_t t (0); t < 1000000; ++t) { - block.hashables.previous.qwords [0] += 1; + block.hashables.previous.qwords[0] += 1; block.block_work_set (t); rai::work_validate (block); } auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); + std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } else if (vm.count ("debug_verify_profile")) @@ -383,7 +382,7 @@ int main (int argc, char * const * argv) rai::validate_message (key.pub, message, signature); } auto end (std::chrono::high_resolution_clock::now ()); - std::cerr << "Signature verifications " << std::chrono::duration_cast (end - begin).count () << std::endl; + std::cerr << "Signature verifications " << std::chrono::duration_cast (end - begin).count () << std::endl; } else if (vm.count ("debug_profile_sign")) { @@ -399,10 +398,10 @@ int main (int argc, char * const * argv) latest = send.hash (); } auto end1 (std::chrono::high_resolution_clock::now ()); - std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); + std::cerr << boost::str (boost::format ("%|1$ 12d|\n") % std::chrono::duration_cast (end1 - begin1).count ()); } } - #if 0 +#if 0 else if (vm.count ("debug_xorshift_profile")) { auto unaligned (new uint8_t [64 * 1024 * 1024 + 16]); @@ -458,7 +457,7 @@ int main (int argc, char * const * argv) std::cerr << "SSE fill 1024 " << std::chrono::duration_cast (end - begin).count () << std::endl; } } - #endif // 0 +#endif // 0 else { std::cout << description << std::endl; diff --git a/rai/rai_wallet/entry.cpp b/rai/rai_wallet/entry.cpp old mode 100755 new mode 100644 index 47dd2379..18334ea0 --- a/rai/rai_wallet/entry.cpp +++ b/rai/rai_wallet/entry.cpp @@ -1,14 +1,14 @@ #include -#include #include #include +#include #include #include -#include #include +#include class qt_wallet_config { @@ -26,47 +26,47 @@ public: auto result (false); switch (version_a) { - case 1: - { - rai::account account; - account.decode_account (tree_a.get ("account")); - tree_a.erase ("account"); - tree_a.put ("account", account.to_account ()); - tree_a.erase ("version"); - tree_a.put ("version", "2"); - result = true; - } - case 2: - { - boost::property_tree::ptree rpc_l; - rpc.serialize_json (rpc_l); - tree_a.put ("rpc_enable", "false"); - tree_a.put_child ("rpc", rpc_l); - tree_a.erase ("version"); - tree_a.put ("version", "3"); - result = true; - } - case 3: - { - auto opencl_enable_l (tree_a.get_optional ("opencl_enable")); - if (!opencl_enable_l) + case 1: { - tree_a.put ("opencl_enable", "false"); + rai::account account; + account.decode_account (tree_a.get ("account")); + tree_a.erase ("account"); + tree_a.put ("account", account.to_account ()); + tree_a.erase ("version"); + tree_a.put ("version", "2"); + result = true; } - auto opencl_l (tree_a.get_child_optional ("opencl")); - if (!opencl_l) + case 2: { - boost::property_tree::ptree opencl_l; - opencl.serialize_json (opencl_l); - tree_a.put_child ("opencl", opencl_l); + boost::property_tree::ptree rpc_l; + rpc.serialize_json (rpc_l); + tree_a.put ("rpc_enable", "false"); + tree_a.put_child ("rpc", rpc_l); + tree_a.erase ("version"); + tree_a.put ("version", "3"); + result = true; } - tree_a.put ("version", "4"); - result = true; - } - case 4: - break; - default: - throw std::runtime_error ("Unknown qt_wallet_config version"); + case 3: + { + auto opencl_enable_l (tree_a.get_optional ("opencl_enable")); + if (!opencl_enable_l) + { + tree_a.put ("opencl_enable", "false"); + } + auto opencl_l (tree_a.get_child_optional ("opencl")); + if (!opencl_l) + { + boost::property_tree::ptree opencl_l; + opencl.serialize_json (opencl_l); + tree_a.put_child ("opencl", opencl_l); + } + tree_a.put ("version", "4"); + result = true; + } + case 4: + break; + default: + throw std::runtime_error ("Unknown qt_wallet_config version"); } return result; } @@ -75,7 +75,7 @@ public: auto error (false); if (!tree_a.empty ()) { - auto version_l (tree_a.get_optional ("version")); + auto version_l (tree_a.get_optional ("version")); if (!version_l) { tree_a.put ("version", "1"); @@ -83,12 +83,12 @@ public: upgraded_a = true; } upgraded_a |= upgrade_json (std::stoull (version_l.get ()), tree_a); - auto wallet_l (tree_a.get ("wallet")); - auto account_l (tree_a.get ("account")); + auto wallet_l (tree_a.get ("wallet")); + auto account_l (tree_a.get ("account")); auto & node_l (tree_a.get_child ("node")); - rpc_enable = tree_a.get ("rpc_enable"); + rpc_enable = tree_a.get ("rpc_enable"); auto & rpc_l (tree_a.get_child ("rpc")); - opencl_enable = tree_a.get ("opencl_enable"); + opencl_enable = tree_a.get ("opencl_enable"); auto & opencl_l (tree_a.get_child ("opencl")); try { @@ -192,12 +192,12 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost { rai_qt::eventloop_processor processor; boost::filesystem::create_directories (data_path); - QPixmap pixmap(":/logo.png"); - QSplashScreen *splash = new QSplashScreen(pixmap); - splash->show(); - application.processEvents(); - splash->showMessage(QSplashScreen::tr("Remember - Backup Your Wallet Seed"), Qt::AlignBottom | Qt::AlignHCenter, Qt::black); - application.processEvents(); + QPixmap pixmap (":/logo.png"); + QSplashScreen * splash = new QSplashScreen (pixmap); + splash->show (); + application.processEvents (); + splash->showMessage (QSplashScreen::tr ("Remember - Backup Your Wallet Seed"), Qt::AlignBottom | Qt::AlignHCenter, Qt::black); + application.processEvents (); qt_wallet_config config (data_path); auto config_path ((data_path / "config.json")); int result (0); @@ -208,17 +208,17 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost { boost::asio::io_service service; config.node.logging.init (data_path); - std::shared_ptr node; - std::shared_ptr gui; + std::shared_ptr node; + std::shared_ptr gui; rai::set_application_icon (application); auto opencl (rai::opencl_work::create (config.opencl_enable, config.opencl, config.node.logging)); - rai::work_pool work (config.node.work_threads, opencl ? [&opencl] (rai::uint256_union const & root_a) - { + rai::work_pool work (config.node.work_threads, opencl ? [&opencl](rai::uint256_union const & root_a) { return opencl->generate_work (root_a); - } : std::function (rai::uint256_union const &)> (nullptr)); + } + : std::function (rai::uint256_union const &)> (nullptr)); rai::alarm alarm (service); rai::node_init init; - node = std::make_shared (init, service, data_path, alarm, config.node, work); + node = std::make_shared (init, service, data_path, alarm, config.node, work); if (!init.error ()) { auto wallet (node->wallets.open (config.wallet)); @@ -258,15 +258,13 @@ int run_wallet (QApplication & application, int argc, char * const * argv, boost rpc.start (); } rai::thread_runner runner (service, node->config.io_threads); - QObject::connect (&application, &QApplication::aboutToQuit, [&] () - { + QObject::connect (&application, &QApplication::aboutToQuit, [&]() { rpc.stop (); node->stop (); }); - application.postEvent (&processor, new rai_qt::eventloop_event ([&] () - { - gui = std::make_shared (application, processor, *node, wallet, config.account); - splash->close(); + application.postEvent (&processor, new rai_qt::eventloop_event ([&]() { + gui = std::make_shared (application, processor, *node, wallet, config.account); + splash->close (); gui->start (); gui->client_window->show (); })); @@ -290,7 +288,7 @@ int main (int argc, char * const * argv) { try { - QApplication application (argc, const_cast (argv)); + QApplication application (argc, const_cast (argv)); boost::program_options::options_description description ("Command line options"); description.add_options () ("help", "Print out options"); rai::add_node_options (description); @@ -312,7 +310,7 @@ int main (int argc, char * const * argv) boost::filesystem::path data_path; if (vm.count ("data_path")) { - auto name (vm ["data_path"].as ()); + auto name (vm["data_path"].as ()); data_path = boost::filesystem::path (name); } else diff --git a/rai/secure.cpp b/rai/secure.cpp old mode 100755 new mode 100644 index 759c2f7c..2c728955 --- a/rai/secure.cpp +++ b/rai/secure.cpp @@ -49,39 +49,39 @@ char const * live_genesis_data = R"%%%({ class ledger_constants { public: -ledger_constants () : -zero_key ("0"), -test_genesis_key (test_private_key_data), -rai_test_account (test_public_key_data), -rai_beta_account (beta_public_key_data), -rai_live_account (live_public_key_data), -rai_test_genesis (test_genesis_data), -rai_beta_genesis (beta_genesis_data), -rai_live_genesis (live_genesis_data), -genesis_account (rai::rai_network == rai::rai_networks::rai_test_network ? rai_test_account : rai::rai_network == rai::rai_networks::rai_beta_network ? rai_beta_account : rai_live_account), -genesis_block (rai::rai_network == rai::rai_networks::rai_test_network ? rai_test_genesis : rai::rai_network == rai::rai_networks::rai_beta_network ? rai_beta_genesis : rai_live_genesis), -genesis_amount (std::numeric_limits ::max ()), -burn_account (0) -{ - CryptoPP::AutoSeededRandomPool random_pool; - // Randomly generating these mean no two nodes will ever have the same sentinal values which protects against some insecure algorithms - random_pool.GenerateBlock (not_a_block.bytes.data (), not_a_block.bytes.size ()); - random_pool.GenerateBlock (not_an_account.bytes.data (), not_an_account.bytes.size ()); -} -rai::keypair zero_key; -rai::keypair test_genesis_key; -rai::account rai_test_account; -rai::account rai_beta_account; -rai::account rai_live_account; -std::string rai_test_genesis; -std::string rai_beta_genesis; -std::string rai_live_genesis; -rai::account genesis_account; -std::string genesis_block; -rai::uint128_t genesis_amount; -rai::block_hash not_a_block; -rai::account not_an_account; -rai::account burn_account; + ledger_constants () : + zero_key ("0"), + test_genesis_key (test_private_key_data), + rai_test_account (test_public_key_data), + rai_beta_account (beta_public_key_data), + rai_live_account (live_public_key_data), + rai_test_genesis (test_genesis_data), + rai_beta_genesis (beta_genesis_data), + rai_live_genesis (live_genesis_data), + genesis_account (rai::rai_network == rai::rai_networks::rai_test_network ? rai_test_account : rai::rai_network == rai::rai_networks::rai_beta_network ? rai_beta_account : rai_live_account), + genesis_block (rai::rai_network == rai::rai_networks::rai_test_network ? rai_test_genesis : rai::rai_network == rai::rai_networks::rai_beta_network ? rai_beta_genesis : rai_live_genesis), + genesis_amount (std::numeric_limits::max ()), + burn_account (0) + { + CryptoPP::AutoSeededRandomPool random_pool; + // Randomly generating these mean no two nodes will ever have the same sentinal values which protects against some insecure algorithms + random_pool.GenerateBlock (not_a_block.bytes.data (), not_a_block.bytes.size ()); + random_pool.GenerateBlock (not_an_account.bytes.data (), not_an_account.bytes.size ()); + } + rai::keypair zero_key; + rai::keypair test_genesis_key; + rai::account rai_test_account; + rai::account rai_beta_account; + rai::account rai_live_account; + std::string rai_test_genesis; + std::string rai_beta_genesis; + std::string rai_live_genesis; + rai::account genesis_account; + std::string genesis_block; + rai::uint128_t genesis_amount; + rai::block_hash not_a_block; + rai::account not_an_account; + rai::account burn_account; }; ledger_constants globals; } @@ -125,31 +125,31 @@ boost::filesystem::path rai::working_path () return result; } -size_t rai::shared_ptr_block_hash::operator () (std::shared_ptr const & block_a) const +size_t rai::shared_ptr_block_hash::operator() (std::shared_ptr const & block_a) const { auto hash (block_a->hash ()); - auto result (static_cast (hash.qwords [0])); + auto result (static_cast (hash.qwords[0])); return result; } -bool rai::shared_ptr_block_hash::operator () (std::shared_ptr const & lhs, std::shared_ptr const & rhs) const +bool rai::shared_ptr_block_hash::operator() (std::shared_ptr const & lhs, std::shared_ptr const & rhs) const { return *lhs == *rhs; } // Sum the weights for each vote and return the winning block with its vote tally -std::pair > rai::ledger::winner (MDB_txn * transaction_a, rai::votes const & votes_a) +std::pair> rai::ledger::winner (MDB_txn * transaction_a, rai::votes const & votes_a) { auto tally_l (tally (transaction_a, votes_a)); auto existing (tally_l.begin ()); return std::make_pair (existing->first, existing->second); } -std::map , std::greater > rai::ledger::tally (MDB_txn * transaction_a, rai::votes const & votes_a) +std::map, std::greater> rai::ledger::tally (MDB_txn * transaction_a, rai::votes const & votes_a) { - std::unordered_map , rai::uint128_t, rai::shared_ptr_block_hash, rai::shared_ptr_block_hash> totals; + std::unordered_map, rai::uint128_t, rai::shared_ptr_block_hash, rai::shared_ptr_block_hash> totals; // Construct a map of blocks -> vote total. - for (auto & i: votes_a.rep_votes) + for (auto & i : votes_a.rep_votes) { auto existing (totals.find (i.second)); if (existing == totals.end ()) @@ -162,21 +162,21 @@ std::map , std::greater second += weight_l; } // Construction a map of vote total -> block in decreasing order. - std::map , std::greater > result; - for (auto & i: totals) + std::map, std::greater> result; + for (auto & i : totals) { - result [i.second] = i.first; + result[i.second] = i.first; } return result; } -rai::votes::votes (std::shared_ptr block_a) : +rai::votes::votes (std::shared_ptr block_a) : id (block_a->root ()) { rep_votes.insert (std::make_pair (rai::not_an_account, block_a)); } -rai::tally_result rai::votes::vote (std::shared_ptr vote_a) +rai::tally_result rai::votes::vote (std::shared_ptr vote_a) { rai::tally_result result; auto existing (rep_votes.find (vote_a->account)); @@ -231,9 +231,9 @@ void rai::serialize_block (rai::stream & stream_a, rai::block const & block_a) block_a.serialize (stream_a); } -std::unique_ptr rai::deserialize_block (MDB_val const & val_a) +std::unique_ptr rai::deserialize_block (MDB_val const & val_a) { - rai::bufferstream stream (reinterpret_cast (val_a.mv_data), val_a.mv_size); + rai::bufferstream stream (reinterpret_cast (val_a.mv_data), val_a.mv_size); return deserialize_block (stream); } @@ -251,7 +251,7 @@ rai::account_info::account_info (MDB_val const & val_a) { assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (head) + sizeof (rep_block) + sizeof (open_block) + sizeof (balance) + sizeof (modified) + sizeof (block_count) == sizeof (*this), "Class not packed"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::account_info::account_info (rai::block_hash const & head_a, rai::block_hash const & rep_block_a, rai::block_hash const & open_block_a, rai::amount const & balance_a, uint64_t modified_a, uint64_t block_count_a) : @@ -300,19 +300,19 @@ bool rai::account_info::deserialize (rai::stream & stream_a) return result; } -bool rai::account_info::operator == (rai::account_info const & other_a) const +bool rai::account_info::operator== (rai::account_info const & other_a) const { return head == other_a.head && rep_block == other_a.rep_block && open_block == other_a.open_block && balance == other_a.balance && modified == other_a.modified && block_count == other_a.block_count; } -bool rai::account_info::operator != (rai::account_info const & other_a) const +bool rai::account_info::operator!= (rai::account_info const & other_a) const { - return ! (*this == other_a); + return !(*this == other_a); } rai::mdb_val rai::account_info::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } rai::store_entry::store_entry () : @@ -323,16 +323,16 @@ second (0, nullptr) void rai::store_entry::clear () { - first = {0, nullptr}; - second = {0, nullptr}; + first = { 0, nullptr }; + second = { 0, nullptr }; } -rai::store_entry * rai::store_entry::operator -> () +rai::store_entry * rai::store_entry::operator-> () { return this; } -rai::store_entry & rai::store_iterator::operator -> () +rai::store_entry & rai::store_iterator::operator-> () { return current; } @@ -394,7 +394,7 @@ rai::store_iterator::~store_iterator () } } -rai::store_iterator & rai::store_iterator::operator ++ () +rai::store_iterator & rai::store_iterator::operator++ () { assert (cursor != nullptr); auto status (mdb_cursor_get (cursor, ¤t.first.value, ¤t.second.value, MDB_NEXT)); @@ -415,7 +415,7 @@ void rai::store_iterator::next_dup () } } -rai::store_iterator & rai::store_iterator::operator = (rai::store_iterator && other_a) +rai::store_iterator & rai::store_iterator::operator= (rai::store_iterator && other_a) { if (cursor != nullptr) { @@ -428,7 +428,7 @@ rai::store_iterator & rai::store_iterator::operator = (rai::store_iterator && ot return *this; } -bool rai::store_iterator::operator == (rai::store_iterator const & other_a) const +bool rai::store_iterator::operator== (rai::store_iterator const & other_a) const { auto result (current.first.data () == other_a.current.first.data ()); assert (!result || (current.first.size () == other_a.current.first.size ())); @@ -437,7 +437,7 @@ bool rai::store_iterator::operator == (rai::store_iterator const & other_a) cons return result; } -bool rai::store_iterator::operator != (rai::store_iterator const & other_a) const +bool rai::store_iterator::operator!= (rai::store_iterator const & other_a) const { return !(*this == other_a); } @@ -516,8 +516,8 @@ int rai::block_store::version_get (MDB_txn * transaction_a) else { rai::uint256_union version_value (data.uint256 ()); - assert (version_value.qwords [2] == 0 && version_value.qwords [1] == 0 && version_value.qwords [0] == 0); - result = version_value.number ().convert_to (); + assert (version_value.qwords[2] == 0 && version_value.qwords[1] == 0 && version_value.qwords[0] == 0); + result = version_value.number ().convert_to (); } return result; } @@ -547,7 +547,7 @@ void rai::block_store::do_upgrades (MDB_txn * transaction_a) case 10: break; default: - assert (false); + assert (false); } } @@ -640,14 +640,14 @@ void rai::block_store::upgrade_v2_to_v3 (MDB_txn * transaction_a) assert (!visitor.result.is_zero ()); info.rep_block = visitor.result; mdb_cursor_put (i.cursor, rai::mdb_val (account_l), info.val (), MDB_CURRENT); - representation_add (transaction_a, visitor.result, info.balance.number()); + representation_add (transaction_a, visitor.result, info.balance.number ()); } } void rai::block_store::upgrade_v3_to_v4 (MDB_txn * transaction_a) { version_put (transaction_a, 4); - std::queue > items; + std::queue> items; for (auto i (pending_begin (transaction_a)), n (pending_end ()); i != n; ++i) { rai::block_hash hash (i->first.uint256 ()); @@ -691,7 +691,7 @@ void rai::block_store::upgrade_v4_to_v5 (MDB_txn * transaction_a) void rai::block_store::upgrade_v5_to_v6 (MDB_txn * transaction_a) { version_put (transaction_a, 6); - std::deque > headers; + std::deque> headers; for (auto i (latest_begin (transaction_a)), n (latest_end ()); i != n; ++i) { rai::account account (i->first.uint256 ()); @@ -733,16 +733,16 @@ void rai::block_store::upgrade_v8_to_v9 (MDB_txn * transaction_a) MDB_dbi sequence; mdb_dbi_open (transaction_a, "sequence", MDB_CREATE | MDB_DUPSORT, &sequence); rai::genesis genesis; - std::shared_ptr block (std::move (genesis.open)); + std::shared_ptr block (std::move (genesis.open)); rai::keypair junk; for (rai::store_iterator i (transaction_a, sequence), n (nullptr); i != n; ++i) { - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); uint64_t sequence; auto error (rai::read (stream, sequence)); // Create a dummy vote with the same sequence number for easy upgrading. This won't have a valid signature. - auto dummy (std::make_shared (rai::account (i->first.uint256 ()), junk.prv, sequence, block)); - std::vector vector; + auto dummy (std::make_shared (rai::account (i->first.uint256 ()), junk.prv, sequence, block)); + std::vector vector; { rai::vectorstream stream (vector); dummy->serialize (stream); @@ -809,9 +809,9 @@ public: rai::block_type type; auto value (store.block_get_raw (transaction, block_a.previous (), type)); assert (value.mv_size != 0); - std::vector data (static_cast (value.mv_data), static_cast (value.mv_data) + value.mv_size); + std::vector data (static_cast (value.mv_data), static_cast (value.mv_data) + value.mv_size); std::copy (hash.bytes.begin (), hash.bytes.end (), data.end () - hash.bytes.size ()); - store.block_put_raw (transaction, store.block_database (type), block_a.previous (), rai::mdb_val (data.size (), data.data())); + store.block_put_raw (transaction, store.block_database (type), block_a.previous (), rai::mdb_val (data.size (), data.data ())); } void send_block (rai::send_block const & block_a) override { @@ -852,7 +852,7 @@ MDB_dbi rai::block_store::block_database (rai::block_type type_a) result = change_blocks; break; default: - assert(false); + assert (false); break; } return result; @@ -867,13 +867,13 @@ void rai::block_store::block_put_raw (MDB_txn * transaction_a, MDB_dbi database_ void rai::block_store::block_put (MDB_txn * transaction_a, rai::block_hash const & hash_a, rai::block const & block_a, rai::block_hash const & successor_a) { assert (successor_a.is_zero () || block_exists (transaction_a, successor_a)); - std::vector vector; + std::vector vector; { rai::vectorstream stream (vector); block_a.serialize (stream); rai::write (stream, successor_a.bytes); } - block_put_raw (transaction_a, block_database (block_a.type ()), hash_a, {vector.size (), vector.data ()}); + block_put_raw (transaction_a, block_database (block_a.type ()), hash_a, { vector.size (), vector.data () }); set_predecessor predecessor (transaction_a, *this); block_a.visit (predecessor); assert (block_a.previous ().is_zero () || block_successor (transaction_a, block_a.previous ()) == hash_a); @@ -918,7 +918,7 @@ MDB_val rai::block_store::block_get_raw (MDB_txn * transaction_a, rai::block_has return result; } -std::unique_ptr rai::block_store::block_random (MDB_txn * transaction_a, MDB_dbi database) +std::unique_ptr rai::block_store::block_random (MDB_txn * transaction_a, MDB_dbi database) { rai::block_hash hash; rai::random_pool.GenerateBlock (hash.bytes.data (), hash.bytes.size ()); @@ -931,11 +931,11 @@ std::unique_ptr rai::block_store::block_random (MDB_txn * transacti return block_get (transaction_a, rai::block_hash (existing->first.uint256 ())); } -std::unique_ptr rai::block_store::block_random (MDB_txn * transaction_a) +std::unique_ptr rai::block_store::block_random (MDB_txn * transaction_a) { auto count (block_count (transaction_a)); auto region (rai::random_pool.GenerateWord32 (0, count.sum () - 1)); - std::unique_ptr result; + std::unique_ptr result; if (region < count.send) { result = block_random (transaction_a, send_blocks); @@ -972,7 +972,7 @@ rai::block_hash rai::block_store::block_successor (MDB_txn * transaction_a, rai: if (value.mv_size != 0) { assert (value.mv_size >= result.bytes.size ()); - rai::bufferstream stream (reinterpret_cast (value.mv_data) + value.mv_size - result.bytes.size (), result.bytes.size ()); + rai::bufferstream stream (reinterpret_cast (value.mv_data) + value.mv_size - result.bytes.size (), result.bytes.size ()); auto error (rai::read (stream, result.bytes)); assert (!error); } @@ -989,14 +989,14 @@ void rai::block_store::block_successor_clear (MDB_txn * transaction_a, rai::bloc block_put (transaction_a, hash_a, *block); } -std::unique_ptr rai::block_store::block_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) +std::unique_ptr rai::block_store::block_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) { rai::block_type type; auto value (block_get_raw (transaction_a, hash_a, type)); - std::unique_ptr result; + std::unique_ptr result; if (value.mv_size != 0) { - rai::bufferstream stream (reinterpret_cast (value.mv_data), value.mv_size); + rai::bufferstream stream (reinterpret_cast (value.mv_data), value.mv_size); result = rai::deserialize_block (stream, type); assert (result != nullptr); } @@ -1098,13 +1098,13 @@ bool rai::block_store::account_get (MDB_txn * transaction_a, rai::account const } else { - rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); + rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); result = info_a.deserialize (stream); assert (!result); } return result; } - + void rai::block_store::frontier_put (MDB_txn * transaction_a, rai::block_hash const & block_a, rai::account const & account_a) { auto status (mdb_put (transaction_a, frontiers, rai::mdb_val (block_a), rai::mdb_val (account_a), 0)); @@ -1177,7 +1177,7 @@ bool rai::block_store::pending_get (MDB_txn * transaction_a, rai::pending_key co { result = false; assert (value.size () == sizeof (pending_a.source.bytes) + sizeof (pending_a.amount.bytes)); - rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); + rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); auto error1 (rai::read (stream, pending_a.source)); assert (!error1); auto error2 (rai::read (stream, pending_a.amount)); @@ -1212,9 +1212,9 @@ amount (0) rai::pending_info::pending_info (MDB_val const & val_a) { - assert(val_a.mv_size == sizeof (*this)); + assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (source) + sizeof (amount) == sizeof (*this), "Packed class"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::pending_info::pending_info (rai::account const & source_a, rai::amount const & amount_a) : @@ -1239,14 +1239,14 @@ bool rai::pending_info::deserialize (rai::stream & stream_a) return result; } -bool rai::pending_info::operator == (rai::pending_info const & other_a) const +bool rai::pending_info::operator== (rai::pending_info const & other_a) const { return source == other_a.source && amount == other_a.amount; } rai::mdb_val rai::pending_info::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } rai::pending_key::pending_key (rai::account const & account_a, rai::block_hash const & hash_a) : @@ -1257,9 +1257,9 @@ hash (hash_a) rai::pending_key::pending_key (MDB_val const & val_a) { - assert(val_a.mv_size == sizeof (*this)); + assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (account) + sizeof (hash) == sizeof (*this), "Packed class"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } void rai::pending_key::serialize (rai::stream & stream_a) const @@ -1278,14 +1278,14 @@ bool rai::pending_key::deserialize (rai::stream & stream_a) return result; } -bool rai::pending_key::operator == (rai::pending_key const & other_a) const +bool rai::pending_key::operator== (rai::pending_key const & other_a) const { return account == other_a.account && hash == other_a.hash; } rai::mdb_val rai::pending_key::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } void rai::block_store::block_info_put (MDB_txn * transaction_a, rai::block_hash const & hash_a, rai::block_info const & block_info_a) @@ -1320,7 +1320,7 @@ bool rai::block_store::block_info_get (MDB_txn * transaction_a, rai::block_hash { result = false; assert (value.size () == sizeof (block_info_a.account.bytes) + sizeof (block_info_a.balance.bytes)); - rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); + rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); auto error1 (rai::read (stream, block_info_a.account)); assert (!error1); auto error2 (rai::read (stream, block_info_a.balance)); @@ -1355,9 +1355,9 @@ balance (0) rai::block_info::block_info (MDB_val const & val_a) { - assert(val_a.mv_size == sizeof (*this)); + assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (account) + sizeof (balance) == sizeof (*this), "Packed class"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::block_info::block_info (rai::account const & account_a, rai::amount const & balance_a) : @@ -1382,14 +1382,14 @@ bool rai::block_info::deserialize (rai::stream & stream_a) return result; } -bool rai::block_info::operator == (rai::block_info const & other_a) const +bool rai::block_info::operator== (rai::block_info const & other_a) const { return account == other_a.account && balance == other_a.balance; } rai::mdb_val rai::block_info::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } rai::uint128_t rai::block_store::representation_get (MDB_txn * transaction_a, rai::account const & account_a) @@ -1401,7 +1401,7 @@ rai::uint128_t rai::block_store::representation_get (MDB_txn * transaction_a, ra if (status == 0) { rai::uint128_union rep; - rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); + rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); auto error (rai::read (stream, rep)); assert (!error); result = rep.number (); @@ -1428,7 +1428,7 @@ rai::store_iterator rai::block_store::representation_begin (MDB_txn * transactio rai::store_iterator rai::block_store::representation_end () { - rai::store_iterator result(nullptr); + rai::store_iterator result (nullptr); return result; } @@ -1438,17 +1438,17 @@ void rai::block_store::unchecked_clear (MDB_txn * transaction_a) assert (status == 0); } -void rai::block_store::unchecked_put (MDB_txn * transaction_a, rai::block_hash const & hash_a, std::shared_ptr const & block_a) +void rai::block_store::unchecked_put (MDB_txn * transaction_a, rai::block_hash const & hash_a, std::shared_ptr const & block_a) { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); unchecked_cache.insert (std::make_pair (hash_a, block_a)); } -std::vector > rai::block_store::unchecked_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) +std::vector> rai::block_store::unchecked_get (MDB_txn * transaction_a, rai::block_hash const & hash_a) { - std::vector > result; + std::vector> result; { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); for (auto i (unchecked_cache.find (hash_a)), n (unchecked_cache.end ()); i != n && i->first == hash_a; ++i) { result.push_back (i->second); @@ -1456,7 +1456,7 @@ std::vector > rai::block_store::unchecked_get (MDB_ } for (auto i (unchecked_begin (transaction_a, hash_a)), n (unchecked_end ()); i != n && rai::block_hash (i->first.uint256 ()) == hash_a; i.next_dup ()) { - rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size()); + rai::bufferstream stream (reinterpret_cast (i->second.data ()), i->second.size ()); result.push_back (rai::deserialize_block (stream)); } return result; @@ -1465,7 +1465,7 @@ std::vector > rai::block_store::unchecked_get (MDB_ void rai::block_store::unchecked_del (MDB_txn * transaction_a, rai::block_hash const & hash_a, rai::block const & block_a) { { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); for (auto i (unchecked_cache.find (hash_a)), n (unchecked_cache.end ()); i != n && i->first == hash_a;) { if (*i->second == block_a) @@ -1478,7 +1478,7 @@ void rai::block_store::unchecked_del (MDB_txn * transaction_a, rai::block_hash c } } } - std::vector vector; + std::vector vector; { rai::vectorstream stream (vector); rai::serialize_block (stream, block_a); @@ -1566,7 +1566,7 @@ bool rai::block_store::checksum_get (MDB_txn * transaction_a, uint64_t prefix, u if (status == 0) { result = false; - rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); + rai::bufferstream stream (reinterpret_cast (value.data ()), value.size ()); auto error (rai::read (stream, hash_a)); assert (!error); } @@ -1587,16 +1587,16 @@ void rai::block_store::checksum_del (MDB_txn * transaction_a, uint64_t prefix, u void rai::block_store::flush (MDB_txn * transaction_a) { - std::unordered_map > sequence_cache_l; - std::unordered_multimap > unchecked_cache_l; + std::unordered_map> sequence_cache_l; + std::unordered_multimap> unchecked_cache_l; { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); sequence_cache_l.swap (vote_cache); unchecked_cache_l.swap (unchecked_cache); } - for (auto &i: unchecked_cache_l) + for (auto & i : unchecked_cache_l) { - std::vector vector; + std::vector vector; { rai::vectorstream stream (vector); rai::serialize_block (stream, *i.second); @@ -1606,7 +1606,7 @@ void rai::block_store::flush (MDB_txn * transaction_a) } for (auto i (sequence_cache_l.begin ()), n (sequence_cache_l.end ()); i != n; ++i) { - std::vector vector; + std::vector vector; { rai::vectorstream stream (vector); i->second->serialize (stream); @@ -1626,24 +1626,24 @@ rai::store_iterator rai::block_store::vote_end () return rai::store_iterator (nullptr); } -std::shared_ptr rai::block_store::vote_get (MDB_txn * transaction_a, rai::account const & account_a) +std::shared_ptr rai::block_store::vote_get (MDB_txn * transaction_a, rai::account const & account_a) { - std::shared_ptr result; + std::shared_ptr result; rai::mdb_val value; auto status (mdb_get (transaction_a, vote, rai::mdb_val (account_a), value)); assert (status == 0 || status == MDB_NOTFOUND); if (status == 0) { - result = std::make_shared (value); + result = std::make_shared (value); assert (result != nullptr); } return result; } -std::shared_ptr rai::block_store::vote_current (MDB_txn * transaction_a, rai::account const & account_a) +std::shared_ptr rai::block_store::vote_current (MDB_txn * transaction_a, rai::account const & account_a) { assert (!cache_mutex.try_lock ()); - std::shared_ptr result; + std::shared_ptr result; auto existing (vote_cache.find (account_a)); if (existing != vote_cache.end ()) { @@ -1655,20 +1655,20 @@ std::shared_ptr rai::block_store::vote_current (MDB_txn * transactio } return result; } - -std::shared_ptr rai::block_store::vote_generate (MDB_txn * transaction_a, rai::account const & account_a, rai::raw_key const & key_a, std::shared_ptr block_a) + +std::shared_ptr rai::block_store::vote_generate (MDB_txn * transaction_a, rai::account const & account_a, rai::raw_key const & key_a, std::shared_ptr block_a) { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); auto result (vote_current (transaction_a, account_a)); uint64_t sequence ((result ? result->sequence : 0) + 1); - result = std::make_shared (account_a, key_a, sequence, block_a); - vote_cache [account_a] = result; + result = std::make_shared (account_a, key_a, sequence, block_a); + vote_cache[account_a] = result; return result; } -std::shared_ptr rai::block_store::vote_max (MDB_txn * transaction_a, std::shared_ptr vote_a) +std::shared_ptr rai::block_store::vote_max (MDB_txn * transaction_a, std::shared_ptr vote_a) { - std::lock_guard lock (cache_mutex); + std::lock_guard lock (cache_mutex); auto current (vote_current (transaction_a, vote_a->account)); auto result (vote_a); if (current != nullptr) @@ -1678,18 +1678,18 @@ std::shared_ptr rai::block_store::vote_max (MDB_txn * transaction_a, result = current; } } - vote_cache [vote_a->account] = result; + vote_cache[vote_a->account] = result; return result; } -rai::vote_result rai::block_store::vote_validate (MDB_txn * transaction_a, std::shared_ptr vote_a) +rai::vote_result rai::block_store::vote_validate (MDB_txn * transaction_a, std::shared_ptr vote_a) { - rai::vote_result result ({rai::vote_code::invalid, 0}); + rai::vote_result result ({ rai::vote_code::invalid, 0 }); // Reject unsigned votes if (!rai::validate_message (vote_a->account, vote_a->hash (), vote_a->signature)) { result.code = rai::vote_code::replay; - result.vote = vote_max (transaction_a, vote_a); // Make sure this sequence number is > any we've seen from this account before + result.vote = vote_max (transaction_a, vote_a); // Make sure this sequence number is > any we've seen from this account before if (result.vote == vote_a) { result.code = rai::vote_code::vote; @@ -1698,14 +1698,14 @@ rai::vote_result rai::block_store::vote_validate (MDB_txn * transaction_a, std:: return result; } -bool rai::vote::operator == (rai::vote const & other_a) const +bool rai::vote::operator== (rai::vote const & other_a) const { return sequence == other_a.sequence && *block == *other_a.block && account == other_a.account && signature == other_a.signature; } -bool rai::vote::operator != (rai::vote const & other_a) const +bool rai::vote::operator!= (rai::vote const & other_a) const { - return ! (*this == other_a); + return !(*this == other_a); } std::string rai::vote::to_json () const @@ -1745,7 +1745,7 @@ public: auto source (store.block_get (transaction, hash)); if (source != nullptr) { - auto send (dynamic_cast (source.get ())); + auto send (dynamic_cast (source.get ())); if (send != nullptr) { result = send->hashables.destination; @@ -1900,7 +1900,8 @@ void balance_visitor::receive_block (rai::receive_block const & block_a) result += block_info.balance.number (); current = 0; } - else { + else + { result += source.result; current = block_a.hashables.previous; } @@ -1922,7 +1923,8 @@ void balance_visitor::change_block (rai::change_block const & block_a) result += block_info.balance.number (); current = 0; } - else { + else + { current = block_a.hashables.previous; } } @@ -1972,7 +1974,7 @@ public: ledger.store.representation_add (transaction, ledger.representative (transaction, hash), 0 - amount); ledger.change_latest (transaction, destination_account, block_a.hashables.previous, representative, ledger.balance (transaction, block_a.hashables.previous), info.block_count - 1); ledger.store.block_del (transaction, hash); - ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount}); + ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), { ledger.account (transaction, block_a.hashables.source), amount }); ledger.store.frontier_del (transaction, hash); ledger.store.frontier_put (transaction, block_a.hashables.previous, destination_account); ledger.store.block_successor_clear (transaction, block_a.hashables.previous); @@ -1989,7 +1991,7 @@ public: ledger.store.representation_add (transaction, ledger.representative (transaction, hash), 0 - amount); ledger.change_latest (transaction, destination_account, 0, 0, 0, 0); ledger.store.block_del (transaction, hash); - ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), {ledger.account (transaction, block_a.hashables.source), amount}); + ledger.store.pending_put (transaction, rai::pending_key (destination_account, block_a.hashables.source), { ledger.account (transaction, block_a.hashables.source), amount }); ledger.store.frontier_del (transaction, hash); } void change_block (rai::change_block const & block_a) override @@ -2029,7 +2031,7 @@ void amount_visitor::compute (rai::block_hash const & block_hash) { if (block_hash == rai::genesis_account) { - result = std::numeric_limits ::max (); + result = std::numeric_limits::max (); } else { @@ -2278,10 +2280,10 @@ void rai::ledger::change_latest (MDB_txn * transaction_a, rai::account const & a } else { - assert (dynamic_cast (store.block_get (transaction_a, hash_a).get ()) != nullptr); + assert (dynamic_cast (store.block_get (transaction_a, hash_a).get ()) != nullptr); info.open_block = hash_a; } - if (!hash_a.is_zero()) + if (!hash_a.is_zero ()) { info.head = hash_a; info.rep_block = rep_block_a; @@ -2304,7 +2306,7 @@ void rai::ledger::change_latest (MDB_txn * transaction_a, rai::account const & a } } -std::unique_ptr rai::ledger::successor (MDB_txn * transaction_a, rai::block_hash const & block_a) +std::unique_ptr rai::ledger::successor (MDB_txn * transaction_a, rai::block_hash const & block_a) { assert (store.account_exists (transaction_a, block_a) || store.block_exists (transaction_a, block_a)); assert (store.account_exists (transaction_a, block_a) || latest (transaction_a, account (transaction_a, block_a)) != block_a); @@ -2326,12 +2328,12 @@ std::unique_ptr rai::ledger::successor (MDB_txn * transaction_a, ra return result; } -std::unique_ptr rai::ledger::forked_block (MDB_txn * transaction_a, rai::block const & block_a) +std::unique_ptr rai::ledger::forked_block (MDB_txn * transaction_a, rai::block const & block_a) { assert (!store.block_exists (transaction_a, block_a.hash ())); auto root (block_a.root ()); assert (store.block_exists (transaction_a, root) || store.account_exists (transaction_a, root)); - std::unique_ptr result (store.block_get (transaction_a, store.block_successor (transaction_a, root))); + std::unique_ptr result (store.block_get (transaction_a, store.block_successor (transaction_a, root))); if (result == nullptr) { rai::account_info info; @@ -2351,7 +2353,7 @@ void ledger_processor::change_block (rai::change_block const & block_a) if (result.code == rai::process_result::progress) { auto previous (ledger.store.block_exists (transaction, block_a.hashables.previous)); - result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) + result.code = previous ? rai::process_result::progress : rai::process_result::gap_previous; // Have we seen the previous block already? (Harmless) if (result.code == rai::process_result::progress) { auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); @@ -2409,7 +2411,7 @@ void ledger_processor::send_block (rai::send_block const & block_a) ledger.store.representation_add (transaction, info.rep_block, 0 - amount); ledger.store.block_put (transaction, hash, block_a); ledger.change_latest (transaction, account, hash, info.rep_block, block_a.hashables.balance, info.block_count + 1); - ledger.store.pending_put (transaction, rai::pending_key (block_a.hashables.destination, hash), {account, amount}); + ledger.store.pending_put (transaction, rai::pending_key (block_a.hashables.destination, hash), { account, amount }); ledger.store.frontier_del (transaction, block_a.hashables.previous); ledger.store.frontier_put (transaction, hash, account); result.account = account; @@ -2428,11 +2430,11 @@ void ledger_processor::receive_block (rai::receive_block const & block_a) result.code = existing ? rai::process_result::old : rai::process_result::progress; // Have we seen this block already? (Harmless) if (result.code == rai::process_result::progress) { - result.code = ledger.store.block_exists (transaction, block_a.hashables.source) ? rai::process_result::progress: rai::process_result::gap_source; // Have we seen the source block already? (Harmless) + result.code = ledger.store.block_exists (transaction, block_a.hashables.source) ? rai::process_result::progress : rai::process_result::gap_source; // Have we seen the source block already? (Harmless) if (result.code == rai::process_result::progress) { auto account (ledger.store.frontier_get (transaction, block_a.hashables.previous)); - result.code = account.is_zero () ? rai::process_result::gap_previous : rai::process_result::progress; //Have we seen the previous block? No entries for account at all (Harmless) + result.code = account.is_zero () ? rai::process_result::gap_previous : rai::process_result::progress; //Have we seen the previous block? No entries for account at all (Harmless) if (result.code == rai::process_result::progress) { result.code = rai::validate_message (account, hash, block_a.signature) ? rai::process_result::bad_signature : rai::process_result::progress; // Is the signature valid (Malformed) @@ -2572,7 +2574,7 @@ rai::vote::vote (bool & error_a, rai::stream & stream_a, rai::block_type type_a) } } -rai::vote::vote (rai::account const & account_a, rai::raw_key const & prv_a, uint64_t sequence_a, std::shared_ptr block_a) : +rai::vote::vote (rai::account const & account_a, rai::raw_key const & prv_a, uint64_t sequence_a, std::shared_ptr block_a) : sequence (sequence_a), block (block_a), account (account_a), @@ -2582,7 +2584,7 @@ signature (rai::sign_message (prv_a, account_a, hash ())) rai::vote::vote (MDB_val const & value_a) { - rai::bufferstream stream (reinterpret_cast (value_a.mv_data), value_a.mv_size); + rai::bufferstream stream (reinterpret_cast (value_a.mv_data), value_a.mv_size); auto error (rai::read (stream, account.bytes)); assert (!error); error = rai::read (stream, signature.bytes); @@ -2599,9 +2601,10 @@ rai::uint256_union rai::vote::hash () const blake2b_state hash; blake2b_init (&hash, sizeof (result.bytes)); blake2b_update (&hash, block->hash ().bytes.data (), sizeof (result.bytes)); - union { + union + { uint64_t qword; - std::array bytes; + std::array bytes; }; qword = sequence; blake2b_update (&hash, bytes.data (), sizeof (bytes)); @@ -2631,8 +2634,8 @@ rai::genesis::genesis () std::stringstream istream (rai::genesis_block); boost::property_tree::read_json (istream, tree); auto block (rai::deserialize_block_json (tree)); - assert (dynamic_cast (block.get ()) != nullptr); - open.reset (static_cast (block.release ())); + assert (dynamic_cast (block.get ()) != nullptr); + open.reset (static_cast (block.release ())); } void rai::genesis::initialize (MDB_txn * transaction_a, rai::block_store & store_a) const @@ -2640,8 +2643,8 @@ void rai::genesis::initialize (MDB_txn * transaction_a, rai::block_store & store auto hash_l (hash ()); assert (store_a.latest_begin (transaction_a) == store_a.latest_end ()); store_a.block_put (transaction_a, hash_l, *open); - store_a.account_put (transaction_a, genesis_account, {hash_l, open->hash (), open->hash (), std::numeric_limits ::max (), store_a.now (), 1}); - store_a.representation_put (transaction_a, genesis_account, std::numeric_limits ::max ()); + store_a.account_put (transaction_a, genesis_account, { hash_l, open->hash (), open->hash (), std::numeric_limits::max (), store_a.now (), 1 }); + store_a.representation_put (transaction_a, genesis_account, std::numeric_limits::max ()); store_a.checksum_put (transaction_a, 0, 0, hash_l); store_a.frontier_put (transaction_a, hash_l, genesis_account); } diff --git a/rai/secure.hpp b/rai/secure.hpp index ae7ebddd..f98fbc60 100644 --- a/rai/secure.hpp +++ b/rai/secure.hpp @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include @@ -12,11 +12,11 @@ namespace boost { template <> -struct hash +struct hash { - size_t operator () (rai::uint256_union const & value_a) const + size_t operator() (rai::uint256_union const & value_a) const { - std::hash hash; + std::hash hash; return hash (value_a); } }; @@ -34,10 +34,10 @@ public: class shared_ptr_block_hash { public: - size_t operator () (std::shared_ptr const &) const; - bool operator () (std::shared_ptr const &, std::shared_ptr const &) const; + size_t operator() (std::shared_ptr const &) const; + bool operator() (std::shared_ptr const &, std::shared_ptr const &) const; }; -std::unique_ptr deserialize_block (MDB_val const &); +std::unique_ptr deserialize_block (MDB_val const &); // Latest information about an account class account_info { @@ -48,8 +48,8 @@ public: account_info (rai::block_hash const &, rai::block_hash const &, rai::block_hash const &, rai::amount const &, uint64_t, uint64_t); void serialize (rai::stream &) const; bool deserialize (rai::stream &); - bool operator == (rai::account_info const &) const; - bool operator != (rai::account_info const &) const; + bool operator== (rai::account_info const &) const; + bool operator!= (rai::account_info const &) const; rai::mdb_val val () const; rai::block_hash head; rai::block_hash rep_block; @@ -63,7 +63,7 @@ class store_entry public: store_entry (); void clear (); - store_entry * operator -> (); + store_entry * operator-> (); rai::mdb_val first; rai::mdb_val second; }; @@ -76,13 +76,13 @@ public: store_iterator (rai::store_iterator &&); store_iterator (rai::store_iterator const &) = delete; ~store_iterator (); - rai::store_iterator & operator ++ (); - void next_dup(); - rai::store_iterator & operator = (rai::store_iterator &&); - rai::store_iterator & operator = (rai::store_iterator const &) = delete; - rai::store_entry & operator -> (); - bool operator == (rai::store_iterator const &) const; - bool operator != (rai::store_iterator const &) const; + rai::store_iterator & operator++ (); + void next_dup (); + rai::store_iterator & operator= (rai::store_iterator &&); + rai::store_iterator & operator= (rai::store_iterator const &) = delete; + rai::store_entry & operator-> (); + bool operator== (rai::store_iterator const &) const; + bool operator!= (rai::store_iterator const &) const; MDB_cursor * cursor; rai::store_entry current; }; @@ -95,7 +95,7 @@ public: pending_info (rai::account const &, rai::amount const &); void serialize (rai::stream &) const; bool deserialize (rai::stream &); - bool operator == (rai::pending_info const &) const; + bool operator== (rai::pending_info const &) const; rai::mdb_val val () const; rai::account source; rai::amount amount; @@ -107,7 +107,7 @@ public: pending_key (MDB_val const &); void serialize (rai::stream &) const; bool deserialize (rai::stream &); - bool operator == (rai::pending_key const &) const; + bool operator== (rai::pending_key const &) const; rai::mdb_val val () const; rai::account account; rai::block_hash hash; @@ -120,7 +120,7 @@ public: block_info (rai::account const &, rai::amount const &); void serialize (rai::stream &) const; bool deserialize (rai::stream &); - bool operator == (rai::block_info const &) const; + bool operator== (rai::block_info const &) const; rai::mdb_val val () const; rai::account account; rai::amount balance; @@ -142,17 +142,17 @@ public: vote (rai::vote const &); vote (bool &, rai::stream &); vote (bool &, rai::stream &, rai::block_type); - vote (rai::account const &, rai::raw_key const &, uint64_t, std::shared_ptr ); + vote (rai::account const &, rai::raw_key const &, uint64_t, std::shared_ptr); vote (MDB_val const &); rai::uint256_union hash () const; - bool operator == (rai::vote const &) const; - bool operator != (rai::vote const &) const; + bool operator== (rai::vote const &) const; + bool operator!= (rai::vote const &) const; void serialize (rai::stream &, rai::block_type); void serialize (rai::stream &); std::string to_json () const; // Vote round sequence number uint64_t sequence; - std::shared_ptr block; + std::shared_ptr block; // Account that's voting rai::account account; // Signature of sequence + block hash @@ -168,32 +168,32 @@ class vote_result { public: rai::vote_code code; - std::shared_ptr vote; + std::shared_ptr vote; }; class block_store { public: block_store (bool &, boost::filesystem::path const &); uint64_t now (); - + MDB_dbi block_database (rai::block_type); void block_put_raw (MDB_txn *, MDB_dbi, rai::block_hash const &, MDB_val); void block_put (MDB_txn *, rai::block_hash const &, rai::block const &, rai::block_hash const & = rai::block_hash (0)); MDB_val block_get_raw (MDB_txn *, rai::block_hash const &, rai::block_type &); rai::block_hash block_successor (MDB_txn *, rai::block_hash const &); void block_successor_clear (MDB_txn *, rai::block_hash const &); - std::unique_ptr block_get (MDB_txn *, rai::block_hash const &); - std::unique_ptr block_random (MDB_txn *); - std::unique_ptr block_random (MDB_txn *, MDB_dbi); + std::unique_ptr block_get (MDB_txn *, rai::block_hash const &); + std::unique_ptr block_random (MDB_txn *); + std::unique_ptr block_random (MDB_txn *, MDB_dbi); void block_del (MDB_txn *, rai::block_hash const &); bool block_exists (MDB_txn *, rai::block_hash const &); rai::block_counts block_count (MDB_txn *); - + void frontier_put (MDB_txn *, rai::block_hash const &, rai::account const &); rai::account frontier_get (MDB_txn *, rai::block_hash const &); void frontier_del (MDB_txn *, rai::block_hash const &); size_t frontier_count (MDB_txn *); - + void account_put (MDB_txn *, rai::account const &, rai::account_info const &); bool account_get (MDB_txn *, rai::account const &, rai::account_info &); void account_del (MDB_txn *, rai::account const &); @@ -201,7 +201,7 @@ public: rai::store_iterator latest_begin (MDB_txn *, rai::account const &); rai::store_iterator latest_begin (MDB_txn *); rai::store_iterator latest_end (); - + void pending_put (MDB_txn *, rai::pending_key const &, rai::pending_info const &); void pending_del (MDB_txn *, rai::pending_key const &); bool pending_get (MDB_txn *, rai::pending_key const &, rai::pending_info &); @@ -209,7 +209,7 @@ public: rai::store_iterator pending_begin (MDB_txn *, rai::pending_key const &); rai::store_iterator pending_begin (MDB_txn *); rai::store_iterator pending_end (); - + void block_info_put (MDB_txn *, rai::block_hash const &, rai::block_info const &); void block_info_del (MDB_txn *, rai::block_hash const &); bool block_info_get (MDB_txn *, rai::block_hash const &, rai::block_info &); @@ -219,49 +219,49 @@ public: rai::store_iterator block_info_end (); rai::uint128_t block_balance (MDB_txn *, rai::block_hash const &); static size_t const block_info_max = 32; - + rai::uint128_t representation_get (MDB_txn *, rai::account const &); void representation_put (MDB_txn *, rai::account const &, rai::uint128_t const &); void representation_add (MDB_txn *, rai::account const &, rai::uint128_t const &); rai::store_iterator representation_begin (MDB_txn *); rai::store_iterator representation_end (); - + void unchecked_clear (MDB_txn *); - void unchecked_put (MDB_txn *, rai::block_hash const &, std::shared_ptr const &); - std::vector > unchecked_get (MDB_txn *, rai::block_hash const &); + void unchecked_put (MDB_txn *, rai::block_hash const &, std::shared_ptr const &); + std::vector> unchecked_get (MDB_txn *, rai::block_hash const &); void unchecked_del (MDB_txn *, rai::block_hash const &, rai::block const &); rai::store_iterator unchecked_begin (MDB_txn *); rai::store_iterator unchecked_begin (MDB_txn *, rai::block_hash const &); rai::store_iterator unchecked_end (); size_t unchecked_count (MDB_txn *); - std::unordered_multimap > unchecked_cache; - + std::unordered_multimap> unchecked_cache; + void unsynced_put (MDB_txn *, rai::block_hash const &); void unsynced_del (MDB_txn *, rai::block_hash const &); bool unsynced_exists (MDB_txn *, rai::block_hash const &); rai::store_iterator unsynced_begin (MDB_txn *, rai::block_hash const &); rai::store_iterator unsynced_begin (MDB_txn *); rai::store_iterator unsynced_end (); - + void checksum_put (MDB_txn *, uint64_t, uint8_t, rai::checksum const &); bool checksum_get (MDB_txn *, uint64_t, uint8_t, rai::checksum &); void checksum_del (MDB_txn *, uint64_t, uint8_t); - - rai::vote_result vote_validate (MDB_txn *, std::shared_ptr ); + + rai::vote_result vote_validate (MDB_txn *, std::shared_ptr); // Return latest vote for an account from store - std::shared_ptr vote_get (MDB_txn *, rai::account const &); + std::shared_ptr vote_get (MDB_txn *, rai::account const &); // Populate vote with the next sequence number - std::shared_ptr vote_generate (MDB_txn *, rai::account const &, rai::raw_key const &, std::shared_ptr ); + std::shared_ptr vote_generate (MDB_txn *, rai::account const &, rai::raw_key const &, std::shared_ptr); // Return either vote or the stored vote with a higher sequence number - std::shared_ptr vote_max (MDB_txn *, std::shared_ptr ); + std::shared_ptr vote_max (MDB_txn *, std::shared_ptr); // Return latest vote for an account considering the vote cache - std::shared_ptr vote_current (MDB_txn *, rai::account const &); + std::shared_ptr vote_current (MDB_txn *, rai::account const &); void flush (MDB_txn *); rai::store_iterator vote_begin (MDB_txn *); rai::store_iterator vote_end (); std::mutex cache_mutex; - std::unordered_map > vote_cache; - + std::unordered_map> vote_cache; + void version_put (MDB_txn *, int); int version_get (MDB_txn *); void do_upgrades (MDB_txn *); @@ -274,9 +274,9 @@ public: void upgrade_v7_to_v8 (MDB_txn *); void upgrade_v8_to_v9 (MDB_txn *); void upgrade_v9_to_v10 (MDB_txn *); - + void clear (MDB_dbi); - + rai::mdb_env environment; // block_hash -> account // Maps head blocks to owning account MDB_dbi frontiers; @@ -337,28 +337,28 @@ enum class tally_result class votes { public: - votes (std::shared_ptr ); - rai::tally_result vote (std::shared_ptr ); + votes (std::shared_ptr); + rai::tally_result vote (std::shared_ptr); // Root block of fork rai::block_hash id; // All votes received by account - std::unordered_map > rep_votes; + std::unordered_map> rep_votes; }; class ledger { public: ledger (rai::block_store &, rai::uint128_t const & = 0); - std::pair > winner (MDB_txn *, rai::votes const & votes_a); + std::pair> winner (MDB_txn *, rai::votes const & votes_a); // Map of weight -> associated block, ordered greatest to least - std::map , std::greater > tally (MDB_txn *, rai::votes const &); + std::map, std::greater> tally (MDB_txn *, rai::votes const &); rai::account account (MDB_txn *, rai::block_hash const &); rai::uint128_t amount (MDB_txn *, rai::block_hash const &); rai::uint128_t balance (MDB_txn *, rai::block_hash const &); rai::uint128_t account_balance (MDB_txn *, rai::account const &); rai::uint128_t account_pending (MDB_txn *, rai::account const &); rai::uint128_t weight (MDB_txn *, rai::account const &); - std::unique_ptr successor (MDB_txn *, rai::block_hash const &); - std::unique_ptr forked_block (MDB_txn *, rai::block const &); + std::unique_ptr successor (MDB_txn *, rai::block_hash const &); + std::unique_ptr forked_block (MDB_txn *, rai::block const &); rai::block_hash latest (MDB_txn *, rai::account const &); rai::block_hash latest_root (MDB_txn *, rai::account const &); rai::block_hash representative (MDB_txn *, rai::block_hash const &); @@ -399,6 +399,6 @@ public: explicit genesis (); void initialize (MDB_txn *, rai::block_store &) const; rai::block_hash hash () const; - std::unique_ptr open; + std::unique_ptr open; }; } diff --git a/rai/slow_test/node.cpp b/rai/slow_test/node.cpp index d72b3f85..a0a763fb 100644 --- a/rai/slow_test/node.cpp +++ b/rai/slow_test/node.cpp @@ -8,10 +8,10 @@ TEST (system, generate_mass_activity) rai::system system (24000, 1); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); size_t count (20); - system.generate_mass_activity (count, *system.nodes [0]); + system.generate_mass_activity (count, *system.nodes[0]); size_t accounts (0); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - for (auto i (system.nodes [0]->store.latest_begin (transaction)), n (system.nodes [0]->store.latest_end ()); i != n; ++i) + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + for (auto i (system.nodes[0]->store.latest_begin (transaction)), n (system.nodes[0]->store.latest_end ()); i != n; ++i) { ++accounts; } @@ -19,16 +19,16 @@ TEST (system, generate_mass_activity) TEST (system, generate_mass_activity_long) { - std::vector threads; + std::vector threads; { rai::system system (24000, 1); - rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads); + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); size_t count (1000000000); - system.generate_mass_activity (count, *system.nodes [0]); + system.generate_mass_activity (count, *system.nodes[0]); size_t accounts (0); - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, false); - for (auto i (system.nodes [0]->store.latest_begin (transaction)), n (system.nodes [0]->store.latest_end ()); i != n; ++i) + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, false); + for (auto i (system.nodes[0]->store.latest_begin (transaction)), n (system.nodes[0]->store.latest_end ()); i != n; ++i) { ++accounts; } @@ -43,25 +43,24 @@ TEST (system, generate_mass_activity_long) TEST (system, receive_while_synchronizing) { - std::vector threads; + std::vector threads; { rai::system system (24000, 1); - rai::thread_runner runner (system.service, system.nodes [0]->config.io_threads); + rai::thread_runner runner (system.service, system.nodes[0]->config.io_threads); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); size_t count (1000); - system.generate_mass_activity (count, *system.nodes [0]); + system.generate_mass_activity (count, *system.nodes[0]); rai::keypair key; rai::node_init init1; - auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); + auto node1 (std::make_shared (init1, system.service, 24001, rai::unique_path (), system.alarm, system.logging, system.work)); ASSERT_FALSE (init1.error ()); - node1->network.send_keepalive (system.nodes [0]->network.endpoint ()); + node1->network.send_keepalive (system.nodes[0]->network.endpoint ()); auto wallet (node1->wallets.create (1)); ASSERT_EQ (key.pub, wallet->insert_adhoc (key.prv)); node1->start (); - system.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds(200), ([&system, &key] () - { - auto hash (system.wallet (0)->send_sync (rai::test_genesis_key.pub, key.pub, system.nodes [0]->config.receive_minimum.number ())); - auto block (system.nodes [0]->store.block_get (rai::transaction (system.nodes [0]->store.environment, nullptr, false), hash)); + system.alarm.add (std::chrono::system_clock::now () + std::chrono::milliseconds (200), ([&system, &key]() { + auto hash (system.wallet (0)->send_sync (rai::test_genesis_key.pub, key.pub, system.nodes[0]->config.receive_minimum.number ())); + auto block (system.nodes[0]->store.block_get (rai::transaction (system.nodes[0]->store.environment, nullptr, false), hash)); std::string block_text; block->serialize_json (block_text); })); @@ -110,15 +109,15 @@ TEST (ledger, deep_account_compute) std::cerr << i << ' '; } auto account (ledger.account (transaction, sprevious)); - (void) account; + (void)account; auto balance (ledger.balance (transaction, rprevious)); - (void) balance; + (void)balance; } } TEST (wallet, multithreaded_send) { - std::vector threads; + std::vector threads; { rai::system system (24000, 1); rai::keypair key; @@ -126,15 +125,14 @@ TEST (wallet, multithreaded_send) wallet_l->insert_adhoc (rai::test_genesis_key.prv); for (auto i (0); i < 20; ++i) { - threads.push_back (std::thread ([wallet_l, &key] () - { + threads.push_back (std::thread ([wallet_l, &key]() { for (auto i (0); i < 1000; ++i) { wallet_l->send_action (rai::test_genesis_key.pub, key.pub, 1000); } })); } - while (system.nodes [0]->balance(rai::test_genesis_key.pub) != (rai::genesis_amount - 20 * 1000 * 1000)) + while (system.nodes[0]->balance (rai::test_genesis_key.pub) != (rai::genesis_amount - 20 * 1000 * 1000)) { system.poll (); } @@ -148,24 +146,23 @@ TEST (wallet, multithreaded_send) TEST (store, load) { rai::system system (24000, 1); - std::vector threads; + std::vector threads; for (auto i (0); i < 100; ++i) { - threads.push_back (std::thread ([&system] () - { + threads.push_back (std::thread ([&system]() { for (auto i (0); i != 1000; ++i) { - rai::transaction transaction (system.nodes [0]->store.environment, nullptr, true); + rai::transaction transaction (system.nodes[0]->store.environment, nullptr, true); for (auto j (0); j != 10; ++j) { rai::block_hash hash; rai::random_pool.GenerateBlock (hash.bytes.data (), hash.bytes.size ()); - system.nodes [0]->store.account_put (transaction, hash, rai::account_info ()); + system.nodes[0]->store.account_put (transaction, hash, rai::account_info ()); } } })); } - for (auto &i: threads) + for (auto & i : threads) { i.join (); } @@ -175,8 +172,8 @@ TEST (node, fork_storm) { rai::system system (24000, 64); system.wallet (0)->insert_adhoc (rai::test_genesis_key.prv); - auto previous (system.nodes [0]->latest (rai::test_genesis_key.pub)); - auto balance (system.nodes [0]->balance (rai::test_genesis_key.pub)); + auto previous (system.nodes[0]->latest (rai::test_genesis_key.pub)); + auto balance (system.nodes[0]->balance (rai::test_genesis_key.pub)); ASSERT_FALSE (previous.is_zero ()); for (auto j (0); j != system.nodes.size (); ++j) { @@ -186,19 +183,19 @@ TEST (node, fork_storm) previous = send.hash (); for (auto i (0); i != system.nodes.size (); ++i) { - auto send_result (system.nodes [i]->process (send)); + auto send_result (system.nodes[i]->process (send)); ASSERT_EQ (rai::process_result::progress, send_result.code); rai::keypair rep; - auto open (std::make_shared (previous, rep.pub, key.pub, key.prv, key.pub, 0)); - system.nodes [i]->generate_work (*open); - auto open_result (system.nodes [i]->process (*open)); + auto open (std::make_shared (previous, rep.pub, key.pub, key.prv, key.pub, 0)); + system.nodes[i]->generate_work (*open); + auto open_result (system.nodes[i]->process (*open)); ASSERT_EQ (rai::process_result::progress, open_result.code); - rai::transaction transaction (system.nodes [i]->store.environment, nullptr, false); - system.nodes [i]->network.republish_block (transaction, open); + rai::transaction transaction (system.nodes[i]->store.environment, nullptr, false); + system.nodes[i]->network.republish_block (transaction, open); } } auto again (true); - + int empty (0); int single (0); int iteration (0); @@ -206,8 +203,7 @@ TEST (node, fork_storm) { empty = 0; single = 0; - std::for_each (system.nodes.begin (), system.nodes.end (), [&] (std::shared_ptr const & node_a) - { + std::for_each (system.nodes.begin (), system.nodes.end (), [&](std::shared_ptr const & node_a) { if (node_a->active.roots.empty ()) { ++empty; @@ -233,7 +229,7 @@ TEST (node, fork_storm) namespace { -size_t heard_count (std::vector const & nodes) +size_t heard_count (std::vector const & nodes) { auto result (0); for (auto i (nodes.begin ()), n (nodes.end ()); i != n; ++i) @@ -260,9 +256,9 @@ TEST (broadcast, world_broadcast_simulate) // 0 = starting state // 1 = heard transaction // 2 = repeated transaction - std::vector nodes; + std::vector nodes; nodes.resize (node_count, 0); - nodes [0] = 1; + nodes[0] = 1; auto any_changed (true); auto message_count (0); while (any_changed) @@ -273,7 +269,7 @@ TEST (broadcast, world_broadcast_simulate) switch (*i) { case 0: - break; + break; case 1: for (auto j (nodes.begin ()), m (nodes.end ()); j != m; ++j) { @@ -312,9 +308,9 @@ TEST (broadcast, sqrt_broadcast_simulate) // 0 = starting state // 1 = heard transaction // 2 = repeated transaction - std::vector nodes; + std::vector nodes; nodes.resize (node_count, 0); - nodes [0] = 1; + nodes[0] = 1; auto any_changed (true); uint64_t message_count (0); while (any_changed) @@ -325,16 +321,16 @@ TEST (broadcast, sqrt_broadcast_simulate) switch (*i) { case 0: - break; + break; case 1: for (auto j (0); j != broadcast_count; ++j) { ++message_count; auto entry (rai::random_pool.GenerateWord32 (0, node_count - 1)); - switch (nodes [entry]) + switch (nodes[entry]) { case 0: - nodes [entry] = 1; + nodes[entry] = 1; any_changed = true; break; case 1: @@ -377,15 +373,15 @@ TEST (peer_container, random_set) auto list (container.random_set (15)); } auto end (std::chrono::system_clock::now ()); - auto old_ms (std::chrono::duration_cast (current - old)); - auto new_ms (std::chrono::duration_cast (end - current)); + auto old_ms (std::chrono::duration_cast (current - old)); + auto new_ms (std::chrono::duration_cast (end - current)); } TEST (store, unchecked_load) { rai::system system (24000, 1); - auto & node (*system.nodes [0]); - auto block (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto & node (*system.nodes[0]); + auto block (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); for (auto i (0); i < 1000000; ++i) { rai::transaction transaction (node.store.environment, nullptr, true); @@ -398,12 +394,12 @@ TEST (store, unchecked_load) TEST (store, vote_load) { rai::system system (24000, 1); - auto & node (*system.nodes [0]); - auto block (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); + auto & node (*system.nodes[0]); + auto block (std::make_shared (0, 0, 0, rai::test_genesis_key.prv, rai::test_genesis_key.pub, 0)); for (auto i (0); i < 1000000; ++i) { rai::transaction transaction (node.store.environment, nullptr, true); - auto vote (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, i, block)); + auto vote (std::make_shared (rai::test_genesis_key.pub, rai::test_genesis_key.prv, i, block)); node.store.vote_validate (transaction, vote); } } diff --git a/rai/versioning.cpp b/rai/versioning.cpp index fd0bc945..96e2fe23 100644 --- a/rai/versioning.cpp +++ b/rai/versioning.cpp @@ -12,7 +12,7 @@ rai::account_info_v1::account_info_v1 (MDB_val const & val_a) { assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (head) + sizeof (rep_block) + sizeof (balance) + sizeof (modified) == sizeof (*this), "Class not packed"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::account_info_v1::account_info_v1 (rai::block_hash const & head_a, rai::block_hash const & rep_block_a, rai::amount const & balance_a, uint64_t modified_a) : @@ -51,7 +51,7 @@ bool rai::account_info_v1::deserialize (rai::stream & stream_a) rai::mdb_val rai::account_info_v1::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } rai::pending_info_v3::pending_info_v3 () : @@ -63,9 +63,9 @@ destination (0) rai::pending_info_v3::pending_info_v3 (MDB_val const & val_a) { - assert(val_a.mv_size == sizeof (*this)); + assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (source) + sizeof (amount) + sizeof (destination) == sizeof (*this), "Packed class"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::pending_info_v3::pending_info_v3 (rai::account const & source_a, rai::amount const & amount_a, rai::account const & destination_a) : @@ -96,14 +96,14 @@ bool rai::pending_info_v3::deserialize (rai::stream & stream_a) return result; } -bool rai::pending_info_v3::operator == (rai::pending_info_v3 const & other_a) const +bool rai::pending_info_v3::operator== (rai::pending_info_v3 const & other_a) const { return source == other_a.source && amount == other_a.amount && destination == other_a.destination; } rai::mdb_val rai::pending_info_v3::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } rai::account_info_v5::account_info_v5 () : @@ -119,7 +119,7 @@ rai::account_info_v5::account_info_v5 (MDB_val const & val_a) { assert (val_a.mv_size == sizeof (*this)); static_assert (sizeof (head) + sizeof (rep_block) + sizeof (open_block) + sizeof (balance) + sizeof (modified) == sizeof (*this), "Class not packed"); - std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); + std::copy (reinterpret_cast (val_a.mv_data), reinterpret_cast (val_a.mv_data) + sizeof (*this), reinterpret_cast (this)); } rai::account_info_v5::account_info_v5 (rai::block_hash const & head_a, rai::block_hash const & rep_block_a, rai::block_hash const & open_block_a, rai::amount const & balance_a, uint64_t modified_a) : @@ -164,5 +164,5 @@ bool rai::account_info_v5::deserialize (rai::stream & stream_a) rai::mdb_val rai::account_info_v5::val () const { - return rai::mdb_val (sizeof (*this), const_cast (this)); + return rai::mdb_val (sizeof (*this), const_cast (this)); } diff --git a/rai/versioning.hpp b/rai/versioning.hpp index a3be6499..07b246a9 100644 --- a/rai/versioning.hpp +++ b/rai/versioning.hpp @@ -28,7 +28,7 @@ public: pending_info_v3 (rai::account const &, rai::amount const &, rai::account const &); void serialize (rai::stream &) const; bool deserialize (rai::stream &); - bool operator == (rai::pending_info_v3 const &) const; + bool operator== (rai::pending_info_v3 const &) const; rai::mdb_val val () const; rai::account source; rai::amount amount;