MCPcopy Create free account
hub / github.com/ElementsProject/elements / MutateTxAddOutPubKey

Function MutateTxAddOutPubKey

src/bitcoin-tx.cpp:329–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

MutateTxFunction · 0.85

Calls 13

ExtractAndValidateValueFunction · 0.85
ParseHexFunction · 0.85
GetScriptForRawPubKeyFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0KeyHashClass · 0.85
ScriptHashClass · 0.85
CConfidentialValueClass · 0.85
IsFullyValidMethod · 0.80
findMethod · 0.80
ParamsClass · 0.70
sizeMethod · 0.45
IsCompressedMethod · 0.45

Tested by

no test coverage detected