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

Function MutateTxAddOutMultiSig

src/bitcoin-tx.cpp:362–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

MutateTxFunction · 0.85

Calls 15

SplitStringFunction · 0.85
ExtractAndValidateValueFunction · 0.85
ParseHexFunction · 0.85
GetScriptForMultisigFunction · 0.85
GetScriptForDestinationFunction · 0.85
WitnessV0ScriptHashClass · 0.85
ScriptHashClass · 0.85
IsFullyValidMethod · 0.80
findMethod · 0.80
ToStringFunction · 0.50
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected