Skip to content

Commit

Permalink
fix IDLValue blob conversion (#517)
Browse files Browse the repository at this point in the history
* fix IDLValue blob conversion

* fix

* bump version
  • Loading branch information
chenyan-dfinity committed Jan 30, 2024
1 parent bf95a9f commit aef1e02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
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
@@ -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
@@ -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
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
@@ -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

0 comments on commit aef1e02

Please sign in to comment.