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

Function CalculateNestedKeyhashInputSize

src/wallet/test/wallet_tests.cpp:533–565  ·  view source on GitHub ↗

Explicit calculation which is used to test the wallet constant We get the same virtual size due to rounding(weight/4) for both use_max_sig values

Source from the content-addressed store, hash-verified

531// Explicit calculation which is used to test the wallet constant
532// We get the same virtual size due to rounding(weight/4) for both use_max_sig values
533static size_t CalculateNestedKeyhashInputSize(bool use_max_sig)
534{
535 // Generate ephemeral valid pubkey
536 CKey key = GenerateRandomKey();
537 CPubKey pubkey = key.GetPubKey();
538
539 // Generate pubkey hash
540 uint160 key_hash(Hash160(pubkey));
541
542 // Create inner-script to enter into keystore. Key hash can't be 0...
543 CScript inner_script = CScript() << OP_0 << std::vector<unsigned char>(key_hash.begin(), key_hash.end());
544
545 // Create outer P2SH script for the output
546 uint160 script_id(Hash160(inner_script));
547 CScript script_pubkey = CScript() << OP_HASH160 << std::vector<unsigned char>(script_id.begin(), script_id.end()) << OP_EQUAL;
548
549 // Add inner-script to key store and key to watchonly
550 FillableSigningProvider keystore;
551 keystore.AddCScript(inner_script);
552 keystore.AddKeyPubKey(key, pubkey);
553
554 // Fill in dummy signatures for fee calculation.
555 SignatureData sig_data;
556
557 if (!ProduceSignature(keystore, use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR : DUMMY_SIGNATURE_CREATOR, script_pubkey, sig_data)) {
558 // We're hand-feeding it correct arguments; shouldn't happen
559 assert(false);
560 }
561
562 CTxIn tx_in;
563 UpdateInput(tx_in, sig_data);
564 return (size_t)GetVirtualTransactionInputSize(tx_in);
565}
566
567BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain100Setup)
568{

Callers 1

BOOST_FIXTURE_TEST_CASEFunction · 0.85

Calls 11

GenerateRandomKeyFunction · 0.85
Hash160Function · 0.85
ProduceSignatureFunction · 0.85
UpdateInputFunction · 0.85
AddCScriptMethod · 0.80
AddKeyPubKeyMethod · 0.80
CScriptClass · 0.50
GetPubKeyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected