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

doc: impl details of #[callback_unwrap] #1319

Closed
wants to merge 10 commits into from
14 changes: 10 additions & 4 deletions examples/adder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ impl Adder {
&self,
#[callback_unwrap] a: DoublePair,
#[callback_unwrap] b: DoublePair,
#[callback_vec] others: Vec<DoublePair>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[callback_vec] isn't really compatible with #[callback_unwrap] to be used in this manner, due to a feature??/bug??, because it revisits the same promise indices, already visited by callback_unwrap,
so others vector in this example contained a and b as first elements

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #1320 to describe with an example + assertion of current behaviour, because it looks like it's not obvious to get it with cargo expand example

) -> DoublePair {
Some(b).iter().chain(others.iter()).fold(a, |acc, el| DoublePair {
Some(b).iter().fold(a, |acc, el| DoublePair {
first: sum_pair(&acc.first, &el.first),
second: sum_pair(&acc.second, &el.second),
})
}

pub fn add_callback_vec(&self, #[callback_vec] elements: Vec<DoublePair>) -> DoublePair {
let start = DoublePair { first: Pair(0, 0), second: Pair(0, 0) };
elements.iter().fold(start, |acc, el| DoublePair {
first: sum_pair(&acc.first, &el.first),
second: sum_pair(&acc.second, &el.second),
})
Expand All @@ -55,8 +62,7 @@ mod tests {

let res = contract.view("__contract_abi").await?;

let abi_root =
serde_json::from_slice::<AbiRoot>(&zstd::decode_all(&res.result[..])?)?;
let abi_root = serde_json::from_slice::<AbiRoot>(&zstd::decode_all(&res.result[..])?)?;

assert_eq!(abi_root.schema_version, "0.4.0");
assert_eq!(abi_root.metadata.name, Some("adder".to_string()));
Expand Down