@@ -3360,8 +3360,18 @@ UniValue listsparkmints(const JSONRPCRequest& request) {
33603360 UniValue results (UniValue::VARR);;
33613361 assert (pwallet != NULL );
33623362
3363- std::unordered_map<uint256, CSparkMintMeta> coins = pwallet->sparkWallet ->getMintMap ();
3364- LogPrintf (" coins.size()=%s\n " , coins.size ());
3363+ std::unordered_map<uint256, CSparkMintMeta> coins_ = pwallet->sparkWallet ->getMintMap ();
3364+
3365+ // sort the result so you can easily compare when testing
3366+ std::vector<std::pair<uint256, CSparkMintMeta> > coins (coins_.begin (), coins_.end ());
3367+ sort (coins.begin (), coins.end (),
3368+ [](decltype (coins)::const_reference m1, decltype (coins)::const_reference m2)->bool {
3369+ CDataStream ds1 (SER_DISK, CLIENT_VERSION), ds2 (SER_DISK, CLIENT_VERSION);
3370+ ds1 << m1;
3371+ ds2 << m2;
3372+ return ds1.str () < ds2.str ();
3373+ });
3374+
33653375 BOOST_FOREACH (const auto & coin, coins)
33663376 {
33673377 UniValue entry (UniValue::VOBJ);
@@ -3370,7 +3380,7 @@ UniValue listsparkmints(const JSONRPCRequest& request) {
33703380 entry.push_back (Pair (" nId" , coin.second .nId ));
33713381 entry.push_back (Pair (" isUsed" , coin.second .isUsed ));
33723382 entry.push_back (Pair (" lTagHash" , coin.first .GetHex ()));
3373- entry.push_back (Pair (" memo" , coin.second .memo ));
3383+ entry.push_back (Pair (" memo" , SanitizeString ( coin.second .memo ) ));
33743384
33753385 CDataStream serialized (SER_NETWORK, PROTOCOL_VERSION);
33763386 serialized << pwallet->sparkWallet ->getCoinFromMeta (coin.second );
@@ -3918,6 +3928,46 @@ UniValue lelantustospark(const JSONRPCRequest& request) {
39183928 return NullUniValue;
39193929}
39203930
3931+ UniValue identifysparkcoins (const JSONRPCRequest& request)
3932+ {
3933+ CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
3934+ if (!EnsureWalletIsAvailable (pwallet, request.fHelp )) {
3935+ return NullUniValue;
3936+ }
3937+
3938+ if (request.fHelp || request.params .size () != 1 )
3939+ throw std::runtime_error (
3940+ " identifysparkcoin \" txHash\"\n "
3941+ " Identifies coins in transaction, and adds into wallet if yours" );
3942+
3943+ EnsureSparkWalletIsAvailable ();
3944+
3945+ uint256 txHash;
3946+ txHash.SetHex (request.params [0 ].get_str ());
3947+
3948+ CTransactionRef tx;
3949+ uint256 hashBlock;
3950+ GetTransaction (txHash, tx, Params ().GetConsensus (), hashBlock);
3951+ CWalletDB walletdb (pwallet->strWalletFile );
3952+
3953+ UniValue results (UniValue::VOBJ);
3954+ results.push_back (Pair (" Old availableBalance" ,pwallet->sparkWallet ->getAvailableBalance ()));
3955+ results.push_back (Pair (" Old unconfirmedBalance" ,pwallet->sparkWallet ->getUnconfirmedBalance ()));
3956+ results.push_back (Pair (" Old fullBalance" ,pwallet->sparkWallet ->getFullBalance ()));
3957+
3958+ if (tx->IsSparkTransaction ()) {
3959+ auto coins = spark::GetSparkMintCoins (*tx);
3960+ uint256 txHash = tx->GetHash ();
3961+ pwallet->sparkWallet ->UpdateMintState (coins, txHash, walletdb);
3962+ }
3963+
3964+ results.push_back (Pair (" availableBalance" ,pwallet->sparkWallet ->getAvailableBalance ()));
3965+ results.push_back (Pair (" unconfirmedBalance" ,pwallet->sparkWallet ->getUnconfirmedBalance ()));
3966+ results.push_back (Pair (" fullBalance" ,pwallet->sparkWallet ->getFullBalance ()));
3967+
3968+ return results;
3969+ }
3970+
39213971UniValue mint (const JSONRPCRequest& request)
39223972{
39233973 CWallet * const pwallet = GetWalletForJSONRPCRequest (request);
@@ -5669,6 +5719,8 @@ static const CRPCCommand commands[] =
56695719 { " wallet" , " automintspark" , &automintspark, false },
56705720 { " wallet" , " spendspark" , &spendspark, false },
56715721 { " wallet" , " lelantustospark" , &lelantustospark, false },
5722+ { " wallet" , " identifysparkcoins" , &identifysparkcoins, false },
5723+
56725724
56735725 // bip47
56745726 { " bip47" , " createrapaddress" , &createrapaddress, true },
0 commit comments