Skip to content

Commit

Permalink
getsparkcoinaddr rpc added (#1397)
Browse files Browse the repository at this point in the history
* getsparkcoinaddr  rpc added

* Fix crashing ui bug

* Bug fixed
  • Loading branch information
levonpetrosyan93 authored Jan 25, 2024
1 parent c1c464d commit 2957748
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1547,18 +1547,19 @@ WalletModel::SendCoinsReturn WalletModel::mintSparkCoins(std::vector<WalletModel
auto reservekey = reserveKeys.begin();

for (size_t i = 0; i != wtxAndFee.size(); i++) {
if (!wallet->CommitTransaction(wtxAndFee[i].first, *reservekey++, g_connman.get(), state))
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));

Q_FOREACH(const SendCoinsRecipient &rcp, transactions[i].getRecipients())
{
// CWalletTx* newTx = transactions[i].getTransaction();
if (!rcp.message.isEmpty()) // Message from normal firo:URI (firo:123...?message=example)
wtxAndFee[i].first.vOrderForm.push_back(make_pair("Message", rcp.message.toStdString()));
if (!wallet->CommitTransaction(wtxAndFee[i].first, *reservekey++, g_connman.get(), state))
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));


CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << *wtxAndFee[i].first.tx;
transaction_array.append(&(ssTx[0]), ssTx.size());

{
std::string strAddress = rcp.address.toStdString();
std::string strLabel = rcp.label.toStdString();
Expand Down
45 changes: 44 additions & 1 deletion src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3937,7 +3937,7 @@ UniValue identifysparkcoins(const JSONRPCRequest& request)

if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"identifysparkcoin \"txHash\"\n"
"identifysparkcoins \"txHash\"\n"
"Identifies coins in transaction, and adds into wallet if yours");

EnsureSparkWalletIsAvailable();
Expand Down Expand Up @@ -3968,6 +3968,48 @@ UniValue identifysparkcoins(const JSONRPCRequest& request)
return results;
}

UniValue getsparkcoinaddr(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
return NullUniValue;
}

if (request.fHelp || request.params.size() != 1)
throw std::runtime_error(
"getsparkcoinaddr \"txHash\"\n"
"Returns all spark outputs to you, address memo and amount for each");

EnsureSparkWalletIsAvailable();

uint256 txHash;
txHash.SetHex(request.params[0].get_str());

CTransactionRef tx;
uint256 hashBlock;
GetTransaction(txHash, tx, Params().GetConsensus(), hashBlock);

UniValue results(UniValue::VARR);;
assert(pwallet != NULL);

std::unordered_map<uint256, CSparkMintMeta> coins = pwallet->sparkWallet->getMintMap();
unsigned char network = spark::GetNetworkType();

for (const auto& coin : coins)
{
if (txHash == coin.second.txid) {
spark::Address address = pwallet->sparkWallet->getAddress(coin.second.i);
UniValue entry(UniValue::VOBJ);
entry.push_back(Pair("address", address.encode(network)));
entry.push_back(Pair("memo", SanitizeString(coin.second.memo)));
entry.push_back(Pair("amount", ValueFromAmount(coin.second.v)));
results.push_back(entry);
}
}

return results;
}

UniValue mint(const JSONRPCRequest& request)
{
CWallet * const pwallet = GetWalletForJSONRPCRequest(request);
Expand Down Expand Up @@ -5720,6 +5762,7 @@ static const CRPCCommand commands[] =
{ "wallet", "spendspark", &spendspark, false },
{ "wallet", "lelantustospark", &lelantustospark, false },
{ "wallet", "identifysparkcoins", &identifysparkcoins, false },
{ "wallet", "getsparkcoinaddr", &getsparkcoinaddr, false },


//bip47
Expand Down

0 comments on commit 2957748

Please sign in to comment.