1 // Copyright (c) 2019 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <test/util/wallet.h>
6 
7 #include <key_io.h>
8 #include <outputtype.h>
9 #include <script/standard.h>
10 #ifdef ENABLE_WALLET
11 #include <wallet/wallet.h>
12 #endif
13 
14 const std::string ADDRESS_BCRT1_UNSPENDABLE = "bcrt1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq3xueyj";
15 
16 #ifdef ENABLE_WALLET
getnewaddress(CWallet & w)17 std::string getnewaddress(CWallet& w)
18 {
19     constexpr auto output_type = OutputType::BECH32;
20     CTxDestination dest;
21     std::string error;
22     if (!w.GetNewDestination(output_type, "", dest, error)) assert(false);
23 
24     return EncodeDestination(dest);
25 }
26 
importaddress(CWallet & wallet,const std::string & address)27 void importaddress(CWallet& wallet, const std::string& address)
28 {
29     auto spk_man = wallet.GetLegacyScriptPubKeyMan();
30     LOCK2(wallet.cs_wallet, spk_man->cs_KeyStore);
31     const auto dest = DecodeDestination(address);
32     assert(IsValidDestination(dest));
33     const auto script = GetScriptForDestination(dest);
34     wallet.MarkDirty();
35     assert(!spk_man->HaveWatchOnly(script));
36     if (!spk_man->AddWatchOnly(script, 0 /* nCreateTime */)) assert(false);
37     wallet.SetAddressBook(dest, /* label */ "", "receive");
38 }
39 #endif // ENABLE_WALLET
40