| 2143 | } |
| 2144 | |
| 2145 | RPCHelpMan 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 |
nothing calls this directly
no test coverage detected