Change ismine to take a CWallet instead of CKeyStore
This commit is contained in:
parent
7c611e2000
commit
e61de6306f
4 changed files with 51 additions and 30 deletions
|
@ -6,10 +6,9 @@
|
||||||
#include <wallet/ismine.h>
|
#include <wallet/ismine.h>
|
||||||
|
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <keystore.h>
|
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
typedef std::vector<unsigned char> valtype;
|
typedef std::vector<unsigned char> valtype;
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ bool PermitsUncompressed(IsMineSigVersion sigversion)
|
||||||
return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
|
return sigversion == IsMineSigVersion::TOP || sigversion == IsMineSigVersion::P2SH;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
|
bool HaveKeys(const std::vector<valtype>& pubkeys, const CWallet& keystore)
|
||||||
{
|
{
|
||||||
for (const valtype& pubkey : pubkeys) {
|
for (const valtype& pubkey : pubkeys) {
|
||||||
CKeyID keyID = CPubKey(pubkey).GetID();
|
CKeyID keyID = CPubKey(pubkey).GetID();
|
||||||
|
@ -55,7 +54,7 @@ bool HaveKeys(const std::vector<valtype>& pubkeys, const CKeyStore& keystore)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsMineResult IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey, IsMineSigVersion sigversion)
|
IsMineResult IsMineInner(const CWallet& keystore, const CScript& scriptPubKey, IsMineSigVersion sigversion)
|
||||||
{
|
{
|
||||||
IsMineResult ret = IsMineResult::NO;
|
IsMineResult ret = IsMineResult::NO;
|
||||||
|
|
||||||
|
@ -172,7 +171,7 @@ IsMineResult IsMineInner(const CKeyStore& keystore, const CScript& scriptPubKey,
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey)
|
isminetype IsMine(const CWallet& keystore, const CScript& scriptPubKey)
|
||||||
{
|
{
|
||||||
switch (IsMineInner(keystore, scriptPubKey, IsMineSigVersion::TOP)) {
|
switch (IsMineInner(keystore, scriptPubKey, IsMineSigVersion::TOP)) {
|
||||||
case IsMineResult::INVALID:
|
case IsMineResult::INVALID:
|
||||||
|
@ -186,7 +185,7 @@ isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey)
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest)
|
isminetype IsMine(const CWallet& keystore, const CTxDestination& dest)
|
||||||
{
|
{
|
||||||
CScript script = GetScriptForDestination(dest);
|
CScript script = GetScriptForDestination(dest);
|
||||||
return IsMine(keystore, script);
|
return IsMine(keystore, script);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
class CKeyStore;
|
class CWallet;
|
||||||
class CScript;
|
class CScript;
|
||||||
|
|
||||||
/** IsMine() return codes */
|
/** IsMine() return codes */
|
||||||
|
@ -28,8 +28,8 @@ enum isminetype : unsigned int
|
||||||
/** used for bitflags of isminetype */
|
/** used for bitflags of isminetype */
|
||||||
typedef uint8_t isminefilter;
|
typedef uint8_t isminefilter;
|
||||||
|
|
||||||
isminetype IsMine(const CKeyStore& keystore, const CScript& scriptPubKey);
|
isminetype IsMine(const CWallet& wallet, const CScript& scriptPubKey);
|
||||||
isminetype IsMine(const CKeyStore& keystore, const CTxDestination& dest);
|
isminetype IsMine(const CWallet& wallet, const CTxDestination& dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cachable amount subdivided into watchonly and spendable parts.
|
* Cachable amount subdivided into watchonly and spendable parts.
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <key.h>
|
#include <key.h>
|
||||||
#include <keystore.h>
|
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/script_error.h>
|
#include <script/script_error.h>
|
||||||
#include <script/standard.h>
|
#include <script/standard.h>
|
||||||
#include <test/setup_common.h>
|
#include <test/setup_common.h>
|
||||||
#include <wallet/ismine.h>
|
#include <wallet/ismine.h>
|
||||||
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
@ -27,13 +27,15 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
CKey uncompressedKey;
|
CKey uncompressedKey;
|
||||||
uncompressedKey.MakeNewKey(false);
|
uncompressedKey.MakeNewKey(false);
|
||||||
CPubKey uncompressedPubkey = uncompressedKey.GetPubKey();
|
CPubKey uncompressedPubkey = uncompressedKey.GetPubKey();
|
||||||
|
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain();
|
||||||
|
|
||||||
CScript scriptPubKey;
|
CScript scriptPubKey;
|
||||||
isminetype result;
|
isminetype result;
|
||||||
|
|
||||||
// P2PK compressed
|
// P2PK compressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
|
scriptPubKey = GetScriptForRawPubKey(pubkeys[0]);
|
||||||
|
|
||||||
// Keystore does not have key
|
// Keystore does not have key
|
||||||
|
@ -48,7 +50,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PK uncompressed
|
// P2PK uncompressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
|
scriptPubKey = GetScriptForRawPubKey(uncompressedPubkey);
|
||||||
|
|
||||||
// Keystore does not have key
|
// Keystore does not have key
|
||||||
|
@ -63,7 +66,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PKH compressed
|
// P2PKH compressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
scriptPubKey = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
|
|
||||||
// Keystore does not have key
|
// Keystore does not have key
|
||||||
|
@ -78,7 +82,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2PKH uncompressed
|
// P2PKH uncompressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
scriptPubKey = GetScriptForDestination(PKHash(uncompressedPubkey));
|
||||||
|
|
||||||
// Keystore does not have key
|
// Keystore does not have key
|
||||||
|
@ -93,7 +98,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2SH
|
// P2SH
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
|
CScript redeemScript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
scriptPubKey = GetScriptForDestination(ScriptHash(redeemScript));
|
||||||
|
@ -115,7 +121,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2SH inside P2SH (invalid)
|
// (P2PKH inside) P2SH inside P2SH (invalid)
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript redeemscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
CScript redeemscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
CScript redeemscript = GetScriptForDestination(ScriptHash(redeemscript_inner));
|
CScript redeemscript = GetScriptForDestination(ScriptHash(redeemscript_inner));
|
||||||
|
@ -131,7 +138,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2SH inside P2WSH (invalid)
|
// (P2PKH inside) P2SH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript redeemscript = GetScriptForDestination(PKHash(pubkeys[0]));
|
CScript redeemscript = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
CScript witnessscript = GetScriptForDestination(ScriptHash(redeemscript));
|
CScript witnessscript = GetScriptForDestination(ScriptHash(redeemscript));
|
||||||
|
@ -147,7 +155,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH inside P2WSH (invalid)
|
// P2WPKH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
CScript witnessscript = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||||
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
scriptPubKey = GetScriptForDestination(WitnessV0ScriptHash(witnessscript));
|
||||||
|
@ -161,7 +170,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// (P2PKH inside) P2WSH inside P2WSH (invalid)
|
// (P2PKH inside) P2WSH inside P2WSH (invalid)
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript witnessscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
CScript witnessscript_inner = GetScriptForDestination(PKHash(pubkeys[0]));
|
||||||
CScript witnessscript = GetScriptForDestination(WitnessV0ScriptHash(witnessscript_inner));
|
CScript witnessscript = GetScriptForDestination(WitnessV0ScriptHash(witnessscript_inner));
|
||||||
|
@ -177,7 +187,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH compressed
|
// P2WPKH compressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(pubkeys[0])));
|
||||||
|
@ -190,7 +201,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WPKH uncompressed
|
// P2WPKH uncompressed
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
||||||
|
|
||||||
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
|
scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(PKHash(uncompressedPubkey)));
|
||||||
|
@ -207,7 +219,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// scriptPubKey multisig
|
// scriptPubKey multisig
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
scriptPubKey = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
|
scriptPubKey = GetScriptForMultisig(2, {uncompressedPubkey, pubkeys[1]});
|
||||||
|
|
||||||
|
@ -236,7 +249,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2SH multisig
|
// P2SH multisig
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
||||||
BOOST_CHECK(keystore.AddKey(keys[1]));
|
BOOST_CHECK(keystore.AddKey(keys[1]));
|
||||||
|
|
||||||
|
@ -255,7 +269,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig with compressed keys
|
// P2WSH multisig with compressed keys
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
BOOST_CHECK(keystore.AddKey(keys[1]));
|
BOOST_CHECK(keystore.AddKey(keys[1]));
|
||||||
|
|
||||||
|
@ -279,7 +294,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig with uncompressed key
|
// P2WSH multisig with uncompressed key
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
BOOST_CHECK(keystore.AddKey(uncompressedKey));
|
||||||
BOOST_CHECK(keystore.AddKey(keys[1]));
|
BOOST_CHECK(keystore.AddKey(keys[1]));
|
||||||
|
|
||||||
|
@ -303,7 +319,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// P2WSH multisig wrapped in P2SH
|
// P2WSH multisig wrapped in P2SH
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
|
|
||||||
CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
|
CScript witnessScript = GetScriptForMultisig(2, {pubkeys[0], pubkeys[1]});
|
||||||
CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
CScript redeemScript = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
|
||||||
|
@ -328,7 +345,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// OP_RETURN
|
// OP_RETURN
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
|
@ -340,7 +358,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// witness unspendable
|
// witness unspendable
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
|
@ -352,7 +371,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// witness unknown
|
// witness unknown
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
|
@ -364,7 +384,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||||
|
|
||||||
// Nonstandard
|
// Nonstandard
|
||||||
{
|
{
|
||||||
CBasicKeyStore keystore;
|
CWallet keystore(chain.get(), WalletLocation(), WalletDatabase::CreateDummy());
|
||||||
|
LOCK(keystore.cs_wallet);
|
||||||
BOOST_CHECK(keystore.AddKey(keys[0]));
|
BOOST_CHECK(keystore.AddKey(keys[0]));
|
||||||
|
|
||||||
scriptPubKey.clear();
|
scriptPubKey.clear();
|
||||||
|
|
|
@ -30,6 +30,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=(
|
||||||
"policy/fees -> txmempool -> validation -> policy/fees"
|
"policy/fees -> txmempool -> validation -> policy/fees"
|
||||||
"qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/guiutil"
|
"qt/guiutil -> qt/walletmodel -> qt/optionsmodel -> qt/guiutil"
|
||||||
"txmempool -> validation -> validationinterface -> txmempool"
|
"txmempool -> validation -> validationinterface -> txmempool"
|
||||||
|
"wallet/ismine -> wallet/wallet -> wallet/ismine"
|
||||||
)
|
)
|
||||||
|
|
||||||
EXIT_CODE=0
|
EXIT_CODE=0
|
||||||
|
|
Loading…
Add table
Reference in a new issue