aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-03-07 00:04:56 +0100
committerWladimir J. van der Laan <laanwj@gmail.com>2018-03-07 00:09:48 +0100
commitb225010a808d475cbb53aeed484295f8dc8751c4 (patch)
tree5ec8bb2bca595b84f4386d7da8abcccacaa7f898 /src/wallet
parent29088b14ee4b3b3ef772af9ba3294fadd33a4d21 (diff)
parent92f1f8b3197c2ba3cf65556070509838098975a4 (diff)
downloadbitcoin-b225010a808d475cbb53aeed484295f8dc8751c4.tar.xz
Merge #11372: Address encoding cleanup
92f1f8b31 Split off key_io_tests from base58_tests (Pieter Wuille) 119b0f85e Split key_io (address/key encodings) off from base58 (Pieter Wuille) ebfe217b1 Stop using CBase58Data for ext keys (Pieter Wuille) 32e69fa0d Replace CBitcoinSecret with {Encode,Decode}Secret (Pieter Wuille) Pull request description: This PR contains some of the changes left as TODO in #11167 (and built on top of that PR). They are not intended for backporting. This removes the `CBase58`, `CBitcoinSecret`, `CBitcoinExtKey`, and `CBitcoinExtPubKey` classes, in favor of simple `Encode`/`Decode` functions. Furthermore, all Bitcoin-specific logic (addresses, WIF, BIP32) is moved to `key_io.{h,cpp}`, leaving `base58.{h,cpp}` as a pure utility that implements the base58 encoding/decoding logic. Tree-SHA512: a5962c0ed27ad53cbe00f22af432cf11aa530e3efc9798e25c004bc9ed1b5673db5df3956e398ee2c085e3a136ac8da69fe7a7d97a05fb2eb3be0b60d0479655
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/rpcdump.cpp46
-rw-r--r--src/wallet/rpcwallet.cpp2
-rw-r--r--src/wallet/wallet.cpp2
-rw-r--r--src/wallet/walletdb.cpp2
4 files changed, 15 insertions, 37 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 930e8bbbb4..0edc8d8d66 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <base58.h>
#include <chain.h>
+#include <key_io.h>
#include <rpc/safemode.h>
#include <rpc/server.h>
#include <wallet/init.h>
@@ -147,13 +147,8 @@ UniValue importprivkey(const JSONRPCRequest& request)
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet is currently rescanning. Abort existing rescan or wait.");
}
- CBitcoinSecret vchSecret;
- bool fGood = vchSecret.SetString(strSecret);
-
- if (!fGood) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
-
- CKey key = vchSecret.GetKey();
- if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
+ CKey key = DecodeSecret(strSecret);
+ if (!key.IsValid()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
@@ -554,9 +549,8 @@ UniValue importwallet(const JSONRPCRequest& request)
boost::split(vstr, line, boost::is_any_of(" "));
if (vstr.size() < 2)
continue;
- CBitcoinSecret vchSecret;
- if (vchSecret.SetString(vstr[0])) {
- CKey key = vchSecret.GetKey();
+ CKey key = DecodeSecret(vstr[0]);
+ if (key.IsValid()) {
CPubKey pubkey = key.GetPubKey();
assert(key.VerifyPubKey(pubkey));
CKeyID keyid = pubkey.GetID();
@@ -659,7 +653,7 @@ UniValue dumpprivkey(const JSONRPCRequest& request)
if (!pwallet->GetKey(keyid, vchSecret)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Private key for address " + strAddress + " is not known");
}
- return CBitcoinSecret(vchSecret).ToString();
+ return EncodeSecret(vchSecret);
}
@@ -742,10 +736,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
CExtKey masterKey;
masterKey.SetMaster(key.begin(), key.size());
- CBitcoinExtKey b58extkey;
- b58extkey.SetKey(masterKey);
-
- file << "# extended private masterkey: " << b58extkey.ToString() << "\n\n";
+ file << "# extended private masterkey: " << EncodeExtKey(masterKey) << "\n\n";
}
}
for (std::vector<std::pair<int64_t, CKeyID> >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) {
@@ -755,7 +746,7 @@ UniValue dumpwallet(const JSONRPCRequest& request)
std::string strLabel;
CKey key;
if (pwallet->GetKey(keyid, key)) {
- file << strprintf("%s %s ", CBitcoinSecret(key).ToString(), strTime);
+ file << strprintf("%s %s ", EncodeSecret(key), strTime);
if (GetWalletAddressesForKey(pwallet, keyid, strAddr, strLabel)) {
file << strprintf("label=%s", strLabel);
} else if (keyid == masterKeyID) {
@@ -911,17 +902,10 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
for (size_t i = 0; i < keys.size(); i++) {
const std::string& privkey = keys[i].get_str();
- CBitcoinSecret vchSecret;
- bool fGood = vchSecret.SetString(privkey);
-
- if (!fGood) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
- }
-
- CKey key = vchSecret.GetKey();
+ CKey key = DecodeSecret(privkey);
if (!key.IsValid()) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
}
CPubKey pubkey = key.GetPubKey();
@@ -1018,16 +1002,10 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
const std::string& strPrivkey = keys[0].get_str();
// Checks.
- CBitcoinSecret vchSecret;
- bool fGood = vchSecret.SetString(strPrivkey);
-
- if (!fGood) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
- }
+ CKey key = DecodeSecret(strPrivkey);
- CKey key = vchSecret.GetKey();
if (!key.IsValid()) {
- throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Private key outside allowed range");
+ throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key encoding");
}
CPubKey pubKey = key.GetPubKey();
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp
index 8b95c56a5f..52b68e97ee 100644
--- a/src/wallet/rpcwallet.cpp
+++ b/src/wallet/rpcwallet.cpp
@@ -4,12 +4,12 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <amount.h>
-#include <base58.h>
#include <chain.h>
#include <consensus/validation.h>
#include <core_io.h>
#include <httpserver.h>
#include <validation.h>
+#include <key_io.h>
#include <net.h>
#include <policy/feerate.h>
#include <policy/fees.h>
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index bb7be2df33..a014f5b2a0 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -5,7 +5,6 @@
#include <wallet/wallet.h>
-#include <base58.h>
#include <checkpoints.h>
#include <chain.h>
#include <wallet/coincontrol.h>
@@ -14,6 +13,7 @@
#include <fs.h>
#include <wallet/init.h>
#include <key.h>
+#include <key_io.h>
#include <keystore.h>
#include <validation.h>
#include <net.h>
diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp
index dd6835a06f..c14fbd1e8c 100644
--- a/src/wallet/walletdb.cpp
+++ b/src/wallet/walletdb.cpp
@@ -5,10 +5,10 @@
#include <wallet/walletdb.h>
-#include <base58.h>
#include <consensus/tx_verify.h>
#include <consensus/validation.h>
#include <fs.h>
+#include <key_io.h>
#include <protocol.h>
#include <serialize.h>
#include <sync.h>