Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpc/util.cpp
// Copyright (c) 2011-2021 The Bitcoin Core developers | // Copyright (c) 2011-2021 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <wallet/rpc/util.h> | #include <wallet/rpc/util.h> | ||||
#include <rpc/util.h> | #include <rpc/util.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <util/url.h> | #include <util/url.h> | ||||
#include <wallet/context.h> | #include <wallet/context.h> | ||||
#include <wallet/wallet.h> | #include <wallet/wallet.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <boost/date_time/posix_time/posix_time.hpp> | |||||
static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; | ||||
const std::string HELP_REQUIRING_PASSPHRASE{ | const std::string HELP_REQUIRING_PASSPHRASE{ | ||||
"\nRequires wallet passphrase to be set with walletpassphrase call if " | "\nRequires wallet passphrase to be set with walletpassphrase call if " | ||||
"wallet is encrypted.\n"}; | "wallet is encrypted.\n"}; | ||||
int64_t ParseISO8601DateTime(const std::string &str) { | |||||
static const boost::posix_time::ptime epoch = | |||||
boost::posix_time::from_time_t(0); | |||||
static const std::locale loc( | |||||
std::locale::classic(), | |||||
new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%SZ")); | |||||
std::istringstream iss(str); | |||||
iss.imbue(loc); | |||||
boost::posix_time::ptime ptime(boost::date_time::not_a_date_time); | |||||
iss >> ptime; | |||||
if (ptime.is_not_a_date_time() || epoch > ptime) { | |||||
return 0; | |||||
} | |||||
return (ptime - epoch).total_seconds(); | |||||
} | |||||
bool GetAvoidReuseFlag(const CWallet *const pwallet, const UniValue ¶m) { | bool GetAvoidReuseFlag(const CWallet *const pwallet, const UniValue ¶m) { | ||||
bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | bool can_avoid_reuse = pwallet->IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); | ||||
bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | bool avoid_reuse = param.isNull() ? can_avoid_reuse : param.get_bool(); | ||||
if (avoid_reuse && !can_avoid_reuse) { | if (avoid_reuse && !can_avoid_reuse) { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_WALLET_ERROR, | RPC_WALLET_ERROR, | ||||
"wallet does not have the \"avoid reuse\" feature enabled"); | "wallet does not have the \"avoid reuse\" feature enabled"); | ||||
▲ Show 20 Lines • Show All 132 Lines • Show Last 20 Lines |