@@ -2768,7 +2768,8 @@ static UniValue listunspent(const JSONRPCRequest& request)
2768
2768
" \" scriptPubKey\" : \" key\" , (string) the script key\n "
2769
2769
" \" amount\" : x.xxx, (numeric) the transaction output amount in " + CURRENCY_UNIT + " \n "
2770
2770
" \" confirmations\" : n, (numeric) The number of confirmations\n "
2771
- " \" redeemScript\" : n (string) The redeemScript if scriptPubKey is P2SH\n "
2771
+ " \" redeemScript\" : \" script\" (string) The redeemScript if scriptPubKey is P2SH"
2772
+ " \" witnessScript\" : \" script\" (string) witnessScript if the scriptPubKey is P2WSH or P2SH-P2WSH\n "
2772
2773
" \" spendable\" : xxx, (bool) Whether we have the private keys to spend this output\n "
2773
2774
" \" solvable\" : xxx, (bool) Whether we know how to spend this output, ignoring the lack of keys\n "
2774
2775
" \" desc\" : xxx, (string, only when solvable) A descriptor for spending this output\n "
@@ -2882,6 +2883,28 @@ static UniValue listunspent(const JSONRPCRequest& request)
2882
2883
CScript redeemScript;
2883
2884
if (pwallet->GetCScript (hash, redeemScript)) {
2884
2885
entry.pushKV (" redeemScript" , HexStr (redeemScript.begin (), redeemScript.end ()));
2886
+ // Now check if the redeemScript is actually a P2WSH script
2887
+ CTxDestination witness_destination;
2888
+ if (redeemScript.IsPayToWitnessScriptHash ()) {
2889
+ bool extracted = ExtractDestination (redeemScript, witness_destination);
2890
+ assert (extracted);
2891
+ // Also return the witness script
2892
+ const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(witness_destination);
2893
+ CScriptID id;
2894
+ CRIPEMD160 ().Write (whash.begin (), whash.size ()).Finalize (id.begin ());
2895
+ CScript witnessScript;
2896
+ if (pwallet->GetCScript (id, witnessScript)) {
2897
+ entry.pushKV (" witnessScript" , HexStr (witnessScript.begin (), witnessScript.end ()));
2898
+ }
2899
+ }
2900
+ }
2901
+ } else if (scriptPubKey.IsPayToWitnessScriptHash ()) {
2902
+ const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(address);
2903
+ CScriptID id;
2904
+ CRIPEMD160 ().Write (whash.begin (), whash.size ()).Finalize (id.begin ());
2905
+ CScript witnessScript;
2906
+ if (pwallet->GetCScript (id, witnessScript)) {
2907
+ entry.pushKV (" witnessScript" , HexStr (witnessScript.begin (), witnessScript.end ()));
2885
2908
}
2886
2909
}
2887
2910
}
@@ -3137,7 +3160,8 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
3137
3160
{" txid" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The transaction id" },
3138
3161
{" vout" , RPCArg::Type::NUM, RPCArg::Optional::NO, " The output number" },
3139
3162
{" scriptPubKey" , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " script key" },
3140
- {" redeemScript" , RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, " (required for P2SH or P2WSH) redeem script" },
3163
+ {" redeemScript" , RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, " (required for P2SH) redeem script" },
3164
+ {" witnessScript" , RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, " (required for P2WSH or P2SH-P2WSH) witness script" },
3141
3165
{" amount" , RPCArg::Type::AMOUNT, RPCArg::Optional::NO, " The amount spent" },
3142
3166
},
3143
3167
},
0 commit comments