forked from mvs-org/metaverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. remove std::cout related code 2. add account-asset-database 3. add…
… block_chain_impl unit test file
- Loading branch information
1 parent
88ed3c0
commit 4b50f1f
Showing
15 changed files
with
780 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
include/bitcoin/database/databases/account_asset_database.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright (c) 2011-2015 metaverse developers (see AUTHORS) | ||
* | ||
* This file is part of mvsd. | ||
* | ||
* libbitcoin is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License with | ||
* additional permissions to the one published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) | ||
* any later version. For more information see LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
#ifndef MVS_DATABASE_ACCOUNT_ASSET_DATABASE_HPP | ||
#define MVS_DATABASE_ACCOUNT_ASSET_DATABASE_HPP | ||
|
||
#include <memory> | ||
#include <boost/filesystem.hpp> | ||
#include <bitcoin/bitcoin.hpp> | ||
#include <bitcoin/database/define.hpp> | ||
#include <bitcoin/database/memory/memory_map.hpp> | ||
#include <bitcoin/database/primitives/record_multimap.hpp> | ||
#include <bitcoin/bitcoin/chain/attachment/asset/asset_detail.hpp> | ||
#include <bitcoin/bitcoin/chain/business_data.hpp> | ||
|
||
using namespace libbitcoin::chain; | ||
|
||
namespace libbitcoin { | ||
namespace database { | ||
|
||
struct BCD_API account_asset_statinfo | ||
{ | ||
/// Number of buckets used in the hashtable. | ||
/// load factor = addrs / buckets | ||
const size_t buckets; | ||
|
||
/// Total number of unique addresses in the database. | ||
const size_t addrs; | ||
|
||
/// Total number of rows across all addresses. | ||
const size_t rows; | ||
}; | ||
|
||
/// This is a multimap where the key is the Bitcoin address hash, | ||
/// which returns several rows giving the account_asset for that address. | ||
class BCD_API account_asset_database | ||
{ | ||
public: | ||
/// Construct the database. | ||
account_asset_database(const boost::filesystem::path& lookup_filename, | ||
const boost::filesystem::path& rows_filename, | ||
std::shared_ptr<shared_mutex> mutex=nullptr); | ||
|
||
/// Close the database (all threads must first be stopped). | ||
~account_asset_database(); | ||
|
||
/// Initialize a new account_asset database. | ||
bool create(); | ||
|
||
/// Call before using the database. | ||
bool start(); | ||
|
||
/// Call to signal a stop of current operations. | ||
bool stop(); | ||
|
||
/// Call to unload the memory map. | ||
bool close(); | ||
|
||
void store(const short_hash& key, const asset_detail& account_asset); | ||
|
||
void delete_last_row(const short_hash& key); | ||
|
||
asset_detail::list get(const short_hash& key) const; | ||
|
||
std::shared_ptr<asset_detail> get(const short_hash& key, const std::string& address) const; | ||
|
||
/// get assets whose status is not issued and stored in local database (not in blockchain) | ||
std::shared_ptr<std::vector<business_address_asset>> get_unissued_assets(const short_hash& key) const; | ||
|
||
/// Synchonise with disk. | ||
void sync(); | ||
|
||
/// Return statistical info about the database. | ||
account_asset_statinfo statinfo() const; | ||
|
||
private: | ||
typedef record_hash_table<short_hash> record_map; | ||
typedef record_multimap<short_hash> record_multiple_map; | ||
|
||
/// Hash table used for start index lookup for linked list by address hash. | ||
memory_map lookup_file_; | ||
record_hash_table_header lookup_header_; | ||
record_manager lookup_manager_; | ||
record_map lookup_map_; | ||
|
||
/// List of account_asset rows. | ||
memory_map rows_file_; | ||
record_manager rows_manager_; | ||
record_list rows_list_; | ||
record_multiple_map rows_multimap_; | ||
}; | ||
|
||
} // namespace database | ||
} // namespace libbitcoin | ||
|
||
#endif | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.