MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MutateTxAddOutPubKey

Function MutateTxAddOutPubKey

src/bitcoin-tx.cpp:319–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317}
318
319static void MutateTxAddOutPubKey(CMutableTransaction& tx, const std::string& strInput)
320{
321 // Separate into VALUE:PUBKEY[:FLAGS]
322 std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
323
324 if (vStrInputParts.size() < 2 || vStrInputParts.size() > 3)
325 throw std::runtime_error("TX output missing or too many separators");
326
327 // Extract and validate VALUE
328 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
329
330 // Extract and validate PUBKEY
331 CPubKey pubkey(ParseHex(vStrInputParts[1]));
332 if (!pubkey.IsFullyValid())
333 throw std::runtime_error("invalid TX output pubkey");
334 CScript scriptPubKey = GetScriptForRawPubKey(pubkey);
335
336 // Extract and validate FLAGS
337 bool bSegWit = false;
338 bool bScriptHash = false;
339 if (vStrInputParts.size() == 3) {
340 const std::string& flags = vStrInputParts[2];
341 bSegWit = (flags.find('W') != std::string::npos);
342 bScriptHash = (flags.find('S') != std::string::npos);
343 }
344
345 if (bSegWit) {
346 if (!pubkey.IsCompressed()) {
347 throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
348 }
349 // Build a P2WPKH script
350 scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(pubkey));
351 }
352 if (bScriptHash) {
353 // Get the ID for the script, and then construct a P2SH destination for it.
354 scriptPubKey = GetScriptForDestination(ScriptHash(scriptPubKey));
355 }
356
357 // construct TxOut, append to transaction output list
358 CTxOut txout(value, scriptPubKey);
359 tx.vout.push_back(txout);
360}
361
362static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput)
363{

Callers 1

MutateTxFunction · 0.85

Calls 12

SplitStringFunction · 0.85
ExtractAndValidateValueFunction · 0.85
ParseHexFunction · 0.85
GetScriptForRawPubKeyFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0KeyHashClass · 0.85
ScriptHashClass · 0.85
IsFullyValidMethod · 0.80
findMethod · 0.80
sizeMethod · 0.45
IsCompressedMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected