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

Function MutateTxAddOutMultiSig

src/bitcoin-tx.cpp:334–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

332}
333
334static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& strInput)
335{
336 // Separate into VALUE:REQUIRED:NUMKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]
337 std::vector<std::string> vStrInputParts;
338 boost::split(vStrInputParts, strInput, boost::is_any_of(":"));
339
340 // Check that there are enough parameters
341 if (vStrInputParts.size()<3)
342 throw std::runtime_error("Not enough multisig parameters");
343
344 // Extract and validate VALUE
345 CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
346
347 // Extract REQUIRED
348 uint32_t required = stoul(vStrInputParts[1]);
349
350 // Extract NUMKEYS
351 uint32_t numkeys = stoul(vStrInputParts[2]);
352
353 // Validate there are the correct number of pubkeys
354 if (vStrInputParts.size() < numkeys + 3)
355 throw std::runtime_error("incorrect number of multisig pubkeys");
356
357 if (required < 1 || required > 20 || numkeys < 1 || numkeys > 20 || numkeys < required)
358 throw std::runtime_error("multisig parameter mismatch. Required " \
359 + std::to_string(required) + " of " + std::to_string(numkeys) + "signatures.");
360
361 // extract and validate PUBKEYs
362 std::vector<CPubKey> pubkeys;
363 for(int pos = 1; pos <= int(numkeys); pos++) {
364 CPubKey pubkey(ParseHex(vStrInputParts[pos + 2]));
365 if (!pubkey.IsFullyValid())
366 throw std::runtime_error("invalid TX output pubkey");
367 pubkeys.push_back(pubkey);
368 }
369
370 // Extract FLAGS
371 bool bSegWit = false;
372 bool bScriptHash = false;
373 if (vStrInputParts.size() == numkeys + 4) {
374 std::string flags = vStrInputParts.back();
375 bSegWit = (flags.find('W') != std::string::npos);
376 bScriptHash = (flags.find('S') != std::string::npos);
377 }
378 else if (vStrInputParts.size() > numkeys + 4) {
379 // Validate that there were no more parameters passed
380 throw std::runtime_error("Too many parameters");
381 }
382
383 CScript scriptPubKey = GetScriptForMultisig(required, pubkeys);
384
385 if (bSegWit) {
386 for (CPubKey& pubkey : pubkeys) {
387 if (!pubkey.IsCompressed()) {
388 throw std::runtime_error("Uncompressed pubkeys are not useable for SegWit outputs");
389 }
390 }
391 // Call GetScriptForWitness() to build a P2WSH scriptPubKey

Callers 1

MutateTxFunction · 0.85

Calls 11

ExtractAndValidateValueFunction · 0.85
ParseHexFunction · 0.85
GetScriptForMultisigFunction · 0.85
GetScriptForWitnessFunction · 0.85
GetScriptForDestinationFunction · 0.85
IsFullyValidMethod · 0.80
CScriptIDClass · 0.70
sizeMethod · 0.45
push_backMethod · 0.45
findMethod · 0.45
IsCompressedMethod · 0.45

Tested by

no test coverage detected