Skip to content

Commit 4a7e43e

Browse files
committed
Store p2sh scripts in AddAndGetDestinationForScript
1 parent 501acb5 commit 4a7e43e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/outputtype.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,30 @@ CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore,
8282
{
8383
// Add script to keystore
8484
keystore.AddCScript(script);
85+
ScriptHash sh(script);
8586
// Note that scripts over 520 bytes are not yet supported.
8687
switch (type) {
8788
case OutputType::LEGACY:
88-
return ScriptHash(script);
89+
keystore.AddCScript(GetScriptForDestination(sh));
90+
return sh;
8991
case OutputType::P2SH_SEGWIT:
9092
case OutputType::BECH32: {
9193
CTxDestination witdest = WitnessV0ScriptHash(script);
9294
CScript witprog = GetScriptForDestination(witdest);
9395
// Check if the resulting program is solvable (i.e. doesn't use an uncompressed key)
94-
if (!IsSolvable(keystore, witprog)) return ScriptHash(script);
96+
if (!IsSolvable(keystore, witprog)) {
97+
// Since the wsh is invalid, add and return the sh instead.
98+
keystore.AddCScript(GetScriptForDestination(sh));
99+
return sh;
100+
}
95101
// Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours.
96102
keystore.AddCScript(witprog);
97103
if (type == OutputType::BECH32) {
98104
return witdest;
99105
} else {
100-
return ScriptHash(witprog);
106+
ScriptHash sh_w = ScriptHash(witprog);
107+
keystore.AddCScript(GetScriptForDestination(sh_w));
108+
return sh_w;
101109
}
102110
}
103111
default: assert(false);

0 commit comments

Comments
 (0)