mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-17 20:32:33 +02:00
Store p2sh scripts in AddAndGetDestinationForScript
This commit is contained in:
parent
501acb5538
commit
4a7e43e846
@ -82,22 +82,30 @@ CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore,
|
|||||||
{
|
{
|
||||||
// Add script to keystore
|
// Add script to keystore
|
||||||
keystore.AddCScript(script);
|
keystore.AddCScript(script);
|
||||||
|
ScriptHash sh(script);
|
||||||
// Note that scripts over 520 bytes are not yet supported.
|
// Note that scripts over 520 bytes are not yet supported.
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case OutputType::LEGACY:
|
case OutputType::LEGACY:
|
||||||
return ScriptHash(script);
|
keystore.AddCScript(GetScriptForDestination(sh));
|
||||||
|
return sh;
|
||||||
case OutputType::P2SH_SEGWIT:
|
case OutputType::P2SH_SEGWIT:
|
||||||
case OutputType::BECH32: {
|
case OutputType::BECH32: {
|
||||||
CTxDestination witdest = WitnessV0ScriptHash(script);
|
CTxDestination witdest = WitnessV0ScriptHash(script);
|
||||||
CScript witprog = GetScriptForDestination(witdest);
|
CScript witprog = GetScriptForDestination(witdest);
|
||||||
// Check if the resulting program is solvable (i.e. doesn't use an uncompressed key)
|
// Check if the resulting program is solvable (i.e. doesn't use an uncompressed key)
|
||||||
if (!IsSolvable(keystore, witprog)) return ScriptHash(script);
|
if (!IsSolvable(keystore, witprog)) {
|
||||||
|
// Since the wsh is invalid, add and return the sh instead.
|
||||||
|
keystore.AddCScript(GetScriptForDestination(sh));
|
||||||
|
return sh;
|
||||||
|
}
|
||||||
// Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours.
|
// Add the redeemscript, so that P2WSH and P2SH-P2WSH outputs are recognized as ours.
|
||||||
keystore.AddCScript(witprog);
|
keystore.AddCScript(witprog);
|
||||||
if (type == OutputType::BECH32) {
|
if (type == OutputType::BECH32) {
|
||||||
return witdest;
|
return witdest;
|
||||||
} else {
|
} else {
|
||||||
return ScriptHash(witprog);
|
ScriptHash sh_w = ScriptHash(witprog);
|
||||||
|
keystore.AddCScript(GetScriptForDestination(sh_w));
|
||||||
|
return sh_w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: assert(false);
|
default: assert(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user