Changeset View
Changeset View
Standalone View
Standalone View
src/bitcoin-tx.cpp
Show First 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | if (vStrInputParts.size() != 2) { | ||||
throw std::runtime_error("TX output missing or too many separators"); | throw std::runtime_error("TX output missing or too many separators"); | ||||
} | } | ||||
// Extract and validate VALUE | // Extract and validate VALUE | ||||
CAmount value = ExtractAndValidateValue(vStrInputParts[0]); | CAmount value = ExtractAndValidateValue(vStrInputParts[0]); | ||||
// extract and validate ADDRESS | // extract and validate ADDRESS | ||||
std::string strAddr = vStrInputParts[1]; | std::string strAddr = vStrInputParts[1]; | ||||
CBitcoinAddress addr(strAddr); | CTxDestination destination = DecodeDestination(strAddr); | ||||
if (!addr.IsValid()) { | if (!IsValidDestination(destination)) { | ||||
throw std::runtime_error("invalid TX output address"); | throw std::runtime_error("invalid TX output address"); | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForDestination(destination); | |||||
// build standard output script via GetScriptForDestination() | |||||
CScript scriptPubKey = GetScriptForDestination(addr.Get()); | |||||
// construct TxOut, append to transaction output list | // construct TxOut, append to transaction output list | ||||
CTxOut txout(value, scriptPubKey); | CTxOut txout(value, scriptPubKey); | ||||
tx.vout.push_back(txout); | tx.vout.push_back(txout); | ||||
} | } | ||||
static void MutateTxAddOutPubKey(CMutableTransaction &tx, | static void MutateTxAddOutPubKey(CMutableTransaction &tx, | ||||
const std::string &strInput) { | const std::string &strInput) { | ||||
Show All 10 Lines | static void MutateTxAddOutPubKey(CMutableTransaction &tx, | ||||
// Extract and validate PUBKEY | // Extract and validate PUBKEY | ||||
CPubKey pubkey(ParseHex(vStrInputParts[1])); | CPubKey pubkey(ParseHex(vStrInputParts[1])); | ||||
if (!pubkey.IsFullyValid()) { | if (!pubkey.IsFullyValid()) { | ||||
throw std::runtime_error("invalid TX output pubkey"); | throw std::runtime_error("invalid TX output pubkey"); | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForRawPubKey(pubkey); | CScript scriptPubKey = GetScriptForRawPubKey(pubkey); | ||||
CBitcoinAddress addr(scriptPubKey); | |||||
// Extract and validate FLAGS | // Extract and validate FLAGS | ||||
bool bScriptHash = false; | bool bScriptHash = false; | ||||
if (vStrInputParts.size() == 3) { | if (vStrInputParts.size() == 3) { | ||||
std::string flags = vStrInputParts[2]; | std::string flags = vStrInputParts[2]; | ||||
bScriptHash = (flags.find("S") != std::string::npos); | bScriptHash = (flags.find("S") != std::string::npos); | ||||
} | } | ||||
if (bScriptHash) { | if (bScriptHash) { | ||||
// Get the address for the redeem script, then call | // Get the ID for the script, and then construct a P2SH destination for | ||||
// GetScriptForDestination() to construct a P2SH scriptPubKey. | // it. | ||||
CBitcoinAddress redeemScriptAddr(scriptPubKey); | scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey)); | ||||
scriptPubKey = GetScriptForDestination(redeemScriptAddr.Get()); | |||||
} | } | ||||
// construct TxOut, append to transaction output list | // construct TxOut, append to transaction output list | ||||
CTxOut txout(value, scriptPubKey); | CTxOut txout(value, scriptPubKey); | ||||
tx.vout.push_back(txout); | tx.vout.push_back(txout); | ||||
} | } | ||||
static void MutateTxAddOutMultiSig(CMutableTransaction &tx, | static void MutateTxAddOutMultiSig(CMutableTransaction &tx, | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | static void MutateTxAddOutMultiSig(CMutableTransaction &tx, | ||||
} else if (vStrInputParts.size() > numkeys + 4) { | } else if (vStrInputParts.size() > numkeys + 4) { | ||||
// Validate that there were no more parameters passed | // Validate that there were no more parameters passed | ||||
throw std::runtime_error("Too many parameters"); | throw std::runtime_error("Too many parameters"); | ||||
} | } | ||||
CScript scriptPubKey = GetScriptForMultisig(required, pubkeys); | CScript scriptPubKey = GetScriptForMultisig(required, pubkeys); | ||||
if (bScriptHash) { | if (bScriptHash) { | ||||
// Get the address for the redeem script, then call | // Get the ID for the script, and then construct a P2SH destination for | ||||
// GetScriptForDestination() to construct a P2SH scriptPubKey. | // it. | ||||
CBitcoinAddress addr(scriptPubKey); | scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey)); | ||||
scriptPubKey = GetScriptForDestination(addr.Get()); | |||||
} | } | ||||
// construct TxOut, append to transaction output list | // construct TxOut, append to transaction output list | ||||
CTxOut txout(value, scriptPubKey); | CTxOut txout(value, scriptPubKey); | ||||
tx.vout.push_back(txout); | tx.vout.push_back(txout); | ||||
} | } | ||||
static void MutateTxAddOutData(CMutableTransaction &tx, | static void MutateTxAddOutData(CMutableTransaction &tx, | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | static void MutateTxAddOutScript(CMutableTransaction &tx, | ||||
// Extract FLAGS | // Extract FLAGS | ||||
bool bScriptHash = false; | bool bScriptHash = false; | ||||
if (vStrInputParts.size() == 3) { | if (vStrInputParts.size() == 3) { | ||||
std::string flags = vStrInputParts.back(); | std::string flags = vStrInputParts.back(); | ||||
bScriptHash = (flags.find("S") != std::string::npos); | bScriptHash = (flags.find("S") != std::string::npos); | ||||
} | } | ||||
if (bScriptHash) { | if (bScriptHash) { | ||||
CBitcoinAddress addr(scriptPubKey); | scriptPubKey = GetScriptForDestination(CScriptID(scriptPubKey)); | ||||
scriptPubKey = GetScriptForDestination(addr.Get()); | |||||
} | } | ||||
// construct TxOut, append to transaction output list | // construct TxOut, append to transaction output list | ||||
CTxOut txout(value, scriptPubKey); | CTxOut txout(value, scriptPubKey); | ||||
tx.vout.push_back(txout); | tx.vout.push_back(txout); | ||||
} | } | ||||
static void MutateTxDelInput(CMutableTransaction &tx, | static void MutateTxDelInput(CMutableTransaction &tx, | ||||
▲ Show 20 Lines • Show All 443 Lines • Show Last 20 Lines |