|
|
|
@ -9,42 +9,6 @@
|
|
|
|
|
namespace xmreg
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse key string, e.g., a viewkey in a string
|
|
|
|
|
* into crypto::secret_key or crypto::public_key
|
|
|
|
|
* depending on the template argument.
|
|
|
|
|
*/
|
|
|
|
|
template <typename T>
|
|
|
|
|
bool
|
|
|
|
|
parse_str_secret_key(const string& key_str, T& secret_key)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// hash and keys have same structure, so to parse string of
|
|
|
|
|
// a key, e.g., a view key, we can first parse it into the hash
|
|
|
|
|
// object using parse_hash256 function, and then copy the reslting
|
|
|
|
|
// hash data into secret key.
|
|
|
|
|
crypto::hash hash_;
|
|
|
|
|
|
|
|
|
|
if(!parse_hash256(key_str, hash_))
|
|
|
|
|
{
|
|
|
|
|
cerr << "Cant parse a key (e.g. viewkey): " << key_str << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// crypto::hash and crypto::secret_key have basicly same
|
|
|
|
|
// structure. They both keep they key/hash as c-style char array
|
|
|
|
|
// of fixed size. Thus we can just copy data from hash
|
|
|
|
|
// to key
|
|
|
|
|
copy(begin(hash_.data), end(hash_.data), secret_key.data);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// explicit instantiations of get template function
|
|
|
|
|
template bool parse_str_secret_key<crypto::secret_key>(const string& key_str, crypto::secret_key& secret_key);
|
|
|
|
|
template bool parse_str_secret_key<crypto::public_key>(const string& key_str, crypto::public_key& secret_key);
|
|
|
|
|
template bool parse_str_secret_key<crypto::hash>(const string& key_str, crypto::hash& secret_key);
|
|
|
|
|
template bool parse_str_secret_key<crypto::hash8>(const string& key_str, crypto::hash8& secret_key);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get transaction tx using given tx hash. Hash is represent as string here,
|
|
|
|
@ -76,20 +40,6 @@ get_tx_pub_key_from_str_hash(Blockchain& core_storage, const string& hash_str, t
|
|
|
|
|
* cryptonote::account_public_address object
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
parse_str_address(const string& address_str,
|
|
|
|
|
address_parse_info& address_info,
|
|
|
|
|
network_type net_type)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!get_account_address_from_str(address_info, net_type, address_str))
|
|
|
|
|
{
|
|
|
|
|
//cerr << "Error getting address: " << address_str << '\n';
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
@ -116,27 +66,6 @@ is_separator(char c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Remove trailinig path separator.
|
|
|
|
|
*/
|
|
|
|
|
string
|
|
|
|
|
remove_trailing_path_separator(const string& in_path)
|
|
|
|
|
{
|
|
|
|
|
string new_string = in_path;
|
|
|
|
|
if (!new_string.empty() && is_separator(new_string[new_string.size() - 1]))
|
|
|
|
|
new_string.erase(new_string.size() - 1);
|
|
|
|
|
return new_string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bf::path
|
|
|
|
|
remove_trailing_path_separator(const bf::path& in_path)
|
|
|
|
|
{
|
|
|
|
|
string path_str = in_path.native();
|
|
|
|
|
return bf::path(remove_trailing_path_separator(path_str));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
|
timestamp_to_str_gm(time_t timestamp, const char* format)
|
|
|
|
|
{
|
|
|
|
@ -236,70 +165,6 @@ generate_key_image(const crypto::key_derivation& derivation,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
|
get_default_lmdb_folder(network_type nettype)
|
|
|
|
|
{
|
|
|
|
|
// default path to monero folder
|
|
|
|
|
// on linux this is /home/<username>/.bitmonero
|
|
|
|
|
string default_monero_dir = tools::get_default_data_dir();
|
|
|
|
|
|
|
|
|
|
if (nettype == cryptonote::network_type::TESTNET)
|
|
|
|
|
default_monero_dir += "/testnet";
|
|
|
|
|
if (nettype == cryptonote::network_type::STAGENET)
|
|
|
|
|
default_monero_dir += "/stagenet";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// the default folder of the lmdb blockchain database
|
|
|
|
|
// is therefore as follows
|
|
|
|
|
return default_monero_dir + string("/lmdb");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ge blockchain exception from command line option
|
|
|
|
|
*
|
|
|
|
|
* If not given, provide default path
|
|
|
|
|
*/
|
|
|
|
|
bool
|
|
|
|
|
get_blockchain_path(bf::path& blockchain_path,
|
|
|
|
|
cryptonote::network_type nettype)
|
|
|
|
|
{
|
|
|
|
|
// the default folder of the lmdb blockchain database
|
|
|
|
|
string default_lmdb_dir = xmreg::get_default_lmdb_folder(nettype);
|
|
|
|
|
|
|
|
|
|
blockchain_path = !blockchain_path.empty()
|
|
|
|
|
? blockchain_path
|
|
|
|
|
: bf::path(default_lmdb_dir);
|
|
|
|
|
|
|
|
|
|
if (!bf::is_directory(blockchain_path))
|
|
|
|
|
{
|
|
|
|
|
cerr << "Given path \"" << blockchain_path << "\" "
|
|
|
|
|
<< "is not a folder or does not exist \n";
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
blockchain_path = xmreg::remove_trailing_path_separator(blockchain_path);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
get_blockchain_path(string& blockchain_path,
|
|
|
|
|
cryptonote::network_type nettype)
|
|
|
|
|
{
|
|
|
|
|
bf::path p {blockchain_path};
|
|
|
|
|
|
|
|
|
|
if (!get_blockchain_path(p, nettype))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
blockchain_path = p.string();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array<uint64_t, 4>
|
|
|
|
|
summary_of_in_out_rct(
|
|
|
|
|
const transaction& tx,
|
|
|
|
@ -1309,22 +1174,6 @@ make_hash(const string& in_str)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
hex_to_tx(string const& tx_hex, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
|
|
|
|
|
{
|
|
|
|
|
std::string tx_blob;
|
|
|
|
|
|
|
|
|
|
epee::string_tools::parse_hexstr_to_binbuff(tx_hex, tx_blob);
|
|
|
|
|
|
|
|
|
|
return parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string
|
|
|
|
|
tx_to_hex(transaction const& tx)
|
|
|
|
|
{
|
|
|
|
|
return epee::string_tools::buff_to_hex_nodelimer(t_serializable_object_to_blob(tx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
hex_to_tx_blob(string const& tx_hex, string& tx_blob)
|
|
|
|
|
{
|
|
|
|
@ -1405,22 +1254,6 @@ blocks_and_txs_from_complete_blocks(
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
addr_and_viewkey_from_string(string const& addres_str,
|
|
|
|
|
string const& viewkey_str,
|
|
|
|
|
network_type net_type,
|
|
|
|
|
address_parse_info& address,
|
|
|
|
|
crypto::secret_key& viewkey)
|
|
|
|
|
{
|
|
|
|
|
if (!xmreg::parse_str_address(addres_str, address, net_type))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!xmreg::parse_str_secret_key(viewkey_str, viewkey))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
output_data_from_hex(
|
|
|
|
|
string const& out_data_hex,
|
|
|
|
|