1 stable release
new 1.7.0 | Nov 26, 2024 |
---|
#11 in #staking
49KB
936 lines
Helper crate defining Gear built-in actors communication protocol.
This crate defines a set of types that contracts can use to interact with the so-called "builtin" actors - that is the actors that are defined for any Gear runtime and provide an API for the applications to build on top of some blockchain logic like staking, governance, etc. For a builtin actor to process a message, it should be able to decode its payload into one of the supported message types.
Examples
The following example shows how a contract can send a message to a builtin actor
(specifically, a staking actor) to bond some value
to self as the controller
so that the contract can later use the staking API to nominate validators.
use gstd::{msg, ActorId};
use gbuiltins::staking::{Request, RewardAccount};
use parity_scale_codec::Encode;
const BUILTIN_ADDRESS: ActorId = ActorId::new(hex_literal::hex!(
"77f65ef190e11bfecb8fc8970fd3749e94bed66a23ec2f7a3623e785d0816761"
));
#[gstd::async_main]
async fn main() {
let value = msg::value();
let payee: RewardAccount = RewardAccount::Program;
let payload = Request::Bond { value, payee }.encode();
let _ = msg::send_bytes_for_reply(BUILTIN_ADDRESS, &payload[..], 0, 0)
.expect("Error sending message")
.await;
}
# fn main() {}
Dependencies
~3.5MB
~66K SLoC