serial: Bring it back home

This commit is contained in:
x
2026-01-01 19:24:00 +00:00
parent 286dac213c
commit ed9be657ab
47 changed files with 430 additions and 170 deletions

29
Cargo.lock generated
View File

@@ -483,17 +483,6 @@ dependencies = [
"rustix", "rustix",
] ]
[[package]]
name = "async-recursion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.111",
]
[[package]] [[package]]
name = "async-signal" name = "async-signal"
version = "0.2.13" version = "0.2.13"
@@ -1800,15 +1789,12 @@ name = "darkfi"
version = "0.5.0" version = "0.5.0"
dependencies = [ dependencies = [
"arti-client", "arti-client",
"async-recursion",
"async-trait", "async-trait",
"blake3", "blake3",
"bs58", "bs58",
"chrono",
"clap 4.5.53", "clap 4.5.53",
"criterion 0.8.1", "criterion 0.8.1",
"crypto_api_chachapoly", "crypto_api_chachapoly",
"darkfi-derive",
"darkfi-sdk", "darkfi-sdk",
"darkfi-serial", "darkfi-serial",
"easy-parallel", "easy-parallel",
@@ -1831,7 +1817,6 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"randomx", "randomx",
"rcgen", "rcgen",
"regex",
"semver", "semver",
"serde", "serde",
"sha2", "sha2",
@@ -1881,8 +1866,6 @@ dependencies = [
[[package]] [[package]]
name = "darkfi-derive" name = "darkfi-derive"
version = "0.5.1" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8ae0dcfc7efc650d952d13559a549c93108a912a32e9242c1fe9527bb865429"
dependencies = [ dependencies = [
"darkfi-derive-internal", "darkfi-derive-internal",
"proc-macro-crate", "proc-macro-crate",
@@ -1894,8 +1877,6 @@ dependencies = [
[[package]] [[package]]
name = "darkfi-derive-internal" name = "darkfi-derive-internal"
version = "0.5.1" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "024e68bb1f1a0363368ed824bd9dd8a67176d00b47ea5aafe1185a1fe4986110"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1948,8 +1929,6 @@ dependencies = [
[[package]] [[package]]
name = "darkfi-serial" name = "darkfi-serial"
version = "0.5.1" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf58eb094bebe226ea473d6d35d8af074a97f7a7eeb9e485b124638448a0ad05"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"blake3", "blake3",
@@ -1959,6 +1938,7 @@ dependencies = [
"num-bigint", "num-bigint",
"pasta_curves", "pasta_curves",
"semver", "semver",
"sled-overlay",
"url", "url",
] ]
@@ -5691,7 +5671,7 @@ dependencies = [
[[package]] [[package]]
name = "randomx" name = "randomx"
version = "1.2.1" version = "1.2.1"
source = "git+https://codeberg.org/darkrenaissance/RandomX#0e31d5a23983164a171276dea7bea94dc58ca8ed" source = "git+https://codeberg.org/darkrenaissance/RandomX?rev=0e31d5a#0e31d5a23983164a171276dea7bea94dc58ca8ed"
dependencies = [ dependencies = [
"bindgen 0.72.1", "bindgen 0.72.1",
"bitflags 2.10.0", "bitflags 2.10.0",
@@ -6555,11 +6535,10 @@ dependencies = [
[[package]] [[package]]
name = "sled-overlay" name = "sled-overlay"
version = "0.1.14" version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd5d8153cababba322b8d9a3815c25b9f1e5cd78e72c81e8004a1ad78a69122c" checksum = "f84cfae62f52cad8adbf36565bd86225f8e432b2cb1be2db7cb21567b2063e01"
dependencies = [ dependencies = [
"darkfi-serial",
"sled", "sled",
] ]

View File

@@ -13,11 +13,6 @@ name = "darkfi"
doctest = false doctest = false
bench = false bench = false
#[profile.release]
#debug = true
#lto = "fat"
#codegen-units = 1
[workspace] [workspace]
members = [ members = [
"bin/zkas", "bin/zkas",
@@ -29,7 +24,6 @@ members = [
"bin/genev/genevd", "bin/genev/genevd",
"bin/genev/genev-cli", "bin/genev/genev-cli",
"bin/darkirc", "bin/darkirc",
#"bin/darkwallet",
"bin/tau/taud", "bin/tau/taud",
"bin/vanityaddr", "bin/vanityaddr",
"bin/lilith", "bin/lilith",
@@ -37,9 +31,9 @@ members = [
"src/sdk", "src/sdk",
"src/sdk/python", "src/sdk/python",
#"src/serial", "src/serial",
#"src/serial/derive", "src/serial/derive",
#"src/serial/derive-internal", "src/serial/derive-internal",
"src/contract/test-harness", "src/contract/test-harness",
"src/contract/money", "src/contract/money",
@@ -56,7 +50,6 @@ thiserror = "2.0.17"
tracing = "0.1.44" tracing = "0.1.44"
# async-runtime # async-runtime
async-recursion = {version = "1.1.1", optional = true}
async-trait = {version = "0.1.89", optional = true} async-trait = {version = "0.1.89", optional = true}
futures = {version = "0.3.31", optional = true} futures = {version = "0.3.31", optional = true}
smol = {version = "2.0.2", optional = true} smol = {version = "2.0.2", optional = true}
@@ -93,24 +86,17 @@ structopt-toml = {version= "0.5.1", optional = true}
toml = {version = "0.9.8", optional = true} toml = {version = "0.9.8", optional = true}
# Utilities # Utilities
#darkfi-serial = {path = "src/serial", optional = true} darkfi-serial = {path = "src/serial", optional = true}
#darkfi-derive = {path = "src/serial/derive", optional = true}
darkfi-serial = {version = "0.5.1", optional = true}
darkfi-derive = {version = "0.5.1", optional = true}
# TODO: check chrono usage and impl our own
chrono = {version = "0.4.42", optional = true}
lazy_static = {version = "1.5.0", optional = true} lazy_static = {version = "1.5.0", optional = true}
num-bigint = {version = "0.4.6", optional = true} num-bigint = {version = "0.4.6", optional = true}
url = {version = "2.5.7", features = ["serde"], optional = true} url = {version = "2.5.7", features = ["serde"], optional = true}
# Misc # Misc
regex = {version = "1.12.2", optional = true}
tracing-subscriber = { version = "0.3.22", default-features = false, features = ["fmt"], optional = true } tracing-subscriber = { version = "0.3.22", default-features = false, features = ["fmt"], optional = true }
tracing-appender = {version = "0.2.4", optional = true } tracing-appender = {version = "0.2.4", optional = true }
nu-ansi-term = {version = "0.50.3", optional = true} nu-ansi-term = {version = "0.50.3", optional = true}
# Crypto # Crypto
rand = {version = "0.8.5", optional = true} rand = {version = "0.8.5", optional = true}
blake3 = {version = "1.8.2", features = ["rayon"], optional = true} blake3 = {version = "1.8.2", features = ["rayon"], optional = true}
@@ -126,10 +112,10 @@ wasmer-compiler-singlepass = {version = "6.1.0", optional = true}
wasmer-middlewares = {version = "6.1.0", optional = true} wasmer-middlewares = {version = "6.1.0", optional = true}
# Blockchain store # Blockchain store
sled-overlay = {version = "0.1.14", optional = true} sled-overlay = {version = "0.1.15", optional = true}
# Miner # Miner
randomx = {git = "https://codeberg.org/darkrenaissance/RandomX", optional = true} randomx = {git = "https://codeberg.org/darkrenaissance/RandomX", rev = "0e31d5a", optional = true}
monero = {version = "0.21.0", optional = true} monero = {version = "0.21.0", optional = true}
tiny-keccak = { version = "2.0.2", features = ["keccak"], optional = true } tiny-keccak = { version = "2.0.2", features = ["keccak"], optional = true }
@@ -141,7 +127,7 @@ plotters = "0.3.7"
easy-parallel = "3.3.1" easy-parallel = "3.3.1"
prettytable-rs = "0.10.0" prettytable-rs = "0.10.0"
# Used for benchmarks # Used for benchmarks
criterion = { version = "0.8.1", features = ["html_reports"] } criterion = {version = "0.8.1", features = ["html_reports"]}
# -----BEGIN LIBRARY FEATURES----- # -----BEGIN LIBRARY FEATURES-----
[features] [features]
@@ -156,7 +142,7 @@ async-sdk = [
] ]
blockchain = [ blockchain = [
"sled-overlay/serial", "sled-overlay",
"monero", "monero",
"num-bigint", "num-bigint",
"primitive-types", "primitive-types",
@@ -164,6 +150,7 @@ blockchain = [
"tiny-keccak", "tiny-keccak",
"darkfi-serial/num-bigint", "darkfi-serial/num-bigint",
"darkfi-serial/sled-overlay",
"tx", "tx",
"util", "util",
@@ -222,7 +209,6 @@ net-defaults = [
"futures", "futures",
"futures-rustls", "futures-rustls",
"rcgen", "rcgen",
"regex",
"semver", "semver",
"serde", "serde",
"socket2", "socket2",
@@ -240,6 +226,8 @@ net-defaults = [
"p2p-tor", "p2p-tor",
#"p2p-nym", #"p2p-nym",
"p2p-i2p", "p2p-i2p",
"p2p-socks5",
"p2p-unix",
] ]
p2p-unix = [] p2p-unix = []
@@ -268,7 +256,6 @@ system = [
tx = [ tx = [
"blake3", "blake3",
"rand",
"async-sdk", "async-sdk",
"async-serial", "async-serial",
@@ -322,14 +309,6 @@ dht = [
"darkfi-serial", "darkfi-serial",
"net", "net",
] ]
# Could not get this to work. Complains manifest-key is ignored.
#[target.'cfg(target_family = "unix")'.features]
#net = ["net-defaults", "p2p-unix"]
#
#[target.'cfg(target_family = "windows")'.features]
#net = ["net-defaults"]
# -----END LIBRARY FEATURES----- # -----END LIBRARY FEATURES-----
[patch.crates-io] [patch.crates-io]

View File

@@ -28,7 +28,7 @@ glam = "0.30.9"
zeromq = { version = "0.4.1", default-features = false, features = ["async-std-runtime", "all-transport"] } zeromq = { version = "0.4.1", default-features = false, features = ["async-std-runtime", "all-transport"] }
darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "net", "util", "system", "zk"]} darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "net", "util", "system", "zk"]}
#darkfi-sdk = {path = "../../src/sdk", features = ["async"]} #darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
darkfi-serial = {version = "0.5.0", features = ["async"]} darkfi-serial = {path = "../../src/serial", features = ["async"]}
fud = { path = "../fud/fud/" } fud = { path = "../fud/fud/" }
bs58 = "0.5.1" bs58 = "0.5.1"
thiserror = "2.0.17" thiserror = "2.0.17"
@@ -43,7 +43,7 @@ futures = "0.3.31"
async-recursion = "1.1.1" async-recursion = "1.1.1"
colored = "3.0.0" colored = "3.0.0"
#rustpython-vm = "0.3.1" #rustpython-vm = "0.3.1"
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
url = "2.5.7" url = "2.5.7"
semver = "1.0.27" semver = "1.0.27"
chrono = "0.4.42" chrono = "0.4.42"

View File

@@ -14,7 +14,7 @@ darkfi = {path = "../../", features = ["async-daemonize", "bs58"]}
darkfi_money_contract = {path = "../../src/contract/money"} darkfi_money_contract = {path = "../../src/contract/money"}
darkfi-contract-test-harness = {path = "../../src/contract/test-harness"} darkfi-contract-test-harness = {path = "../../src/contract/test-harness"}
darkfi-sdk = {path = "../../src/sdk"} darkfi-sdk = {path = "../../src/sdk"}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../src/serial"}
# Misc # Misc
blake3 = "1.8.2" blake3 = "1.8.2"
@@ -22,7 +22,7 @@ bs58 = "0.5.1"
tracing = "0.1.44" tracing = "0.1.44"
num-bigint = "0.4.6" num-bigint = "0.4.6"
rand = "0.8.5" rand = "0.8.5"
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
toml = "0.9.8" toml = "0.9.8"
# JSON-RPC # JSON-RPC

View File

@@ -20,11 +20,11 @@ path = "src/main.rs"
[dependencies] [dependencies]
darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "rpc", "zk"]} darkfi = {path = "../../", features = ["async-daemonize", "event-graph", "rpc", "zk"]}
darkfi-sdk = {path = "../../src/sdk", features = ["async"]} darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
darkfi-serial = {version = "0.5.0", features = ["async"]} darkfi-serial = {path = "../../src/serial", features = ["async"]}
libc = "0.2.178" libc = "0.2.178"
# Event Graph DB # Event Graph DB
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# TLS # TLS
async-trait = "0.1.89" async-trait = "0.1.89"

View File

@@ -15,7 +15,7 @@ darkfi_money_contract = {path = "../../src/contract/money", features = ["no-entr
darkfi_dao_contract = {path = "../../src/contract/dao", features = ["no-entrypoint", "client"]} darkfi_dao_contract = {path = "../../src/contract/dao", features = ["no-entrypoint", "client"]}
darkfi_deployooor_contract = {path = "../../src/contract/deployooor", features = ["no-entrypoint", "client"]} darkfi_deployooor_contract = {path = "../../src/contract/deployooor", features = ["no-entrypoint", "client"]}
darkfi-sdk = {path = "../../src/sdk", features = ["async"]} darkfi-sdk = {path = "../../src/sdk", features = ["async"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../src/serial"}
# Misc # Misc
blake3 = "1.8.2" blake3 = "1.8.2"
@@ -29,7 +29,7 @@ prettytable-rs = "0.10.0"
rand = "0.8.5" rand = "0.8.5"
rodio = {version = "0.21.1", default-features = false, features = ["playback", "mp3"]} rodio = {version = "0.21.1", default-features = false, features = ["playback", "mp3"]}
rusqlite = {version = "0.37.0", features = ["sqlcipher"]} rusqlite = {version = "0.37.0", features = ["sqlcipher"]}
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
toml = "0.9.8" toml = "0.9.8"
tracing = "0.1.44" tracing = "0.1.44"
url = "2.5.7" url = "2.5.7"

View File

@@ -11,7 +11,7 @@ edition = "2021"
# Darkfi # Darkfi
darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]} darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]}
darkfi-sdk = {path = "../../../src/sdk"} darkfi-sdk = {path = "../../../src/sdk"}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# JSON-RPC # JSON-RPC
async-trait = "0.1.89" async-trait = "0.1.89"
@@ -32,7 +32,7 @@ structopt = "0.3.26"
structopt-toml = "0.5.1" structopt-toml = "0.5.1"
# Database # Database
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# Misc # Misc
blake3 = "1.8.2" blake3 = "1.8.2"

View File

@@ -19,7 +19,7 @@ path = "src/main.rs"
[dependencies] [dependencies]
darkfi = {path = "../../../", features = ["async-daemonize", "geode", "rpc", "dht", "sled-overlay"]} darkfi = {path = "../../../", features = ["async-daemonize", "geode", "rpc", "dht", "sled-overlay"]}
darkfi-sdk = {path = "../../../src/sdk"} darkfi-sdk = {path = "../../../src/sdk"}
darkfi-serial = {version = "0.5.0", features = ["hash"]} darkfi-serial = {path = "../../../src/serial", features = ["hash"]}
# Encoding # Encoding
bs58 = "0.5.1" bs58 = "0.5.1"
@@ -48,7 +48,7 @@ blake2 = "0.10.6"
equix = "0.5.1" equix = "0.5.1"
# Database # Database
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# Argument parsing # Argument parsing
serde = {version = "1.0.228", features = ["derive"]} serde = {version = "1.0.228", features = ["derive"]}

View File

@@ -12,7 +12,7 @@ repository = "https://codeberg.org/darkrenaissance/darkfi"
genevd = {path = "../genevd"} genevd = {path = "../genevd"}
darkfi = {path = "../../../", features = ["event-graph", "rpc", "bs58"]} darkfi = {path = "../../../", features = ["event-graph", "rpc", "bs58"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
smol = "2.0.2" smol = "2.0.2"
clap = {version = "4.4.11", features = ["derive"]} clap = {version = "4.4.11", features = ["derive"]}

View File

@@ -22,13 +22,13 @@ darkfi = { path = "../../../", features = [
"event-graph", "event-graph",
"rpc", "rpc",
] } ] }
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# Crypto # Crypto
blake3 = "1.8.2" blake3 = "1.8.2"
# Event Graph DB # Event Graph DB
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# Misc # Misc
async-trait = "0.1.89" async-trait = "0.1.89"

View File

@@ -25,10 +25,10 @@ darkfi = { path = "../../../", features = [
] } ] }
darkfi-sdk = {path = "../../../src/sdk", features = ["async"]} darkfi-sdk = {path = "../../../src/sdk", features = ["async"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# Event Graph DB # Event Graph DB
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# Crypto # Crypto
blake3 = "1.8.2" blake3 = "1.8.2"

View File

@@ -12,7 +12,7 @@ edition = "2021"
[dependencies] [dependencies]
# ANCHOR: darkfi # ANCHOR: darkfi
darkfi = {path = "../../../", features = ["toml", "async-daemonize", "rpc"]} darkfi = {path = "../../../", features = ["toml", "async-daemonize", "rpc"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# ANCHOR_END: darkfi # ANCHOR_END: darkfi
# daemon # daemon

View File

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
darkfi-sdk = { path = "../../src/sdk", features = ["wasm"] } darkfi-sdk = { path = "../../src/sdk", features = ["wasm"] }
darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] } darkfi-serial = { path = "../../src/serial", features = ["derive", "crypto"] }
# We need to disable random using "custom" which makes the crate a noop # We need to disable random using "custom" which makes the crate a noop
# so the wasm32-unknown-unknown target is enabled. # so the wasm32-unknown-unknown target is enabled.

View File

@@ -16,7 +16,7 @@ wasm_hello_world = {path = "../", features = [ "client" ]}
# Darkfi # Darkfi
darkfi = {path = "../../../", features = ["tx", "rpc"]} darkfi = {path = "../../../", features = ["tx", "rpc"]}
darkfi-sdk = {path = "../../../src/sdk"} darkfi-sdk = {path = "../../../src/sdk"}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# Misc # Misc
clap = {version = "4.4.11", features = ["derive"]} clap = {version = "4.4.11", features = ["derive"]}

View File

@@ -23,10 +23,10 @@ path = "example/send.rs"
[dependencies] [dependencies]
darkfi = {path = "../../", features = ["event-graph"]} darkfi = {path = "../../", features = ["event-graph"]}
darkfi-serial = {version = "0.5.0", features = ["async"]} darkfi-serial = {path = "../../src/serial", features = ["async"]}
# Event Graph DB # Event Graph DB
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
# Crypto # Crypto
blake3 = "1.8.2" blake3 = "1.8.2"

View File

@@ -10,7 +10,7 @@ edition = "2021"
[dependencies] [dependencies]
darkfi = {path = "../../", features = ["net"]} darkfi = {path = "../../", features = ["net"]}
darkfi-serial = {version = "0.5.0"} darkfi-serial = {path = "../../src/serial"}
url = {version = "2.5.7", features = ["serde"]} url = {version = "2.5.7", features = ["serde"]}
smol = "2.0.2" smol = "2.0.2"

View File

@@ -1 +0,0 @@
keys

View File

@@ -12,7 +12,7 @@ edition = "2021"
[dependencies] [dependencies]
# Darkfi # Darkfi
darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]} darkfi = {path = "../../../", features = ["async-daemonize", "validator", "rpc"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../src/serial"}
# Misc # Misc
tracing = "0.1.44" tracing = "0.1.44"

View File

@@ -12,7 +12,7 @@ edition = "2021"
[dependencies] [dependencies]
# Darkfi # Darkfi
darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]} darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
# Misc # Misc
clap = {version = "4.4.11", features = ["derive"]} clap = {version = "4.4.11", features = ["derive"]}

View File

@@ -12,7 +12,7 @@ edition = "2021"
[dependencies] [dependencies]
# Darkfi # Darkfi
darkfi = {path = "../../../../", features = ["async-daemonize", "rpc"]} darkfi = {path = "../../../../", features = ["async-daemonize", "rpc"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
# Misc # Misc
tracing = "0.1.44" tracing = "0.1.44"

View File

@@ -11,7 +11,7 @@ edition = "2021"
[dependencies] [dependencies]
darkfi = {path = "../../../", features = ["async-daemonize", "net"]} darkfi = {path = "../../../", features = ["async-daemonize", "net"]}
darkfi-serial = {version = "0.5.0", features = ["async"]} darkfi-serial = {path = "../../../src/serial", features = ["async"]}
rand = "0.8.5" rand = "0.8.5"
# Daemon # Daemon

View File

@@ -18,7 +18,7 @@ darkfi = {path = "../../../", features = ["bs58", "validator"]}
darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]} darkfi_money_contract = {path = "../../../src/contract/money", features = ["no-entrypoint", "client"]}
darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"} darkfi-contract-test-harness = {path = "../../../src/contract/test-harness"}
darkfi-sdk = {path = "../../../src/sdk"} darkfi-sdk = {path = "../../../src/sdk"}
darkfi-serial = "0.5.1" darkfi-serial = {path = "../../../src/serial"}
# Misc # Misc
bs58 = "0.5.1" bs58 = "0.5.1"

View File

@@ -13,7 +13,7 @@ edition = "2021"
# Darkfi # Darkfi
darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]} darkfi = {path = "../../../../", features = ["async-sdk", "rpc"]}
darkfi-sdk = {path = "../../../../src/sdk"} darkfi-sdk = {path = "../../../../src/sdk"}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
rlnd = {path = "../rlnd"} rlnd = {path = "../rlnd"}
# Misc # Misc

View File

@@ -13,11 +13,11 @@ edition = "2021"
# Darkfi # Darkfi
darkfi = {path = "../../../../", features = ["async-daemonize", "async-sdk", "rpc", "sled-overlay"]} darkfi = {path = "../../../../", features = ["async-daemonize", "async-sdk", "rpc", "sled-overlay"]}
darkfi-sdk = {path = "../../../../src/sdk"} darkfi-sdk = {path = "../../../../src/sdk"}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
# Misc # Misc
bs58 = "0.5.1" bs58 = "0.5.1"
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
tracing = "0.1.44" tracing = "0.1.44"
# JSON-RPC # JSON-RPC

View File

@@ -15,12 +15,12 @@ darkfi = {path = "../../../../", features = ["zk"]}
halo2_proofs = {version = "0.3.2", features = ["circuit-params"]} halo2_proofs = {version = "0.3.2", features = ["circuit-params"]}
halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]} halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]}
rand = "0.8.5" rand = "0.8.5"
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
[dev-dependencies] [dev-dependencies]
halo2_proofs = {version = "0.3.1", features = ["dev-graph", "sanity-checks"]} halo2_proofs = {version = "0.3.1", features = ["dev-graph", "sanity-checks"]}
halo2_gadgets = "0.3.1" halo2_gadgets = "0.3.1"
[patch.crates-io] [patch.crates-io]
halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v031"} halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v032"}
halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v031"} halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v032"}

View File

@@ -12,11 +12,11 @@ edition = "2024"
[dependencies] [dependencies]
darkfi-sdk = {path = "../../../../src/sdk"} darkfi-sdk = {path = "../../../../src/sdk"}
darkfi = {path = "../../../../", features = ["zk"]} darkfi = {path = "../../../../", features = ["zk"]}
darkfi-serial = "0.5.0" darkfi-serial = {path = "../../../../src/serial"}
[patch.crates-io] [patch.crates-io]
halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v031"} halo2_proofs = {git="https://github.com/parazyd/halo2", branch="v032"}
halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v031"} halo2_gadgets = {git="https://github.com/parazyd/halo2", branch="v032"}
[profile.release] [profile.release]
debug = true debug = true

View File

@@ -28,14 +28,11 @@ use darkfi_sdk::{
use darkfi_serial::async_trait; use darkfi_serial::async_trait;
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable}; use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
use num_bigint::BigUint; use num_bigint::BigUint;
use sled_overlay::{ use sled_overlay::{sled, SledDbOverlayStateDiff};
serial::{parse_record, parse_u32_key_record},
sled, SledDbOverlayStateDiff,
};
use crate::{tx::Transaction, util::time::Timestamp, Error, Result}; use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
use super::{Header, HeaderHash, SledDbOverlayPtr}; use super::{parse_record, parse_u32_key_record, Header, HeaderHash, SledDbOverlayPtr};
/// This struct represents a tuple of the form (`header`, `txs`, `signature`). /// This struct represents a tuple of the form (`header`, `txs`, `signature`).
/// ///

View File

@@ -26,7 +26,7 @@ use darkfi_sdk::{
monotree::{MemoryDb, Monotree, SledOverlayDb, SledTreeDb, EMPTY_HASH}, monotree::{MemoryDb, Monotree, SledOverlayDb, SledTreeDb, EMPTY_HASH},
}; };
use darkfi_serial::{deserialize, serialize}; use darkfi_serial::{deserialize, serialize};
use sled_overlay::{serial::parse_record, sled, SledDbOverlayStateDiff}; use sled_overlay::{sled, SledDbOverlayStateDiff};
use tracing::{debug, error}; use tracing::{debug, error};
use crate::{ use crate::{
@@ -35,7 +35,7 @@ use crate::{
Error, Result, Error, Result,
}; };
use super::SledDbOverlayPtr; use super::{parse_record, SledDbOverlayPtr};
pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts"; pub const SLED_CONTRACTS_TREE: &[u8] = b"_contracts";
pub const SLED_CONTRACTS_TREES_TREE: &[u8] = b"_contracts_trees"; pub const SLED_CONTRACTS_TREES_TREE: &[u8] = b"_contracts_trees";

View File

@@ -26,16 +26,13 @@ use darkfi_sdk::{
#[cfg(feature = "async-serial")] #[cfg(feature = "async-serial")]
use darkfi_serial::{async_trait, FutAsyncWriteExt}; use darkfi_serial::{async_trait, FutAsyncWriteExt};
use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable}; use darkfi_serial::{deserialize, serialize, Encodable, SerialDecodable, SerialEncodable};
use sled_overlay::{ use sled_overlay::sled;
serial::{parse_record, parse_u32_key_record},
sled,
};
use crate::{util::time::Timestamp, Error, Result}; use crate::{util::time::Timestamp, Error, Result};
use super::{ use super::{
monero::{extract_aux_merkle_root, MoneroPowData}, monero::{extract_aux_merkle_root, MoneroPowData},
SledDbOverlayPtr, parse_record, parse_u32_key_record, SledDbOverlayPtr,
}; };
/// Struct representing the Proof of Work used in a block. /// Struct representing the Proof of Work used in a block.

View File

@@ -25,9 +25,16 @@ use darkfi_sdk::{
monotree::{self, Monotree}, monotree::{self, Monotree},
tx::TransactionHash, tx::TransactionHash,
}; };
use sled_overlay::{sled, sled::Transactional}; use darkfi_serial::{deserialize, Decodable};
use sled_overlay::{
sled,
sled::{IVec, Transactional},
};
use tracing::debug; use tracing::debug;
#[cfg(feature = "async-serial")]
use darkfi_serial::{deserialize_async, AsyncDecodable};
use crate::{tx::Transaction, util::time::Timestamp, Error, Result}; use crate::{tx::Transaction, util::time::Timestamp, Error, Result};
/// Block related definitions and storage implementations /// Block related definitions and storage implementations
@@ -704,6 +711,71 @@ impl BlockchainOverlay {
} }
} }
/// Parse a sled record in the form of a tuple (`key`, `value`).
pub fn parse_record<T1: Decodable, T2: Decodable>(record: (IVec, IVec)) -> Result<(T1, T2)> {
let key = deserialize(&record.0)?;
let value = deserialize(&record.1)?;
Ok((key, value))
}
/// Parse a sled record with a u32 key, encoded in Big Endian bytes,
/// in the form of a tuple (`key`, `value`).
pub fn parse_u32_key_record<T: Decodable>(record: (IVec, IVec)) -> Result<(u32, T)> {
let key_bytes: [u8; 4] = record.0.as_ref().try_into().unwrap();
let key = u32::from_be_bytes(key_bytes);
let value = deserialize(&record.1)?;
Ok((key, value))
}
/// Parse a sled record with a u64 key, encoded in Big Endian bytes,
/// in the form of a tuple (`key`, `value`).
pub fn parse_u64_key_record<T: Decodable>(record: (IVec, IVec)) -> Result<(u64, T)> {
let key_bytes: [u8; 8] = record.0.as_ref().try_into().unwrap();
let key = u64::from_be_bytes(key_bytes);
let value = deserialize(&record.1)?;
Ok((key, value))
}
#[cfg(feature = "async-serial")]
/// Parse a sled record in the form of a tuple (`key`, `value`).
pub async fn parse_record_async<T1: AsyncDecodable, T2: AsyncDecodable>(
record: (IVec, IVec),
) -> Result<(T1, T2)> {
let key = deserialize_async(&record.0).await?;
let value = deserialize_async(&record.1).await?;
Ok((key, value))
}
#[cfg(feature = "async-serial")]
/// Parse a sled record with a u32 key, encoded in Big Endian bytes,
/// in the form of a tuple (`key`, `value`).
pub async fn parse_u32_key_record_async<T: AsyncDecodable>(
record: (IVec, IVec),
) -> Result<(u32, T)> {
let key_bytes: [u8; 4] = record.0.as_ref().try_into().unwrap();
let key = u32::from_be_bytes(key_bytes);
let value = deserialize_async(&record.1).await?;
Ok((key, value))
}
#[cfg(feature = "async-serial")]
/// Parse a sled record with a u64 key, encoded in Big Endian bytes,
/// in the form of a tuple (`key`, `value`).
pub async fn parse_u64_key_record_async<T: AsyncDecodable>(
record: (IVec, IVec),
) -> Result<(u64, T)> {
let key_bytes: [u8; 8] = record.0.as_ref().try_into().unwrap();
let key = u64::from_be_bytes(key_bytes);
let value = deserialize_async(&record.1).await?;
Ok((key, value))
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::validator::pow::{RANDOMX_KEY_CHANGE_DELAY, RANDOMX_KEY_CHANGING_HEIGHT}; use crate::validator::pow::{RANDOMX_KEY_CHANGE_DELAY, RANDOMX_KEY_CHANGING_HEIGHT};

View File

@@ -20,14 +20,11 @@ use std::collections::HashMap;
use darkfi_sdk::tx::TransactionHash; use darkfi_sdk::tx::TransactionHash;
use darkfi_serial::{deserialize, serialize}; use darkfi_serial::{deserialize, serialize};
use sled_overlay::{ use sled_overlay::sled;
serial::{parse_record, parse_u64_key_record},
sled,
};
use crate::{tx::Transaction, Error, Result}; use crate::{tx::Transaction, Error, Result};
use super::SledDbOverlayPtr; use super::{parse_record, parse_u64_key_record, SledDbOverlayPtr};
pub const SLED_TX_TREE: &[u8] = b"_transactions"; pub const SLED_TX_TREE: &[u8] = b"_transactions";
pub const SLED_TX_LOCATION_TREE: &[u8] = b"_transaction_location"; pub const SLED_TX_LOCATION_TREE: &[u8] = b"_transaction_location";

View File

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
blake2b_simd = "1.0.3" blake2b_simd = "1.0.3"
bs58 = "0.5.1" bs58 = "0.5.1"
darkfi-sdk = { path = "../../sdk", features = ["wasm"] } darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] } darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
darkfi_money_contract = { path = "../money", features = ["no-entrypoint"] } darkfi_money_contract = { path = "../money", features = ["no-entrypoint"] }
thiserror = "2.0.17" thiserror = "2.0.17"

View File

@@ -10,7 +10,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
darkfi-sdk = { path = "../../sdk", features = ["wasm"] } darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] } darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
thiserror = "2.0.17" thiserror = "2.0.17"
wasmparser = "0.243.0" wasmparser = "0.243.0"

View File

@@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]
blake3 = "1.8.2" blake3 = "1.8.2"
bs58 = "0.5.1" bs58 = "0.5.1"
darkfi-sdk = { path = "../../sdk", features = ["wasm"] } darkfi-sdk = { path = "../../sdk", features = ["wasm"] }
darkfi-serial = { version = "0.5.0", features = ["derive", "crypto"] } darkfi-serial = { path = "../../serial", features = ["derive", "crypto"] }
thiserror = "2.0.17" thiserror = "2.0.17"
# The following dependencies are used for the client API and # The following dependencies are used for the client API and

View File

@@ -7,8 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
darkfi = {path = "../../../", features = ["validator"]} darkfi = {path = "../../../", features = ["validator"]}
darkfi-sdk = {path = "../../../src/sdk"} darkfi-sdk = {path = "../../sdk"}
darkfi-serial = {version = "0.5.0", features = ["crypto"]} darkfi-serial = {path = "../../serial", features = ["crypto"]}
darkfi_dao_contract = {path = "../dao", features = ["client", "no-entrypoint"]} darkfi_dao_contract = {path = "../dao", features = ["client", "no-entrypoint"]}
darkfi_money_contract = {path = "../money", features = ["client", "no-entrypoint"]} darkfi_money_contract = {path = "../money", features = ["client", "no-entrypoint"]}

View File

@@ -21,7 +21,7 @@ wasm = []
thiserror = "2.0.17" thiserror = "2.0.17"
# Serialization # Serialization
darkfi-serial = {version = "0.5.1", features = ["crypto"]} darkfi-serial = {path = "../serial", features = ["crypto"]}
# Encoding # Encoding
bs58 = {version = "0.5.1", features = ["check"]} bs58 = {version = "0.5.1", features = ["check"]}
@@ -46,7 +46,7 @@ subtle = "2.6.1"
hashbrown = "0.16.1" hashbrown = "0.16.1"
# Storage # Storage
sled-overlay = "0.1.14" sled-overlay = "0.1.15"
[dev-dependencies] [dev-dependencies]
halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]} halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]}

View File

@@ -19,7 +19,7 @@ darkfi_money_contract = {path = "../../contract/money", features=["no-entrypoint
darkfi_dao_contract = {path = "../../contract/dao", features=["no-entrypoint", "client"]} darkfi_dao_contract = {path = "../../contract/dao", features=["no-entrypoint", "client"]}
darkfi_deployooor_contract = {path = "../../contract/deployooor", features=["no-entrypoint", "client"]} darkfi_deployooor_contract = {path = "../../contract/deployooor", features=["no-entrypoint", "client"]}
darkfi-sdk = {path = "../"} darkfi-sdk = {path = "../"}
darkfi-serial = {version = "0.5.1", features = ["crypto"]} darkfi-serial = {path = "../../serial", features = ["crypto"]}
halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]} halo2_proofs = {version = "0.3.2", features = ["circuit-params", "dev-graph", "sanity-checks"]}
halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]} halo2_gadgets = {version = "0.4.0", features = ["circuit-params"]}
plotters = "0.3.7" plotters = "0.3.7"

View File

@@ -8,16 +8,8 @@ repository = "https://codeberg.org/darkrenaissance/darkfi"
license = "AGPL-3.0-only" license = "AGPL-3.0-only"
edition = "2021" edition = "2021"
# Uncomment this when publishing crate
#[workspace]
#members = [
# "./derive-internal",
# "./derive",
# "./",
#]
[dependencies] [dependencies]
darkfi-derive = {version = "0.5.1", optional = true} darkfi-derive = {path = "./derive", optional = true}
futures-lite = {version = "2", optional = true} futures-lite = {version = "2", optional = true}
async-trait = {version = "0", optional = true} async-trait = {version = "0", optional = true}
@@ -29,6 +21,7 @@ pasta_curves = {version = "0.5", optional = true}
semver = {version = "1", optional = true} semver = {version = "1", optional = true}
url = {version = "2", optional = true} url = {version = "2", optional = true}
num-bigint = {version = "0.4", optional = true} num-bigint = {version = "0.4", optional = true}
sled-overlay = {version = "0.1.15", optional = true}
[features] [features]
default = ["derive", "semver"] default = ["derive", "semver"]

View File

@@ -17,7 +17,7 @@ proc-macro2 = "1"
quote = "1" quote = "1"
syn = {version = "2", features = ["full", "fold"]} syn = {version = "2", features = ["full", "fold"]}
darkfi-derive-internal = "0.5.1" darkfi-derive-internal = {path = "../derive-internal"}
[features] [features]
default = [] default = []

View File

@@ -18,7 +18,7 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
io::{Error, ErrorKind, Result}, io::{Error, Result},
}; };
pub use async_trait::async_trait; pub use async_trait::async_trait;
@@ -69,7 +69,7 @@ pub async fn deserialize_async<T: AsyncDecodable>(data: &[u8]) -> Result<T> {
// Fail if data is not consumed entirely. // Fail if data is not consumed entirely.
if consumed != data.len() { if consumed != data.len() {
return Err(Error::new(ErrorKind::Other, "Data not consumed fully on deserialization")) return Err(Error::other("Data not consumed fully on deserialization"))
} }
Ok(rv) Ok(rv)
@@ -431,7 +431,7 @@ impl AsyncDecodable for VarInt {
0xFF => { 0xFF => {
let x = AsyncReadExt::read_u64_async(d).await?; let x = AsyncReadExt::read_u64_async(d).await?;
if x < 0x100000000 { if x < 0x100000000 {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x)) Ok(VarInt(x))
} }
@@ -439,7 +439,7 @@ impl AsyncDecodable for VarInt {
0xFE => { 0xFE => {
let x = AsyncReadExt::read_u32_async(d).await?; let x = AsyncReadExt::read_u32_async(d).await?;
if x < 0x10000 { if x < 0x10000 {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x as u64)) Ok(VarInt(x as u64))
} }
@@ -447,7 +447,7 @@ impl AsyncDecodable for VarInt {
0xFD => { 0xFD => {
let x = AsyncReadExt::read_u16_async(d).await?; let x = AsyncReadExt::read_u16_async(d).await?;
if x < 0xFD { if x < 0xFD {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x as u64)) Ok(VarInt(x as u64))
} }
@@ -665,7 +665,7 @@ impl AsyncDecodable for String {
async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<String> { async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<String> {
match String::from_utf8(AsyncDecodable::decode_async(d).await?) { match String::from_utf8(AsyncDecodable::decode_async(d).await?) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")), Err(_) => Err(Error::other("Invalid UTF-8 for string")),
} }
} }
} }

View File

@@ -18,7 +18,7 @@
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
io::{Cursor, Error, ErrorKind, Read, Write}, io::{Cursor, Error, Read, Write},
}; };
#[cfg(feature = "derive")] #[cfg(feature = "derive")]
@@ -74,7 +74,7 @@ pub fn deserialize<T: Decodable>(data: &[u8]) -> Result<T, Error> {
// Fail if data is not consumed entirely. // Fail if data is not consumed entirely.
if consumed != data.len() { if consumed != data.len() {
return Err(Error::new(ErrorKind::Other, "Data not consumed fully on deserialization")) return Err(Error::other("Data not consumed fully on deserialization"))
} }
Ok(rv) Ok(rv)
@@ -341,7 +341,7 @@ impl Decodable for VarInt {
0xFF => { 0xFF => {
let x = ReadExt::read_u64(d)?; let x = ReadExt::read_u64(d)?;
if x < 0x100000000 { if x < 0x100000000 {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x)) Ok(VarInt(x))
} }
@@ -349,7 +349,7 @@ impl Decodable for VarInt {
0xFE => { 0xFE => {
let x = ReadExt::read_u32(d)?; let x = ReadExt::read_u32(d)?;
if x < 0x10000 { if x < 0x10000 {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x as u64)) Ok(VarInt(x as u64))
} }
@@ -357,7 +357,7 @@ impl Decodable for VarInt {
0xFD => { 0xFD => {
let x = ReadExt::read_u16(d)?; let x = ReadExt::read_u16(d)?;
if x < 0xFD { if x < 0xFD {
return Err(Error::new(ErrorKind::Other, "Non-minimal VarInt")) return Err(Error::other("Non-minimal VarInt"))
} }
Ok(VarInt(x as u64)) Ok(VarInt(x as u64))
} }
@@ -592,7 +592,7 @@ impl Decodable for String {
fn decode<D: Read>(d: &mut D) -> Result<String, Error> { fn decode<D: Read>(d: &mut D) -> Result<String, Error> {
match String::from_utf8(Decodable::decode(d)?) { match String::from_utf8(Decodable::decode(d)?) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")), Err(_) => Err(Error::other("Invalid UTF-8 for string")),
} }
} }
} }
@@ -614,7 +614,7 @@ impl Decodable for Cow<'static, str> {
fn decode<D: Read>(d: D) -> Result<Cow<'static, str>, Error> { fn decode<D: Read>(d: D) -> Result<Cow<'static, str>, Error> {
match String::from_utf8(Decodable::decode(d)?) { match String::from_utf8(Decodable::decode(d)?) {
Ok(v) => v.map(Cow::Owned), Ok(v) => v.map(Cow::Owned),
Err(_) => Err(Error::new(ErrorKind::Other, "Invalid UTF-8 for string")), Err(_) => Err(Error::other("Invalid UTF-8 for string")),
} }
} }
} }

View File

@@ -38,3 +38,6 @@ mod semver;
#[cfg(feature = "num-bigint")] #[cfg(feature = "num-bigint")]
mod bigint; mod bigint;
#[cfg(feature = "sled-overlay")]
mod sled_overlay;

View File

@@ -17,7 +17,7 @@
*/ */
use core::fmt::Debug; use core::fmt::Debug;
use std::io::{Error, ErrorKind, Read, Result, Write}; use std::io::{Error, Read, Result, Write};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use crate::{AsyncDecodable, AsyncEncodable}; use crate::{AsyncDecodable, AsyncEncodable};
@@ -128,7 +128,7 @@ impl<H: Decodable + Ord + Clone> Decodable for bridgetree::NonEmptyFrontier<H> {
match Self::from_parts(position, leaf, ommers) { match Self::from_parts(position, leaf, ommers) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "FrontierError")), Err(_) => Err(Error::other("FrontierError")),
} }
} }
} }
@@ -143,7 +143,7 @@ impl<H: AsyncDecodable + Send + Ord + Clone> AsyncDecodable for bridgetree::NonE
match Self::from_parts(position, leaf, ommers) { match Self::from_parts(position, leaf, ommers) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "FrontierError")), Err(_) => Err(Error::other("FrontierError")),
} }
} }
} }
@@ -287,7 +287,7 @@ impl<
let max_checkpoints = Decodable::decode(d)?; let max_checkpoints = Decodable::decode(d)?;
match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) { match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "BridgeTreeError")), Err(_) => Err(Error::other("BridgeTreeError")),
} }
} }
} }
@@ -308,7 +308,7 @@ impl<
let max_checkpoints = AsyncDecodable::decode_async(d).await?; let max_checkpoints = AsyncDecodable::decode_async(d).await?;
match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) { match Self::from_parts(prior_bridges, current_bridge, saved, checkpoints, max_checkpoints) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "BridgeTreeError")), Err(_) => Err(Error::other("BridgeTreeError")),
} }
} }
} }

View File

@@ -17,7 +17,7 @@
*/ */
//! Implementations for pasta curves //! Implementations for pasta curves
use std::io::{Error, ErrorKind, Read, Result, Write}; use std::io::{Error, Read, Result, Write};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use crate::{ use crate::{
@@ -58,7 +58,7 @@ impl Decodable for Fp {
d.read_slice(&mut bytes)?; d.read_slice(&mut bytes)?;
match Self::from_repr(bytes).into() { match Self::from_repr(bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Base")), None => Err(Error::other("Noncanonical bytes for pallas::Base")),
} }
} }
} }
@@ -70,7 +70,7 @@ impl AsyncDecodable for Fp {
d.read_slice_async(&mut bytes).await?; d.read_slice_async(&mut bytes).await?;
match Self::from_repr(bytes).into() { match Self::from_repr(bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Base")), None => Err(Error::other("Noncanonical bytes for pallas::Base")),
} }
} }
} }
@@ -97,7 +97,7 @@ impl Decodable for Fq {
d.read_slice(&mut bytes)?; d.read_slice(&mut bytes)?;
match Self::from_repr(bytes).into() { match Self::from_repr(bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Scalar")), None => Err(Error::other("Noncanonical bytes for pallas::Scalar")),
} }
} }
} }
@@ -110,7 +110,7 @@ impl AsyncDecodable for Fq {
d.read_slice_async(&mut bytes).await?; d.read_slice_async(&mut bytes).await?;
match Self::from_repr(bytes).into() { match Self::from_repr(bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Scalar")), None => Err(Error::other("Noncanonical bytes for pallas::Scalar")),
} }
} }
} }
@@ -137,7 +137,7 @@ impl Decodable for Ep {
d.read_slice(&mut bytes)?; d.read_slice(&mut bytes)?;
match Self::from_bytes(&bytes).into() { match Self::from_bytes(&bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Point")), None => Err(Error::other("Noncanonical bytes for pallas::Point")),
} }
} }
} }
@@ -150,7 +150,7 @@ impl AsyncDecodable for Ep {
d.read_slice_async(&mut bytes).await?; d.read_slice_async(&mut bytes).await?;
match Self::from_bytes(&bytes).into() { match Self::from_bytes(&bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for pallas::Point")), None => Err(Error::other("Noncanonical bytes for pallas::Point")),
} }
} }
} }
@@ -177,7 +177,7 @@ impl Decodable for Eq {
d.read_slice(&mut bytes)?; d.read_slice(&mut bytes)?;
match Self::from_bytes(&bytes).into() { match Self::from_bytes(&bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for vesta::Point")), None => Err(Error::other("Noncanonical bytes for vesta::Point")),
} }
} }
} }
@@ -190,7 +190,7 @@ impl AsyncDecodable for Eq {
d.read_slice_async(&mut bytes).await?; d.read_slice_async(&mut bytes).await?;
match Self::from_bytes(&bytes).into() { match Self::from_bytes(&bytes).into() {
Some(v) => Ok(v), Some(v) => Ok(v),
None => Err(Error::new(ErrorKind::Other, "Noncanonical bytes for vesta::Point")), None => Err(Error::other("Noncanonical bytes for vesta::Point")),
} }
} }
} }

View File

@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::io::{Error, ErrorKind, Read, Result, Write}; use std::io::{Error, Read, Result, Write};
#[cfg(feature = "async")] #[cfg(feature = "async")]
use crate::{AsyncDecodable, AsyncEncodable}; use crate::{AsyncDecodable, AsyncEncodable};
@@ -47,7 +47,7 @@ impl Decodable for semver::Prerelease {
match Self::new(&s) { match Self::new(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "Failed deserializing semver::Prerelase")), Err(_) => Err(Error::other("Failed deserializing semver::Prerelase")),
} }
} }
} }
@@ -60,7 +60,7 @@ impl AsyncDecodable for semver::Prerelease {
match Self::new(&s) { match Self::new(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => Err(Error::new(ErrorKind::Other, "Failed deserializing semver::Prerelease")), Err(_) => Err(Error::other("Failed deserializing semver::Prerelease")),
} }
} }
} }
@@ -85,9 +85,7 @@ impl Decodable for semver::BuildMetadata {
match Self::new(&s) { match Self::new(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => { Err(_) => Err(Error::other("Failed deserializing semver::BuildMetadata")),
Err(Error::new(ErrorKind::Other, "Failed deserializing semver::BuildMetadata"))
}
} }
} }
} }
@@ -100,9 +98,7 @@ impl AsyncDecodable for semver::BuildMetadata {
match Self::new(&s) { match Self::new(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(_) => { Err(_) => Err(Error::other("Failed deserializing semver::BuildMetadata")),
Err(Error::new(ErrorKind::Other, "Failed deserializing semver::BuildMetadata"))
}
} }
} }
} }

View File

@@ -0,0 +1,248 @@
/* This file is part of DarkFi (https://dark.fi)
*
* Copyright (C) 2020-2026 Dyne.org foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use std::{
collections::BTreeMap,
io::{Read, Result, Write},
};
use sled_overlay::{SledDbOverlayStateDiff, SledTreeOverlayStateDiff};
#[cfg(feature = "async")]
use crate::{AsyncDecodable, AsyncEncodable};
#[cfg(feature = "async")]
use async_trait::async_trait;
#[cfg(feature = "async")]
use futures_lite::{AsyncRead, AsyncWrite};
use crate::{Decodable, Encodable, VarInt};
impl Encodable for SledTreeOverlayStateDiff {
fn encode<S: Write>(&self, s: &mut S) -> Result<usize> {
let mut len = 0;
len += VarInt(self.cache.len() as u64).encode(s)?;
for (key, (previous, current)) in self.cache.iter() {
len += key.to_vec().encode(s)?;
let previous = previous.as_ref().map(|p| p.to_vec());
len += previous.encode(s)?;
len += current.to_vec().encode(s)?;
}
len += VarInt(self.removed.len() as u64).encode(s)?;
for (key, value) in self.removed.iter() {
len += key.to_vec().encode(s)?;
len += value.to_vec().encode(s)?;
}
Ok(len)
}
}
#[cfg(feature = "async")]
#[async_trait]
impl AsyncEncodable for SledTreeOverlayStateDiff {
async fn encode_async<S: AsyncWrite + Unpin + Send>(&self, s: &mut S) -> Result<usize> {
let mut len = 0;
len += VarInt(self.cache.len() as u64).encode_async(s).await?;
for (key, (previous, current)) in self.cache.iter() {
len += key.to_vec().encode_async(s).await?;
let previous = previous.as_ref().map(|p| p.to_vec());
len += previous.encode_async(s).await?;
len += current.to_vec().encode_async(s).await?;
}
len += VarInt(self.removed.len() as u64).encode_async(s).await?;
for (key, value) in self.removed.iter() {
len += key.to_vec().encode_async(s).await?;
len += value.to_vec().encode_async(s).await?;
}
Ok(len)
}
}
impl Decodable for SledTreeOverlayStateDiff {
fn decode<D: Read>(d: &mut D) -> Result<Self> {
let len = VarInt::decode(d)?.0;
let mut cache = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = Decodable::decode(d)?;
let (previous, current): (Option<Vec<u8>>, Vec<u8>) = Decodable::decode(d)?;
let previous = previous.as_ref().map(|p| p.clone().into());
cache.insert(key.into(), (previous, current.into()));
}
let len = VarInt::decode(d)?.0;
let mut removed = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = Decodable::decode(d)?;
let entry: Vec<u8> = Decodable::decode(d)?;
removed.insert(key.into(), entry.into());
}
Ok(Self { cache, removed })
}
}
#[cfg(feature = "async")]
#[async_trait]
impl AsyncDecodable for SledTreeOverlayStateDiff {
async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<Self> {
let len = VarInt::decode_async(d).await?.0;
let mut cache = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
let (previous, current): (Option<Vec<u8>>, Vec<u8>) =
AsyncDecodable::decode_async(d).await?;
let previous = previous.as_ref().map(|p| p.clone().into());
cache.insert(key.into(), (previous, current.into()));
}
let len = VarInt::decode_async(d).await?.0;
let mut removed = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
let entry: Vec<u8> = AsyncDecodable::decode_async(d).await?;
removed.insert(key.into(), entry.into());
}
Ok(Self { cache, removed })
}
}
impl Encodable for SledDbOverlayStateDiff {
fn encode<S: Write>(&self, s: &mut S) -> Result<usize> {
let mut len = 0;
len += VarInt(self.initial_tree_names.len() as u64).encode(s)?;
for tree_name in &self.initial_tree_names {
len += tree_name.to_vec().encode(s)?;
}
len += VarInt(self.caches.len() as u64).encode(s)?;
for (key, (cache, drop)) in self.caches.iter() {
len += key.to_vec().encode(s)?;
len += cache.encode(s)?;
len += drop.encode(s)?;
}
len += VarInt(self.dropped_trees.len() as u64).encode(s)?;
for (key, (cache, restore)) in self.dropped_trees.iter() {
len += key.to_vec().encode(s)?;
len += cache.encode(s)?;
len += restore.encode(s)?;
}
Ok(len)
}
}
#[cfg(feature = "async")]
#[async_trait]
impl AsyncEncodable for SledDbOverlayStateDiff {
async fn encode_async<S: AsyncWrite + Unpin + Send>(&self, s: &mut S) -> Result<usize> {
let mut len = 0;
len += VarInt(self.initial_tree_names.len() as u64).encode_async(s).await?;
for tree_name in &self.initial_tree_names {
len += tree_name.to_vec().encode_async(s).await?;
}
len += VarInt(self.caches.len() as u64).encode_async(s).await?;
for (key, (cache, drop)) in self.caches.iter() {
len += key.to_vec().encode_async(s).await?;
len += cache.encode_async(s).await?;
len += drop.encode_async(s).await?;
}
len += VarInt(self.dropped_trees.len() as u64).encode_async(s).await?;
for (key, (cache, restore)) in self.dropped_trees.iter() {
len += key.to_vec().encode_async(s).await?;
len += cache.encode_async(s).await?;
len += restore.encode_async(s).await?;
}
Ok(len)
}
}
impl Decodable for SledDbOverlayStateDiff {
fn decode<D: Read>(d: &mut D) -> Result<Self> {
let len = VarInt::decode(d)?.0;
let mut initial_tree_names = vec![];
for _ in 0..len {
let initial_tree_name: Vec<u8> = Decodable::decode(d)?;
initial_tree_names.push(initial_tree_name.into());
}
let len = VarInt::decode(d)?.0;
let mut caches = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = Decodable::decode(d)?;
let cache = Decodable::decode(d)?;
let drop = Decodable::decode(d)?;
caches.insert(key.into(), (cache, drop));
}
let len = VarInt::decode(d)?.0;
let mut dropped_trees = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = Decodable::decode(d)?;
let cache = Decodable::decode(d)?;
let restore = Decodable::decode(d)?;
dropped_trees.insert(key.into(), (cache, restore));
}
Ok(Self { initial_tree_names, caches, dropped_trees })
}
}
#[cfg(feature = "async")]
#[async_trait]
impl AsyncDecodable for SledDbOverlayStateDiff {
async fn decode_async<D: AsyncRead + Unpin + Send>(d: &mut D) -> Result<Self> {
let len = VarInt::decode_async(d).await?.0;
let mut initial_tree_names = vec![];
for _ in 0..len {
let initial_tree_name: Vec<u8> = AsyncDecodable::decode_async(d).await?;
initial_tree_names.push(initial_tree_name.into());
}
let len = VarInt::decode_async(d).await?.0;
let mut caches = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
let cache = AsyncDecodable::decode_async(d).await?;
let drop = AsyncDecodable::decode_async(d).await?;
caches.insert(key.into(), (cache, drop));
}
let len = VarInt::decode_async(d).await?.0;
let mut dropped_trees = BTreeMap::new();
for _ in 0..len {
let key: Vec<u8> = AsyncDecodable::decode_async(d).await?;
let cache = AsyncDecodable::decode_async(d).await?;
let restore = AsyncDecodable::decode_async(d).await?;
dropped_trees.insert(key.into(), (cache, restore));
}
Ok(Self { initial_tree_names, caches, dropped_trees })
}
}

View File

@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::io::{Error, ErrorKind, Read, Result, Write}; use std::io::{Error, Read, Result, Write};
use url::Url; use url::Url;
#[cfg(feature = "async")] #[cfg(feature = "async")]
@@ -47,7 +47,7 @@ impl Decodable for Url {
let s: String = Decodable::decode(d)?; let s: String = Decodable::decode(d)?;
match Url::parse(&s) { match Url::parse(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(e) => Err(Error::new(ErrorKind::Other, e)), Err(e) => Err(Error::other(e)),
} }
} }
} }
@@ -59,7 +59,7 @@ impl AsyncDecodable for Url {
let s: String = AsyncDecodable::decode_async(d).await?; let s: String = AsyncDecodable::decode_async(d).await?;
match Url::parse(&s) { match Url::parse(&s) {
Ok(v) => Ok(v), Ok(v) => Ok(v),
Err(e) => Err(Error::new(ErrorKind::Other, e)), Err(e) => Err(Error::other(e)),
} }
} }
} }