Skip to content

Commit 5ab108c

Browse files
committed
feat: implementation of RPC 'protx register' for descriptor wallets
1 parent d44b0d5 commit 5ab108c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/rpc/evo.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -776,18 +776,23 @@ static UniValue protx_register_common_wrapper(const JSONRPCRequest& request,
776776
ret.pushKV("signMessage", ptx.MakeSignString());
777777
return ret;
778778
} 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
791796
SetTxPayload(tx, ptx);
792797
return SignAndSendSpecialTx(request, chain_helper, chainman, tx, fSubmit);
793798
}

0 commit comments

Comments
 (0)