MCPcopy Create free account
hub / github.com/ElementsProject/elements / dumpissuanceblindingkey

Function dumpissuanceblindingkey

src/wallet/rpc/backup.cpp:2289–2350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2287}
2288
2289RPCHelpMan dumpissuanceblindingkey()
2290{
2291 return RPCHelpMan{"dumpissuanceblindingkey",
2292 "\nDumps the private blinding key for an asset issuance in wallet.",
2293 {
2294 {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id of the issuance"},
2295 {"vin", RPCArg::Type::NUM, RPCArg::Optional::NO, "The input number of the issuance in the transaction."},
2296 },
2297 RPCResult{
2298 RPCResult::Type::STR, "blindingkey", "the issuance blinding key",
2299 },
2300 RPCExamples{
2301 HelpExampleCli("dumpissuanceblindingkey", "\"<txid>\", 0")
2302 },
2303 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2304{
2305 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
2306 if (!wallet) return NullUniValue;
2307 CWallet* const pwallet = wallet.get();
2308
2309 LOCK(pwallet->cs_wallet);
2310
2311 if (!request.params[0].isStr() || !IsHex(request.params[0].get_str()) || request.params[0].get_str().size() != 64) {
2312 throw JSONRPCError(RPC_TYPE_ERROR, "First argument must be a txid string");
2313 }
2314 std::string txidstr = request.params[0].get_str();
2315 uint256 txid;
2316 txid.SetHex(txidstr);
2317
2318 uint32_t vindex;
2319 if (!request.params[1].isNum()) {
2320 throw JSONRPCError(RPC_TYPE_ERROR, "vin must be an integer");
2321 }
2322 vindex = request.params[1].get_int();
2323
2324 // Process as issuance key dump
2325 for (std::map<uint256, CWalletTx>::const_iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) {
2326 const CWalletTx* pcoin = &(*it).second;
2327 if (pcoin->tx->GetHash() != txid) {
2328 continue;
2329 }
2330 if (pcoin->tx->vin.size() <= vindex) {
2331 throw JSONRPCError(RPC_WALLET_ERROR, "Transaction is in wallet but vin does not exist");
2332 }
2333 if (pcoin->tx->vin[vindex].assetIssuance.IsNull()) {
2334 throw JSONRPCError(RPC_WALLET_ERROR, "Transaction input has no issuance");
2335 }
2336 // We can actually deblind the input
2337 if (pcoin->GetIssuanceAmount(*pwallet, vindex, false) != -1 ) {
2338 CScript blindingScript(CScript() << OP_RETURN << std::vector<unsigned char>(pcoin->tx->vin[vindex].prevout.hash.begin(), pcoin->tx->vin[vindex].prevout.hash.end()) << pcoin->tx->vin[vindex].prevout.n);
2339 CKey key;
2340 key = wallet->GetBlindingKey(&blindingScript);
2341 return HexStr(Span<const unsigned char>(key.begin(), key.size()));
2342 } else {
2343 // We don't know how to deblind this using our wallet
2344 throw JSONRPCError(RPC_WALLET_ERROR, "Unable to unblind issuance with wallet blinding key.");
2345 }
2346 }

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
IsHexFunction · 0.85
JSONRPCErrorFunction · 0.85
isStrMethod · 0.80
isNumMethod · 0.80
get_intMethod · 0.80
GetIssuanceAmountMethod · 0.80
GetBlindingKeyMethod · 0.80
CScriptClass · 0.50
HexStrFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected