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

fix IDLValue blob conversion #517

Merged
merged 3 commits into from
Jan 30, 2024
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@

# Changelog

## 2023-01-30

### Candid 0.10.3

* Fix parser when converting `vec { number }` into `blob` type.

### candid_parser 0.1.3

* Add Typescript binding for init args.

### Candid UI

* Fix HTTP header.
* Fix agent routing when running in remote environments.

## 2023-01-03

### Candid 0.10.2
Expand Down
2 changes: 1 addition & 1 deletion rust/candid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid"
version = "0.10.2"
version = "0.10.3"
edition = "2021"
rust-version.workspace = true
authors = ["DFINITY Team"]
Expand Down
21 changes: 13 additions & 8 deletions rust/candid/src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,22 @@ impl IDLValue {
(_, TypeInner::Opt(_)) if !from_parser => IDLValue::None,
(IDLValue::Blob(blob), ty) if ty.is_blob(env) => IDLValue::Blob(blob.to_vec()),
(IDLValue::Vec(vec), ty) if ty.is_blob(env) => {
let blob = vec
.iter()
.filter_map(|x| match *x {
IDLValue::Nat8(n) => Some(n),
_ => None,
})
.collect();
let mut blob = Vec::with_capacity(vec.len());
for e in vec.iter() {
match e {
IDLValue::Nat8(n) => blob.push(*n),
IDLValue::Number(n) => blob.push(n.parse::<u8>()?),
_ => {
return Err(Error::msg(format!(
"type mismatch: {e} cannot be of type nat8"
)))
}
}
}
IDLValue::Blob(blob)
}
(IDLValue::Vec(vec), TypeInner::Vec(ty)) => {
let mut res = Vec::new();
let mut res = Vec::with_capacity(vec.len());
for e in vec.iter() {
let v = e.annotate_type(from_parser, env, ty)?;
res.push(v);
Expand Down
2 changes: 1 addition & 1 deletion rust/candid_parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "candid_parser"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
rust-version.workspace = true
authors = ["DFINITY Team"]
Expand Down
Loading