mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 15:19:07 +01:00
Use script matching rather than destination matching for watch-only.
This changes the keystore data format, wallet format and IsMine logic to detect watch-only outputs based on direct script matching rather than first trying to convert outputs to destinations (addresses). The reason is that we don't know how the software that has the spending keys works. It may support the same types of scripts as us, but that is not guaranteed. Furthermore, it removes the ambiguity between addresses used as identifiers for output scripts or identifiers for public keys. One practical implication is that adding a normal pay-to-pubkey-hash address via importaddress will not cause payments to the corresponding full public key to be detected as IsMine. If that is wanted, add those scripts directly (importaddress now also accepts any hex-encoded script). Conflicts: src/wallet.cpp
This commit is contained in:
@@ -1456,13 +1456,11 @@ public:
|
||||
bool operator()(const CScriptID &scriptID) const { return keystore->HaveCScript(scriptID); }
|
||||
};
|
||||
|
||||
isminetype IsMine(const CKeyStore &keystore, const CTxDestination &dest)
|
||||
isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest)
|
||||
{
|
||||
if (boost::apply_visitor(CKeyStoreIsMineVisitor(&keystore), dest))
|
||||
return MINE_SPENDABLE;
|
||||
if (keystore.HaveWatchOnly(dest))
|
||||
return MINE_WATCH_ONLY;
|
||||
return MINE_NO;
|
||||
CScript script;
|
||||
script.SetDestination(dest);
|
||||
return IsMine(keystore, script);
|
||||
}
|
||||
|
||||
isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
@@ -1470,7 +1468,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
vector<valtype> vSolutions;
|
||||
txnouttype whichType;
|
||||
if (!Solver(scriptPubKey, whichType, vSolutions)) {
|
||||
if (keystore.HaveWatchOnly(scriptPubKey.GetID()))
|
||||
if (keystore.HaveWatchOnly(scriptPubKey))
|
||||
return MINE_WATCH_ONLY;
|
||||
return MINE_NO;
|
||||
}
|
||||
@@ -1485,15 +1483,11 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
keyID = CPubKey(vSolutions[0]).GetID();
|
||||
if (keystore.HaveKey(keyID))
|
||||
return MINE_SPENDABLE;
|
||||
if (keystore.HaveWatchOnly(keyID))
|
||||
return MINE_WATCH_ONLY;
|
||||
break;
|
||||
case TX_PUBKEYHASH:
|
||||
keyID = CKeyID(uint160(vSolutions[0]));
|
||||
if (keystore.HaveKey(keyID))
|
||||
return MINE_SPENDABLE;
|
||||
if (keystore.HaveWatchOnly(keyID))
|
||||
return MINE_WATCH_ONLY;
|
||||
break;
|
||||
case TX_SCRIPTHASH:
|
||||
{
|
||||
@@ -1501,11 +1495,9 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
CScript subscript;
|
||||
if (keystore.GetCScript(scriptID, subscript)) {
|
||||
isminetype ret = IsMine(keystore, subscript);
|
||||
if (ret)
|
||||
if (ret == MINE_SPENDABLE)
|
||||
return ret;
|
||||
}
|
||||
if (keystore.HaveWatchOnly(scriptID))
|
||||
return MINE_WATCH_ONLY;
|
||||
break;
|
||||
}
|
||||
case TX_MULTISIG:
|
||||
@@ -1522,7 +1514,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey)
|
||||
}
|
||||
}
|
||||
|
||||
if (keystore.HaveWatchOnly(scriptPubKey.GetID()))
|
||||
if (keystore.HaveWatchOnly(scriptPubKey))
|
||||
return MINE_WATCH_ONLY;
|
||||
return MINE_NO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user