Auto merge of #3213 - str4d:3202-precursor, r=str4d
Upstream encoding cleanups Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#7922 - bitcoin/bitcoin#7825 - bitcoin/bitcoin#8317 - bitcoin/bitcoin#9804 - Only the commit that changed `base58.cpp` Precursor to #3202.
This commit is contained in:
commit
90304c4214
|
@ -104,7 +104,7 @@ std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend)
|
||||||
|
|
||||||
std::string EncodeBase58(const std::vector<unsigned char>& vch)
|
std::string EncodeBase58(const std::vector<unsigned char>& vch)
|
||||||
{
|
{
|
||||||
return EncodeBase58(&vch[0], &vch[0] + vch.size());
|
return EncodeBase58(vch.data(), vch.data() + vch.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
|
bool DecodeBase58(const std::string& str, std::vector<unsigned char>& vchRet)
|
||||||
|
@ -154,7 +154,7 @@ void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const
|
||||||
vchVersion = vchVersionIn;
|
vchVersion = vchVersionIn;
|
||||||
vchData.resize(nSize);
|
vchData.resize(nSize);
|
||||||
if (!vchData.empty())
|
if (!vchData.empty())
|
||||||
memcpy(&vchData[0], pdata, nSize);
|
memcpy(vchData.data(), pdata, nSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const unsigned char* pbegin, const unsigned char* pend)
|
void CBase58Data::SetData(const std::vector<unsigned char>& vchVersionIn, const unsigned char* pbegin, const unsigned char* pend)
|
||||||
|
@ -174,8 +174,8 @@ bool CBase58Data::SetString(const char* psz, unsigned int nVersionBytes)
|
||||||
vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
|
vchVersion.assign(vchTemp.begin(), vchTemp.begin() + nVersionBytes);
|
||||||
vchData.resize(vchTemp.size() - nVersionBytes);
|
vchData.resize(vchTemp.size() - nVersionBytes);
|
||||||
if (!vchData.empty())
|
if (!vchData.empty())
|
||||||
memcpy(&vchData[0], &vchTemp[nVersionBytes], vchData.size());
|
memcpy(vchData.data(), vchTemp.data() + nVersionBytes, vchData.size());
|
||||||
memory_cleanse(&vchTemp[0], vchData.size());
|
memory_cleanse(vchTemp.data(), vchTemp.size());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ CTxDestination CBitcoinAddress::Get() const
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
return CNoDestination();
|
return CNoDestination();
|
||||||
uint160 id;
|
uint160 id;
|
||||||
memcpy(&id, &vchData[0], 20);
|
memcpy(&id, vchData.data(), 20);
|
||||||
if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
|
if (vchVersion == Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
|
||||||
return CKeyID(id);
|
return CKeyID(id);
|
||||||
else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS))
|
else if (vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS))
|
||||||
|
@ -280,7 +280,7 @@ bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const
|
||||||
if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
|
if (!IsValid() || vchVersion != Params().Base58Prefix(CChainParams::PUBKEY_ADDRESS))
|
||||||
return false;
|
return false;
|
||||||
uint160 id;
|
uint160 id;
|
||||||
memcpy(&id, &vchData[0], 20);
|
memcpy(&id, vchData.data(), 20);
|
||||||
keyID = CKeyID(id);
|
keyID = CKeyID(id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,8 +194,8 @@ public:
|
||||||
K GetKey() {
|
K GetKey() {
|
||||||
K ret;
|
K ret;
|
||||||
if (vchData.size() == Size) {
|
if (vchData.size() == Size) {
|
||||||
//if base58 encoded data not holds a ext key, return a !IsValid() key
|
// If base58 encoded data does not hold an ext key, return a !IsValid() key
|
||||||
ret.Decode(&vchData[0]);
|
ret.Decode(vchData.data());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -598,7 +598,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address");
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Zcash address");
|
||||||
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
CScript scriptPubKey = GetScriptForDestination(address.Get());
|
||||||
if (!IsMine(*pwalletMain, scriptPubKey))
|
if (!IsMine(*pwalletMain, scriptPubKey))
|
||||||
return (double)0.0;
|
return ValueFromAmount(0);
|
||||||
|
|
||||||
// Minimum confirmations
|
// Minimum confirmations
|
||||||
int nMinDepth = 1;
|
int nMinDepth = 1;
|
||||||
|
@ -676,7 +676,7 @@ UniValue getreceivedbyaccount(const UniValue& params, bool fHelp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (double)nAmount / (double)COIN;
|
return ValueFromAmount(nAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2344,7 +2344,9 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||||
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
" \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n"
|
||||||
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
" \"scriptPubKey\" : \"key\", (string) the script key\n"
|
||||||
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
|
" \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n"
|
||||||
" \"confirmations\" : n (numeric) The number of confirmations\n"
|
" \"confirmations\" : n, (numeric) The number of confirmations\n"
|
||||||
|
" \"redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n"
|
||||||
|
" \"spendable\" : xxx (bool) Whether we have the private keys to spend this output\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" ,...\n"
|
" ,...\n"
|
||||||
"]\n"
|
"]\n"
|
||||||
|
@ -2388,38 +2390,34 @@ UniValue listunspent(const UniValue& params, bool fHelp)
|
||||||
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
|
if (out.nDepth < nMinDepth || out.nDepth > nMaxDepth)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (setAddress.size()) {
|
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address))
|
const CScript& scriptPubKey = out.tx->vout[out.i].scriptPubKey;
|
||||||
|
bool fValidAddress = ExtractDestination(scriptPubKey, address);
|
||||||
|
|
||||||
|
if (setAddress.size() && (!fValidAddress || !setAddress.count(address)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!setAddress.count(address))
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CAmount nValue = out.tx->vout[out.i].nValue;
|
|
||||||
const CScript& pk = out.tx->vout[out.i].scriptPubKey;
|
|
||||||
UniValue entry(UniValue::VOBJ);
|
UniValue entry(UniValue::VOBJ);
|
||||||
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
entry.push_back(Pair("txid", out.tx->GetHash().GetHex()));
|
||||||
entry.push_back(Pair("vout", out.i));
|
entry.push_back(Pair("vout", out.i));
|
||||||
entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
entry.push_back(Pair("generated", out.tx->IsCoinBase()));
|
||||||
CTxDestination address;
|
|
||||||
if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) {
|
if (fValidAddress) {
|
||||||
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
entry.push_back(Pair("address", CBitcoinAddress(address).ToString()));
|
||||||
|
|
||||||
if (pwalletMain->mapAddressBook.count(address))
|
if (pwalletMain->mapAddressBook.count(address))
|
||||||
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name));
|
||||||
}
|
|
||||||
entry.push_back(Pair("scriptPubKey", HexStr(pk.begin(), pk.end())));
|
if (scriptPubKey.IsPayToScriptHash()) {
|
||||||
if (pk.IsPayToScriptHash()) {
|
|
||||||
CTxDestination address;
|
|
||||||
if (ExtractDestination(pk, address)) {
|
|
||||||
const CScriptID& hash = boost::get<CScriptID>(address);
|
const CScriptID& hash = boost::get<CScriptID>(address);
|
||||||
CScript redeemScript;
|
CScript redeemScript;
|
||||||
if (pwalletMain->GetCScript(hash, redeemScript))
|
if (pwalletMain->GetCScript(hash, redeemScript))
|
||||||
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
|
entry.push_back(Pair("redeemScript", HexStr(redeemScript.begin(), redeemScript.end())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entry.push_back(Pair("amount",ValueFromAmount(nValue)));
|
|
||||||
|
entry.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())));
|
||||||
|
entry.push_back(Pair("amount", ValueFromAmount(out.tx->vout[out.i].nValue)));
|
||||||
entry.push_back(Pair("confirmations", out.nDepth));
|
entry.push_back(Pair("confirmations", out.nDepth));
|
||||||
entry.push_back(Pair("spendable", out.fSpendable));
|
entry.push_back(Pair("spendable", out.fSpendable));
|
||||||
results.push_back(entry);
|
results.push_back(entry);
|
||||||
|
|
Loading…
Reference in New Issue