aboutsummaryrefslogtreecommitdiff
path: root/pkg/blockchain/blockinfodatabase/blockrecord.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/blockchain/blockinfodatabase/blockrecord.go')
-rw-r--r--pkg/blockchain/blockinfodatabase/blockrecord.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/pkg/blockchain/blockinfodatabase/blockrecord.go b/pkg/blockchain/blockinfodatabase/blockrecord.go
new file mode 100644
index 0000000..8f8846a
--- /dev/null
+++ b/pkg/blockchain/blockinfodatabase/blockrecord.go
@@ -0,0 +1,65 @@
+package blockinfodatabase
+
+import (
+ "Chain/pkg/block"
+ "Chain/pkg/pro"
+)
+
+// BlockRecord contains information about where a Block
+// and its UndoBlock are stored on Disk.
+// Header is the Block's Header.
+// Height is the height of the Block.
+// NumberOfTransactions is the number of Transactions in the Block.
+// BlockFile is the name of the file where the Block is stored.
+// BlockStartOffset is the starting offset of the Block within the
+// BlockFile.
+// BlockEndOffset is the ending offset of the Block within
+// the BlockFile.
+// UndoFile is the name of the file where the UndoBlock is stored.
+// UndoStartOffset is the starting offset of the UndoBlock within
+// the UndoFile.
+// UndoEndOffset is the ending offset of the UndoBlock within the
+// UndoFile.
+type BlockRecord struct {
+ Header *block.Header
+ Height uint32
+ NumberOfTransactions uint32
+
+ BlockFile string
+ BlockStartOffset uint32
+ BlockEndOffset uint32
+
+ UndoFile string
+ UndoStartOffset uint32
+ UndoEndOffset uint32
+}
+
+// EncodeBlockRecord returns a pro.BlockRecord given a BlockRecord.
+func EncodeBlockRecord(br *BlockRecord) *pro.BlockRecord {
+ return &pro.BlockRecord{
+ Header: block.EncodeHeader(br.Header),
+ Height: br.Height,
+ NumberOfTransactions: br.NumberOfTransactions,
+ BlockFile: br.BlockFile,
+ BlockStartOffset: br.BlockStartOffset,
+ BlockEndOffset: br.BlockEndOffset,
+ UndoFile: br.UndoFile,
+ UndoStartOffset: br.UndoStartOffset,
+ UndoEndOffset: br.UndoEndOffset,
+ }
+}
+
+// DecodeBlockRecord returns a BlockRecord given a pro.BlockRecord.
+func DecodeBlockRecord(pbr *pro.BlockRecord) *BlockRecord {
+ return &BlockRecord{
+ Header: block.DecodeHeader(pbr.GetHeader()),
+ Height: pbr.GetHeight(),
+ NumberOfTransactions: pbr.GetNumberOfTransactions(),
+ BlockFile: pbr.GetBlockFile(),
+ BlockStartOffset: pbr.GetBlockStartOffset(),
+ BlockEndOffset: pbr.GetBlockEndOffset(),
+ UndoFile: pbr.GetUndoFile(),
+ UndoStartOffset: pbr.GetUndoStartOffset(),
+ UndoEndOffset: pbr.GetUndoEndOffset(),
+ }
+}