-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Blockchain | ||
import Codec | ||
import Foundation | ||
import RocksDBSwift | ||
|
||
struct JamCoder<Key: Encodable, Value: Codable>: StoreCoder { | ||
typealias Key = Key | ||
typealias Value = Value | ||
|
||
private let config: ProtocolConfigRef | ||
private let prefix: Data | ||
|
||
init(config: ProtocolConfigRef, prefix: Data = Data()) { | ||
self.config = config | ||
self.prefix = prefix | ||
} | ||
|
||
func encode(key: Key) throws -> Data { | ||
let encoder = JamEncoder(prefix) | ||
try encoder.encode(key) | ||
return encoder.data | ||
} | ||
|
||
func encode(value: Value) throws -> Data { | ||
try JamEncoder.encode(value) | ||
} | ||
|
||
func decode(data: Data) throws -> Value { | ||
try JamDecoder.decode(Value.self, from: data, withConfig: config) | ||
} | ||
} | ||
|
||
struct NoopCoder: StoreCoder { | ||
typealias Key = Data | ||
typealias Value = Data | ||
|
||
func encode(key: Key) throws -> Data { | ||
key | ||
} | ||
|
||
func encode(value: Value) throws -> Data { | ||
value | ||
} | ||
|
||
func decode(data: Data) throws -> Value { | ||
data | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Blockchain | ||
import Foundation | ||
import RocksDBSwift | ||
import Utils | ||
|
||
enum StoreId: UInt8, ColumnFamilyKey { | ||
// metadata and configurations | ||
case meta = 0 | ||
// blocks | ||
// blockHash => blockBody | ||
case blocks = 1 | ||
// timeslot => blockHash | ||
// blockNumber => blockHash | ||
case blockIndexes = 2 | ||
// state trie | ||
// hash => trie node | ||
// value hash => state value | ||
case state = 3 | ||
// ref count | ||
// node hash => ref count | ||
// value hash => ref count | ||
case stateRefs = 4 | ||
} | ||
|
||
enum MetaKey: UInt8 { | ||
case genesisHash = 0 // Data32 | ||
case heads = 1 // Set<Data32> | ||
case finalizedHead = 2 // Data32 | ||
|
||
var key: Data { | ||
Data([rawValue]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters