Code Template
Steps
1. Implement CommandTrait :
CommandTrait :2. Submit with inventory::submit
inventory::submit3. To get inputs, define a struct that implement Deserialize:
#[derive(Serialize, Deserialize, Debug)]
pub struct Input {
// special types like Keypair, Pubkey, Signature, Decimal
// have to be decorated with `#[serde(with = "...")]`
#[serde(with = "value::keypair")]
pub sender: Keypair,
#[serde(with = "value::pubkey")]
pub recipient: Pubkey,
// use default and ::opt for optional value
#[serde(default, with = "value::pubkey::opt")]
pub opt_pubkey: Option<Pubkey>,
#[serde(with = "value::decimal")]
pub amount: Decimal,
// optional input with a default value,
// use `#[serde(default = ...)]`
#[serde(default = "value::default::bool_true")]
pub submit: bool,
}4. Output is the same, but derive Serialize on it and use value::to_map.
value::to_map.Example

Last updated