diff --git a/docs/src/indexing/fuel-types/receipts/burn.md b/docs/src/indexing/fuel-types/receipts/burn.md index 417066451..9455c572f 100644 --- a/docs/src/indexing/fuel-types/receipts/burn.md +++ b/docs/src/indexing/fuel-types/receipts/burn.md @@ -1,8 +1,8 @@ -# Burn +# `Burn` -> - A `Burn` receipt is generated whenever an asset is burned in a Sway contract. [Read more about `Burn` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#burn-receipt) +> A `Burn` receipt is generated whenever an asset is burned in a Sway contract. [Read more about `Burn` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#burn-receipt) -### Definition +## Definition ```rust, ignore use fuel_types::{AssetId, ContractId}; @@ -15,13 +15,28 @@ pub struct Burn { } ``` -### Usage - +## Usage You can handle functions that produce a `Burn` receipt type by adding a parameter with the type `Burn`. ```rust, ignore -fn handle_burn(burn: Burn) { - // handle the emitted Burn receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_burn_receipt(block_data: BlockData) { + let height = block_data.header.height; + if !block_data.transactions.is_empty() { + let transaction = block_data.transactions[0]; + for receipt in transaction.receipts { + match receipt { + fuel::Receipt::Burn { contract_id, .. } => { + info!("Found burn receipt from contract {contract_id:?}"); + } + } + } + } + } } ``` diff --git a/docs/src/indexing/fuel-types/receipts/call.md b/docs/src/indexing/fuel-types/receipts/call.md index 480bab4e3..3892d91cd 100644 --- a/docs/src/indexing/fuel-types/receipts/call.md +++ b/docs/src/indexing/fuel-types/receipts/call.md @@ -1,4 +1,8 @@ -# Call +# `Call` + +> A `Call` receipt is generated whenever a function is called in a Sway contract. The `fn_name` field contains the name of the called function from the aforementioned contract. [Read more about `Call` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#call-receipt). + +## Definition ```rust, ignore use fuel_types::{AssetId, ContractId}; @@ -12,14 +16,26 @@ pub struct Call { } ``` -- A `Call` receipt is generated whenever a function is called in a Sway contract. -- The `fn_name` field contains the name of the called function from the aforementioned contract. -- [Read more about `Call` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#call-receipt) - -You can handle functions that produce a `Call` receipt type by adding a parameter with the type `Call`. +## Usage ```rust, ignore -fn handle_call(call: Call) { - // handle the emitted Call receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_call_receipt(block_data: BlockData) { + let height = block_data.header.height; + if !block_data.transactions.is_empty() { + let transaction = block_data.transactions[0]; + for receipt in transaction.receipts { + match receipt { + fuel::Receipt::Call { contract_id, .. } => { + info!("Found call receipt from contract {contract_id:?}"); + } + } + } + } + } } ``` diff --git a/docs/src/indexing/fuel-types/receipts/log.md b/docs/src/indexing/fuel-types/receipts/log.md index 88a60f8c1..63a9563db 100644 --- a/docs/src/indexing/fuel-types/receipts/log.md +++ b/docs/src/indexing/fuel-types/receipts/log.md @@ -1,4 +1,8 @@ -# Log +# `Log` + +> A `Log` receipt is generated when calling `log()` on a non-reference types in a Sway contracts - specifically `bool`, `u8`, `u16`, `u32`, and `u64`. The `ra` field includes the value being logged while `rb` may include a non-zero value representing a unique ID for the `log` instance. [Read more about `Log` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#log-receipt). + +## Definition ```rust, ignore use fuel_types::ContractId; @@ -9,15 +13,26 @@ pub struct Log { } ``` -- A `Log` receipt is generated when calling `log()` on a non-reference types in a Sway contracts. - - Specifically `bool`, `u8`, `u16`, `u32`, and `u64`. -- The `ra` field includes the value being logged while `rb` may include a non-zero value representing a unique ID for the `log` instance. -- [Read more about `Log` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#log-receipt) - -You can handle functions that produce a `Log` receipt type by adding a parameter with the type `Log`. +## Usage ```rust, ignore -fn handle_log(log: Log) { - // handle the emitted Log receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_log_receipt(block_data: BlockData) { + let height = block_data.header.height; + if !block_data.transactions.is_empty() { + let transaction = block_data.transactions[0]; + for receipt in transaction.receipts { + match receipt { + fuel::Receipt::Log { contract_id, .. } => { + info!("Found log receipt from contract {contract_id:?}"); + } + } + } + } + } } ``` diff --git a/docs/src/indexing/fuel-types/receipts/logdata.md b/docs/src/indexing/fuel-types/receipts/logdata.md index 8da6540a9..3ca421cbc 100644 --- a/docs/src/indexing/fuel-types/receipts/logdata.md +++ b/docs/src/indexing/fuel-types/receipts/logdata.md @@ -1,5 +1,13 @@ -# LogData +# `LogData` + +> A `LogData` receipt is generated when calling `log()` in a Sway contract on a reference type; this includes all types _except_ non-reference types. +> +> The `data` field will include the logged value as a hexadecimal. The `rb` field will contain a unique ID that can be used to look up the logged data type. [Read more about `LogData` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#logdata-receipt). +> +> Note: the example below will run both when the type `MyEvent` is logged as well as when `MyEvent` is returned from a function + +## Definition ```rust,ignore use fuel_types::ContractId; @@ -12,17 +20,16 @@ pub struct LogData { } ``` -- A `LogData` receipt is generated when calling `log()` in a Sway contract on a reference type; this includes all types _except_ non-reference types. -- The `data` field will include the logged value as a hexadecimal. - - The `rb` field will contain a unique ID that can be used to look up the logged data type. -- [Read more about `LogData` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#logdata-receipt) - -You can handle functions that produce a `LogData` receipt type by using the logged type as a function parameter. - -> Note: the example below will run both when the type `MyStruct` is logged as well as when `MyStruct` is returned from a function. +## Usage ```rust, ignore -fn handle_log_data(data: MyStruct) { - // handle the emitted LogData receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_log_data(event: MyEvent) { + info!("Event {event:?} was logged in the contract"); + } } ``` diff --git a/docs/src/indexing/fuel-types/receipts/messageout.md b/docs/src/indexing/fuel-types/receipts/messageout.md index f996db3ca..19d157bb5 100644 --- a/docs/src/indexing/fuel-types/receipts/messageout.md +++ b/docs/src/indexing/fuel-types/receipts/messageout.md @@ -1,4 +1,10 @@ -# MessageOut +# `MessageOut` + +> A `MessageOut` receipt is generated as a result of the `send_typed_message()` Sway method in which a message is sent to a recipient address along with a certain amount of coins. +> +> The `data` field supports data of an arbitrary type `T` and will be decoded by the indexer upon receipt. [Read more about `MessageOut` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#messageout-receipt). + +## Definition ```rust,ignore use fuel_types::{MessageId, Bytes32, Address}; @@ -14,14 +20,16 @@ pub struct MessageOut { } ``` -- A `MessageOut` receipt is generated as a result of the `send_typed_message()` Sway method in which a message is sent to a recipient address along with a certain amount of coins. -- The `data` field supports data of an arbitrary type `T` and will be decoded by the indexer upon receipt. -- [Read more about `MessageOut` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#messageout-receipt) - -You can handle functions that produce a `MessageOut` receipt type by adding a parameter with the type `MessageOut`. +## Usage ```rust, ignore -fn handle_message_out(message_out: MessageOut) { - // handle the emitted MessageOut receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_message_out(event: MyEvent) { + info!("Event {event:?} was logged in the contract"); + } } ``` diff --git a/docs/src/indexing/fuel-types/receipts/mint.md b/docs/src/indexing/fuel-types/receipts/mint.md index 2017478b2..fd63e46c5 100644 --- a/docs/src/indexing/fuel-types/receipts/mint.md +++ b/docs/src/indexing/fuel-types/receipts/mint.md @@ -1,4 +1,8 @@ -# Mint +# `Mint` + +> A `Mint` receipt is generated whenever an asset is burned in a Sway contract. [Read more about `Mint` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#mint-receipt). + +## Definition ```rust, ignore use fuel_types::{AssetId, ContractId}; @@ -11,13 +15,26 @@ pub struct Mint { } ``` -- A `Mint` receipt is generated whenever an asset is burned in a Sway contract. -- [Read more about `Mint` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#mint-receipt) - -You can handle functions that produce a `Mint` receipt type by adding a parameter with the type `Mint`. +## Usage ```rust, ignore -fn handle_mint(mint: Mint) { - // handle the emitted Mint receipt +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "my_indexer.manifest.yaml")] +mod my_indexer { + fn handle_mint_receipt(block_data: BlockData) { + let height = block_data.header.height; + if !block_data.transactions.is_empty() { + let transaction = block_data.transactions[0]; + for receipt in transaction.receipts { + match receipt { + fuel::Receipt::Mint { contract_id, .. } => { + info!("Found mint receipt from contract {contract_id:?}"); + } + } + } + } + } } ``` diff --git a/docs/src/indexing/fuel-types/transaction-status.md b/docs/src/indexing/fuel-types/transaction-status.md index 6a089adbb..a5aa02ea3 100644 --- a/docs/src/indexing/fuel-types/transaction-status.md +++ b/docs/src/indexing/fuel-types/transaction-status.md @@ -38,21 +38,19 @@ mod my_indexer { if !block_data.transactions.is_empty() { let transaction = block_data.transactions[0]; match transaction.transaction { - fuel::Transaction::Script(tx) => { - match tx.status { - fuel::TransactionStatus::Success { - block_id, time - } => { - info!("Transaction {} in block {} was successful at {}", tx.id, block_id, time); - } + fuel::Transaction::Script(tx) => match tx.status { + fuel::TransactionStatus::Success { block_id, time } => { + info!( + "Transaction {} in block {} was successful at {}", + tx.id, block_id, time + ); } - } + }, _ => { info!("We don't care about this transaction type"); } } } - } } ``` diff --git a/docs/src/indexing/fuel-types/transactions.md b/docs/src/indexing/fuel-types/transactions.md index 500a22460..e4191ab22 100644 --- a/docs/src/indexing/fuel-types/transactions.md +++ b/docs/src/indexing/fuel-types/transactions.md @@ -25,9 +25,14 @@ mod my_indexer { let height = block_data.header.height; if !block_data.transactions.is_empty() { let transaction = block_data.transactions[0]; - info!("Transaction {} in block at height {} has {} receipts", transaction.id, block_data.header.height, transaction.receipts.len()); + info!( + "Transaction {} in block at height {} has {} receipts", + transaction.id, + block_data.header.height, + transaction.receipts.len() + ); } - } } + ``` \ No newline at end of file