2017-09-05 13:44:41 +02:00
|
|
|
/*
|
2017-11-09 19:34:51 +01:00
|
|
|
* This file is part of the Flowee project
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2017,2019 Tom Zander <tom@flowee.org>
|
2017-09-05 13:44:41 +02:00
|
|
|
*
|
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-01-15 15:26:12 +00:00
|
|
|
#ifndef FLOWEE_PRIMITIVES_FASTUNDOBLOCK_H
|
|
|
|
|
#define FLOWEE_PRIMITIVES_FASTUNDOBLOCK_H
|
2017-09-05 13:44:41 +02:00
|
|
|
|
|
|
|
|
#include <streaming/ConstBuffer.h>
|
2018-07-23 18:05:43 +02:00
|
|
|
#include <streaming/MessageParser.h>
|
2017-09-05 13:44:41 +02:00
|
|
|
#include <undo.h>
|
|
|
|
|
|
2018-07-23 18:05:43 +02:00
|
|
|
#include <deque>
|
2017-09-05 13:44:41 +02:00
|
|
|
|
|
|
|
|
class CBlockUndo;
|
|
|
|
|
|
|
|
|
|
class FastUndoBlock
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-07-23 18:05:43 +02:00
|
|
|
struct Item {
|
|
|
|
|
/// Create a new item that was inserted into the UTXO, that when undone will be removed
|
|
|
|
|
Item (const uint256 &prevTxId, int outputIndex)
|
|
|
|
|
: prevTxId(prevTxId), outputIndex(outputIndex) {}
|
|
|
|
|
|
|
|
|
|
/// Create a new item that was deleted from the UTXO, that when undo will be re-inserted.
|
|
|
|
|
Item (const uint256 &prevTxId, int outputIndex, int blockHeight, int offsetInBlock)
|
|
|
|
|
: prevTxId(prevTxId), outputIndex(outputIndex), blockHeight(blockHeight), offsetInBlock(offsetInBlock) {}
|
|
|
|
|
|
|
|
|
|
Item() {}
|
|
|
|
|
|
|
|
|
|
bool isInsert() const {
|
|
|
|
|
return blockHeight == -1;
|
|
|
|
|
}
|
|
|
|
|
bool isValid() const {
|
|
|
|
|
return !prevTxId.IsNull();
|
|
|
|
|
}
|
|
|
|
|
uint256 prevTxId;
|
|
|
|
|
int outputIndex = -1;
|
|
|
|
|
int blockHeight = -1;
|
|
|
|
|
int offsetInBlock = -1;
|
|
|
|
|
};
|
2017-09-05 13:44:41 +02:00
|
|
|
FastUndoBlock(const Streaming::ConstBuffer &rawBlock);
|
|
|
|
|
FastUndoBlock(const FastUndoBlock &other) = default;
|
|
|
|
|
|
|
|
|
|
/// return the total size of this block.
|
|
|
|
|
inline int size() const {
|
|
|
|
|
return m_data.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// \internal
|
|
|
|
|
inline Streaming::ConstBuffer data() const {
|
|
|
|
|
return m_data;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 18:05:43 +02:00
|
|
|
Item nextItem();
|
2019-04-21 21:42:01 +02:00
|
|
|
void restartStream();
|
2018-07-23 18:05:43 +02:00
|
|
|
|
2017-09-05 13:44:41 +02:00
|
|
|
private:
|
|
|
|
|
Streaming::ConstBuffer m_data;
|
2018-07-23 18:05:43 +02:00
|
|
|
Streaming::MessageParser m_parser;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UndoBlockBuilder {
|
|
|
|
|
public:
|
2023-12-21 15:13:56 +01:00
|
|
|
UndoBlockBuilder(const uint256 &blockId, const std::shared_ptr<Streaming::BufferPool> &pool);
|
2018-07-23 18:05:43 +02:00
|
|
|
|
|
|
|
|
void append(const std::deque<FastUndoBlock::Item> &items);
|
|
|
|
|
|
|
|
|
|
std::deque<Streaming::ConstBuffer> finish() const;
|
|
|
|
|
|
|
|
|
|
private:
|
2023-12-21 15:13:56 +01:00
|
|
|
std::shared_ptr<Streaming::BufferPool> m_pool;
|
2018-07-23 18:05:43 +02:00
|
|
|
std::deque<Streaming::ConstBuffer> m_data;
|
2017-09-05 13:44:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|