Bitcoin Forum
April 28, 2024, 05:12:36 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Bitcoin / Development & Technical Discussion / List all received and sent transactions by address on: September 14, 2021, 01:34:27 PM
The code below (adapted from getreceivedbyaddress() RPC) list all received transactions by an address.

I would like to list all received and sent transactions by an address.

How can this be done ?

Code:
    std::vector<uint256> txids;
    for (const std::pair<const uint256, CWalletTx>& wtx_pair : wallet.mapWallet) {
        const CWalletTx& wtx = wtx_pair.second;
        if (wtx.IsCoinBase() || !wallet.chain().checkFinalTx(*wtx.tx) || wallet.GetTxDepthInMainChain(wtx) < min_depth) {
            continue;
        }

        for (const CTxOut& txout : wtx.tx->vout) {
            CTxDestination address;
            if (ExtractDestination(txout.scriptPubKey, address) && wallet.IsMine(address) && address_set.count(address)) {
                txids.push_back(wtx.GetHash());
            }
        }
    }
2  Bitcoin / Development & Technical Discussion / Re: What is the purpose of CAddrInfo::nRefCount ? on: June 01, 2021, 04:54:29 PM
Can infoExisting.nRefCount > 1 && pinfo->nRefCount == 0 (from code snippet below) also be removed ?

Since infoExisting.nRefCount > 1 will never be true, only infoExisting.IsTerrible() is really being evaluated in the code.

Code:
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
{
         ....
        if (!fInsert) {
            CAddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
            if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {
                // Overwrite the existing new table entry.
                fInsert = true;
            }
        }
        ....
}
3  Bitcoin / Development & Technical Discussion / Re: What is the purpose of CAddrInfo::nRefCount ? on: June 01, 2021, 04:12:21 PM
So, if this field is only going to be 0 or 1 in the current implementation, can the test below be removed from the code ?

ADDRMAN_NEW_BUCKETS_PER_ADDRESS will never be reached.
And the stochastic test makes it harder for the same address to fill multiple entries, something that is impossible today (since the entry is deterministic for each address).

Code:
        
bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
{
         ....
        // do not update if the max reference count is reached
        if (pinfo->nRefCount == ADDRMAN_NEW_BUCKETS_PER_ADDRESS)
            return false;

        // stochastic test: previous nRefCount == N: 2^N times harder to increase it
        int nFactor = 1;
        for (int n = 0; n < pinfo->nRefCount; n++)
            nFactor *= 2;
        if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
            return false;
        ....
}
4  Bitcoin / Development & Technical Discussion / What is the purpose of CAddrInfo::nRefCount ? on: June 01, 2021, 02:38:06 PM
According to the field comment, CAddrInfo::nRefCount represents "reference count in new sets (memory only)".
But since the commit e6b343d880 [1], each address deterministically hashes to a single fixed location in the "new" and "tried" tables.
So the "new" table will always have only one entry with the same address.

Before this commit, the same address could be inserted in multiple entries (at least, 8 entries as defined in ADDRMAN_NEW_BUCKETS_PER_ADDRESS), so it made sense to keep track how many reference to same addresses were in the "new" table.

If the purpose is to know if the address is in "new" or "tried" table, wouldn't a boolean field do the trick ?

[1] https://github.com/bitcoin/bitcoin/commit/e6b343d880f50d52390c5af8623afa15fcbc65a2
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!