diff --git a/packages/notification/Readme.md b/packages/notification/Readme.md index bc19b95..4cf0538 100644 --- a/packages/notification/Readme.md +++ b/packages/notification/Readme.md @@ -6,7 +6,9 @@ These functions are meant to help you easily create notification channels for pr ### Implementing a `NotificationData` struct -Each notification channel will have a specified data format, which is defined by creating a struct that implements the `NotificationData` trait, which has two methods: `to_cbor` and `channel_id`. The following example illustrates how you might implement this for a channel called `my_channel` and notification data containing two fields: `message` and `amount`. +Each notification channel will have a specified data format, which is defined by creating a struct that implements the `NotificationData` trait, which has two methods: `to_cbor` and `channel_id`. + +The following example illustrates how you might implement this for a channel called `my_channel` and notification data containing two fields: `message` and `amount`. ```rust #[derive(Serialize, Debug, Deserialize, Clone)] @@ -36,16 +38,19 @@ The `api` parameter for `to_cbor` is not used in this example, but is there for ### Sending a TxHash notification -To send a notification to a recipient you then create a new `Notification` passing in the address of the recipient along with the notification data you want to send. The following creates a notification for the above `my_channel` and adds it to the contract `Response` as a plaintext attribute. +To send a notification to a recipient you first create a new `Notification` struct passing in the address of the recipient along with the notification data you want to send. Then to turn it into a `TxHashNotification` execute the `to_txhash_notification` method on the `Notification` by passing in `deps.api`, `env`, and an internal `secret`, which is a randomly generated byte slice that has been stored previously in your contract during initialization. + +The following code snippet creates a notification for the above `my_channel` and adds it to the contract `Response` as a plaintext attribute. ```rust -let note = Notification::new( +let notification = Notification::new( recipient, MyNotificationData { "hello".to_string(), 1000_u128, } -); +) +.to_txhash_notification(deps.api, &env, secret)?; // ... other code @@ -53,8 +58,8 @@ let note = Notification::new( Ok(Response::new() .set_data(to_binary(&ExecuteAnswer::MyMessage { status: Success } )?) .add_attribute_plaintext( - note.id_plaintext(), - note.data_plaintext(), + notification.id_plaintext(), + notification.data_plaintext(), ) ) ```