mirror of
https://github.com/logos-storage/logos-storage-nim-validator.git
synced 2026-01-03 05:53:06 +00:00
42 lines
1.2 KiB
Nim
42 lines
1.2 KiB
Nim
import pkg/protobuf_serialization
|
|
import ../basics
|
|
import ../hashing
|
|
import ../transaction
|
|
import ../transaction/serialization
|
|
import ./blockid
|
|
import ./blck
|
|
|
|
export protobuf_serialization
|
|
|
|
type BlockIdMessage* {.proto3.} = object
|
|
author* {.fieldNumber: 1, pint.}: uint32
|
|
round* {.fieldNumber: 2, pint.}: uint64
|
|
hash* {.fieldNumber: 3.}: seq[byte]
|
|
|
|
func init*(_: type BlockIdMessage, id: BlockId): BlockIdMessage =
|
|
BlockIdMessage(
|
|
author: id.author.uint32,
|
|
round: id.round,
|
|
hash: @(id.hash.toBytes())
|
|
)
|
|
|
|
func toBytes*(id: BlockId): seq[byte] =
|
|
Protobuf.encode(BlockIdMessage.init(id))
|
|
|
|
type BlockMessage* {.proto3.} = object
|
|
author* {.fieldNumber: 1, pint.}: uint32
|
|
round* {.fieldNumber: 2, pint.}: uint64
|
|
parents* {.fieldNumber: 3.}: seq[BlockIdMessage]
|
|
transactions* {.fieldNumber: 4.}: seq[TransactionMessage]
|
|
|
|
func init*(_: type BlockMessage, blck: Block): BlockMessage =
|
|
BlockMessage(
|
|
author: blck.author.uint32,
|
|
round: blck.round,
|
|
parents: blck.parents.mapIt(BlockIdMessage.init(it)),
|
|
transactions: blck.transactions.mapIt(TransactionMessage.init(it))
|
|
)
|
|
|
|
func toBytes*(blck: Block): seq[byte] =
|
|
Protobuf.encode(BlockMessage.init(blck))
|