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

Function importissuanceblindingkey

src/wallet/rpc/backup.cpp:2145–2217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2143}
2144
2145RPCHelpMan importissuanceblindingkey()
2146{
2147 return RPCHelpMan{"importissuanceblindingkey",
2148 "\nImports a private blinding key in hex for an asset issuance.",
2149 {
2150 {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction id of the issuance"},
2151 {"vin", RPCArg::Type::NUM, RPCArg::Optional::NO, "The input number of the issuance in the transaction."},
2152 {"blindingkey", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The blinding key in hex"},
2153 },
2154 RPCResult{RPCResult::Type::NONE, "", ""},
2155 RPCExamples{
2156 HelpExampleCli("importblindingkey", "\"my blinded CT address\" <blindinghex>")
2157 },
2158 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
2159{
2160 std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
2161 if (!wallet) return NullUniValue;
2162 CWallet* const pwallet = wallet.get();
2163
2164 LOCK(pwallet->cs_wallet);
2165
2166 if (!request.params[0].isStr() || !IsHex(request.params[0].get_str()) || request.params[0].get_str().size() != 64) {
2167 throw JSONRPCError(RPC_TYPE_ERROR, "First argument must be a txid string");
2168 }
2169 std::string txidstr = request.params[0].get_str();
2170 uint256 txid;
2171 txid.SetHex(txidstr);
2172
2173 uint32_t vindex;
2174 if (!request.params[1].isNum()) {
2175 throw JSONRPCError(RPC_TYPE_ERROR, "vin must be an integer");
2176 }
2177 vindex = request.params[1].get_int();
2178
2179 if (!request.params[2].isStr() || !IsHex(request.params[2].get_str()) || request.params[2].get_str().size() != 64) {
2180 throw JSONRPCError(RPC_TYPE_ERROR, "blinding key must be a hex string of length 64");
2181 }
2182
2183 std::vector<unsigned char> keydata = ParseHex(request.params[2].get_str());
2184 if (keydata.size() != 32) {
2185 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid hexadecimal key length");
2186 }
2187 CKey key;
2188 key.Set(keydata.begin(), keydata.end(), true);
2189
2190 // Process as issuance key dump
2191 for (std::map<uint256, CWalletTx>::const_iterator it = pwallet->mapWallet.begin(); it != pwallet->mapWallet.end(); ++it) {
2192 const CWalletTx* pcoin = &(*it).second;
2193 if (pcoin->GetHash() != txid) {
2194 continue;
2195 }
2196 if (pcoin->tx->vin.size() <= vindex) {
2197 throw JSONRPCError(RPC_WALLET_ERROR, "Transaction is in wallet but vin does not exist");
2198 }
2199 if (pcoin->tx->vin[vindex].assetIssuance.IsNull()) {
2200 throw JSONRPCError(RPC_WALLET_ERROR, "Transaction input has no issuance");
2201 }
2202

Callers

nothing calls this directly

Calls 15

HelpExampleCliFunction · 0.85
IsHexFunction · 0.85
JSONRPCErrorFunction · 0.85
ParseHexFunction · 0.85
CScriptIDClass · 0.85
isStrMethod · 0.80
isNumMethod · 0.80
get_intMethod · 0.80
CScriptClass · 0.50
getMethod · 0.45

Tested by

no test coverage detected