【发布时间】:2019-08-02 01:49:39
【问题描述】:
RocksDb:每个键有多个值 (c++)
我想做什么
我正在尝试调整我的简单区块链实现以定期将区块链保存到硬盘驱动器,因此我查看了不同的数据库解决方案。我决定使用 RocksDb,因为它易于使用以及良好的文档和示例。我通读了文档,无法弄清楚如何使其适应我的用例。 我有一个班级阻止 `
class Block {
public:
string PrevHash;
private:
blockheader header; // The header of the block
uint32_t index; // height of this block
std::vector<tx_data> transactions; // All transactions in the block in a vector
std::string hash; // The hash of the block
uint64_t timestamp; // The timestamp this block was created by the node
std::string data; // Extra data that can be appended to blocks (for example text or a smart contract)
// - The larger this feild the higher the fee and the max size is defined in config.h
};
其中包含一些变量和一个 struct tx_data 的向量。我想将此数据加载到 RocksDB 数据库中。
我尝试过的
在 google 未能返回使用一个密钥对存储多个值的任何结果后,我决定我必须将每个块数据在开头的 0xa1 中,然后在结尾的 0x2a 中括起来
*0x2a*
header
index
txns
hash
timestamp
data
*0x2a*
但决定肯定有更简单的方法。我尝试查看turtlecoin 使用的代码,一种使用rocksdb 作为其数据库的货币,但那里的代码几乎无法辨认,我听说过序列化,但似乎没有什么信息。
也许我误解了数据库的使用?
【问题讨论】:
标签: c++ blockchain rocksdb