## Gear 智能合约 -- Vara Network
### Gstd v1.1.1 新特性概览
- https://github.com/gear-tech/gear/releases/tag/v1.1.1
- `assert_panicked_with` gtest assert panic string
- https://github.com/gear-tech/gear/releases/tag/v1.1.0
- `gr_env_vars()` syscall
- `dbg!` macro
- `critical::set_hook` custom panic hook
- Next: Builtin Actors Framework
---
#### 📚 New testing function has been added to `gtest` that allows to assert that message panicked with specific string (#3670);
> [!TIP]
> Check out following `gtest` API snapshot:
```diff
let panic_msg = "panic!";
- assert_eq!(result.log().len(), 1);
- assert!(matches!(
- result.log()[0].reply_code(),
- Some(ReplyCode::Error(ErrorReplyReason::Execution(
- SimpleExecutionError::UserspacePanic
- )))
- ));
- let payload = String::from_utf8(result.log()[0].payload().into())
- .expect("Unable to decode panic message");
- assert!(payload.contains(&format!("panicked with '{panic_msg}'")));
+ result.assert_panicked_with(panic_msg);
```
---
#### 📖 New syscall `gr_env_vars()` that allows to query some actual blockchain parameters added (#3403);
> [!TIP]
> Check out following `gstd` API snapshot:
```rust
use gstd::exec;
let vars = exec::env_vars();
// Current multiplier percent recommended to use with explicit gas amounts.
let _ = vars.performance_multiplier;
// Current value of existential deposit (minimum balance).
let _ = vars.existential_deposit;
// Current value of mailbox threshold (minimum gas applied for message to user to be inserted into `Mailbox`).
let _ = vars.mailbox_threshold;
// Current value of gas multiplier (how much value, where value is 10^(-12) Token, is in a single gas).
let _ = vars.gas_multiplier;
```
---
#### 📚 Added `dbg!` macro for `gstd` (#3610);
> [!NOTE]
> Its usage is identical to Rust `std` one: [link](https://doc.rust-lang.org/beta/std/macro.dbg.html)
---
#### 📖 `gstd` now has critical hooks: the code guaranteed to be executed even if panic occurs (#3503);
> [!TIP]
> This API allows to revert state changes applied if something went wrong with business process.
> Check out a small demo and dive into `gstd`s module docs for more info:
```rust
use gstd::{critical, msg};
#[gstd::async_main]
async fn main() {
let source = msg::source();
critical::set_hook(move || {
msg::send(source, "I failed :c", 0).expect("Failed to send emergency message");
});
let reply = msg::send_for_reply(source, "Say my name", 0, 0)
.expect("Failed to send message")
.await
.expect("Received error reply");
// here goes "reply" processing //
// processing ends panicking,
// but user guaranteed to receive emergency message.
}
```
---
Next: Builtin Actors Framework
> Following the discussion on reworking the original approach to builtin actors (#3504), a new extensible framework for Runtime builtin actors is proposed.
> Examples of actual "production" builtin actor (like staking-proxy one) are beyond the scope of this PR and will be added subsequently.
https://github.com/gear-tech/gear/pull/3624
---
# Questions
<img src="https://hackmd.io/_uploads/SyK8P72d2.jpg" width="240" alt="GEAR">
<img src="https://hackmd.io/_uploads/By_kgE3_2.png" width="240" alt="VARA">
课后答疑频道: https://t.me/Gear_CN
{"title":"Gstd v1.1.1 新特性概览","slideOptions":"{\"theme\":\"dark\",\"spotlight\":{\"enabled\":false},\"width\":1600,\"height\":900}","description":"本 PPT 链接: https://hackmd.io/@btwiuse/gstd111","contributors":"[{\"id\":\"94262fbf-81ae-4ed7-933c-561a41bd977a\",\"add\":6966,\"del\":3558}]"}