Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getsparkcoinaddr rpc added #1397

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading