| 834 | |
| 835 | template <typename ParseTag> |
| 836 | std::vector<blocksci::RawBlock> BlockProcessor::addNewBlocks(const ParserConfiguration<ParseTag> &config, std::vector<BlockInfo<ParseTag>> blocks, UTXOState &utxoState, UTXOAddressState &utxoAddressState, AddressState &addressState, UTXOScriptState &utxoScriptState) { |
| 837 | |
| 838 | AddressWriter addressWriter{config}; |
| 839 | IndexedFileWriter<1> txFile(blocksci::ChainAccess::txFilePath(config.dataConfig.chainDirectory())); |
| 840 | FixedSizeFileWriter<OutputLinkData> linkDataFile(config.txUpdatesFilePath()); |
| 841 | FixedSizeFileWriter<blocksci::uint256> txHashFile{blocksci::ChainAccess::txHashesFilePath(config.dataConfig.chainDirectory())}; |
| 842 | |
| 843 | auto discardFunc = [](RawTransaction &) { return false; }; |
| 844 | |
| 845 | auto progressBar = blocksci::makeProgressBar(totalTxCount, [=](RawTransaction &tx) { |
| 846 | std::cout << ", Block " << tx.blockHeight << "/" << maxBlockHeight; |
| 847 | }); |
| 848 | |
| 849 | /* Advance function of the last step |
| 850 | * Optimization: Only push tx to finished_transaction_queue if it meets certain conditions, otherwise de-allocate it */ |
| 851 | |
| 852 | auto serializeAddressDiscardFunc = [&](RawTransaction &tx) { |
| 853 | progressBar.update(tx.txNum - startingTxCount, tx); |
| 854 | return tx.realSize >= 800; |
| 855 | }; |
| 856 | |
| 857 | // Definition of all ProcessStep objects for the processing pipeline |
| 858 | ProcessStepQueue processQueue; |
| 859 | |
| 860 | // 0. Step: Calculate hash of transaction and write it to the hash file (chain/tx_hashes.dat) |
| 861 | processQueue.addStep(makeStandardProcessStep(std::make_unique<CalculateTxHashStep>(txHashFile), discardFunc, discardFunc)); |
| 862 | |
| 863 | // 1. Step: Parse the output scripts (into CScriptView) of the transaction in order to identify address types and extract relevant information. |
| 864 | processQueue.addStep(makeStandardProcessStep(std::make_unique<GenerateScriptOutputsStep>(), discardFunc, discardFunc)); |
| 865 | |
| 866 | // 2. Step: Store information about the spent output with each input of the transaction. Then store information about each output for future lookup. |
| 867 | processQueue.addStep(makeStandardProcessStep(std::make_unique<ConnectUTXOsStep>(utxoState), discardFunc, discardFunc)); |
| 868 | |
| 869 | /* 3. Step: Parse the input script of each input based information about the associated output script. |
| 870 | * Then store information about each output address for future lookup. */ |
| 871 | processQueue.addStep(makeStandardProcessStep(std::make_unique<GenerateScriptInputStep>(utxoAddressState), discardFunc, discardFunc)); |
| 872 | |
| 873 | /* 4. Step: Attach a scriptNum to each script in the transaction. For address types which are |
| 874 | deduplicated (Pubkey, ScriptHash, Multisig and their varients) use the previously allocated |
| 875 | scriptNum if the address was seen before. Increment the scriptNum counter for newly seen addresses. */ |
| 876 | processQueue.addStep(makeStandardProcessStep(std::make_unique<ProcessAddressesStep>(addressState), discardFunc, discardFunc)); |
| 877 | |
| 878 | /* 5. Step: Record the scriptNum for each output for later reference. Assign each spent input with |
| 879 | the scriptNum of the output its spending */ |
| 880 | processQueue.addStep(makeStandardProcessStep(std::make_unique<RecordAddressesStep>(utxoScriptState), discardFunc, discardFunc)); |
| 881 | |
| 882 | // 6. Step: Serialize transaction data, inputs, and outputs and write them to the txFile |
| 883 | processQueue.addStep(makeStandardProcessStep(std::make_unique<SerializeTransactionStep>(txFile, linkDataFile), discardFunc, discardFunc)); |
| 884 | |
| 885 | // 7. Step: Save address data into files for the analysis library |
| 886 | processQueue.addStep(makeStandardProcessStep(std::make_unique<SerializeAddressesStep>(addressWriter), discardFunc, serializeAddressDiscardFunc, false, true)); |
| 887 | |
| 888 | // Two hold stages for ATOR |
| 889 | processQueue.addStep(makeHoldTxStep()); // 8 |
| 890 | processQueue.addStep(makeHoldTxStep()); // 9 |
| 891 | |
| 892 | processQueue.setStepOrder({ |
| 893 | {0, 0}, // calculate tx hash |
no test coverage detected