mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
Make CScript -> CScriptID conversion explicit
This commit is contained in:
parent
07825088f9
commit
952d8213a6
2 changed files with 10 additions and 8 deletions
|
@ -23,7 +23,7 @@ class CScriptID : public uint160
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CScriptID() : uint160() {}
|
CScriptID() : uint160() {}
|
||||||
CScriptID(const CScript& in);
|
explicit CScriptID(const CScript& in);
|
||||||
CScriptID(const uint160& in) : uint160(in) {}
|
CScriptID(const uint160& in) : uint160(in) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -224,10 +224,11 @@ void ImportScript(CWallet* const pwallet, const CScript& script, const std::stri
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRedeemScript) {
|
if (isRedeemScript) {
|
||||||
if (!pwallet->HaveCScript(script) && !pwallet->AddCScript(script)) {
|
const CScriptID id(script);
|
||||||
|
if (!pwallet->HaveCScript(id) && !pwallet->AddCScript(script)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
|
||||||
}
|
}
|
||||||
ImportAddress(pwallet, CScriptID(script), strLabel);
|
ImportAddress(pwallet, id, strLabel);
|
||||||
} else {
|
} else {
|
||||||
CTxDestination destination;
|
CTxDestination destination;
|
||||||
if (ExtractDestination(script, destination)) {
|
if (ExtractDestination(script, destination)) {
|
||||||
|
@ -602,7 +603,8 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
} else if(IsHex(vstr[0])) {
|
} else if(IsHex(vstr[0])) {
|
||||||
std::vector<unsigned char> vData(ParseHex(vstr[0]));
|
std::vector<unsigned char> vData(ParseHex(vstr[0]));
|
||||||
CScript script = CScript(vData.begin(), vData.end());
|
CScript script = CScript(vData.begin(), vData.end());
|
||||||
if (pwallet->HaveCScript(script)) {
|
CScriptID id(script);
|
||||||
|
if (pwallet->HaveCScript(id)) {
|
||||||
LogPrintf("Skipping import of %s (script already present)\n", vstr[0]);
|
LogPrintf("Skipping import of %s (script already present)\n", vstr[0]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -613,7 +615,7 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
int64_t birth_time = DecodeDumpTime(vstr[1]);
|
int64_t birth_time = DecodeDumpTime(vstr[1]);
|
||||||
if (birth_time > 0) {
|
if (birth_time > 0) {
|
||||||
pwallet->m_script_metadata[CScriptID(script)].nCreateTime = birth_time;
|
pwallet->m_script_metadata[id].nCreateTime = birth_time;
|
||||||
nTimeBegin = std::min(nTimeBegin, birth_time);
|
nTimeBegin = std::min(nTimeBegin, birth_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -899,12 +901,12 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding address to wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pwallet->HaveCScript(redeemScript) && !pwallet->AddCScript(redeemScript)) {
|
CScriptID redeem_id(redeemScript);
|
||||||
|
if (!pwallet->HaveCScript(redeem_id) && !pwallet->AddCScript(redeemScript)) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Error adding p2sh redeemScript to wallet");
|
||||||
}
|
}
|
||||||
|
|
||||||
CTxDestination redeem_dest = CScriptID(redeemScript);
|
CScript redeemDestination = GetScriptForDestination(redeem_id);
|
||||||
CScript redeemDestination = GetScriptForDestination(redeem_dest);
|
|
||||||
|
|
||||||
if (::IsMine(*pwallet, redeemDestination) == ISMINE_SPENDABLE) {
|
if (::IsMine(*pwallet, redeemDestination) == ISMINE_SPENDABLE) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
|
throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
|
||||||
|
|
Loading…
Add table
Reference in a new issue