Skip to content

Commit

Permalink
Added is_mine property to listtokens return value if token balance is… (
Browse files Browse the repository at this point in the history
#930)

* Added is_mine property to listtokens return value if token balance is greater than 0

* Updated to filter by key instead of just balance

* Added a missing lock

* Reworked logic for is_mine

* Updated the help text for listtokens rpc command
  • Loading branch information
mxaddict authored Feb 10, 2022
1 parent d23ba73 commit a4c9382
Showing 1 changed file with 24 additions and 3 deletions.
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

0 comments on commit a4c9382

Please sign in to comment.