Skip to content

Commit

Permalink
dummy run
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc committed Jun 19, 2024
1 parent 6b02994 commit 1ef063b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Blockchain/Sources/Blockchain/Types/SafroleState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public struct SafroleState {
extension SafroleState: Dummy {
public static var dummy: SafroleState {
SafroleState(
pendingValidators: [],
pendingValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy),
epochRoot: BandersnatchRingVRFRoot(),
slotSealerSeries: .left([]),
slotSealerSeries: .right(FixedSizeArray(defaultValue: BandersnatchPublicKey())),
ticketAccumulator: []
)
}
Expand Down
12 changes: 6 additions & 6 deletions Blockchain/Sources/Blockchain/Types/State.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,17 @@ public typealias StateRef = Ref<State>
extension State: Dummy {
public static var dummy: State {
State(
coreAuthorizationPool: [],
coreAuthorizationPool: FixedSizeArray(defaultValue: []),
lastBlock: Block.dummy,
safroleState: SafroleState.dummy,
serviceAccounts: [:],
entropyPool: (H256(), H256(), H256(), H256()),
validatorQueue: [],
currentValidators: [],
previousValidators: [],
reports: [],
validatorQueue: FixedSizeArray(defaultValue: ValidatorKey.dummy),
currentValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy),
previousValidators: FixedSizeArray(defaultValue: ValidatorKey.dummy),
reports: FixedSizeArray(defaultValue: nil),
timestamp: 0,
authorizationQueue: [],
authorizationQueue: FixedSizeArray(defaultValue: FixedSizeArray(defaultValue: H256())),
privilegedServiceIndices: (
empower: ServiceIdentifier(),
assign: ServiceIdentifier(),
Expand Down
47 changes: 46 additions & 1 deletion Boka/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
{
"originHash" : "c2c4ac49ab6304f22b8cf4828c0252cd6132c8f70c5f448a10f35a165e73f638",
"originHash" : "bd44440d7f85d30386716bbd2cc933f21b5ebbc0e75fbfc91dc6a138b6c8ce43",
"pins" : [
{
"identity" : "async-channels",
"kind" : "remoteSourceControl",
"location" : "https://github.com/gh123man/Async-Channels",
"state" : {
"branch" : "679ee7d",
"revision" : "679ee7d35e493e181be844dadbe78636cefaace4"
}
},
{
"identity" : "scalecodec.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tesseract-one/ScaleCodec.swift.git",
"state" : {
"revision" : "af241cfa8491ac0312ff89ff0389c09879d41a74",
"version" : "0.3.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
Expand All @@ -9,6 +27,33 @@
"revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b",
"version" : "1.4.0"
}
},
{
"identity" : "swift-async-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-async-algorithms",
"state" : {
"revision" : "6ae9a051f76b81cc668305ceed5b0e0a7fd93d20",
"version" : "1.0.1"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
}
},
{
"identity" : "tuples.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/tesseract-one/Tuples.swift.git",
"state" : {
"revision" : "4d2cf7c64443cdf4df833d0bedd767bf9dbc49d9",
"version" : "0.1.3"
}
}
],
"version" : 3
Expand Down
2 changes: 2 additions & 0 deletions Boka/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let package = Package(
.macOS(.v14),
],
dependencies: [
.package(path: "../Node"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.4.0"),
],
targets: [
Expand All @@ -17,6 +18,7 @@ let package = Package(
.executableTarget(
name: "Boka",
dependencies: [
"Node",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
Expand Down
4 changes: 3 additions & 1 deletion Boka/Sources/Boka.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// https://swiftpackageindex.com/apple/swift-argument-parser/documentation

import ArgumentParser
import Node

@main
struct Boka: ParsableCommand {
mutating func run() throws {
print("Hello, world!")
let node = try Node(genesis: .dev)
node.sayHello()
}
}
4 changes: 2 additions & 2 deletions Node/Sources/Node/Genesis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public enum Genesis {
}

public extension Genesis {
func toState() -> StateRef {
func toState() throws -> StateRef {
switch self {
case .file:
fatalError("TODO: not implemented")
case .dev:
fatalError("TODO: not implemented")
StateRef.dummy
}
}
}
5 changes: 3 additions & 2 deletions Node/Sources/Node/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import Blockchain
public class Node {
public private(set) var blockchain: Blockchain

public init(genesis: StateRef) {
blockchain = Blockchain(heads: [genesis], finalizedHead: genesis)
public init(genesis: Genesis) throws {
let genesisState = try genesis.toState()
blockchain = Blockchain(heads: [genesisState], finalizedHead: genesisState)
}

public func sayHello() {
Expand Down
2 changes: 1 addition & 1 deletion Utils/Sources/Utils/LimitedSizeArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public struct LimitedSizeArray<T, TMinLength: ConstInt, TMaxLength: ConstInt> {

private func validate() {
assert(array.count >= Self.minLength)
assert(array.count < Self.maxLength)
assert(array.count <= Self.maxLength)
}
}

Expand Down
10 changes: 8 additions & 2 deletions Utils/Sources/Utils/Ref.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
public class Ref<T> {
public final class Ref<T> {
public let value: T

public init(_ value: T) {
self.value = value
}
}

public class RefMut<T> {
public final class RefMut<T> {
public var value: T

public init(_ value: T) {
Expand All @@ -29,3 +29,9 @@ extension Ref: Hashable where T: Hashable {
hasher.combine(value)
}
}

extension Ref: Dummy where T: Dummy {
public static var dummy: Ref<T> {
Ref(T.dummy)
}
}

0 comments on commit 1ef063b

Please sign in to comment.