mirror of
https://github.com/logos-storage/nim-mysticeti.git
synced 2026-05-05 17:39:28 +00:00
Transaction type can be set at compile time
This commit is contained in:
parent
5a9602a9be
commit
6f0035c8fa
@ -35,16 +35,18 @@ export committee.`$`
|
||||
|
||||
import ./mysticeti/blocks
|
||||
|
||||
export blocks.Transaction
|
||||
export blocks.Block
|
||||
export blocks.BlockId
|
||||
export blocks.author
|
||||
export blocks.round
|
||||
export blocks.parents
|
||||
export blocks.id
|
||||
export blocks.SignedBlock
|
||||
export blocks.blck
|
||||
export blocks.signer
|
||||
|
||||
import ./mysticeti/blocks/signed
|
||||
|
||||
export signed.SignedBlock
|
||||
export signed.blck
|
||||
export signed.signer
|
||||
|
||||
import ./mysticeti/dependencies/signing
|
||||
|
||||
@ -57,3 +59,8 @@ export signing.`$`
|
||||
import ./mysticeti/dependencies/hashing
|
||||
|
||||
export hashing.`$`
|
||||
|
||||
import ./mysticeti/dependencies/transacting
|
||||
|
||||
export transacting.Transaction
|
||||
export transacting.`$`
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import ./blocks/transaction
|
||||
import ./blocks/blck
|
||||
import ./blocks/blockid
|
||||
import ./blocks/signed
|
||||
|
||||
export transaction
|
||||
export blck
|
||||
export blockid
|
||||
export signed
|
||||
|
||||
@ -1,21 +1,20 @@
|
||||
import ../basics
|
||||
import ../committee
|
||||
import ./blockid
|
||||
import ./transaction
|
||||
|
||||
type
|
||||
Block*[Dependencies] = object
|
||||
author: CommitteeMember
|
||||
round: uint64
|
||||
parents: seq[BlockId[Dependencies]]
|
||||
transactions: seq[Transaction]
|
||||
transactions: seq[Transaction[Dependencies]]
|
||||
|
||||
func new*[Dependencies](
|
||||
_: type Block[Dependencies];
|
||||
author: CommitteeMember,
|
||||
round: uint64,
|
||||
parents: seq[BlockId[Dependencies]],
|
||||
transactions: seq[Transaction]
|
||||
transactions: seq[Transaction[Dependencies]]
|
||||
): auto =
|
||||
Block[Dependencies](
|
||||
author: author,
|
||||
|
||||
@ -1 +0,0 @@
|
||||
type Transaction* = object
|
||||
@ -1,7 +1,13 @@
|
||||
import ./dependencies/hashing
|
||||
import ./dependencies/signing
|
||||
import ./dependencies/transacting
|
||||
|
||||
export hashing
|
||||
export signing
|
||||
export transacting
|
||||
|
||||
type Dependencies*[Hashing, Signing] = object
|
||||
type Dependencies*[
|
||||
Hashing,
|
||||
Signing,
|
||||
Transacting
|
||||
] = object
|
||||
|
||||
10
mysticeti/dependencies/transacting.nim
Normal file
10
mysticeti/dependencies/transacting.nim
Normal file
@ -0,0 +1,10 @@
|
||||
type
|
||||
Transaction*[Dependencies] = object
|
||||
value: Dependencies.Transacting.Transaction
|
||||
Transacting*[Transaction] = object
|
||||
|
||||
func init*[T: Transaction](_: type T, value: T.Dependencies.Transacting.Transaction): T =
|
||||
T(value: value)
|
||||
|
||||
func `$`*(transaction: Transaction): string =
|
||||
$transaction.value
|
||||
@ -7,8 +7,8 @@ import mysticeti/dependencies
|
||||
proc example*(T: type SomeInteger): T =
|
||||
rand(T)
|
||||
|
||||
proc example*(_: type Transaction): Transaction =
|
||||
discard
|
||||
proc example*(T: type Transaction): T =
|
||||
T.init(T.Dependencies.Transacting.Transaction.example)
|
||||
|
||||
proc example*(T: type Identity): T =
|
||||
T.init()
|
||||
@ -34,7 +34,7 @@ proc example*(
|
||||
round = uint64.example
|
||||
): T =
|
||||
let parents = seq[BlockId[T.Dependencies]].example
|
||||
let transactions = seq[Transaction].example
|
||||
let transactions = seq[Transaction[T.Dependencies]].example
|
||||
T.new(author, round, parents, transactions)
|
||||
|
||||
proc example*(
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
import mysticeti/dependencies
|
||||
import ./mocks/signing
|
||||
import ./mocks/hashing
|
||||
import ./mocks/transacting
|
||||
|
||||
export signing
|
||||
export hashing
|
||||
export transacting
|
||||
|
||||
type MockDependencies* = Dependencies[MockHashing, MockSigning]
|
||||
type MockDependencies* = Dependencies[
|
||||
MockHashing,
|
||||
MockSigning,
|
||||
MockTransacting
|
||||
]
|
||||
|
||||
8
tests/mysticeti/mocks/transacting.nim
Normal file
8
tests/mysticeti/mocks/transacting.nim
Normal file
@ -0,0 +1,8 @@
|
||||
import mysticeti/dependencies/transacting
|
||||
|
||||
type
|
||||
MockTransaction = object
|
||||
MockTransacting* = Transacting[MockTransaction]
|
||||
|
||||
proc example*(_: type MockTransaction): MockTransaction =
|
||||
discard
|
||||
@ -1,6 +1,9 @@
|
||||
import mysticeti
|
||||
import ./basics
|
||||
import ./simulator
|
||||
|
||||
type SignedBlock = mysticeti.SignedBlock[MockDependencies]
|
||||
|
||||
proc scenarioFigure4*(simulator: NetworkSimulator): ?!seq[seq[SignedBlock]] =
|
||||
# replays scenario from figure 4 in the Mysticeti paper
|
||||
# https://arxiv.org/pdf/2310.14821v4
|
||||
|
||||
@ -2,10 +2,11 @@ import ./basics
|
||||
import mysticeti
|
||||
import mysticeti/blocks
|
||||
|
||||
type Validator* = mysticeti.Validator[MockDependencies]
|
||||
type Committee* = mysticeti.Committee[MockDependencies]
|
||||
type Identity* = mysticeti.Identity[MockDependencies]
|
||||
type SignedBlock* = blocks.SignedBlock[MockDependencies]
|
||||
type Validator = mysticeti.Validator[MockDependencies]
|
||||
type Committee = mysticeti.Committee[MockDependencies]
|
||||
type Identity = mysticeti.Identity[MockDependencies]
|
||||
type Transaction = mysticeti.Transaction[MockDependencies]
|
||||
type SignedBlock = blocks.SignedBlock[MockDependencies]
|
||||
|
||||
type NetworkSimulator* = object
|
||||
identities: seq[Identity]
|
||||
|
||||
@ -8,6 +8,7 @@ suite "Blocks":
|
||||
type Block = mysticeti.Block[MockDependencies]
|
||||
type BlockId = mysticeti.BlockId[MockDependencies]
|
||||
type Identity = mysticeti.Identity[MockDependencies]
|
||||
type Transaction = mysticeti.Transaction[MockDependencies]
|
||||
type Hash = hashing.Hash[MockDependencies]
|
||||
|
||||
test "blocks have an author, a round, parents and transactions":
|
||||
|
||||
@ -4,6 +4,7 @@ import mysticeti
|
||||
type Validator = mysticeti.Validator[MockDependencies]
|
||||
type Identity = mysticeti.Identity[MockDependencies]
|
||||
type Committee = mysticeti.Committee[MockDependencies]
|
||||
type Transaction = mysticeti.Transaction[MockDependencies]
|
||||
|
||||
suite "Validator":
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ suite "Validator Network":
|
||||
type Validator = mysticeti.Validator[MockDependencies]
|
||||
type Committee = mysticeti.Committee[MockDependencies]
|
||||
type Identity = mysticeti.Identity[MockDependencies]
|
||||
type Transaction = mysticeti.Transaction[MockDependencies]
|
||||
type Block = blocks.Block[MockDependencies]
|
||||
type BlockId = blocks.BlockId[MockDependencies]
|
||||
type Hash = hashing.Hash[MockDependencies]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user