mirror of
https://github.com/logos-storage/logos-storage-nim-validator.git
synced 2026-01-03 14:03:07 +00:00
47 lines
1.1 KiB
Nim
47 lines
1.1 KiB
Nim
|
|
import ../basics
|
||
|
|
import ../signatures
|
||
|
|
import ../hashing
|
||
|
|
import ../transaction
|
||
|
|
import ../transaction/deserialization
|
||
|
|
import ./blck
|
||
|
|
import ./blockid
|
||
|
|
import ./serialization
|
||
|
|
|
||
|
|
func init*(
|
||
|
|
_: type BlockId,
|
||
|
|
message: BlockIdMessage
|
||
|
|
): ?!BlockId =
|
||
|
|
success BlockId.init(
|
||
|
|
CommitteeMember(message.author),
|
||
|
|
message.round,
|
||
|
|
? Hash.fromBytes(message.hash)
|
||
|
|
)
|
||
|
|
|
||
|
|
func init*(
|
||
|
|
_: type Block,
|
||
|
|
message: BlockMessage
|
||
|
|
): ?!Block =
|
||
|
|
success Block(
|
||
|
|
author: CommitteeMember(message.author),
|
||
|
|
round: message.round,
|
||
|
|
parents: message.parents.mapIt(? BlockId.init(it)),
|
||
|
|
transactions: message.transactions.mapIt(? Transaction.init(it))
|
||
|
|
)
|
||
|
|
|
||
|
|
func init*(
|
||
|
|
_: type Signed[Block],
|
||
|
|
message: SignedBlockMessage
|
||
|
|
): ?!Signed[Block] =
|
||
|
|
success Signed[Block].init(
|
||
|
|
? Block.init(message.blck),
|
||
|
|
? Identifier.fromBytes(message.signer),
|
||
|
|
? Signature.fromBytes(message.signature)
|
||
|
|
)
|
||
|
|
|
||
|
|
func fromBytes*(
|
||
|
|
_: type Signed[Block],
|
||
|
|
bytes: openArray[byte]
|
||
|
|
): ?!Signed[Block] =
|
||
|
|
let message = ? Protobuf.decode(bytes, SignedBlockMessage).catch()
|
||
|
|
Signed[Block].init(message)
|