programmingbitcoin
programmingbitcoin copied to clipboard
Chap. 5 p101 : When transaction cache is hit the `testnet` field of the cached tx is assigned again
In the class method fetch of class TxFetcher the line cls.cache[tx_id].testnet = testnet appears outside of the preceding if branch causing an unnecessary reassignment of the field testnet of the transaction when there has been a cache hit (ie. when both fresh and tx_id not in cls.cache equal False). This assignment should only be made if we are entering a new transaction into the cache (ie. a cache miss) or refreshing an existing transaction in the cache due to the fresh parameter being True - ie. when we enter the if branch. Thus the line cls.cache[tx_id].testnet = testnet should be indented one tab to appear within the if branch. This bug does not cause the code to malfunction but fixing it would clarify the code for reading.