Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move protocol types into its own crate #82

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/build-crate-and-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions chia-bls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions chia-protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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"]
2 changes: 1 addition & 1 deletion src/bytes.rs → chia-protocol/src/bytes.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions chia-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod bytes;
pub mod chia_error;
pub mod streamable;
2 changes: 1 addition & 1 deletion src/streamable.rs → chia-protocol/src/streamable.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions clvm-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ repository = "https://github.com/Chia-Network/chia_rs/clvm-utils"

[dependencies]
clvmr = "=0.1.24"

[profile.release]
lto = true
2 changes: 1 addition & 1 deletion src/gen/coin_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::bytes::Bytes32;
use chia_protocol::bytes::Bytes32;
use clvmr::allocator::{Allocator, NodePtr};
use clvmr::sha2::{Digest, Sha256};

Expand Down
2 changes: 1 addition & 1 deletion src/gen/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gen/get_puzzle_and_solution.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions wheel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 3 additions & 3 deletions wheel/py_streamable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn py_streamable_macro(input: TokenStream) -> TokenStream {
#[staticmethod]
pub fn from_bytes(blob: &[u8]) -> PyResult<Self> {
let mut input = std::io::Cursor::<&[u8]>::new(blob);
Self::parse(&mut input).map_err(|e| <chia::chia_error::Error as Into<PyErr>>::into(e))
Self::parse(&mut input).map_err(|e| <chia_protocol::chia_error::Error as Into<PyErr>>::into(e))
}

// returns the type as well as the number of bytes read from the buffer
Expand All @@ -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| <chia::chia_error::Error as Into<PyErr>>::into(e)).map(|v| (v, input.position() as u32))
Self::parse(&mut input).map_err(|e| <chia_protocol::chia_error::Error as Into<PyErr>>::into(e)).map(|v| (v, input.position() as u32))
}

pub fn get_hash<'p>(&self, py: Python<'p>) -> PyResult<&'p pyo3::types::PyBytes> {
Expand All @@ -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::<u8>::new();
self.stream(&mut writer).map_err(|e| <chia::chia_error::Error as Into<PyErr>>::into(e))?;
self.stream(&mut writer).map_err(|e| <chia_protocol::chia_error::Error as Into<PyErr>>::into(e))?;
Ok(pyo3::types::PyBytes::new(py, &writer))
}

Expand Down
2 changes: 1 addition & 1 deletion wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions wheel/src/coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions wheel/src/coin_state.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion wheel/src/from_json_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions wheel/src/respond_to_ph_updates.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions wheel/src/run_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion wheel/src/to_json_dict.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chia::bytes::{Bytes, BytesImpl};
use chia_protocol::bytes::{Bytes, BytesImpl};
use pyo3::prelude::*;
use pyo3::types::PyList;

Expand Down