From 705e890bb53a55b4272ad1b685936064e2c482cf Mon Sep 17 00:00:00 2001 From: FornaxA Date: Fri, 3 Jul 2020 20:55:52 +0200 Subject: [PATCH 1/5] Correctly set parameter parsing for listtokentransactions and listtokenssinceblock --- src/rpc/client.cpp | 5 +++++ src/tokens/rpctokenwallet.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 790f43714f72..0aae6e93552a 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -84,6 +84,9 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listtransactionrecords", 1, "count" }, { "listtransactionrecords", 2, "skip" }, { "listtransactionrecords", 3, "include_watchonly" }, + { "listtokentransactions", 1, "count" }, + { "listtokentransactions", 2, "skip" }, + { "listtokentransactions", 3, "include_watchonly" }, { "listaccounts", 0, "minconf" }, { "listaccounts", 1, "addlocked" }, { "listaccounts", 2, "include_watchonly" }, @@ -93,6 +96,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "listsinceblock", 1, "target_confirmations" }, { "listsinceblock", 2, "include_watchonly" }, { "listsinceblock", 3, "include_removed" }, + { "listtokenssinceblock", 2, "target_confirmations" }, + { "listtokenssinceblock", 3, "include_watchonly" }, { "sendmany", 1, "amounts" }, { "sendmany", 2, "minconf" }, { "sendmany", 3, "addlocked" }, diff --git a/src/tokens/rpctokenwallet.cpp b/src/tokens/rpctokenwallet.cpp index b3dc0a0e6f96..b63cbd17b8a5 100644 --- a/src/tokens/rpctokenwallet.cpp +++ b/src/tokens/rpctokenwallet.cpp @@ -469,10 +469,13 @@ extern UniValue listtokentransactions(const JSONRPCRequest& request) if (request.fHelp || request.params.size() > 4) throw std::runtime_error( - "listtokentransactions (\"groupid\")\n" + "listtokentransactions (\"groupid\" count skip include_watchonly)\n" "\nReturns transactions for given groupid.\n" "\nArguments:\n" - "1. \"groupid\" (string, required) the token group identifier.\n" + "1. \"groupid\" (string, required) the token group identifier.\n" + "2. count (numeric, optional, default=10) The number of transactions to return\n" + "3. skip (numeric, optional, default=0) The number of transactions to skip\n" + "4. include_watchonly (bool, optional, default=false) Include transactions to watch-only addresses (see 'importaddress')\n" "\nResult:\n" "[\n" " {\n" @@ -520,7 +523,7 @@ extern UniValue listtokentransactions(const JSONRPCRequest& request) unsigned int curparam = 0; std::string strAccount = "*"; - bool fAllGroups; + bool fAllGroups = true; CTokenGroupID grpID; if (request.params.size() > curparam) From 0d5961cdb92d56d4f5fc47eeabd37f2629451a8c Mon Sep 17 00:00:00 2001 From: FornaxA Date: Thu, 30 Jul 2020 22:10:36 +0200 Subject: [PATCH 2/5] Add minimum confirmations option to token balance functions --- src/rpc/client.cpp | 1 + src/tokens/rpctokenwallet.cpp | 13 ++++++++++--- src/tokens/tokengroupwallet.cpp | 8 ++++---- src/tokens/tokengroupwallet.h | 4 ++-- src/wallet/wallet.cpp | 4 ++-- src/wallet/wallet.h | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 0aae6e93552a..081a54aca989 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -65,6 +65,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getbalance", 1, "minconf" }, { "getbalance", 2, "addlocked" }, { "getbalance", 3, "include_watchonly" }, + { "gettokenbalance", 2, "minconf" }, { "getchaintips", 0, "count" }, { "getchaintips", 1, "branchlen" }, { "getblockhash", 0, "height" }, diff --git a/src/tokens/rpctokenwallet.cpp b/src/tokens/rpctokenwallet.cpp index b63cbd17b8a5..31ae3466e0b5 100644 --- a/src/tokens/rpctokenwallet.cpp +++ b/src/tokens/rpctokenwallet.cpp @@ -390,13 +390,14 @@ extern UniValue gettokenbalance(const JSONRPCRequest& request) "\nArguments:\n" "1. \"groupid\" (string, optional) the token group identifier to filter\n" "2. \"address\" (string, optional) the ION address to filter\n" + "3. \"minconf\" (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "\n" "\nExamples:\n" + HelpExampleCli("gettokenbalance", "groupid ionrt1zwm0kzlyptdmwy3849fd6z5epesnjkruqlwlv02u7y6ymf75nk4qs6u85re") + "\n" ); - if (request.params.size() > 2) + if (request.params.size() > 3) { throw std::runtime_error("Invalid number of argument to token balance"); } @@ -407,7 +408,7 @@ extern UniValue gettokenbalance(const JSONRPCRequest& request) { std::unordered_map balances; std::unordered_map authorities; - GetAllGroupBalancesAndAuthorities(pwallet, balances, authorities); + GetAllGroupBalancesAndAuthorities(pwallet, balances, authorities, 1); UniValue ret(UniValue::VARR); for (const auto &item : balances) { @@ -448,9 +449,15 @@ extern UniValue gettokenbalance(const JSONRPCRequest& request) { dst = DecodeDestination(request.params[curparam].get_str(), Params()); } + curparam++; + int nMinDepth = 0; + if (request.params.size() > curparam) + { + nMinDepth = request.params[curparam].get_int(); + } CAmount balance; GroupAuthorityFlags authorities; - GetGroupBalanceAndAuthorities(balance, authorities, grpID, dst, pwallet); + GetGroupBalanceAndAuthorities(balance, authorities, grpID, dst, pwallet, nMinDepth); UniValue retobj(UniValue::VOBJ); retobj.push_back(Pair("groupID", EncodeTokenGroup(grpID))); retobj.push_back(Pair("balance", tokenGroupManager->TokenValueFromAmount(balance, grpID))); diff --git a/src/tokens/tokengroupwallet.cpp b/src/tokens/tokengroupwallet.cpp index d3fb989c949f..0768cc0f0663 100644 --- a/src/tokens/tokengroupwallet.cpp +++ b/src/tokens/tokengroupwallet.cpp @@ -70,7 +70,7 @@ void GetAllGroupBalances(const CWallet *wallet, std::unordered_map &balances, std::unordered_map &authorities) +void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map &balances, std::unordered_map &authorities, const int nMinDepth) { std::vector coins; wallet->FilterCoins(coins, [&balances, &authorities](const CWalletTx *tx, const CTxOut *out) { @@ -87,7 +87,7 @@ void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map } } return false; // I don't want to actually filter anything - }); + }, nMinDepth); } void ListAllGroupAuthorities(const CWallet *wallet, std::vector &coins) { @@ -144,7 +144,7 @@ CAmount GetGroupBalance(const CTokenGroupID &grpID, const CTxDestination &dest, return balance; } -void GetGroupBalanceAndAuthorities(CAmount &balance, GroupAuthorityFlags &authorities, const CTokenGroupID &grpID, const CTxDestination &dest, const CWallet *wallet) +void GetGroupBalanceAndAuthorities(CAmount &balance, GroupAuthorityFlags &authorities, const CTokenGroupID &grpID, const CTxDestination &dest, const CWallet *wallet, const int nMinDepth) { std::vector coins; balance = 0; @@ -178,7 +178,7 @@ void GetGroupBalanceAndAuthorities(CAmount &balance, GroupAuthorityFlags &author } } return false; - }); + }, nMinDepth); } void GetGroupCoins(const CWallet *wallet, std::vector& coins, CAmount& balance, const CTokenGroupID &grpID, const CTxDestination &dest) { diff --git a/src/tokens/tokengroupwallet.h b/src/tokens/tokengroupwallet.h index 89794bfc79b6..20bd83e213ed 100644 --- a/src/tokens/tokengroupwallet.h +++ b/src/tokens/tokengroupwallet.h @@ -21,11 +21,11 @@ CAmount GetGroupBalance(const CTokenGroupID &grpID, const CTxDestination &dest, // Returns a mapping of groupID->balance void GetAllGroupBalances(const CWallet *wallet, std::unordered_map &balances); void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map &balances, - std::unordered_map &authorities); + std::unordered_map &authorities, const int nMinDepth = 0); void ListAllGroupAuthorities(const CWallet *wallet, std::vector &coins); void ListGroupAuthorities(const CWallet *wallet, std::vector &coins, const CTokenGroupID &grpID); void GetGroupBalanceAndAuthorities(CAmount &balance, GroupAuthorityFlags &authorities, const CTokenGroupID &grpID, - const CTxDestination &dest, const CWallet *wallet); + const CTxDestination &dest, const CWallet *wallet, const int nMinDepth = 0); void GetGroupCoins(const CWallet *wallet, std::vector& coins, CAmount& balance, const CTokenGroupID &grpID, const CTxDestination &dest = CNoDestination()); void GetGroupAuthority(const CWallet *wallet, std::vector& coins, GroupAuthorityFlags flags, const CTokenGroupID &grpID, const CTxDestination &dest = CNoDestination()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d0b261d3cded..508c43536193 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2936,7 +2936,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const } unsigned int CWallet::FilterCoins(std::vector &vCoins, - std::function func) const + std::function func, int nMinDepth) const { vCoins.clear(); unsigned int ret = 0; @@ -2955,7 +2955,7 @@ unsigned int CWallet::FilterCoins(std::vector &vCoins, continue; int nDepth = pcoin->GetDepthInMainChain(); - if (nDepth < 0) + if (nDepth < nMinDepth) continue; // We should not consider coins which aren't at least in our mempool diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 8c1c0038fb20..ec9ffefe4505 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -947,7 +947,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface Returns the number of matches. */ unsigned int FilterCoins(std::vector &vCoins, - std::function) const; + std::function, int nMinDepth = 0) const; /** * Return list of available coins and locked coins grouped by non-change output address. From bc59bc5ac86a8d24a9dacc4eda028dabf9e2894f Mon Sep 17 00:00:00 2001 From: FornaxA Date: Thu, 30 Jul 2020 22:10:59 +0200 Subject: [PATCH 3/5] Check if mining manager object has been created when shutting down --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index b2fb076e9694..301ae53845eb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -259,7 +259,7 @@ void PrepareShutdown() pwallet->Flush(false); } #endif - miningManager->GenerateBitcoins(false, 0); + if (miningManager.get() != nullptr) miningManager->GenerateBitcoins(false, 0); MapPort(false); From 512af67b95829e6ad8d71c78b38687d3e671e73d Mon Sep 17 00:00:00 2001 From: FornaxA Date: Thu, 6 Aug 2020 13:36:49 +0200 Subject: [PATCH 4/5] Take zerocoin (deprecated) and unspendable coins into account in coin supply --- src/rpc/blockchain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6072e73bcb56..f5f9eb065fc6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1073,12 +1073,16 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash, ss << hash; ss << VARINT(outputs.begin()->second.nHeight * 4 + outputs.begin()->second.fCoinStake * 2 + outputs.begin()->second.fCoinBase); stats.nTransactions++; + for (const auto output : outputs) { ss << VARINT(output.first + 1); ss << output.second.out.scriptPubKey; ss << VARINT(output.second.out.nValue); stats.nTransactionOutputs++; - stats.nTotalAmount += output.second.out.nValue; + const CScript& script = output.second.out.scriptPubKey; + if (script.size() > 0 && script.size() < MAX_SCRIPT_SIZE && *script.begin() != OP_RETURN && *script.begin() != OP_ZEROCOINMINT) { + stats.nTotalAmount += output.second.out.nValue; + } stats.nBogoSize += 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + 8 /* amount */ + 2 /* scriptPubKey len */ + output.second.out.scriptPubKey.size() /* scriptPubKey */; } From 29295f2ab1c01204ad17f2da0d1ea4cb5756483f Mon Sep 17 00:00:00 2001 From: CkTi Date: Tue, 13 Apr 2021 12:14:39 +0100 Subject: [PATCH 5/5] Add in correct circleci config --- .circleci/config.yml | 38 ++++++++++++++++++++++++++++++++------ .travis/lint_04_install.sh | 6 +++--- .travis/lint_06_script.sh | 2 +- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 68e35d1d1150..436a11e55bd8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: command: | apt-get -y update apt-get -y install python-pip - git clone --depth 1 https://bitbucket.org/ioncoin/ion . + git clone --depth 1 https://github.com/cryptolinux-ion/ion . source .travis/lint_04_install.sh source .travis/lint_05_before_script.sh # LevelDB @@ -26,12 +26,12 @@ jobs: # univalue git remote add -f univalue https://github.com/jgarzik/univalue # snap - git remote add -f snap https://github.com/ioncoincore/ion + #git remote add -f snap https://github.com/ioncoincore/ion git rm -rf src/leveldb git rm -rf src/secp256k1 git rm -rf src/crypto/ctaes git rm -rf src/univalue - git rm -rf snap + #git rm -rf snap git add . git config --global user.email "lint@dev.null" git config --global user.name "Lint Check" @@ -45,7 +45,7 @@ jobs: # univalue git subtree add --prefix src/univalue univalue 9f0b9975925b202ab130714e5422f8dd8bf40ac3 --squash # snap - git subtree add --prefix snap snap snap --squash + #git subtree add --prefix snap snap snap --squash source .travis/lint_06_script.sh x86_64_bionic: docker: @@ -73,6 +73,28 @@ jobs: python3 setup.py install cd - test/functional/test_runner.py + x86_64_focal: + docker: + - image: circleci/buildpack-deps:focal + user: root + environment: + HOST: x86_64-linux-gnu + JOBS: 4 + steps: + - checkout + - run: + command: | + git submodule update --init --recursive + apt-get -y update + apt-get -y install pkg-config autoconf libtool automake bsdmainutils ca-certificates python3 cmake libxkbcommon0 gcc-8 g++-8 libpython3.9-dev python3-distutils + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 + update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 100 + update-alternatives --install /usr/bin/${HOST}-gcc ${HOST}-gcc /usr/bin/${HOST}-gcc-8 100 + update-alternatives --install /usr/bin/${HOST}-g++ ${HOST}-g++ /usr/bin/${HOST}-g++-8 100 + make -j${JOBS} -C depends HOST=${HOST} + ./autogen.sh + ./configure --host=${HOST} --prefix=`pwd`/depends/${HOST} --enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++ + make -j${JOBS} i686_bionic: docker: - image: ioncoin/gitian:latest @@ -118,7 +140,7 @@ jobs: make install cd ../.. ./autogen.sh - ./configure --host=${HOST} --prefix=/ --enable-zmq --with-incompatible-bdb --with-gui=qt5 CPPFLAGS=-DDEBUG_LOCKORDER --disable-hardening --disable-asm + ./configure --host=${HOST} --prefix=/ --enable-zmq --with-incompatible-bdb --with-gui=qt5 CPPFLAGS=-DDEBUG_LOCKORDER --disable-hardening --disable-asm --disable-tests make -j${JOBS} arm32_bionic: docker: @@ -226,7 +248,8 @@ jobs: tar -C `pwd`/depends/SDKs -xJf ./MacOSX10.11.sdk.tar.xz make -j${JOBS} -C depends HOST=${HOST} ./autogen.sh - ./configure --host=${HOST} --prefix=`pwd`/depends/${HOST} --enable-reduce-exports --enable-werror --disable-ccache --disable-maintainer-mode --disable-dependency-tracking + ./configure --host=${HOST} --prefix=`pwd`/depends/${HOST} --enable-reduce-exports --enable-werror --disable-ccache --disable-maintainer-mode --disable-dependency-tracking --disable-bench --disable-gui-tests + make -j${JOBS} snapcraft_build: docker: @@ -249,6 +272,9 @@ workflows: - x86_64_xenial: requires: - lint_all + - x86_64_focal: + requires: + - lint_all - arm32_bionic: requires: - lint_all diff --git a/.travis/lint_04_install.sh b/.travis/lint_04_install.sh index 16b44aeffb9b..2f7d7ff19f91 100755 --- a/.travis/lint_04_install.sh +++ b/.travis/lint_04_install.sh @@ -6,9 +6,9 @@ export LC_ALL=C -pip install codespell==1.13.0 -pip install flake8==3.5.0 -pip install vulture==0.29 +pip2 install codespell==1.13.0 +pip2 install flake8==3.5.0 +pip2 install vulture==0.29 SHELLCHECK_VERSION=v0.6.0 curl -s "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/ diff --git a/.travis/lint_06_script.sh b/.travis/lint_06_script.sh index 127addf345ab..97be7c818313 100755 --- a/.travis/lint_06_script.sh +++ b/.travis/lint_06_script.sh @@ -10,7 +10,7 @@ contrib/devtools/git-subtree-check.sh src/leveldb contrib/devtools/git-subtree-check.sh src/secp256k1 contrib/devtools/git-subtree-check.sh src/crypto/ctaes contrib/devtools/git-subtree-check.sh src/univalue -contrib/devtools/git-subtree-check.sh snap +#contrib/devtools/git-subtree-check.sh snap # Fails with error 10 as not all commands are documented #contrib/devtools/check-doc.py