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

Added is_mine property to listtokens return value if token balance is… #930

Merged
Merged
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
27 changes: 24 additions & 3 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5989,12 +5989,12 @@ UniValue listtokens(const UniValue& params, bool fHelp)
if (fHelp)
throw std::runtime_error(
"listtokens (mine)\n"
"\nList the confidential tokens. Set mine to true to show only tokens with balance.\n"
"\nList the confidential tokens. Set mine to true to show only tokens you own.\n"

+ HelpExampleCli("listtokens", "")
);

LOCK(cs_main);
LOCK2(cs_main, pwalletMain->cs_wallet);

bool fMine = params[0].getBool();

Expand Down Expand Up @@ -6039,7 +6039,28 @@ UniValue listtokens(const UniValue& params, bool fHelp)
}
o.pushKV("nfts", a);
}
if (!fMine || (fMine && balance > 0))

// Is this token ours?
bool fTokenIsMine = false;

blsctKey pk;
if (!pwalletMain->GetBLSCTTokenKey(it->second.key, pk))
{
blsctKey sk;

if (!pwalletMain->GetBLSCTSpendKey(sk))
throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available");

pk = sk.PrivateChildHash(SerializeHash("nft/"+it->second.sName+it->second.sDesc));

pwalletMain->AddBLSCTTokenKey(pk);
}

if (pk.GetG1Element() == it->second.key)
fTokenIsMine = true;

o.pushKV("is_mine", fTokenIsMine);
if (!fMine || (fMine && fTokenIsMine))
ret.push_back(o);
}
}
Expand Down