Advanced Message

Having to pass two arguments to create the Message is annoying, why not pass the Message directly!

First let's add some documentation to the struct:

/// A simple message with a title
#[derive(BorshDeserialize, BorshSerialize, Deserialize, Serialize)]
#[serde(crate = "near_sdk::serde")]
#[witgen]
pub struct Message {
    /// Title that describes the message
    title: String,
    /// body of the  message
    body: String,
}

Deserialize and Serialize are now needed to allow the Message to be parsed to and from JSON.

Update methods

#[near_bindgen]
impl StatusMessage {
    pub fn set_status(&mut self, message: Message) {
        let account_id = env::signer_account_id();
        self.records.insert(&account_id, &message);
    }

    pub fn get_status(&self, account_id: AccountId) -> Option<Message> {
        self.records.get(&account_id)
    }
}

Now we have Message as a argument to set_status and don't need to convert Message manually when returning it from get_status.