diff --git a/.github/workflows/build-crate-and-npm.yml b/.github/workflows/build-crate-and-npm.yml index 2a1592bf6..435071b8d 100644 --- a/.github/workflows/build-crate-and-npm.yml +++ b/.github/workflows/build-crate-and-npm.yml @@ -42,11 +42,16 @@ jobs: run: cargo test && cargo test --release - name: build run: cargo build --release - - name: dry-run of `cargo publish` + - name: dry-run of `cargo publish` (chia_rs) + run: cargo publish --dry-run + - name: dry-run of `cargo publish` (clvm-utils) run: | - cargo publish --dry-run cd clvm-utils cargo publish --dry-run + - name: dry-run of `cargo publish` (chia-protocol) + run: | + cd chia-protocol + cargo publish --dry-run - name: Upload crate artifacts uses: actions/upload-artifact@v2 @@ -75,6 +80,8 @@ jobs: cargo publish cd clvm-utils cargo publish + cd ../chia-protocol + cargo publish # this has not been tested, so probably needs to be debugged next time a tag is created - name: publish to npmjs.com if tagged diff --git a/Cargo.toml b/Cargo.toml index 536e91f2d..27c71d5f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ # the "wheel" crate is excluded from the workspace because pyo3 has problems with # "cargo test" and "cargo bench" [workspace] -members = ["wasm", "chia_streamable_macro", "chia-bls", "clvm-utils"] +members = ["wasm", "chia_streamable_macro", "chia-bls", "clvm-utils", "chia-protocol"] exclude = ["wheel"] [package] @@ -21,8 +21,8 @@ py-bindings = ["dep:pyo3"] clvmr = "=0.1.24" hex = "=0.4.3" pyo3 = { version = "=0.15.1", features = ["extension-module"], optional = true } -chia_streamable_macro = { version = "=0.2.3", path = "chia_streamable_macro" } clvm-utils = { version = "=0.1.14", path = "clvm-utils" } +chia-protocol = { version = "=0.1.14", path = "chia-protocol" } [dev-dependencies] num-traits = "=0.2.15" diff --git a/chia-bls/Cargo.toml b/chia-bls/Cargo.toml index a744b5e26..b118b3849 100644 --- a/chia-bls/Cargo.toml +++ b/chia-bls/Cargo.toml @@ -23,6 +23,9 @@ hex = "^0.4.3" rand = "^0.8.5" criterion = "^0.4" +[lib] +crate-type = ["rlib"] + [[bench]] name = "derive_key" harness = false diff --git a/chia-protocol/Cargo.toml b/chia-protocol/Cargo.toml new file mode 100644 index 000000000..6cc765f1c --- /dev/null +++ b/chia-protocol/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "chia-protocol" +version = "0.1.14" +edition = "2021" +license = "Apache-2.0" +description = "Chia network protocol message types" +authors = ["Arvid Norberg "] +homepage = "https://github.com/Chia-Network/chia_rs/chia-protocol/" +repository = "https://github.com/Chia-Network/chia_rs/chia-protocol/" + +[features] +py-bindings = ["dep:pyo3"] + +[dependencies] +pyo3 = { version = "=0.15.1", features = ["extension-module"], optional = true } +sha2 = "=0.10.2" +hex = "=0.4.3" +chia_streamable_macro = { version = "=0.2.3", path = "../chia_streamable_macro" } +clvmr = "=0.1.24" + +[lib] +crate-type = ["rlib"] diff --git a/src/bytes.rs b/chia-protocol/src/bytes.rs similarity index 99% rename from src/bytes.rs rename to chia-protocol/src/bytes.rs index 5b048547f..7ad941942 100644 --- a/src/bytes.rs +++ b/chia-protocol/src/bytes.rs @@ -1,7 +1,7 @@ use crate::chia_error; use crate::streamable::{read_bytes, Streamable}; -use clvmr::sha2::{Digest, Sha256}; use core::fmt::Formatter; +use sha2::{Digest, Sha256}; use std::convert::AsRef; use std::convert::TryInto; use std::fmt; diff --git a/src/chia_error.rs b/chia-protocol/src/chia_error.rs similarity index 100% rename from src/chia_error.rs rename to chia-protocol/src/chia_error.rs diff --git a/chia-protocol/src/lib.rs b/chia-protocol/src/lib.rs new file mode 100644 index 000000000..0ce934f47 --- /dev/null +++ b/chia-protocol/src/lib.rs @@ -0,0 +1,3 @@ +pub mod bytes; +pub mod chia_error; +pub mod streamable; diff --git a/src/streamable.rs b/chia-protocol/src/streamable.rs similarity index 99% rename from src/streamable.rs rename to chia-protocol/src/streamable.rs index b63a8c2ee..8e1e25372 100644 --- a/src/streamable.rs +++ b/chia-protocol/src/streamable.rs @@ -1,5 +1,5 @@ use crate::chia_error::{Error, Result}; -use clvmr::sha2::{Digest, Sha256}; +use sha2::{Digest, Sha256}; use std::convert::TryInto; use std::io::Cursor; use std::mem::size_of; diff --git a/clvm-utils/Cargo.toml b/clvm-utils/Cargo.toml index 762ac57b5..61ce9fd68 100644 --- a/clvm-utils/Cargo.toml +++ b/clvm-utils/Cargo.toml @@ -10,6 +10,3 @@ repository = "https://github.com/Chia-Network/chia_rs/clvm-utils" [dependencies] clvmr = "=0.1.24" - -[profile.release] -lto = true diff --git a/src/gen/coin_id.rs b/src/gen/coin_id.rs index ee6fadb49..087ef6c35 100644 --- a/src/gen/coin_id.rs +++ b/src/gen/coin_id.rs @@ -1,4 +1,4 @@ -use crate::bytes::Bytes32; +use chia_protocol::bytes::Bytes32; use clvmr::allocator::{Allocator, NodePtr}; use clvmr::sha2::{Digest, Sha256}; diff --git a/src/gen/conditions.rs b/src/gen/conditions.rs index 5b6caf20d..94a967cc0 100644 --- a/src/gen/conditions.rs +++ b/src/gen/conditions.rs @@ -11,11 +11,11 @@ use super::opcodes::{ }; use super::sanitize_int::sanitize_uint; use super::validation_error::{first, next, rest, ErrorCode, ValidationErr}; -use crate::bytes::Bytes32; use crate::gen::flags::COND_ARGS_NIL; use crate::gen::flags::NO_UNKNOWN_CONDS; use crate::gen::flags::STRICT_ARGS_COUNT; use crate::gen::validation_error::check_nil; +use chia_protocol::bytes::Bytes32; use clvmr::allocator::{Allocator, NodePtr, SExp}; use clvmr::cost::Cost; use clvmr::op_utils::u64_from_bytes; diff --git a/src/gen/get_puzzle_and_solution.rs b/src/gen/get_puzzle_and_solution.rs index cec8ff01a..4d9d3e3bf 100644 --- a/src/gen/get_puzzle_and_solution.rs +++ b/src/gen/get_puzzle_and_solution.rs @@ -1,5 +1,5 @@ -use crate::bytes::Bytes32; use crate::gen::validation_error::{atom, check_nil, first, next, rest, ErrorCode, ValidationErr}; +use ::chia_protocol::bytes::Bytes32; use clvm_utils::tree_hash::tree_hash; use clvmr::allocator::{Allocator, NodePtr}; use clvmr::op_utils::u64_from_bytes; diff --git a/src/lib.rs b/src/lib.rs index da581d9fa..56714cfca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,5 @@ -pub mod bytes; -pub mod chia_error; pub mod gen; pub mod merkle_set; -pub mod streamable; #[cfg(fuzzing)] pub mod fuzzing_utils; diff --git a/wheel/Cargo.toml b/wheel/Cargo.toml index 7a8c1f2cf..796b01dca 100644 --- a/wheel/Cargo.toml +++ b/wheel/Cargo.toml @@ -16,6 +16,7 @@ path = "src/lib.rs" [dependencies] chia = { path = "..", features = ["py-bindings"] } +chia-protocol = { path = "../chia-protocol", features = ["py-bindings"] } clvmr = "=0.1.24" pyo3 = { version = "=0.15.1", features = ["extension-module", "multiple-pymethods"] } py_streamable = { path = "py_streamable" } diff --git a/wheel/py_streamable/src/lib.rs b/wheel/py_streamable/src/lib.rs index d3856a87d..6e60ecbf5 100644 --- a/wheel/py_streamable/src/lib.rs +++ b/wheel/py_streamable/src/lib.rs @@ -65,7 +65,7 @@ pub fn py_streamable_macro(input: TokenStream) -> TokenStream { #[staticmethod] pub fn from_bytes(blob: &[u8]) -> PyResult { let mut input = std::io::Cursor::<&[u8]>::new(blob); - Self::parse(&mut input).map_err(|e| >::into(e)) + Self::parse(&mut input).map_err(|e| >::into(e)) } // returns the type as well as the number of bytes read from the buffer @@ -78,7 +78,7 @@ pub fn py_streamable_macro(input: TokenStream) -> TokenStream { std::slice::from_raw_parts(blob.buf_ptr() as *const u8, blob.len_bytes()) }; let mut input = std::io::Cursor::<&[u8]>::new(slice); - Self::parse(&mut input).map_err(|e| >::into(e)).map(|v| (v, input.position() as u32)) + Self::parse(&mut input).map_err(|e| >::into(e)).map(|v| (v, input.position() as u32)) } pub fn get_hash<'p>(&self, py: Python<'p>) -> PyResult<&'p pyo3::types::PyBytes> { @@ -88,7 +88,7 @@ pub fn py_streamable_macro(input: TokenStream) -> TokenStream { } pub fn to_bytes<'p>(&self, py: Python<'p>) -> PyResult<&'p pyo3::types::PyBytes> { let mut writer = Vec::::new(); - self.stream(&mut writer).map_err(|e| >::into(e))?; + self.stream(&mut writer).map_err(|e| >::into(e))?; Ok(pyo3::types::PyBytes::new(py, &writer)) } diff --git a/wheel/src/api.rs b/wheel/src/api.rs index 7f77767af..094f2665a 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -22,7 +22,7 @@ use crate::run_program::{ }; use crate::adapt_response::eval_err_to_pyresult; -use chia::bytes::Bytes32; +use chia_protocol::bytes::Bytes32; use chia::gen::get_puzzle_and_solution::get_puzzle_and_solution_for_coin as parse_puzzle_solution; use chia::gen::validation_error::ValidationErr; use clvmr::allocator::Allocator; diff --git a/wheel/src/coin.rs b/wheel/src/coin.rs index 3790cc65f..531595dca 100644 --- a/wheel/src/coin.rs +++ b/wheel/src/coin.rs @@ -3,9 +3,9 @@ use crate::to_json_dict::ToJsonDict; use chia_streamable_macro::Streamable; use py_streamable::PyStreamable; -use chia::bytes::Bytes32; -use chia::chia_error; -use chia::streamable::Streamable; +use chia_protocol::bytes::Bytes32; +use chia_protocol::chia_error; +use chia_protocol::streamable::Streamable; use clvmr::sha2::{Digest, Sha256}; use pyo3::prelude::*; use pyo3::types::PyBytes; diff --git a/wheel/src/coin_state.rs b/wheel/src/coin_state.rs index b397a2cb6..30b216476 100644 --- a/wheel/src/coin_state.rs +++ b/wheel/src/coin_state.rs @@ -1,8 +1,8 @@ use crate::coin::Coin; use crate::from_json_dict::FromJsonDict; use crate::to_json_dict::ToJsonDict; -use chia::chia_error; -use chia::streamable::Streamable; +use chia_protocol::chia_error; +use chia_protocol::streamable::Streamable; use chia_streamable_macro::Streamable; use py_streamable::PyStreamable; diff --git a/wheel/src/from_json_dict.rs b/wheel/src/from_json_dict.rs index 1e3f2c076..716ff24ef 100644 --- a/wheel/src/from_json_dict.rs +++ b/wheel/src/from_json_dict.rs @@ -2,7 +2,7 @@ use pyo3::exceptions::PyValueError; use pyo3::PyAny; use pyo3::PyResult; -use chia::bytes::{Bytes, BytesImpl}; +use chia_protocol::bytes::{Bytes, BytesImpl}; use hex::FromHex; use std::convert::TryInto; diff --git a/wheel/src/respond_to_ph_updates.rs b/wheel/src/respond_to_ph_updates.rs index 7e161688e..f05aefd9f 100644 --- a/wheel/src/respond_to_ph_updates.rs +++ b/wheel/src/respond_to_ph_updates.rs @@ -1,12 +1,12 @@ use crate::from_json_dict::FromJsonDict; use crate::to_json_dict::ToJsonDict; -use chia::chia_error; -use chia::streamable::Streamable; +use chia_protocol::chia_error; +use chia_protocol::streamable::Streamable; use chia_streamable_macro::Streamable; use py_streamable::PyStreamable; use crate::coin_state::CoinState; -use chia::bytes::Bytes32; +use chia_protocol::bytes::Bytes32; use pyo3::prelude::*; #[pyclass(unsendable)] diff --git a/wheel/src/run_generator.rs b/wheel/src/run_generator.rs index 19c4499d4..7296e4884 100644 --- a/wheel/src/run_generator.rs +++ b/wheel/src/run_generator.rs @@ -2,7 +2,7 @@ use super::adapt_response::eval_err_to_pyresult; use super::from_json_dict::FromJsonDict; use super::to_json_dict::ToJsonDict; -use chia::bytes::{Bytes, Bytes32, Bytes48}; +use chia_protocol::bytes::{Bytes, Bytes32, Bytes48}; use chia::gen::conditions::{parse_spends, Spend, SpendBundleConditions}; use chia::gen::validation_error::{ErrorCode, ValidationErr}; @@ -16,8 +16,8 @@ use clvmr::serialize::node_from_bytes; use pyo3::prelude::*; -use chia::chia_error; -use chia::streamable::Streamable; +use chia_protocol::chia_error; +use chia_protocol::streamable::Streamable; use chia_streamable_macro::Streamable; use py_streamable::PyStreamable; diff --git a/wheel/src/to_json_dict.rs b/wheel/src/to_json_dict.rs index 75cc534f3..70a4598b1 100644 --- a/wheel/src/to_json_dict.rs +++ b/wheel/src/to_json_dict.rs @@ -1,4 +1,4 @@ -use chia::bytes::{Bytes, BytesImpl}; +use chia_protocol::bytes::{Bytes, BytesImpl}; use pyo3::prelude::*; use pyo3::types::PyList;