Skip to content

Commit e8b4744

Browse files
committed
Switch CID/multibase imports from ::cid to ::ipld_core::cid
1 parent eb9f064 commit e8b4744

8 files changed

Lines changed: 13 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pyo3 = { version = "0.28.3", features = ["generate-import-lib", "anyhow"] }
1717
python3-dll-a = "0.2.15"
1818
anyhow = "1.0.102"
1919
cid = "0.11.3"
20+
ipld-core = "0.4"
2021
cbor4ii = { version = "1.2.2" }
2122

2223
[build-dependencies]

src/car.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn decode_car<'py>(py: Python<'py>, data: &[u8]) -> PyResult<(Py<PyAny>, Bou
7171
// `&[u8]` is itself an `io::Read`, so we hand it to `Cid::read_bytes`
7272
// directly and recover the consumed length from the slice shrink.
7373
let mut slice: &[u8] = cid_bytes_before;
74-
let cid_result = ::cid::Cid::read_bytes(&mut slice);
74+
let cid_result = ::ipld_core::cid::Cid::read_bytes(&mut slice);
7575
let Ok(cid) = cid_result else {
7676
return Err(value_error(
7777
"Failed to read CID of block",

src/cid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ pub(crate) fn looks_like_cid(bytes: &[u8]) -> bool {
2727
bytes.len() == 34 && bytes[0] == 0x12 && bytes[1] == 0x20
2828
}
2929

30-
pub(crate) fn extract_cid(data: &Bound<PyAny>) -> PyResult<::cid::Cid> {
30+
pub(crate) fn extract_cid(data: &Bound<PyAny>) -> PyResult<::ipld_core::cid::Cid> {
3131
let cid = if let Ok(s) = data.cast::<PyString>() {
32-
::cid::Cid::try_from(s.to_str()?)
32+
::ipld_core::cid::Cid::try_from(s.to_str()?)
3333
} else {
34-
::cid::Cid::try_from(extract_bytes(data)?)
34+
::ipld_core::cid::Cid::try_from(extract_bytes(data)?)
3535
};
3636

3737
if let Ok(cid) = cid {

src/cid/de.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use pyo3::types::*;
33

44
use crate::cid::extract_cid;
55

6-
fn hash_to_pydict<'py>(py: Python<'py>, cid: &::cid::Cid) -> PyResult<Bound<'py, PyDict>> {
6+
fn hash_to_pydict<'py>(py: Python<'py>, cid: &::ipld_core::cid::Cid) -> PyResult<Bound<'py, PyDict>> {
77
let hash = cid.hash();
88
let dict_obj = PyDict::new(py);
99

@@ -14,7 +14,7 @@ fn hash_to_pydict<'py>(py: Python<'py>, cid: &::cid::Cid) -> PyResult<Bound<'py,
1414
Ok(dict_obj)
1515
}
1616

17-
fn to_pydict<'py>(py: Python<'py>, cid: &::cid::Cid) -> PyResult<Bound<'py, PyDict>> {
17+
fn to_pydict<'py>(py: Python<'py>, cid: &::ipld_core::cid::Cid) -> PyResult<Bound<'py, PyDict>> {
1818
let dict_obj = PyDict::new(py);
1919

2020
dict_obj.set_item("version", cid.version() as u64)?;

src/dag_cbor/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ where
143143
}
144144

145145
let cid_without_prefix = &cid[1..];
146-
if ::cid::Cid::try_from(cid_without_prefix).is_err() {
146+
if ::ipld_core::cid::Cid::try_from(cid_without_prefix).is_err() {
147147
return Err(anyhow!("Invalid CID"));
148148
}
149149

src/dag_cbor/ser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where
133133
if tp == &raw mut ffi::PyBytes_Type {
134134
let b = obj.cast_unchecked::<PyBytes>();
135135
let bytes = b.as_bytes();
136-
if looks_like_cid(bytes) && ::cid::Cid::try_from(bytes).is_ok() {
136+
if looks_like_cid(bytes) && ::ipld_core::cid::Cid::try_from(bytes).is_ok() {
137137
// by providing custom encoding we avoid extra allocation
138138
types::Tag(42, PrefixedCidBytes(bytes)).encode(w)?;
139139
} else {
@@ -187,7 +187,7 @@ where
187187
Ok(())
188188
} else if let Ok(b) = obj.cast::<PyBytes>() {
189189
let bytes = b.as_bytes();
190-
if looks_like_cid(bytes) && ::cid::Cid::try_from(bytes).is_ok() {
190+
if looks_like_cid(bytes) && ::ipld_core::cid::Cid::try_from(bytes).is_ok() {
191191
types::Tag(42, PrefixedCidBytes(bytes)).encode(w)?;
192192
} else {
193193
types::Bytes(bytes).encode(w)?;

src/multibase/de.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::error::value_error;
55

66
#[pyfunction]
77
pub fn decode_multibase<'py>(py: Python<'py>, data: &str) -> PyResult<(char, Bound<'py, PyBytes>)> {
8-
let base = ::cid::multibase::decode(data);
8+
let base = ::ipld_core::cid::multibase::decode(data);
99
if let Ok((base, data)) = base {
1010
Ok((base.code(), PyBytes::new(py, &data)))
1111
} else {

src/multibase/ser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::error::value_error;
66
#[pyfunction]
77
pub fn encode_multibase(code: char, data: &Bound<PyAny>) -> PyResult<String> {
88
let data_bytes = extract_bytes(data)?;
9-
let base = ::cid::multibase::Base::from_code(code);
9+
let base = ::ipld_core::cid::multibase::Base::from_code(code);
1010
if let Ok(base) = base {
11-
Ok(::cid::multibase::encode(base, data_bytes))
11+
Ok(::ipld_core::cid::multibase::encode(base, data_bytes))
1212
} else {
1313
Err(value_error(
1414
"Failed to encode multibase",

0 commit comments

Comments
 (0)