You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cross contract calls: document the non panicking version #413
Our current cross contract call example panics when the called contract panics.
However, often times the calling contract would be interested in handling the error, rather than panicing. It would be beneficial to either add this to our existing cross contract how-to or potentially somewhere else.
For example, instead of this call, which will panic when add() panics:
let client = contract_a::ContractClient::new(&env, contract_id);
client.add(&x,&y)
We can introduce something like this call, which will return 0 when add() panics:
let client = contract_a::ContractClient::new(&env, contract_id);
client.try_add(&x,&y).unwrap_or(Ok(0)).unwrap()
When we demonstrate it in the docs it'd be good to demonstrate the Result destructing a little more verbosely. There's nothing wrong with using unwrap_or, but we should show contracts how to take different actions for different errors.
For example:
let client = contract_a::ContractClient::new(&env, contract_id);match client.try_add(&x,&y){// the contract returned a valueOk(Ok(number)) => todo!("do something with the number returned"),Ok(Err(ConversionError)) => todo!("got a value back, but it wasn't a number like we expected"),// the contract erroredErr(Ok(Error::AnError)) => todo!("do something when an error occurs that the contract included in its contract spec"),Err(Err(status)) => todo!("do something when an unrecognized error, or system error, occurs"),}
This 👍 And also if I can add something (was not sure about making a new issue for it), it would be good to show usages of invoke_contract and try_invoke_contract by extension. Plus a discussion on pros/cons like fees.
(I was looking if there was a bounty entry for cross contract calls as I now spent some time playing around and could have tried to contribute. Regardless, happy to try and take a stab at it if wanted cc @briwylde08 😃)
Thanks again for your contribution @tupui! Your bounty submission has qualified for $150 worth of XLM. Is the previously summitted information still valid for your award payment?
Activity
leighmcculloch commentedon May 3, 2023
When we demonstrate it in the docs it'd be good to demonstrate the
Resultdestructing a little more verbosely. There's nothing wrong with usingunwrap_or, but we should show contracts how to take different actions for different errors.For example:
[Soroban Merge] Create a "Smart Contracts" section (stellar#388)
tupui commentedon Jul 29, 2024
This 👍 And also if I can add something (was not sure about making a new issue for it), it would be good to show usages of
invoke_contractandtry_invoke_contractby extension. Plus a discussion on pros/cons like fees.(I was looking if there was a bounty entry for cross contract calls as I now spent some time playing around and could have tried to contribute. Regardless, happy to try and take a stab at it if wanted cc @briwylde08 😃)
briwylde08 commentedon Jul 31, 2024
@janewang, I see this has been labeled as part of the Horizon scrum, do you know if this is being worked on internally?
janewang commentedon Jul 31, 2024
It does not appear to be. I added to the Dev X docpocalyse so perhaps we could get to it this week.
briwylde08 commentedon Aug 1, 2024
@tupui: feel free to take this one! We'll offer $150 worth of XLM for the docs bounty!
tupui commentedon Aug 1, 2024
Thanks! Starting right away
tupui commentedon Aug 2, 2024
I opened a PR 😃 #853 Thanks again all!
briwylde08 commentedon Aug 12, 2024
Thanks again for your contribution @tupui! Your bounty submission has qualified for $150 worth of XLM. Is the previously summitted information still valid for your award payment?
tupui commentedon Aug 13, 2024
All is still valid. Thanks again everyone, that was a fun program to participate in 😃