# Bitcoin Core 0.15 and addrindex

**URL:** <https://forums.counterparty.io/t/bitcoin-core-0-15-and-addrindex/3933>\
**Category:** Development\
**Created:** [October 22, 2017, 1:11pm UTC](https://forums.counterparty.io/t/bitcoin-core-0-15-and-addrindex/3933 "2017-10-22T13:11:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![something](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/something/32/240_2.png) [@something](https://forums.counterparty.io/u/something)\
**Post date:** [October 22, 2017, 1:11pm UTC](https://forums.counterparty.io/t/bitcoin-core-0-15-and-addrindex/3933/1 "2017-10-22T13:11:25Z")

</div>

Just spent some time trying to apply the patch from 0.14 to 0.15, no luck (because no competence).

But here are some things that I forgot and remembered today as I was digging through repos and issues:

- CP doesn’t cache addrindex transactions - [https://github.com/CounterpartyXCP/counterparty-lib/pull/525](https://github.com/CounterpartyXCP/counterparty-lib/pull/525) ([background](https://www.bountysource.com/issues/6995691-jmcorgan-address-index-not-updated-immediately-upon-tx-broadcast))
- Sometimes transactions cannot be found in addrindex - [https://github.com/CounterpartyXCP/counterparty-lib/blob/v9.54.0/counterpartylib/lib/blocks.py#L1208](https://github.com/CounterpartyXCP/counterparty-lib/blob/v9.54.0/counterpartylib/lib/blocks.py#L1208)

Bitcoin Core and addrindex related stuff:

- One of good reasons to use an external index (txindex and addrindex) is that addrindex share Bitcoin Core cache space [1]. Now that the indexes are large, it’s a challenge to cache them without adjusting these parameters. See [issue](https://github.com/btcdrak/bitcoin/issues/10).
- Scripts to report on transaction history and ending balance for a Bitcoin address: [https://github.com/weex/addrindex-balance](https://github.com/weex/addrindex-balance). addrindex doesn’t have this functionality.
- v0.15: GetCoins (which is causing me problems) was removed - [https://github.com/bitcoin/bitcoin/commit/629d75faac84bc0a00533d01dd291a4e6394a51f](https://github.com/bitcoin/bitcoin/commit/629d75faac84bc0a00533d01dd291a4e6394a51f)
- v0.15: GetCoins method was replaced with ModifyCoins - [https://github.com/bitcoin/bitcoin/commit/f28aec014edd29cfc669cf1c3f795c0f1e2ae7e2](https://github.com/bitcoin/bitcoin/commit/f28aec014edd29cfc669cf1c3f795c0f1e2ae7e2) (in [3], this causes problem because GetCoins is gone)

If anybody wants to try:

- Difference between Bitcoin Core 0.13 and addrindex 0.13.0: [https://github.com/bitcoin/bitcoin/compare/0.13...btcdrak:addrindex-0.13](https://github.com/bitcoin/bitcoin/compare/0.13...btcdrak:addrindex-0.13)
- Difference between Bitcoin Core 0.14 and addrindex 0.14.2: [https://github.com/bitcoin/bitcoin/compare/0.14...btcdrak:addrindex-0.14](https://github.com/bitcoin/bitcoin/compare/0.14...btcdrak:addrindex-0.14) (this isn’t a good comparison, I should compare addrindex 0.14.2 vs. Core 0.14.2, but…)
- Difference between Bitcoin Core 0.15 and addrindex 0.14: [https://github.com/bitcoin/bitcoin/compare/0.15...btcdrak:addrindex-0.14](https://github.com/bitcoin/bitcoin/compare/0.15...btcdrak:addrindex-0.14)
- Compared to 0.14, in 0.15 some parts moved to validation.cpp, some to transaction.cpp.
- In some places you need to make slight modifications to the code, e.g. `GetBoolArg` becomes `gArgs.GetBoolArg` (validation.cpp) and `params.size()` becomes `request.params.size()` (rpc/rawtransaction.cpp)
- I had a problem transplanting [https://github.com/btcdrak/bitcoin/blob/addrindex-0.14/src/validation.cpp#L1995](https://github.com/btcdrak/bitcoin/blob/addrindex-0.14/src/validation.cpp#L1995) to 0.15 - I added `#include <boost/foreach.hpp>` to the file ([https://answers.ros.org/question/202155/when-i-use-the-code-copy-from-rosbag-tutorialsthere-some-wrong/](https://answers.ros.org/question/202155/when-i-use-the-code-copy-from-rosbag-tutorialsthere-some-wrong/)) but it didn’t help.
- I can’t get past [3]

[1]

```auto
nBlockTreeDBCache = std::min(nBlockTreeDBCache, ((GetBoolArg("-txindex", DEFAULT_TXINDEX) && GetBoolArg("-addrindex", DEFAULT_ADDRINDEX)) ? nMaxBlockDBAndTxIndexCache : nMaxBlockDBCache) << 20);
nTotalCache -= nBlockTreeDBCache;
int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); // cap total coins db cache
nTotalCache -= nCoinDBCache;
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache

```

[2]

```auto

    UniValue result(UniValue::VARR);
    while (it != setpos.end() && nCount--) {
        //std::string CTransactionRef tx;
        CTransactionRef tx;
        uint256 hashBlock;
        //if (!ReadTransaction(tx, *it, hashBlock))
        // throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Cannot read transaction from disk");
        CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
        ssTx << tx;
        std::string strHex = HexStr(ssTx.begin(), ssTx.end());
        // strHex = HexStr(ssTx.begin(), ssTx.end());
        if (fVerbose) {
            UniValue object(UniValue::VOBJ);
            TxToJSON(*tx, hashBlock, object);
            object.push_back(Pair("hex", strHex));
            result.push_back(object);
        } else {
            result.push_back(strHex);
        }
        it++;
    }

```

[3]

Edit: I am down just to this error (but who knows what other errors are to follow).

```auto
validation.cpp: In function ‘bool ConnectBlock(const CBlock&, CValidationState&, CBlockIndex*, CCoinsViewCache&, const CChainParams&, bool)’:
validation.cpp:1878:21: error: ‘CCoins’ was not declared in this scope
                     CCoins coins;
                     ^
validation.cpp:1879:26: error: ‘class CCoinsViewCache’ has no member named ‘GetCoins’
                     view.GetCoins(txin.prevout.hash, coins);
                          ^
validation.cpp:1879:54: error: ‘coins’ was not declared in this scope
                     view.GetCoins(txin.prevout.hash, coins);
                                                      ^
  CXX libbitcoin_common_a-coins.o
In file included from ./script/script.h:11:0,
                 from primitives/transaction.h:11,
                 from coins.h:9,
                 from validation.h:14,
                 from validation.cpp:6:
./serialize.h: In instantiation of ‘void Unserialize(Stream&, T&) [with Stream = CAutoFile; T = CTransaction]’:
streams.h:553:22: required from ‘CAutoFile& CAutoFile::operator>>(T&) [with T = CTransaction]’
validation.cpp:968:17: required from here
./serialize.h:544:5: error: ‘class CTransaction’ has no member named ‘Unserialize’
     a.Unserialize(is);
     ^

```

---

<div class="post-metadata">

**Author:** ![something](https://yyz2.discourse-cdn.com/flex004/user_avatar/forums.counterparty.io/something/32/240_2.png) [@something](https://forums.counterparty.io/u/something)\
**Post date:** [October 31, 2017, 5:53am UTC](https://forums.counterparty.io/t/bitcoin-core-0-15-and-addrindex/3933/2 "2017-10-31T05:53:46Z")

</div>

The answer to C++ issues:

> <https://github.com/alexmat/bitcoin-addrindex/commit/41e76c48674b832bd7f9021229893eaffacd70ec>
