From 06b642dfe4b27216615310440ecd8d37db5652a0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 16 Oct 2016 16:52:45 +0100 Subject: wallet_api: add address validation functions The payment id from integrated addresses is also parsed --- src/wallet/api/wallet.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/wallet/api/wallet.cpp') diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index d1c849537..50a399e9e 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -162,6 +162,26 @@ bool Wallet::paymentIdValid(const string &paiment_id) return tools::wallet2::parse_short_payment_id(paiment_id, pid); } +bool Wallet::addressValid(const std::string &str, bool testnet) +{ + bool has_payment_id; + cryptonote::account_public_address address; + crypto::hash8 pid; + return get_account_integrated_address_from_str(address, has_payment_id, pid, testnet, str); +} + +std::string Wallet::paymentIdFromAddress(const std::string &str, bool testnet) +{ + bool has_payment_id; + cryptonote::account_public_address address; + crypto::hash8 pid; + if (!get_account_integrated_address_from_str(address, has_payment_id, pid, testnet, str)) + return ""; + if (!has_payment_id) + return ""; + return epee::string_tools::pod_to_hex(pid); +} + uint64_t Wallet::maximumAllowedAmount() { return std::numeric_limits::max(); -- cgit v1.2.3