1
0
Fork 0
forked from lthn/blockchain

upstream changes

This commit is contained in:
sowle 2024-09-23 14:33:22 +02:00
parent 08281059fb
commit c117a76a04
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
20 changed files with 2382 additions and 176 deletions

View file

@ -226,7 +226,12 @@ endif()
message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}")
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.00)
set(Boost_LIBRARIES "libboost.a")
if(NOT DEFINED SKIP_BOOST_FATLIB_LIB OR NOT SKIP_BOOST_FATLIB_LIB)
message("Ios: libboost.a included as library")
set(Boost_LIBRARIES "libboost.a")
else()
message("Ios: libboost.a not included as library")
endif()
#workaround for new XCode 12 policy for builds(now it includes a slice for the "arm64" when builds for simulator)
set(__iphoneos_archs "arm64")
#set(__iphonesimulator_archs "arm64,x86_64")

View file

@ -35,7 +35,19 @@
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <filesystem>
#if __has_include(<filesystem>)
#include <filesystem>
namespace stdfs = std::filesystem;
#else
#if TARGET_OS_IOS
#error "This should never happen on ios."
#endif
namespace stdfs = boost::filesystem;
#endif
//#include <filesystem>
#ifndef MAKE64
#define MAKE64(low,high) ((__int64)(((DWORD)(low)) | ((__int64)((DWORD)(high))) << 32))
@ -562,10 +574,10 @@ namespace file_io_utils
try
{
std::filesystem::directory_iterator end_itr; // default construction yields past-the-end
for ( std::filesystem::directory_iterator itr( epee::string_encoding::utf8_to_wstring(path) ); itr != end_itr; ++itr )
stdfs::directory_iterator end_itr; // default construction yields past-the-end
for (stdfs::directory_iterator itr( epee::string_encoding::utf8_to_wstring(path) ); itr != end_itr; ++itr )
{
if ( only_files && std::filesystem::is_directory(itr->status()) )
if ( only_files && stdfs::is_directory(itr->status()) )
{
continue;
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2019 Zano Project
// Copyright (c) 2014-2024 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -394,10 +394,67 @@ namespace tools
}
return true;
}
const char* lmdb_db_backend::name()
{
return "lmdb";
}
bool lmdb_db_backend::convert_db_4kb_page_to_16kb_page(const std::string& source_path, const std::string& destination_path)
{
#define MDB_CHECK(x, msg) {int rc = x; CHECK_AND_ASSERT_MES(rc == MDB_SUCCESS, false, "LMDB 4k->16k error: " << msg << ": " << mdb_strerror(rc));}
MDB_env *env_src = nullptr, *env_dst = nullptr;
// source
MDB_CHECK(mdb_env_create(&env_src), "failed to create LMDB environment");
MDB_CHECK(mdb_env_set_mapsize(env_src, 4 * 1024 * 1024), "failed to set mapsize"); // mapsize ?
MDB_CHECK(mdb_env_open(env_src, source_path.c_str(), 0, 0664), "failed to open source LMDB");
// destination (16k page size)
MDB_CHECK(mdb_env_create(&env_dst), "failed to create LMDB environment");
MDB_CHECK(mdb_env_set_mapsize(env_dst, 16 * 1024 * 1024), "failed to set mapsize"); // mapsize ?
// TODO uncomment after mdb_env_set_pagesize is supported
// MDB_CHECK(mdb_env_set_pagesize(env_dst, 16 * 1024), "failed to set page size to 16K");
MDB_CHECK(mdb_env_open(env_dst, destination_path.c_str(), 0, 0664), "failed to open destination LMDB");
// begin transactions
MDB_txn *txn_src = nullptr, *txn_dst = nullptr;
MDB_dbi dbi_src, dbi_dst;
MDB_CHECK(mdb_txn_begin(env_src, nullptr, MDB_RDONLY, &txn_src), "failed to begin source transaction");
MDB_CHECK(mdb_dbi_open(txn_src, nullptr, 0, &dbi_src), "failed to open source database");
MDB_CHECK(mdb_txn_begin(env_dst, nullptr, 0, &txn_dst), "failed to begin destination transaction");
MDB_CHECK(mdb_dbi_open(txn_dst, nullptr, MDB_CREATE, &dbi_dst), "failed to open destination database");
MDB_cursor *cursor;
MDB_val key, data;
// Iterate over the source database and copy all key-value pairs to the destination database
MDB_CHECK(mdb_cursor_open(txn_src, dbi_src, &cursor), "failed to open cursor");
while (mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == MDB_SUCCESS)
{
MDB_CHECK(mdb_put(txn_dst, dbi_dst, &key, &data, 0), "failed to put data in destination database");
}
mdb_cursor_close(cursor);
// commit transactions
MDB_CHECK(mdb_txn_commit(txn_src), "failed to commit source transaction");
MDB_CHECK(mdb_txn_commit(txn_dst), "failed to commit destination transaction");
mdb_dbi_close(env_src, dbi_src);
mdb_dbi_close(env_dst, dbi_dst);
mdb_env_close(env_src);
mdb_env_close(env_dst);
return true;
#undef MDB_CHECK
}
}
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2019 Zano Project
// Copyright (c) 2014-2024 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@ -36,6 +36,7 @@ namespace tools
boost::recursive_mutex m_write_exclusive_lock;
std::map<std::thread::id, transactions_list> m_txs; // size_t -> count of nested read_only transactions
bool pop_tx_entry(tx_entry& txe);
public:
lmdb_db_backend();
~lmdb_db_backend();
@ -60,6 +61,8 @@ namespace tools
bool have_tx();
MDB_txn* get_current_tx();
static bool convert_db_4kb_page_to_16kb_page(const std::string& source_path, const std::string& destination_path);
};
}
}

View file

@ -3391,5 +3391,9 @@ namespace tools
CHECK_AND_ASSERT_THROW_MES(it!= wordsMap.end(), "unable to find word \"" << w << "\" in mnemonic dictionary");
return it->second;
}
const map<string, uint32_t>& get_words_map()
{
return wordsMap;
}
}
}

View file

@ -47,5 +47,6 @@ namespace tools
std::string word_by_num(uint32_t n);
uint64_t num_by_word(const std::string& w);
bool valid_word(const std::string& w);
const std::map<std::string, uint32_t>& get_words_map();
}
}

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2019 Zano Project
// Copyright (c) 2014-2024 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -25,6 +25,7 @@ using namespace epee;
#include "storages/http_abstract_invoke.h"
#include "net/http_client.h"
#include "currency_core/genesis_acc.h"
#include "common/db_backend_lmdb.h"
#include <cstdlib>
namespace po = boost::program_options;
@ -63,6 +64,7 @@ namespace
const command_line::arg_descriptor<std::string> arg_pack_file ("pack-file", "perform gzip-packing and calculate hash for a given file");
const command_line::arg_descriptor<std::string> arg_unpack_file ("unpack-file", "Perform gzip-unpacking and calculate hash for a given file");
const command_line::arg_descriptor<std::string> arg_target_file ("target-file", "Specify target file for pack-file and unpack-file commands");
const command_line::arg_descriptor<std::string> arg_lmdb_page_4to16 ("convert-lmdb-4to16", "Perform LMDB conversion from 4k page size to 16k page size");
//const command_line::arg_descriptor<std::string> arg_send_ipc ("send-ipc", "Send IPC request to UI");
}
@ -1220,7 +1222,10 @@ bool handle_pack_file(po::variables_map& vm)
}
if (!command_line::has_arg(vm, arg_target_file))
{
std::cout << "Error: Parameter target_file is not set." << ENDL;
return false;
}
path_target = command_line::get_arg(vm, arg_target_file);
std::ifstream source;
@ -1251,6 +1256,34 @@ bool handle_pack_file(po::variables_map& vm)
}
}
bool handle_lmdb_page_4to16(po::variables_map& vm)
{
std::string path_source;
std::string path_target;
if (!command_line::has_arg(vm, arg_lmdb_page_4to16))
return false;
path_source = command_line::get_arg(vm, arg_lmdb_page_4to16);
if (!command_line::has_arg(vm, arg_target_file))
{
std::cout << "Error: Parameter target_file is not set." << ENDL;
return false;
}
path_target = command_line::get_arg(vm, arg_target_file);
if (tools::db::lmdb_db_backend::convert_db_4kb_page_to_16kb_page(path_source, path_target))
{
std::cout << "Conversion failed" << ENDL;
return false;
}
std::cout << "Converted successfully" << ENDL;
return true;
}
//---------------------------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
@ -1375,6 +1408,10 @@ int main(int argc, char* argv[])
{
return handle_pack_file(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
else if (command_line::has_arg(vm, arg_lmdb_page_4to16))
{
return handle_lmdb_page_4to16(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
/*else if (command_line::has_arg(vm, arg_send_ipc))
{
handle_send_ipc(command_line::get_arg(vm, arg_send_ipc)) ? EXIT_SUCCESS : EXIT_FAILURE;

View file

@ -43,7 +43,7 @@ void generate_system_random_bytes(size_t n, void *result) {
void generate_system_random_bytes(size_t n, void *result) {
int fd;
if ((fd = open("/dev/urandom", O_RDONLY | O_NOCTTY | O_CLOEXEC)) < 0) {
err(EXIT_FAILURE, "open /dev/urandom");
exit(EXIT_FAILURE);
}
for (;;) {
ssize_t res = read(fd, result, n);
@ -52,17 +52,17 @@ void generate_system_random_bytes(size_t n, void *result) {
}
if (res < 0) {
if (errno != EINTR) {
err(EXIT_FAILURE, "read /dev/urandom");
exit(EXIT_FAILURE);
}
} else if (res == 0) {
errx(EXIT_FAILURE, "read /dev/urandom: end of file");
exit(EXIT_FAILURE);
} else {
result = padd(result, (size_t) res);
n -= (size_t) res;
}
}
if (close(fd) < 0) {
err(EXIT_FAILURE, "close /dev/urandom");
exit(EXIT_FAILURE);
}
}

View file

@ -91,11 +91,11 @@ namespace currency
}
std::string keys_seed_text = tools::mnemonic_encoding::binary2text(processed_seed_binary);
std::string timestamp_word = currency::get_word_from_timstamp(m_creation_timestamp, !password.empty());
std::string timestamp_word = currency::get_word_from_timestamp(m_creation_timestamp, !password.empty());
// floor creation time to WALLET_BRAIN_DATE_QUANTUM to make checksum calculation stable
bool self_check_is_password_used = false;
uint64_t creation_timestamp_rounded = get_timstamp_from_word(timestamp_word, self_check_is_password_used);
uint64_t creation_timestamp_rounded = get_timestamp_from_word(timestamp_word, self_check_is_password_used);
CHECK_AND_ASSERT_THROW_MES(self_check_is_password_used == !password.empty(), "Account seed phrase internal error: password flag encoded wrong");
constexpr uint16_t checksum_max = tools::mnemonic_encoding::NUMWORDS >> 1; // maximum value of checksum
@ -134,11 +134,12 @@ namespace currency
return true;
}
//-----------------------------------------------------------------
bool account_base::restore_from_seed_phrase(const std::string& seed_phrase, const std::string& seed_password)
bool account_base::restore_from_seed_phrase(const std::string& seed_phrase_, const std::string& seed_password)
{
//cut the last timestamp word from restore_dats
std::list<std::string> words;
boost::split(words, seed_phrase, boost::is_space());
std::string seed_phrase = epee::string_tools::trim(seed_phrase_);
boost::split(words, seed_phrase, boost::is_space(), boost::token_compress_on);
std::string keys_seed_text, timestamp_word, auditable_flag_and_checksum_word;
if (words.size() == SEED_PHRASE_V1_WORDS_COUNT)
@ -183,7 +184,7 @@ namespace currency
bool has_password = false;
try {
m_creation_timestamp = get_timstamp_from_word(timestamp_word, has_password);
m_creation_timestamp = get_timestamp_from_word(timestamp_word, has_password);
}
catch (...)
{
@ -237,11 +238,13 @@ namespace currency
return seed_phrase.find(':') != std::string::npos;
}
//-----------------------------------------------------------------
bool account_base::is_seed_password_protected(const std::string& seed_phrase, bool& is_password_protected)
bool account_base::is_seed_password_protected(const std::string& seed_phrase_, bool& is_password_protected)
{
//cut the last timestamp word from restore_dats
std::list<std::string> words;
boost::split(words, seed_phrase, boost::is_space());
std::string seed_phrase = epee::string_tools::trim(seed_phrase_);
boost::split(words, seed_phrase, boost::is_space(), boost::token_compress_on);
//let's validate each word
for (const auto& w: words)
@ -267,7 +270,7 @@ namespace currency
return false;
}
get_timstamp_from_word(timestamp_word, is_password_protected);
get_timestamp_from_word(timestamp_word, is_password_protected);
return true;
}

View file

@ -803,6 +803,13 @@ namespace currency
BOOST_END_VERSION_UNDER(1)
BOOST_SERIALIZE(opt_asset_id)
END_BOOST_SERIALIZATION()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(operation_type) DOC_DSCR("Asset operation type identifier") DOC_EXMP(1) DOC_END
KV_SERIALIZE(descriptor) DOC_DSCR("Asset descriptor") DOC_EXMP_AUTO() DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(amount_commitment) DOC_DSCR("Amount commitment") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(opt_asset_id) DOC_DSCR("ID of an asset.") DOC_EXMP("cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6") DOC_END
END_KV_SERIALIZE_MAP()
};
struct asset_operation_proof
@ -856,6 +863,11 @@ namespace currency
BOOST_SERIALIZE(eth_sig)
BOOST_SERIALIZE(version)
END_BOOST_SERIALIZATION()
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(eth_sig) DOC_DSCR("HEX-encoded ETH signature (64 bytes)") DOC_EXMP("674bb56a5b4fa562e679ccacc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6add697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE(version) DOC_DSCR("Structure version") DOC_EXMP(0) DOC_END
END_KV_SERIALIZE_MAP()
};
struct extra_padding

View file

@ -2832,7 +2832,7 @@ namespace currency
return reward;
}
//---------------------------------------------------------------
std::string get_word_from_timstamp(uint64_t timestamp, bool use_password)
std::string get_word_from_timestamp(uint64_t timestamp, bool use_password)
{
uint64_t date_offset = timestamp > WALLET_BRAIN_DATE_OFFSET ? timestamp - WALLET_BRAIN_DATE_OFFSET : 0;
uint64_t weeks_count = date_offset / WALLET_BRAIN_DATE_QUANTUM;
@ -2847,7 +2847,7 @@ namespace currency
return tools::mnemonic_encoding::word_by_num(weeks_count_32);
}
//---------------------------------------------------------------
uint64_t get_timstamp_from_word(std::string word, bool& password_used)
uint64_t get_timestamp_from_word(std::string word, bool& password_used)
{
uint64_t count_of_weeks = tools::mnemonic_encoding::num_by_word(word);
if (count_of_weeks >= WALLET_BRAIN_DATE_MAX_WEEKS_COUNT)

View file

@ -455,9 +455,9 @@ namespace currency
bool fill_block_rpc_details(block_rpc_extended_info& pei_rpc, const block_extended_info& bei_chain, const crypto::hash& h);
void append_per_block_increments_for_tx(const transaction& tx, std::unordered_map<uint64_t, uint32_t>& gindices);
std::string get_word_from_timstamp(uint64_t timestamp, bool use_password);
uint64_t get_timstamp_from_word(std::string word, bool& password_used, const std::string& buff);
uint64_t get_timstamp_from_word(std::string word, bool& password_used);
std::string get_word_from_timestamp(uint64_t timestamp, bool use_password);
uint64_t get_timestamp_from_word(std::string word, bool& password_used, const std::string& buff);
uint64_t get_timestamp_from_word(std::string word, bool& password_used);
bool parse_vote(const std::string& buff, std::list<std::pair<std::string, bool>>& votes);
std::string generate_origin_for_htlc(const txout_htlc& htlc, const account_keys& acc_keys);

View file

@ -1369,6 +1369,110 @@ namespace currency
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_find_outs_in_recent_blocks(const COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS::request& req, COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS::response& resp, epee::json_rpc::error& error_resp, connection_context& cntx)
{
#define LOCAL_CHECK(cond, msg) if (!(cond)) { error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM; error_resp.message = msg; LOG_PRINT_L1("on_find_outs_in_recent_blocks: " << msg); return false; }
#define LOCAL_CHECK_INT_ERR(cond, msg) if (!(cond)) { error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR; error_resp.message = msg; LOG_PRINT_L1("on_find_outs_in_recent_blocks: " << msg); return false; }
LOCAL_CHECK(req.address != account_public_address{}, "address is missing");
LOCAL_CHECK(req.viewkey != null_skey, "viewkey is missing");
LOCAL_CHECK(0 <= req.blocks_limit && req.blocks_limit <= 5, "blocks_limit is out of allowed bounds");
// verify addess keys
crypto::point_t view_pk, spend_pk;
LOCAL_CHECK(view_pk.from_public_key(req.address.view_public_key), "cannon load point from address.view_public_key");
LOCAL_CHECK(view_pk.is_in_main_subgroup(), "address.view_public_key isn't in main subgroup");
LOCAL_CHECK(spend_pk.from_public_key(req.address.spend_public_key), "cannon load point from address.spend_public_key");
LOCAL_CHECK(spend_pk.is_in_main_subgroup(), "address.spend_public_key isn't in main subgroup");
// verify viewkey
crypto::scalar_t view_sc = req.viewkey;
LOCAL_CHECK(view_sc.is_reduced(), "viewkey is invalid");
LOCAL_CHECK(view_sc * crypto::c_point_G == view_pk, "viewkey doesn't correspond to the given address");
const blockchain_storage& bcs = m_core.get_blockchain_storage();
resp.blockchain_top_block_height = bcs.get_top_block_height();
resp.blocks_limit = req.blocks_limit;
// get blockchain transactions
std::unordered_map<uint64_t, std::pair<std::vector<crypto::hash>, std::list<transaction>>> blockchain_txs; // block height -> (vector of tx_ids, list of txs)
if (req.blocks_limit > 0)
{
uint64_t start_offset = resp.blockchain_top_block_height - req.blocks_limit + 1;
std::list<block> recent_blocks;
LOCAL_CHECK_INT_ERR(bcs.get_blocks(start_offset, static_cast<size_t>(req.blocks_limit), recent_blocks), "cannot get recent blocks");
std::vector<crypto::hash> blockchain_tx_ids, missed_tx;
for(auto& b : recent_blocks)
{
blockchain_tx_ids.insert(blockchain_tx_ids.end(), b.tx_hashes.begin(), b.tx_hashes.end());
uint64_t height = get_block_height(b);
auto& el = blockchain_txs[height];
el.first = b.tx_hashes;
missed_tx.clear();
LOCAL_CHECK_INT_ERR(bcs.get_transactions(b.tx_hashes, el.second, missed_tx), "bcs.get_transactions failed");
LOCAL_CHECK_INT_ERR(missed_tx.empty(), "missed_tx is not empty");
LOCAL_CHECK_INT_ERR(el.first.size() == el.second.size(), "el.first.size() != el.second.size()");
}
}
// get pool transactions
std::list<transaction> pool_txs;
LOCAL_CHECK_INT_ERR(m_core.get_tx_pool().get_transactions(pool_txs), "cannot get txs from pool");
// processor lambda
auto process_tx = [&](const transaction& tx, const crypto::hash& tx_id, const int64_t height) {
crypto::key_derivation derivation{};
LOCAL_CHECK(generate_key_derivation(get_tx_pub_key_from_extra(tx), req.viewkey, derivation), "generate_key_derivation failed");
for(size_t i = 0, sz = tx.vout.size(); i < sz; ++i)
{
const tx_out_v& outv = tx.vout[i];
if (outv.type() != typeid(tx_out_zarcanum))
continue;
uint64_t decoded_amount = 0;
crypto::public_key decoded_asset_id{};
crypto::scalar_t amount_blinding_mask{}, asset_id_blinding_mask{};
if (!is_out_to_acc(req.address, boost::get<tx_out_zarcanum>(outv), derivation, i, decoded_amount, decoded_asset_id, amount_blinding_mask, asset_id_blinding_mask))
continue;
auto& el = resp.outputs.emplace_back();
el.amount = decoded_amount;
el.asset_id = decoded_asset_id;
el.tx_id = tx_id;
el.tx_block_height = height;
el.output_tx_index = i;
}
return true;
};
// process blockchain txs
for(auto& [height, pair] : blockchain_txs)
{
LOCAL_CHECK(pair.first.size() == pair.second.size(), "container size inconsistency");
auto tx_it = pair.second.begin();
for(size_t i = 0, sz = pair.first.size(); i < sz; ++i, ++tx_it)
{
const crypto::hash& tx_id = pair.first[i];
LOCAL_CHECK(process_tx(*tx_it, tx_id, height), "process blockchain tx failed for tx " + crypto::pod_to_hex(tx_id));
}
}
// process pool txs
for(auto& tx : pool_txs)
{
crypto::hash tx_id = get_transaction_hash(tx);
LOCAL_CHECK(process_tx(tx, tx_id, -1), "process pool tx failed for tx " + crypto::pod_to_hex(tx_id));
}
resp.status = resp.outputs.empty() ? API_RETURN_CODE_NOT_FOUND : API_RETURN_CODE_OK;
return true;
#undef LOCAL_CHECK_INT_ERR
#undef LOCAL_CHECK
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_aliases_by_address(const COMMAND_RPC_GET_ALIASES_BY_ADDRESS::request& req, COMMAND_RPC_GET_ALIASES_BY_ADDRESS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
account_public_address addr = AUTO_VAL_INIT(addr);

View file

@ -95,6 +95,7 @@ namespace currency
bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_get_alt_blocks_details(const COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_ALT_BLOCKS_DETAILS::response& res, connection_context& cntx);
bool on_get_est_height_from_date(const COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::request& req, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE::response& res, connection_context& cntx);
bool on_find_outs_in_recent_blocks(const COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS::request& req, COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_validate_signature(const COMMAND_VALIDATE_SIGNATURE::request& req, COMMAND_VALIDATE_SIGNATURE::response& res, epee::json_rpc::error& er, connection_context& cntx);
@ -134,6 +135,8 @@ namespace currency
MAP_JON_RPC_WE("get_alias_by_address", on_aliases_by_address, COMMAND_RPC_GET_ALIASES_BY_ADDRESS)
MAP_JON_RPC_WE("get_alias_reward", on_get_alias_reward, COMMAND_RPC_GET_ALIAS_REWARD)
MAP_JON_RPC ("get_est_height_from_date", on_get_est_height_from_date, COMMAND_RPC_GET_EST_HEIGHT_FROM_DATE)
MAP_JON_RPC_WE("find_outs_in_recent_blocks", on_find_outs_in_recent_blocks, COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS)
//block explorer api
MAP_JON_RPC ("get_blocks_details", on_rpc_get_blocks_details, COMMAND_RPC_GET_BLOCKS_DETAILS)
MAP_JON_RPC_WE("get_tx_details", on_get_tx_details, COMMAND_RPC_GET_TX_DETAILS)

View file

@ -342,6 +342,58 @@ namespace currency
};
};
//-----------------------------------------------
struct COMMAND_RPC_FIND_OUTS_IN_RECENT_BLOCKS
{
DOC_COMMAND("Retrieves information about outputs in recent blocks that are targeted for the given address with the corresponding secret view key.")
static constexpr uint64_t blocks_limit_default = 5;
struct request
{
account_public_address address;
crypto::secret_key viewkey;
uint64_t blocks_limit = blocks_limit_default;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_ADDRESS_AS_TEXT(address) DOC_DSCR("Target address for which outputs are being searched") DOC_EXMP("ZxCSpsGGeJsS8fwvQ4HktDU3qBeauoJTR6j73jAWWZxFXdF7XTbGm4YfS2kXJmAP4Rf5BVsSQ9iZ45XANXEYsrLN2L2W77dH7") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(viewkey) DOC_DSCR("Secret view key corresponding to the given address.") DOC_EXMP("5fa8eaaf231a305053260ff91d69c6ef1ecbd0f5") DOC_END
KV_SERIALIZE(blocks_limit) DOC_DSCR("Block count limit. If 0, only the transaction pool will be searched. Maximum and default is " + epee::string_tools::num_to_string_fast(blocks_limit_default) + ".") DOC_EXMP(1711021795) DOC_END
END_KV_SERIALIZE_MAP()
};
struct out_entry
{
uint64_t amount;
crypto::public_key asset_id;
crypto::hash tx_id;
int64_t tx_block_height;
uint64_t output_tx_index;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amount) DOC_DSCR("The amount of the output.") DOC_EXMP(1000000000000) DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Asset ID of the output.") DOC_EXMP("cc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) DOC_DSCR("Transaction ID where the output is present, if found.") DOC_EXMP("a6e8da986858e6825fce7a192097e6afae4e889cabe853a9c29b964985b23da8") DOC_END
KV_SERIALIZE(tx_block_height) DOC_DSCR("Block height where the transaction is present.") DOC_EXMP(2555000) DOC_END
KV_SERIALIZE(output_tx_index) DOC_DSCR("Index of the output in the transaction.") DOC_EXMP(2) DOC_END
END_KV_SERIALIZE_MAP()
};
struct response
{
std::vector<out_entry> outputs;
uint64_t blockchain_top_block_height;
uint64_t blocks_limit;
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(outputs) DOC_DSCR("List of found outputs.") DOC_EXMP_AUTO(1) DOC_END
KV_SERIALIZE(blockchain_top_block_height) DOC_DSCR("Height of the most recent block in the blockchain.") DOC_EXMP(2555000) DOC_END
KV_SERIALIZE(blocks_limit) DOC_DSCR("Used limit for block count.") DOC_EXMP(5) DOC_END
KV_SERIALIZE(status) DOC_DSCR("Status of the call.") DOC_EXMP(API_RETURN_CODE_OK) DOC_END
END_KV_SERIALIZE_MAP()
};
};
//-----------------------------------------------
struct COMMAND_RPC_GET_TX_POOL
{
DOC_COMMAND("Retreives transactions from tx pool (and other information).")
@ -643,12 +695,14 @@ namespace currency
struct request
{
std::string tx_as_hex;
std::string tx_as_json;
request() {}
explicit request(const transaction &);
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tx_as_hex) DOC_DSCR("The transaction data as a hexadecimal string, ready for network broadcast.") DOC_EXMP("00018ed1535b8b4862e.....368cdc5a86") DOC_END
KV_SERIALIZE(tx_as_hex) DOC_DSCR("[either] The transaction data as a hexadecimal string, ready for network broadcast.") DOC_EXMP("00018ed1535b8b4862e.....368cdc5a86") DOC_END
KV_SERIALIZE_BLOB_AS_BASE64_STRING(tx_as_json) DOC_DSCR("[or] The transaction data as a base64-encoded json, ready for network broadcast.") DOC_EXMP("ARMBgKCUpY0dBBoAAAAAAAAAABoCAAAAA.......AAAAAAAAABoPAAAAAAAAACVA4FRLH") DOC_END
END_KV_SERIALIZE_MAP()
};

View file

@ -12,6 +12,7 @@
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/join.hpp>
#include "include_base_utils.h"
#include "common/command_line.h"
#include "common/util.h"
@ -26,7 +27,7 @@
#include "string_coding.h"
#include "wallet/wrap_service.h"
#include "common/general_purpose_commands_defs.h"
#include "common/mnemonic-encoding.h"
#include "wallet/wallet_helpers.h"
@ -143,6 +144,7 @@ namespace
const command_line::arg_descriptor<unsigned int> arg_set_timeout("set-timeout", "Set timeout for the wallet");
const command_line::arg_descriptor<std::string> arg_voting_config_file("voting-config-file", "Set voting config instead of getting if from daemon", "");
const command_line::arg_descriptor<bool> arg_no_password_confirmations("no-password-confirmation", "Enable/Disable password confirmation for transactions", false);
const command_line::arg_descriptor<bool> arg_seed_doctor("seed-doctor", "Experimental: if your seed is not working for recovery this is likely because you've made a mistake whene you were doing back up(typo, wrong words order, missing word). This experimental code will attempt to recover seed phrase from with few approaches.");
const command_line::arg_descriptor< std::vector<std::string> > arg_command ("command", "");

View file

@ -7,10 +7,11 @@
#pragma once
#define WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR -1
#define WALLET_RPC_ERROR_CODE_WRONG_ADDRESS -2
#define WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY -3
#define WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR -4
#define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5
#define WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT -6
#define WALLET_RPC_ERROR_CODE_NOT_ENOUGH_MONEY -7
#define WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR -1
#define WALLET_RPC_ERROR_CODE_WRONG_ADDRESS -2
#define WALLET_RPC_ERROR_CODE_DAEMON_IS_BUSY -3
#define WALLET_RPC_ERROR_CODE_GENERIC_TRANSFER_ERROR -4
#define WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID -5
#define WALLET_RPC_ERROR_CODE_WRONG_ARGUMENT -6
#define WALLET_RPC_ERROR_CODE_NOT_ENOUGH_MONEY -7
#define WALLET_RPC_ERROR_CODE_WRONG_MIXINS_FOR_AUDITABLE_WALLET -8

View file

@ -312,139 +312,139 @@ TEST(decompose_amount_randomly, 1)
TEST(print_money_brief, 1)
{
// decimal point 12 (default)
ASSERT_EQ(print_money_brief( 0), "0.0");
ASSERT_EQ(print_money_brief( 1), "0.000000000001");
ASSERT_EQ(print_money_brief( 1000000000000), "1.0");
ASSERT_EQ(print_money_brief( 1900000000000), "1.9");
ASSERT_EQ(print_money_brief( 1000000100000), "1.0000001");
ASSERT_EQ(print_money_brief( 1000000000001), "1.000000000001");
ASSERT_EQ(print_money_brief( 9999999999999), "9.999999999999");
ASSERT_EQ(print_money_brief( 90009990009900), "90.0099900099");
ASSERT_EQ(print_money_brief(10109010000000000000), "10109010.0");
ASSERT_EQ(print_money_brief(10109010010000000000), "10109010.01");
ASSERT_EQ(print_money_brief(18446744073709551610), "18446744.07370955161");
ASSERT_EQ(print_money_brief(18446744073709551614), "18446744.073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615), "18446744.073709551615");
ASSERT_EQ(print_money_brief( 0ull), "0.0");
ASSERT_EQ(print_money_brief( 1ull), "0.000000000001");
ASSERT_EQ(print_money_brief( 1000000000000ull), "1.0");
ASSERT_EQ(print_money_brief( 1900000000000ull), "1.9");
ASSERT_EQ(print_money_brief( 1000000100000ull), "1.0000001");
ASSERT_EQ(print_money_brief( 1000000000001ull), "1.000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull), "9.999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull), "90.0099900099");
ASSERT_EQ(print_money_brief(10109010000000000000ull), "10109010.0");
ASSERT_EQ(print_money_brief(10109010010000000000ull), "10109010.01");
ASSERT_EQ(print_money_brief(18446744073709551610ull), "18446744.07370955161");
ASSERT_EQ(print_money_brief(18446744073709551614ull), "18446744.073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull), "18446744.073709551615");
// decimal point 0
ASSERT_EQ(print_money_brief( 0, 0), "0");
ASSERT_EQ(print_money_brief( 1, 0), "1");
ASSERT_EQ(print_money_brief( 1000000000000, 0), "1000000000000");
ASSERT_EQ(print_money_brief( 1900000000000, 0), "1900000000000");
ASSERT_EQ(print_money_brief( 1000000100000, 0), "1000000100000");
ASSERT_EQ(print_money_brief( 1000000000001, 0), "1000000000001");
ASSERT_EQ(print_money_brief( 9999999999999, 0), "9999999999999");
ASSERT_EQ(print_money_brief( 90009990009900, 0), "90009990009900");
ASSERT_EQ(print_money_brief(10109010000000000000, 0), "10109010000000000000");
ASSERT_EQ(print_money_brief(10109010010000000000, 0), "10109010010000000000");
ASSERT_EQ(print_money_brief(18446744073709551610, 0), "18446744073709551610");
ASSERT_EQ(print_money_brief(18446744073709551614, 0), "18446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615, 0), "18446744073709551615");
ASSERT_EQ(print_money_brief( 0ull, 0), "0");
ASSERT_EQ(print_money_brief( 1ull, 0), "1");
ASSERT_EQ(print_money_brief( 1000000000000ull, 0), "1000000000000");
ASSERT_EQ(print_money_brief( 1900000000000ull, 0), "1900000000000");
ASSERT_EQ(print_money_brief( 1000000100000ull, 0), "1000000100000");
ASSERT_EQ(print_money_brief( 1000000000001ull, 0), "1000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 0), "9999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 0), "90009990009900");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 0), "10109010000000000000");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 0), "10109010010000000000");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 0), "18446744073709551610");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 0), "18446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 0), "18446744073709551615");
// decimal point 1
ASSERT_EQ(print_money_brief( 0, 1), "0.0");
ASSERT_EQ(print_money_brief( 1, 1), "0.1");
ASSERT_EQ(print_money_brief( 1000000000000, 1), "100000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000, 1), "190000000000.0");
ASSERT_EQ(print_money_brief( 1000000100000, 1), "100000010000.0");
ASSERT_EQ(print_money_brief( 1000000000001, 1), "100000000000.1");
ASSERT_EQ(print_money_brief( 9999999999999, 1), "999999999999.9");
ASSERT_EQ(print_money_brief( 90009990009900, 1), "9000999000990.0");
ASSERT_EQ(print_money_brief(10109010000000000000, 1), "1010901000000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000, 1), "1010901001000000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610, 1), "1844674407370955161.0");
ASSERT_EQ(print_money_brief(18446744073709551614, 1), "1844674407370955161.4");
ASSERT_EQ(print_money_brief(18446744073709551615, 1), "1844674407370955161.5");
ASSERT_EQ(print_money_brief( 0ull, 1), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 1), "0.1");
ASSERT_EQ(print_money_brief( 1000000000000ull, 1), "100000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000ull, 1), "190000000000.0");
ASSERT_EQ(print_money_brief( 1000000100000ull, 1), "100000010000.0");
ASSERT_EQ(print_money_brief( 1000000000001ull, 1), "100000000000.1");
ASSERT_EQ(print_money_brief( 9999999999999ull, 1), "999999999999.9");
ASSERT_EQ(print_money_brief( 90009990009900ull, 1), "9000999000990.0");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 1), "1010901000000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 1), "1010901001000000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 1), "1844674407370955161.0");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 1), "1844674407370955161.4");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 1), "1844674407370955161.5");
// decimal point 2
ASSERT_EQ(print_money_brief( 0, 2), "0.0");
ASSERT_EQ(print_money_brief( 1, 2), "0.01");
ASSERT_EQ(print_money_brief( 1000000000000, 2), "10000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000, 2), "19000000000.0");
ASSERT_EQ(print_money_brief( 1000000100000, 2), "10000001000.0");
ASSERT_EQ(print_money_brief( 1000000000001, 2), "10000000000.01");
ASSERT_EQ(print_money_brief( 9999999999999, 2), "99999999999.99");
ASSERT_EQ(print_money_brief( 90009990009900, 2), "900099900099.0");
ASSERT_EQ(print_money_brief(10109010000000000000, 2), "101090100000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000, 2), "101090100100000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610, 2), "184467440737095516.1");
ASSERT_EQ(print_money_brief(18446744073709551614, 2), "184467440737095516.14");
ASSERT_EQ(print_money_brief(18446744073709551615, 2), "184467440737095516.15");
ASSERT_EQ(print_money_brief( 0ull, 2), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 2), "0.01");
ASSERT_EQ(print_money_brief( 1000000000000ull, 2), "10000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000ull, 2), "19000000000.0");
ASSERT_EQ(print_money_brief( 1000000100000ull, 2), "10000001000.0");
ASSERT_EQ(print_money_brief( 1000000000001ull, 2), "10000000000.01");
ASSERT_EQ(print_money_brief( 9999999999999ull, 2), "99999999999.99");
ASSERT_EQ(print_money_brief( 90009990009900ull, 2), "900099900099.0");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 2), "101090100000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 2), "101090100100000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 2), "184467440737095516.1");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 2), "184467440737095516.14");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 2), "184467440737095516.15");
// decimal point 3
ASSERT_EQ(print_money_brief( 0, 3), "0.0");
ASSERT_EQ(print_money_brief( 1, 3), "0.001");
ASSERT_EQ(print_money_brief( 1000000000000, 3), "1000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000, 3), "1900000000.0");
ASSERT_EQ(print_money_brief( 1000000100000, 3), "1000000100.0");
ASSERT_EQ(print_money_brief( 1000000000001, 3), "1000000000.001");
ASSERT_EQ(print_money_brief( 9999999999999, 3), "9999999999.999");
ASSERT_EQ(print_money_brief( 90009990009900, 3), "90009990009.9");
ASSERT_EQ(print_money_brief(10109010000000000000, 3), "10109010000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000, 3), "10109010010000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610, 3), "18446744073709551.61");
ASSERT_EQ(print_money_brief(18446744073709551614, 3), "18446744073709551.614");
ASSERT_EQ(print_money_brief(18446744073709551615, 3), "18446744073709551.615");
ASSERT_EQ(print_money_brief( 0ull, 3), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 3), "0.001");
ASSERT_EQ(print_money_brief( 1000000000000ull, 3), "1000000000.0");
ASSERT_EQ(print_money_brief( 1900000000000ull, 3), "1900000000.0");
ASSERT_EQ(print_money_brief( 1000000100000ull, 3), "1000000100.0");
ASSERT_EQ(print_money_brief( 1000000000001ull, 3), "1000000000.001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 3), "9999999999.999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 3), "90009990009.9");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 3), "10109010000000000.0");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 3), "10109010010000000.0");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 3), "18446744073709551.61");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 3), "18446744073709551.614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 3), "18446744073709551.615");
// decimal point 18
ASSERT_EQ(print_money_brief( 0, 18), "0.0");
ASSERT_EQ(print_money_brief( 1, 18), "0.000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000, 18), "0.000001");
ASSERT_EQ(print_money_brief( 1900000000000, 18), "0.0000019");
ASSERT_EQ(print_money_brief( 1000000100000, 18), "0.0000010000001");
ASSERT_EQ(print_money_brief( 1000000000001, 18), "0.000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999, 18), "0.000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900, 18), "0.0000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000, 18), "10.10901");
ASSERT_EQ(print_money_brief(10109010010000000000, 18), "10.10901001");
ASSERT_EQ(print_money_brief(18446744073709551610, 18), "18.44674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614, 18), "18.446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615, 18), "18.446744073709551615");
ASSERT_EQ(print_money_brief( 0ull, 18), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 18), "0.000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000ull, 18), "0.000001");
ASSERT_EQ(print_money_brief( 1900000000000ull, 18), "0.0000019");
ASSERT_EQ(print_money_brief( 1000000100000ull, 18), "0.0000010000001");
ASSERT_EQ(print_money_brief( 1000000000001ull, 18), "0.000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 18), "0.000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 18), "0.0000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 18), "10.10901");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 18), "10.10901001");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 18), "18.44674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 18), "18.446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 18), "18.446744073709551615");
// decimal point 19
ASSERT_EQ(print_money_brief( 0, 19), "0.0");
ASSERT_EQ(print_money_brief( 1, 19), "0.0000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000, 19), "0.0000001");
ASSERT_EQ(print_money_brief( 1900000000000, 19), "0.00000019");
ASSERT_EQ(print_money_brief( 1000000100000, 19), "0.00000010000001");
ASSERT_EQ(print_money_brief( 1000000000001, 19), "0.0000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999, 19), "0.0000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900, 19), "0.00000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000, 19), "1.010901");
ASSERT_EQ(print_money_brief(10109010010000000000, 19), "1.010901001");
ASSERT_EQ(print_money_brief(18446744073709551610, 19), "1.844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614, 19), "1.8446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615, 19), "1.8446744073709551615");
ASSERT_EQ(print_money_brief( 0ull, 19), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 19), "0.0000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000ull, 19), "0.0000001");
ASSERT_EQ(print_money_brief( 1900000000000ull, 19), "0.00000019");
ASSERT_EQ(print_money_brief( 1000000100000ull, 19), "0.00000010000001");
ASSERT_EQ(print_money_brief( 1000000000001ull, 19), "0.0000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 19), "0.0000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 19), "0.00000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 19), "1.010901");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 19), "1.010901001");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 19), "1.844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 19), "1.8446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 19), "1.8446744073709551615");
// TODO: remove it after setting reasonable limit of 18
// decimal point 20
ASSERT_EQ(print_money_brief( 0, 20), "0.0");
ASSERT_EQ(print_money_brief( 1, 20), "0.00000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000, 20), "0.00000001");
ASSERT_EQ(print_money_brief( 1900000000000, 20), "0.000000019");
ASSERT_EQ(print_money_brief( 1000000100000, 20), "0.000000010000001");
ASSERT_EQ(print_money_brief( 1000000000001, 20), "0.00000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999, 20), "0.00000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900, 20), "0.000000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000, 20), "0.1010901");
ASSERT_EQ(print_money_brief(10109010010000000000, 20), "0.1010901001");
ASSERT_EQ(print_money_brief(18446744073709551610, 20), "0.1844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614, 20), "0.18446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615, 20), "0.18446744073709551615");
ASSERT_EQ(print_money_brief( 0ull, 20), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 20), "0.00000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000ull, 20), "0.00000001");
ASSERT_EQ(print_money_brief( 1900000000000ull, 20), "0.000000019");
ASSERT_EQ(print_money_brief( 1000000100000ull, 20), "0.000000010000001");
ASSERT_EQ(print_money_brief( 1000000000001ull, 20), "0.00000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 20), "0.00000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 20), "0.000000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 20), "0.1010901");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 20), "0.1010901001");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 20), "0.1844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 20), "0.18446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 20), "0.18446744073709551615");
// TODO: remove it after setting reasonable limit of 18
// decimal point 21
ASSERT_EQ(print_money_brief( 0, 21), "0.0");
ASSERT_EQ(print_money_brief( 1, 21), "0.000000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000, 21), "0.000000001");
ASSERT_EQ(print_money_brief( 1900000000000, 21), "0.0000000019");
ASSERT_EQ(print_money_brief( 1000000100000, 21), "0.0000000010000001");
ASSERT_EQ(print_money_brief( 1000000000001, 21), "0.000000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999, 21), "0.000000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900, 21), "0.0000000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000, 21), "0.01010901");
ASSERT_EQ(print_money_brief(10109010010000000000, 21), "0.01010901001");
ASSERT_EQ(print_money_brief(18446744073709551610, 21), "0.01844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614, 21), "0.018446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615, 21), "0.018446744073709551615");
ASSERT_EQ(print_money_brief( 0ull, 21), "0.0");
ASSERT_EQ(print_money_brief( 1ull, 21), "0.000000000000000000001");
ASSERT_EQ(print_money_brief( 1000000000000ull, 21), "0.000000001");
ASSERT_EQ(print_money_brief( 1900000000000ull, 21), "0.0000000019");
ASSERT_EQ(print_money_brief( 1000000100000ull, 21), "0.0000000010000001");
ASSERT_EQ(print_money_brief( 1000000000001ull, 21), "0.000000001000000000001");
ASSERT_EQ(print_money_brief( 9999999999999ull, 21), "0.000000009999999999999");
ASSERT_EQ(print_money_brief( 90009990009900ull, 21), "0.0000000900099900099");
ASSERT_EQ(print_money_brief(10109010000000000000ull, 21), "0.01010901");
ASSERT_EQ(print_money_brief(10109010010000000000ull, 21), "0.01010901001");
ASSERT_EQ(print_money_brief(18446744073709551610ull, 21), "0.01844674407370955161");
ASSERT_EQ(print_money_brief(18446744073709551614ull, 21), "0.018446744073709551614");
ASSERT_EQ(print_money_brief(18446744073709551615ull, 21), "0.018446744073709551615");
}

File diff suppressed because it is too large Load diff

View file

@ -2,10 +2,13 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <exception>
#include "gtest/gtest.h"
#include "include_base_utils.h"
#include "currency_core/account.h"
#include "currency_core/currency_format_utils.h"
TEST(wallet_seed, store_restore_test)
{
@ -211,3 +214,151 @@ TEST(wallet_seed, basic_test)
}
}
TEST(wallet_seed, word_from_timestamp)
{
//timestamp = 0; use_password = false
ASSERT_EQ("like", currency::get_word_from_timestamp(0, false));
// timestamp = 0; use_password = true
ASSERT_EQ("among", currency::get_word_from_timestamp(0, true));
// timestamp = WALLET_BRAIN_DATE_OFFSET = 1543622400; use_password = false
ASSERT_EQ("like", currency::get_word_from_timestamp(1543622400, false));
// timestamp = WALLET_BRAIN_DATE_OFFSET = 1543622400; use_password = true
ASSERT_EQ("among", currency::get_word_from_timestamp(1543622400, true));
// timestamp = WALLET_BRAIN_DATE_OFFSET - 1 = 1543622399; use_password = false
ASSERT_EQ("like", currency::get_word_from_timestamp(1543622399, false));
// timestamp = WALLET_BRAIN_DATE_OFFSET + 1 = 1543622401; use_password = false
ASSERT_EQ("like", currency::get_word_from_timestamp(1543622401, false));
// timestamp = WALLET_BRAIN_DATE_OFFSET + 1 = 1543622401; use_password = true
ASSERT_EQ("among", currency::get_word_from_timestamp(1543622401, true));
/*
Values get_word_from_timestamp(1, true),
get_word_from_timestamp(1543622401, true) must be equal.
*/
ASSERT_EQ("among", currency::get_word_from_timestamp(1, true));
ASSERT_EQ(currency::get_word_from_timestamp(1, true),
currency::get_word_from_timestamp(1543622401, true));
/*
2027462399 is the largest timestamp argument value under which the
inequality weeks_count < WALLET_BRAIN_DATE_MAX_WEEKS_COUNT is satisfied.
timestamp = 2027462399
date_offset = timestamp - WALLET_BRAIN_DATE_OFFSET = 483839999
weeks_count = date_offset / WALLET_BRAIN_DATE_QUANTUM = 799
WALLET_BRAIN_DATE_MAX_WEEKS_COUNT = 800
WALLET_BRAIN_DATE_QUANTUM = 604800
floor(483839999 / 604800) = 799
floor(483840000 / 604800) = 800
*/
// weeks_count_32 = 799; wordsArray[799] = "ugly"
ASSERT_EQ("ugly", currency::get_word_from_timestamp(2027462399, false));
// weeks_count_32 = 799 + 800 = 1599; wordsArray[1599] = "moan"
ASSERT_EQ("moan", currency::get_word_from_timestamp(2027462399, true));
/*
If you pass values >= 2027462399 + 1, then the inequality
weeks_count < WALLET_BRAIN_DATE_MAX_WEEKS_COUNT is not satisfied. The
function throws an exception.
*/
EXPECT_THROW(currency::get_word_from_timestamp(2027462400, false),
std::runtime_error);
EXPECT_THROW(currency::get_word_from_timestamp(2027462400, true),
std::runtime_error);
}
TEST(wallet_seed, timestamp_from_word)
{
{
// WALLET_BRAIN_DATE_OFFSET = 1543622400
{
bool password_used{false};
ASSERT_EQ(1543622400,
currency::get_timestamp_from_word("like", password_used));
ASSERT_FALSE(password_used);
}
{
bool password_used{true};
ASSERT_EQ(1543622400,
currency::get_timestamp_from_word("like", password_used));
ASSERT_FALSE(password_used);
}
}
{
// WALLET_BRAIN_DATE_OFFSET = 1543622400
{
bool password_used{true};
ASSERT_EQ(1543622400,
currency::get_timestamp_from_word("among", password_used));
ASSERT_TRUE(password_used);
}
{
bool password_used{false};
ASSERT_EQ(1543622400,
currency::get_timestamp_from_word("among", password_used));
ASSERT_TRUE(password_used);
}
}
{
// (1625 - 800) * 604800 + 1543622400 = 2042582400
{
bool password_used{false};
ASSERT_EQ(2026857600,
currency::get_timestamp_from_word("ugly", password_used));
ASSERT_FALSE(password_used);
}
{
bool password_used{true};
ASSERT_EQ(2026857600,
currency::get_timestamp_from_word("ugly", password_used));
ASSERT_FALSE(password_used);
}
}
{
// (1625 - 800) * 604800 + 1543622400 = 2042582400
{
bool password_used{false};
ASSERT_EQ(2042582400,
currency::get_timestamp_from_word("weary", password_used));
ASSERT_TRUE(password_used);
}
{
bool password_used{true};
ASSERT_EQ(2042582400,
currency::get_timestamp_from_word("weary", password_used));
ASSERT_TRUE(password_used);
}
}
}