| 1344 | } |
| 1345 | |
| 1346 | static CTransactionRef SendGenerationTransaction(const CScript& asset_script, const CPubKey &asset_pubkey, const CScript& token_script, const CPubKey &token_pubkey, CAmount asset_amount, CAmount token_amount, IssuanceDetails* issuance_details, CWallet* pwallet) |
| 1347 | { |
| 1348 | CAsset reissue_token = issuance_details->reissuance_token; |
| 1349 | CAmount curBalance = GetBalance(*pwallet).m_mine_trusted[reissue_token]; |
| 1350 | |
| 1351 | if (!reissue_token.IsNull() && curBalance <= 0) { |
| 1352 | throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "No available reissuance tokens in wallet."); |
| 1353 | } |
| 1354 | |
| 1355 | std::vector<CRecipient> vecSend; |
| 1356 | // Signal outputs to skip "funding" with fixed asset numbers 1, 2, ... |
| 1357 | // We don't know the asset during initial issuance until inputs are chosen |
| 1358 | if (asset_script.size() > 0) { |
| 1359 | vecSend.push_back({asset_script, asset_amount, CAsset(uint256S("1")), asset_pubkey, false}); |
| 1360 | } |
| 1361 | if (token_script.size() > 0) { |
| 1362 | CRecipient recipient = {token_script, token_amount, CAsset(uint256S("2")), token_pubkey, false}; |
| 1363 | // We need to select the issuance token(s) to spend |
| 1364 | if (!reissue_token.IsNull()) { |
| 1365 | recipient.asset = reissue_token; |
| 1366 | recipient.nAmount = curBalance; // Or 1? |
| 1367 | // If the issuance token *is* the fee asset, subtract fee from this output |
| 1368 | if (reissue_token == ::policyAsset) { |
| 1369 | recipient.fSubtractFeeFromAmount = true; |
| 1370 | } |
| 1371 | } |
| 1372 | vecSend.push_back(recipient); |
| 1373 | } |
| 1374 | |
| 1375 | CAmount nFeeRequired; |
| 1376 | int nChangePosRet = -1; |
| 1377 | bilingual_str error; |
| 1378 | FeeCalculation fee_calc_out; |
| 1379 | CCoinControl dummy_control; |
| 1380 | BlindDetails blind_details; |
| 1381 | CTransactionRef tx_ref; |
| 1382 | if (!CreateTransaction(*pwallet, vecSend, tx_ref, nFeeRequired, nChangePosRet, error, dummy_control, fee_calc_out, true, &blind_details, issuance_details)) { |
| 1383 | throw JSONRPCError(RPC_WALLET_ERROR, error.original); |
| 1384 | } |
| 1385 | |
| 1386 | mapValue_t map_value; |
| 1387 | pwallet->CommitTransaction(tx_ref, std::move(map_value), {} /* orderForm */, &blind_details); |
| 1388 | |
| 1389 | return tx_ref; |
| 1390 | } |
| 1391 | |
| 1392 | RPCHelpMan issueasset() |
| 1393 | { |
no test coverage detected