/* * This file is part of the Flowee project * Copyright (C) 2018-2026 Tom Zander * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "BlocksDB.h" #include "UnspentOutputData.h" #include "chain.h" #include #include UnspentOutputData UnspentOutputData::fromUtxoDB(const UnspentOutput &uo) { if (!uo.isValid()) throw std::runtime_error("invalid UnspentOutput"); assert(uo.offsetInBlock() > 80); Blocks::DB *blockDb = Blocks::DB::instance(); auto blockIndex = blockDb->headerChain()[uo.blockHeight()]; if (blockIndex == nullptr) throw std::runtime_error("Invalid blockheight"); auto block = blockDb->loadBlock(blockIndex->GetBlockPos()); if (!block.isFullBlock()) throw std::runtime_error("Missing block"); assert(block.size() > uo.offsetInBlock()); Tx::Iterator iter(block, uo.offsetInBlock()); iter.next(); assert(iter.tag() == Tx::TxVersion); auto prevTxVersion = iter.intData(); auto answer = UnspentOutputData(iter.nextOutput(uo.outIndex())); answer.blockHeight = uo.blockHeight(); answer.isCoinbase = uo.offsetInBlock() < 100; answer.prevTxVersion = prevTxVersion; return answer; }