@@ -776,18 +776,23 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
776
776
ret.pushKV (" signMessage" , ptx.MakeSignString ());
777
777
return ret;
778
778
} else {
779
- // lets prove we own the collateral
780
- // TODO: make collateral works with Descriptor wallets too
781
- const LegacyScriptPubKeyMan* spk_man = wallet->GetLegacyScriptPubKeyMan ();
782
- if (!spk_man) {
783
- throw JSONRPCError (RPC_WALLET_ERROR, " This type of wallet does not support this command" );
784
- }
785
-
786
- CKey key;
787
- if (!spk_man->GetKey (ToKeyID (*pkhash), key)) {
788
- throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, strprintf (" collateral key not in wallet: %s" , EncodeDestination (txDest)));
789
- }
790
- SignSpecialTxPayloadByString (tx, ptx, key);
779
+ {
780
+ LOCK (wallet->cs_wallet );
781
+ // lets prove we own the collateral
782
+ CScript scriptPubKey = GetScriptForDestination (txDest);
783
+ std::unique_ptr<SigningProvider> provider = wallet->GetSolvingProvider (scriptPubKey);
784
+
785
+ std::string signed_payload;
786
+ SigningResult err = wallet->SignMessage (ptx.MakeSignString (), *pkhash, signed_payload);
787
+ if (err == SigningResult::SIGNING_FAILED) {
788
+ throw JSONRPCError (RPC_INVALID_ADDRESS_OR_KEY, SigningResultString (err));
789
+ } else if (err != SigningResult::OK){
790
+ throw JSONRPCError (RPC_WALLET_ERROR, SigningResultString (err));
791
+ }
792
+ bool invalid = false ;
793
+ ptx.vchSig = DecodeBase64 (signed_payload.c_str (), &invalid);
794
+ if (invalid) throw JSONRPCError (RPC_INTERNAL_ERROR, " failed to decode base64 ready signature for protx" );
795
+ } // cs_wallet
791
796
SetTxPayload (tx, ptx);
792
797
return SignAndSendSpecialTx (request, chain_helper, chainman, tx, fSubmit );
793
798
}
0 commit comments