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

Function MutateTxAddOutMultiSig

src/bitcoin-tx.cpp:373–445  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

371}
372
373static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput)
374{
375 // Separate into VALUE:REQUIRED:NUMKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]
376 std::vector<std::string> vStrInputParts;
377 boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
378
379 // Check that there are enough parameters
380 if (vStrInputParts.size()<3)
381 throw std::runtime_error("Not enough multisig parameters");
382
383 // Extract and validate VALUE
384 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
385
386 // Extract REQUIRED
387 const uint32_t required{TrimAndParse<uint32_t>(vStrInputParts.at(1), "invalid multisig required number")};
388
389 // Extract NUMKEYS
390 const uint32_t numkeys{TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid multisig total number")};
391
392 // Validate there are the correct number of pubkeys
393 if (vStrInputParts.size() < numkeys + 3)
394 throw std::runtime_error("incorrect number of multisig pubkeys");
395
396 if (required < 1 || required > MAX_PUBKEYS_PER_MULTISIG || numkeys < 1 || numkeys > MAX_PUBKEYS_PER_MULTISIG || numkeys < required)
397 throw std::runtime_error("multisig parameter mismatch. Required " \
398 + ToString(required) + " of " + ToString(numkeys) + "signatures.");
399
400 // extract and validate PUBKEYs
401 std::vector<CPubKey> pubkeys;
402 for(int pos = 1; pos <= int(numkeys); pos++) {
403 CPubKey pubkey(ParseHex(vStrInputParts[pos + 2]));
404 if (!pubkey.IsFullyValid())
405 throw std::runtime_error("invalid TX output pubkey");
406 pubkeys.push_back(pubkey);
407 }
408
409 // Extract FLAGS
410 bool bSegWit = false;
411 bool bScriptHash = false;
412 if (vStrInputParts.size() == numkeys + 4) {
413 std::string flags = vStrInputParts.back();
414 bSegWit = (flags.find('W') != std::string::npos);
415 bScriptHash = (flags.find('S') != std::string::npos);
416 }
417 else if (vStrInputParts.size() > numkeys + 4) {
418 // Validate that there were no more parameters passed
419 throw std::runtime_error("Too many parameters");
420 }
421
422 CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);
423
424 if (bSegWit) {
425 for (const CPubKey& pubkey : pubkeys) {
426 if (!pubkey.IsCompressed()) {
427 throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
428 }
429 }
430 // Build a P2WSH with the multisig script

Callers 1

MutateTxFunction · 0.85

Calls 14

ExtractAndValidateValueFunction · 0.85
ParseHexFunction · 0.85
GetScriptForMultisigFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0ScriptHashClass · 0.85
ScriptHashClass · 0.85
CConfidentialValueClass · 0.85
IsFullyValidMethod · 0.80
findMethod · 0.80
ParamsClass · 0.70
ToStringFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected