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

Correct coin supply stats #24

Closed
wants to merge 9 commits into from
38 changes: 32 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/ioncoincore/ion .
source .travis/lint_04_install.sh
source .travis/lint_05_before_script.sh
# LevelDB
Expand All @@ -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 "[email protected]"
git config --global user.name "Lint Check"
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -249,6 +272,9 @@ workflows:
- x86_64_xenial:
requires:
- lint_all
- x86_64_focal:
requires:
- lint_all
- arm32_bionic:
requires:
- lint_all
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void PrepareShutdown()
pwallet->Flush(false);
}
#endif
miningManager->GenerateBitcoins(false, 0);
if (miningManager.get() != nullptr) miningManager->GenerateBitcoins(false, 0);

MapPort(false);

Expand Down
6 changes: 5 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */;
}
Expand Down
6 changes: 6 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -84,6 +85,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" },
Expand All @@ -93,6 +97,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" },
Expand Down
22 changes: 16 additions & 6 deletions src/tokens/rpctokenwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -407,7 +408,7 @@ extern UniValue gettokenbalance(const JSONRPCRequest& request)
{
std::unordered_map<CTokenGroupID, CAmount> balances;
std::unordered_map<CTokenGroupID, GroupAuthorityFlags> authorities;
GetAllGroupBalancesAndAuthorities(pwallet, balances, authorities);
GetAllGroupBalancesAndAuthorities(pwallet, balances, authorities, 1);
UniValue ret(UniValue::VARR);
for (const auto &item : balances)
{
Expand Down Expand Up @@ -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)));
Expand All @@ -469,10 +476,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"
Expand Down Expand Up @@ -520,7 +530,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)
Expand Down
8 changes: 4 additions & 4 deletions src/tokens/tokengroupwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void GetAllGroupBalances(const CWallet *wallet, std::unordered_map<CTokenGroupID
});
}

void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map<CTokenGroupID, CAmount> &balances, std::unordered_map<CTokenGroupID, GroupAuthorityFlags> &authorities)
void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map<CTokenGroupID, CAmount> &balances, std::unordered_map<CTokenGroupID, GroupAuthorityFlags> &authorities, const int nMinDepth)
{
std::vector<COutput> coins;
wallet->FilterCoins(coins, [&balances, &authorities](const CWalletTx *tx, const CTxOut *out) {
Expand All @@ -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<COutput> &coins) {
Expand Down Expand Up @@ -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<COutput> coins;
balance = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ void GetGroupBalanceAndAuthorities(CAmount &balance, GroupAuthorityFlags &author
}
}
return false;
});
}, nMinDepth);
}

void GetGroupCoins(const CWallet *wallet, std::vector<COutput>& coins, CAmount& balance, const CTokenGroupID &grpID, const CTxDestination &dest) {
Expand Down
4 changes: 2 additions & 2 deletions src/tokens/tokengroupwallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<CTokenGroupID, CAmount> &balances);
void GetAllGroupBalancesAndAuthorities(const CWallet *wallet, std::unordered_map<CTokenGroupID, CAmount> &balances,
std::unordered_map<CTokenGroupID, GroupAuthorityFlags> &authorities);
std::unordered_map<CTokenGroupID, GroupAuthorityFlags> &authorities, const int nMinDepth = 0);
void ListAllGroupAuthorities(const CWallet *wallet, std::vector<COutput> &coins);
void ListGroupAuthorities(const CWallet *wallet, std::vector<COutput> &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<COutput>& coins, CAmount& balance, const CTokenGroupID &grpID, const CTxDestination &dest = CNoDestination());
void GetGroupAuthority(const CWallet *wallet, std::vector<COutput>& coins, GroupAuthorityFlags flags, const CTokenGroupID &grpID, const CTxDestination &dest = CNoDestination());
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,7 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
}

unsigned int CWallet::FilterCoins(std::vector<COutput> &vCoins,
std::function<bool(const CWalletTx *, const CTxOut *)> func) const
std::function<bool(const CWalletTx *, const CTxOut *)> func, int nMinDepth) const
{
vCoins.clear();
unsigned int ret = 0;
Expand All @@ -2955,7 +2955,7 @@ unsigned int CWallet::FilterCoins(std::vector<COutput> &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
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
Returns the number of matches.
*/
unsigned int FilterCoins(std::vector<COutput> &vCoins,
std::function<bool(const CWalletTx *, const CTxOut *)>) const;
std::function<bool(const CWalletTx *, const CTxOut *)>, int nMinDepth = 0) const;

/**
* Return list of available coins and locked coins grouped by non-change output address.
Expand Down