mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-12-23 13:47:47 +00:00
allow user I/O in millinero, micronero, nanonero, piconero
This commit is contained in:
parent
beee286c7b
commit
2c468dd429
6 changed files with 124 additions and 11 deletions
|
@ -31,6 +31,7 @@
|
|||
#include "include_base_utils.h"
|
||||
using namespace epee;
|
||||
|
||||
#include <atomic>
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "cryptonote_config.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
@ -65,6 +66,8 @@ static const uint64_t valid_decomposed_outputs[] = {
|
|||
(uint64_t)10000000000000000000ull
|
||||
};
|
||||
|
||||
static std::atomic<unsigned int> default_decimal_point(CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
//---------------------------------------------------------------
|
||||
|
@ -142,12 +145,12 @@ namespace cryptonote
|
|||
if (std::string::npos != point_index)
|
||||
{
|
||||
fraction_size = str_amount.size() - point_index - 1;
|
||||
while (CRYPTONOTE_DISPLAY_DECIMAL_POINT < fraction_size && '0' == str_amount.back())
|
||||
while (default_decimal_point < fraction_size && '0' == str_amount.back())
|
||||
{
|
||||
str_amount.erase(str_amount.size() - 1, 1);
|
||||
--fraction_size;
|
||||
}
|
||||
if (CRYPTONOTE_DISPLAY_DECIMAL_POINT < fraction_size)
|
||||
if (default_decimal_point < fraction_size)
|
||||
return false;
|
||||
str_amount.erase(point_index, 1);
|
||||
}
|
||||
|
@ -159,9 +162,9 @@ namespace cryptonote
|
|||
if (str_amount.empty())
|
||||
return false;
|
||||
|
||||
if (fraction_size < CRYPTONOTE_DISPLAY_DECIMAL_POINT)
|
||||
if (fraction_size < default_decimal_point)
|
||||
{
|
||||
str_amount.append(CRYPTONOTE_DISPLAY_DECIMAL_POINT - fraction_size, '0');
|
||||
str_amount.append(default_decimal_point - fraction_size, '0');
|
||||
}
|
||||
|
||||
return string_tools::get_xtype_from_string(amount, str_amount);
|
||||
|
@ -504,14 +507,59 @@ namespace cryptonote
|
|||
cn_fast_hash(blob.data(), blob.size(), res);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
std::string print_money(uint64_t amount)
|
||||
void set_default_decimal_point(unsigned int decimal_point)
|
||||
{
|
||||
std::string s = std::to_string(amount);
|
||||
if(s.size() < CRYPTONOTE_DISPLAY_DECIMAL_POINT+1)
|
||||
switch (decimal_point)
|
||||
{
|
||||
s.insert(0, CRYPTONOTE_DISPLAY_DECIMAL_POINT+1 - s.size(), '0');
|
||||
case 12:
|
||||
case 9:
|
||||
case 6:
|
||||
case 3:
|
||||
case 0:
|
||||
default_decimal_point = decimal_point;
|
||||
break;
|
||||
default:
|
||||
ASSERT_MES_AND_THROW("Invalid decimal point specificatin: " << decimal_point);
|
||||
}
|
||||
s.insert(s.size() - CRYPTONOTE_DISPLAY_DECIMAL_POINT, ".");
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
unsigned int get_default_decimal_point()
|
||||
{
|
||||
return default_decimal_point;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
std::string get_unit(unsigned int decimal_point)
|
||||
{
|
||||
if (decimal_point == (unsigned int)-1)
|
||||
decimal_point = default_decimal_point;
|
||||
switch (std::atomic_load(&default_decimal_point))
|
||||
{
|
||||
case 12:
|
||||
return "monero";
|
||||
case 9:
|
||||
return "millinero";
|
||||
case 6:
|
||||
return "micronero";
|
||||
case 3:
|
||||
return "nanonero";
|
||||
case 0:
|
||||
return "piconero";
|
||||
default:
|
||||
ASSERT_MES_AND_THROW("Invalid decimal point specificatin: " << default_decimal_point);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
std::string print_money(uint64_t amount, unsigned int decimal_point)
|
||||
{
|
||||
if (decimal_point == (unsigned int)-1)
|
||||
decimal_point = default_decimal_point;
|
||||
std::string s = std::to_string(amount);
|
||||
if(s.size() < decimal_point+1)
|
||||
{
|
||||
s.insert(0, decimal_point+1 - s.size(), '0');
|
||||
}
|
||||
if (decimal_point > 0)
|
||||
s.insert(s.size() - decimal_point, ".");
|
||||
return s;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
|
|
@ -102,7 +102,10 @@ namespace cryptonote
|
|||
uint64_t get_block_height(const block& b);
|
||||
std::vector<uint64_t> relative_output_offsets_to_absolute(const std::vector<uint64_t>& off);
|
||||
std::vector<uint64_t> absolute_output_offsets_to_relative(const std::vector<uint64_t>& off);
|
||||
std::string print_money(uint64_t amount);
|
||||
void set_default_decimal_point(unsigned int decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||
unsigned int get_default_decimal_point();
|
||||
std::string get_unit(unsigned int decimal_point = -1);
|
||||
std::string print_money(uint64_t amount, unsigned int decimal_point = -1);
|
||||
//---------------------------------------------------------------
|
||||
template<class t_object>
|
||||
bool t_serializable_object_to_blob(const t_object& to, blobdata& b_blob)
|
||||
|
|
|
@ -590,6 +590,36 @@ bool simple_wallet::set_ask_password(const std::vector<std::string> &args/* = st
|
|||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::set_unit(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
const std::string &unit = args[1];
|
||||
unsigned int decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT;
|
||||
|
||||
if (unit == "monero")
|
||||
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT;
|
||||
else if (unit == "millinero")
|
||||
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 3;
|
||||
else if (unit == "micronero")
|
||||
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 6;
|
||||
else if (unit == "nanonero")
|
||||
decimal_point = CRYPTONOTE_DISPLAY_DECIMAL_POINT - 9;
|
||||
else if (unit == "piconero")
|
||||
decimal_point = 0;
|
||||
else
|
||||
{
|
||||
fail_msg_writer() << tr("invalid unit");
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto pwd_container = get_and_verify_password();
|
||||
if (pwd_container)
|
||||
{
|
||||
m_wallet->set_default_decimal_point(decimal_point);
|
||||
m_wallet->rewrite(m_wallet_file, pwd_container->password());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
|
||||
{
|
||||
success_msg_writer() << get_commands_str();
|
||||
|
@ -629,7 +659,7 @@ simple_wallet::simple_wallet()
|
|||
m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), tr("Display private view key"));
|
||||
m_cmd_binder.set_handler("spendkey", boost::bind(&simple_wallet::spendkey, this, _1), tr("Display private spend key"));
|
||||
m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), tr("Display Electrum-style mnemonic seed"));
|
||||
m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; print-ring-members <1|0> - whether to print detailed information about ring members during confirmation; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-mixin <n> - set default mixin (default is 4); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [1|2|3] - normal/elevated/priority fee; confirm-missing-payment-id <1|0>; ask-password <1|0>"));
|
||||
m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), tr("Available options: seed language - set wallet seed language; always-confirm-transfers <1|0> - whether to confirm unsplit txes; print-ring-members <1|0> - whether to print detailed information about ring members during confirmation; store-tx-info <1|0> - whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference; default-mixin <n> - set default mixin (default is 4); auto-refresh <1|0> - whether to automatically sync new blocks from the daemon; refresh-type <full|optimize-coinbase|no-coinbase|default> - set wallet refresh behaviour; priority [1|2|3] - normal/elevated/priority fee; confirm-missing-payment-id <1|0>; ask-password <1|0>; unit <monero|millinero|micronero|nanonero|piconero> - set default monero (sub-)unit"));
|
||||
m_cmd_binder.set_handler("rescan_spent", boost::bind(&simple_wallet::rescan_spent, this, _1), tr("Rescan blockchain for spent outputs"));
|
||||
m_cmd_binder.set_handler("get_tx_key", boost::bind(&simple_wallet::get_tx_key, this, _1), tr("Get transaction key (r) for a given <txid>"));
|
||||
m_cmd_binder.set_handler("check_tx_key", boost::bind(&simple_wallet::check_tx_key, this, _1), tr("Check amount going to <address> in <txid>"));
|
||||
|
@ -663,6 +693,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
success_msg_writer() << "priority = " << m_wallet->get_default_priority();
|
||||
success_msg_writer() << "confirm-missing-payment-id = " << m_wallet->confirm_missing_payment_id();
|
||||
success_msg_writer() << "ask-password = " << m_wallet->ask_password();
|
||||
success_msg_writer() << "unit = " << cryptonote::get_unit(m_wallet->get_default_decimal_point());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -798,6 +829,19 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else if (args[0] == "unit")
|
||||
{
|
||||
if (args.size() <= 1)
|
||||
{
|
||||
fail_msg_writer() << tr("set unit: needs an argument (monero, millinero, micronero, nanop, piconero)");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
set_unit(args);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
fail_msg_writer() << tr("set: unrecognized argument(s)");
|
||||
return true;
|
||||
|
|
|
@ -116,6 +116,7 @@ namespace cryptonote
|
|||
bool set_refresh_type(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_confirm_missing_payment_id(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_ask_password(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool set_unit(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool help(const std::vector<std::string> &args = std::vector<std::string>());
|
||||
bool start_mining(const std::vector<std::string> &args);
|
||||
bool stop_mining(const std::vector<std::string> &args);
|
||||
|
|
|
@ -1880,6 +1880,9 @@ bool wallet2::store_keys(const std::string& keys_file_name, const std::string& p
|
|||
value2.SetInt(m_ask_password ? 1 :0);
|
||||
json.AddMember("ask_password", value2, json.GetAllocator());
|
||||
|
||||
value2.SetInt(cryptonote::get_default_decimal_point());
|
||||
json.AddMember("default_decimal_point", value2, json.GetAllocator());
|
||||
|
||||
// Serialize the JSON object
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
|
@ -2010,6 +2013,8 @@ bool wallet2::load_keys(const std::string& keys_file_name, const std::string& pa
|
|||
m_confirm_missing_payment_id = field_confirm_missing_payment_id;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, ask_password, int, Int, false, true);
|
||||
m_ask_password = field_ask_password;
|
||||
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, default_decimal_point, int, Int, false, CRYPTONOTE_DISPLAY_DECIMAL_POINT);
|
||||
cryptonote::set_default_decimal_point(field_default_decimal_point);
|
||||
}
|
||||
|
||||
const cryptonote::account_keys& keys = m_account.get_keys();
|
||||
|
@ -2274,6 +2279,16 @@ bool wallet2::parse_payment_id(const std::string& payment_id_str, crypto::hash&
|
|||
return false;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
void wallet2::set_default_decimal_point(unsigned int decimal_point)
|
||||
{
|
||||
cryptonote::set_default_decimal_point(decimal_point);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
unsigned int wallet2::get_default_decimal_point() const
|
||||
{
|
||||
return cryptonote::get_default_decimal_point();
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
bool wallet2::prepare_file_names(const std::string& file_path)
|
||||
{
|
||||
do_prepare_file_names(file_path, m_keys_file, m_wallet_file);
|
||||
|
|
|
@ -510,6 +510,8 @@ namespace tools
|
|||
void confirm_missing_payment_id(bool always) { m_confirm_missing_payment_id = always; }
|
||||
bool ask_password() const { return m_ask_password; }
|
||||
void ask_password(bool always) { m_ask_password = always; }
|
||||
void set_default_decimal_point(unsigned int decimal_point);
|
||||
unsigned int get_default_decimal_point() const;
|
||||
|
||||
bool get_tx_key(const crypto::hash &txid, crypto::secret_key &tx_key) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue