mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
Introduce wrappers around CBitcoinAddress
This patch removes the need for the intermediary Base58 type
CBitcoinAddress, by providing {Encode,Decode,IsValid}Destination
function that directly operate on the conversion between strings
and CTxDestination.
This commit is contained in:
@@ -271,11 +271,11 @@ static void MutateTxAddOutAddr(CMutableTransaction& tx, const std::string& strIn
|
||||
|
||||
// extract and validate ADDRESS
|
||||
std::string strAddr = vStrInputParts[1];
|
||||
CBitcoinAddress addr(strAddr);
|
||||
if (!addr.IsValid())
|
||||
CTxDestination destination = DecodeDestination(strAddr);
|
||||
if (!IsValidDestination(destination)) {
|
||||
throw std::runtime_error("invalid TX output address");
|
||||
// build standard output script via GetScriptForDestination()
|
||||
CScript scriptPubKey = GetScriptForDestination(addr.Get());
|
||||
}
|
||||
CScript scriptPubKey = GetScriptForDestination(destination);
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
CTxOut txout(value, scriptPubKey);
|
||||
@@ -314,10 +314,8 @@ static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& str
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
}
|
||||
if (bScriptHash) {
|
||||
// Get the address for the redeem script, then call
|
||||
// GetScriptForDestination() to construct a P2SH scriptPubKey.
|
||||
CBitcoinAddress redeemScriptAddr(scriptPubKey);
|
||||
scriptPubKey = GetScriptForDestination(redeemScriptAddr.Get());
|
||||
// Get the ID for the script, and then construct a P2SH destination for it.
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
|
||||
}
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
@@ -381,10 +379,8 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
}
|
||||
if (bScriptHash) {
|
||||
// Get the address for the redeem script, then call
|
||||
// GetScriptForDestination() to construct a P2SH scriptPubKey.
|
||||
CBitcoinAddress addr(scriptPubKey);
|
||||
scriptPubKey = GetScriptForDestination(addr.Get());
|
||||
// Get the ID for the script, and then construct a P2SH destination for it.
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
|
||||
}
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
@@ -444,11 +440,10 @@ static void MutateTxAddOutScript(CMutableTransaction& tx, const std::string& str
|
||||
}
|
||||
|
||||
if (bSegWit) {
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
scriptPubKey = GetScriptForWitness(scriptPubKey);
|
||||
}
|
||||
if (bScriptHash) {
|
||||
CBitcoinAddress addr(scriptPubKey);
|
||||
scriptPubKey = GetScriptForDestination(addr.Get());
|
||||
scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey));
|
||||
}
|
||||
|
||||
// construct TxOut, append to transaction output list
|
||||
|
||||
Reference in New Issue
Block a user