@@ -550,7 +550,11 @@ static UniValue signmessage(const JSONRPCRequest& request)
550
550
throw JSONRPCError (RPC_TYPE_ERROR, " Address does not refer to key" );
551
551
}
552
552
553
- const SigningProvider* provider = pwallet->GetSigningProvider ();
553
+ CScript script_pub_key = GetScriptForDestination (*pkhash);
554
+ const SigningProvider* provider = pwallet->GetSigningProvider (script_pub_key);
555
+ if (!provider) {
556
+ throw JSONRPCError (RPC_WALLET_ERROR, " Private key not available" );
557
+ }
554
558
555
559
CKey key;
556
560
CKeyID keyID (*pkhash);
@@ -2933,34 +2937,36 @@ static UniValue listunspent(const JSONRPCRequest& request)
2933
2937
entry.pushKV (" label" , i->second .name );
2934
2938
}
2935
2939
2936
- const SigningProvider* provider = pwallet->GetSigningProvider ();
2937
- if (scriptPubKey.IsPayToScriptHash ()) {
2938
- const CScriptID& hash = CScriptID (boost::get<ScriptHash>(address));
2939
- CScript redeemScript;
2940
- if (provider->GetCScript (hash, redeemScript)) {
2941
- entry.pushKV (" redeemScript" , HexStr (redeemScript.begin (), redeemScript.end ()));
2942
- // Now check if the redeemScript is actually a P2WSH script
2943
- CTxDestination witness_destination;
2944
- if (redeemScript.IsPayToWitnessScriptHash ()) {
2945
- bool extracted = ExtractDestination (redeemScript, witness_destination);
2946
- CHECK_NONFATAL (extracted);
2947
- // Also return the witness script
2948
- const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(witness_destination);
2949
- CScriptID id;
2950
- CRIPEMD160 ().Write (whash.begin (), whash.size ()).Finalize (id.begin ());
2951
- CScript witnessScript;
2952
- if (provider->GetCScript (id, witnessScript)) {
2953
- entry.pushKV (" witnessScript" , HexStr (witnessScript.begin (), witnessScript.end ()));
2940
+ const SigningProvider* provider = pwallet->GetSigningProvider (scriptPubKey);
2941
+ if (provider) {
2942
+ if (scriptPubKey.IsPayToScriptHash ()) {
2943
+ const CScriptID& hash = CScriptID (boost::get<ScriptHash>(address));
2944
+ CScript redeemScript;
2945
+ if (provider->GetCScript (hash, redeemScript)) {
2946
+ entry.pushKV (" redeemScript" , HexStr (redeemScript.begin (), redeemScript.end ()));
2947
+ // Now check if the redeemScript is actually a P2WSH script
2948
+ CTxDestination witness_destination;
2949
+ if (redeemScript.IsPayToWitnessScriptHash ()) {
2950
+ bool extracted = ExtractDestination (redeemScript, witness_destination);
2951
+ CHECK_NONFATAL (extracted);
2952
+ // Also return the witness script
2953
+ const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(witness_destination);
2954
+ CScriptID id;
2955
+ CRIPEMD160 ().Write (whash.begin (), whash.size ()).Finalize (id.begin ());
2956
+ CScript witnessScript;
2957
+ if (provider->GetCScript (id, witnessScript)) {
2958
+ entry.pushKV (" witnessScript" , HexStr (witnessScript.begin (), witnessScript.end ()));
2959
+ }
2954
2960
}
2955
2961
}
2956
- }
2957
- } else if (scriptPubKey. IsPayToWitnessScriptHash ()) {
2958
- const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(address) ;
2959
- CScriptID id ;
2960
- CRIPEMD160 (). Write (whash. begin (), whash. size ()). Finalize (id. begin ()) ;
2961
- CScript witnessScript;
2962
- if (provider-> GetCScript (id , witnessScript)) {
2963
- entry. pushKV ( " witnessScript " , HexStr (witnessScript. begin (), witnessScript. end ()));
2962
+ } else if (scriptPubKey. IsPayToWitnessScriptHash ()) {
2963
+ const WitnessV0ScriptHash& whash = boost::get<WitnessV0ScriptHash>(address);
2964
+ CScriptID id ;
2965
+ CRIPEMD160 (). Write (whash. begin (), whash. size ()). Finalize (id. begin ()) ;
2966
+ CScript witnessScript ;
2967
+ if (provider-> GetCScript (id, witnessScript)) {
2968
+ entry. pushKV ( " witnessScript " , HexStr (witnessScript. begin () , witnessScript. end ()));
2969
+ }
2964
2970
}
2965
2971
}
2966
2972
}
@@ -2971,8 +2977,11 @@ static UniValue listunspent(const JSONRPCRequest& request)
2971
2977
entry.pushKV (" spendable" , out.fSpendable );
2972
2978
entry.pushKV (" solvable" , out.fSolvable );
2973
2979
if (out.fSolvable ) {
2974
- auto descriptor = InferDescriptor (scriptPubKey, *pwallet->GetLegacyScriptPubKeyMan ());
2975
- entry.pushKV (" desc" , descriptor->ToString ());
2980
+ const SigningProvider* provider = pwallet->GetSigningProvider (scriptPubKey);
2981
+ if (provider) {
2982
+ auto descriptor = InferDescriptor (scriptPubKey, *provider);
2983
+ entry.pushKV (" desc" , descriptor->ToString ());
2984
+ }
2976
2985
}
2977
2986
if (avoid_reuse) entry.pushKV (" reused" , reused);
2978
2987
entry.pushKV (" safe" , out.fSafe );
@@ -3281,9 +3290,23 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
3281
3290
// Parse the prevtxs array
3282
3291
ParsePrevouts (request.params [1 ], nullptr , coins);
3283
3292
3293
+ std::set<const SigningProvider*> providers;
3294
+ for (const std::pair<COutPoint, Coin> coin_pair : coins) {
3295
+ const SigningProvider* provider = pwallet->GetSigningProvider (coin_pair.second .out .scriptPubKey );
3296
+ if (provider) {
3297
+ providers.insert (std::move (provider));
3298
+ }
3299
+ }
3300
+ if (providers.size () == 0 ) {
3301
+ // When there are no available providers, use DUMMY_SIGNING_PROVIDER so we can check if the tx is complete
3302
+ providers.insert (&DUMMY_SIGNING_PROVIDER);
3303
+ }
3304
+
3284
3305
UniValue result (UniValue::VOBJ);
3285
- SignTransaction (mtx, &*pwallet->GetLegacyScriptPubKeyMan (), coins, request.params [2 ], result);
3286
- return result;
3306
+ for (const SigningProvider* provider : providers) {
3307
+ SignTransaction (mtx, provider, coins, request.params [2 ], result);
3308
+ }
3309
+ return result;
3287
3310
}
3288
3311
3289
3312
static UniValue bumpfee (const JSONRPCRequest& request)
@@ -3648,9 +3671,10 @@ static UniValue DescribeWalletAddress(CWallet* pwallet, const CTxDestination& de
3648
3671
{
3649
3672
UniValue ret (UniValue::VOBJ);
3650
3673
UniValue detail = DescribeAddress (dest);
3674
+ CScript script = GetScriptForDestination (dest);
3651
3675
const SigningProvider* provider = nullptr ;
3652
3676
if (pwallet) {
3653
- provider = pwallet->GetSigningProvider ();
3677
+ provider = pwallet->GetSigningProvider (script );
3654
3678
}
3655
3679
ret.pushKVs (detail);
3656
3680
ret.pushKVs (boost::apply_visitor (DescribeWalletAddressVisitor (provider), dest));
@@ -3742,11 +3766,11 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
3742
3766
3743
3767
CScript scriptPubKey = GetScriptForDestination (dest);
3744
3768
ret.pushKV (" scriptPubKey" , HexStr (scriptPubKey.begin (), scriptPubKey.end ()));
3745
- const SigningProvider* provider = pwallet->GetSigningProvider ();
3769
+ const SigningProvider* provider = pwallet->GetSigningProvider (scriptPubKey );
3746
3770
3747
3771
isminetype mine = pwallet->IsMine (dest);
3748
3772
ret.pushKV (" ismine" , bool (mine & ISMINE_SPENDABLE));
3749
- bool solvable = IsSolvable (*provider, scriptPubKey);
3773
+ bool solvable = provider && IsSolvable (*provider, scriptPubKey);
3750
3774
ret.pushKV (" solvable" , solvable);
3751
3775
if (solvable) {
3752
3776
ret.pushKV (" desc" , InferDescriptor (scriptPubKey, *provider)->ToString ());
@@ -3759,7 +3783,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
3759
3783
}
3760
3784
ret.pushKV (" ischange" , pwallet->IsChange (scriptPubKey));
3761
3785
3762
- ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan ();
3786
+ ScriptPubKeyMan* spk_man = pwallet->GetScriptPubKeyMan (scriptPubKey );
3763
3787
if (spk_man) {
3764
3788
CKeyID key_id = GetKeyForDestination (*provider, dest);
3765
3789
const CKeyMetadata* meta = nullptr ;
0 commit comments