From 8ead11a00555b7e5cff2d2c9747141631a1e1537 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Wed, 9 Feb 2022 07:00:08 +0800 Subject: [PATCH 1/5] Added is_mine property to listtokens return value if token balance is greater than 0 --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9304bcb20..a89215c2a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6039,6 +6039,7 @@ UniValue listtokens(const UniValue& params, bool fHelp) } o.pushKV("nfts", a); } + o.pushKV("is_mine", balance > 0); if (!fMine || (fMine && balance > 0)) ret.push_back(o); } From 2d7e4345f919e7b6a5fa87a7f63aa84d257cf153 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Wed, 9 Feb 2022 11:49:45 +0800 Subject: [PATCH 2/5] Updated to filter by key instead of just balance --- src/wallet/rpcwallet.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a89215c2a..2f9a6f573 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6039,8 +6039,27 @@ UniValue listtokens(const UniValue& params, bool fHelp) } o.pushKV("nfts", a); } - o.pushKV("is_mine", balance > 0); - if (!fMine || (fMine && balance > 0)) + + // Is this token ours? + bool fTokenIsMine = true; + + if (!pwalletMain->HaveBLSCTTokenKey(it->second.key)) + { + blsctKey sk; + + if (!pwalletMain->GetBLSCTSpendKey(sk)) + throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available"); + + blsctKey pk = sk.PrivateChildHash(SerializeHash("nft/"+it->second.sName+it->second.sDesc)); + + if (pk.GetG1Element() != it->second.key) + fTokenIsMine = false; + + pwalletMain->AddBLSCTTokenKey(pk); + } + + o.pushKV("is_mine", fTokenIsMine); + if (!fMine || (fMine && fTokenIsMine)) ret.push_back(o); } } From a9cafefed1c22a87042b738c4eaebfb53d8efa12 Mon Sep 17 00:00:00 2001 From: mxaddict Date: Thu, 10 Feb 2022 03:32:50 +0800 Subject: [PATCH 3/5] Added a missing lock --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2f9a6f573..85b23c53e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5994,7 +5994,7 @@ UniValue listtokens(const UniValue& params, bool fHelp) + HelpExampleCli("listtokens", "") ); - LOCK(cs_main); + LOCK2(cs_main, pwalletMain->cs_wallet); bool fMine = params[0].getBool(); From fb3804b21c9dd2c314cb5f1a3cb188396964fd6a Mon Sep 17 00:00:00 2001 From: mxaddict Date: Thu, 10 Feb 2022 16:50:55 +0800 Subject: [PATCH 4/5] Reworked logic for is_mine --- src/wallet/rpcwallet.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 85b23c53e..c36dded3f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6041,23 +6041,24 @@ UniValue listtokens(const UniValue& params, bool fHelp) } // Is this token ours? - bool fTokenIsMine = true; + bool fTokenIsMine = false; - if (!pwalletMain->HaveBLSCTTokenKey(it->second.key)) + blsctKey pk; + if (!pwalletMain->GetBLSCTTokenKey(it->second.key, pk)) { blsctKey sk; if (!pwalletMain->GetBLSCTSpendKey(sk)) throw JSONRPCError(RPC_TYPE_ERROR, "Wallet not available"); - blsctKey pk = sk.PrivateChildHash(SerializeHash("nft/"+it->second.sName+it->second.sDesc)); - - if (pk.GetG1Element() != it->second.key) - fTokenIsMine = false; + 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); From 56736308d79bbcd7b6b6149faf5ad5d774ed357b Mon Sep 17 00:00:00 2001 From: mxaddict Date: Fri, 11 Feb 2022 06:21:35 +0800 Subject: [PATCH 5/5] Updated the help text for listtokens rpc command --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c36dded3f..8a5dafa6f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5989,7 +5989,7 @@ 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", "") );