diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 4e0881ac9..8561828ad 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -16,26 +16,12 @@ - [Manifest](./project-components/manifest.md) - [Schema](./project-components/schema.md) - [Module](./project-components/module.md) -- [Indexing](./indexing/index.md) - - [Custom Types](./indexing/custom-types/index.md) - - [Fuel Types](./indexing/fuel-types/index.md) - - [Blocks](./indexing/fuel-types/blocks.md) - - [Transactions](./indexing/fuel-types/transactions.md) - - [Transaction Status](./indexing/fuel-types/transaction-status.md) - - [Receipts](./indexing/fuel-types/receipts/index.md) - - [Burn](./indexing/fuel-types/receipts/burn.md) - - [Call](./indexing/fuel-types/receipts/call.md) - - [Log](./indexing/fuel-types/receipts/log.md) - - [LogData](./indexing/fuel-types/receipts/logdata.md) - - [MessageOut](./indexing/fuel-types/receipts/messageout.md) - - [Mint](./indexing/fuel-types/receipts/mint.md) - - [Panic](./indexing/fuel-types/receipts/panic.md) - - [Return](./indexing/fuel-types/receipts/return.md) - - [ReturnData](./indexing/fuel-types/receipts/returndata.md) - - [Revert](./indexing/fuel-types/receipts/revert.md) - - [ScriptResult](./indexing/fuel-types/receipts/scriptresult.md) - - [Transfer](./indexing/fuel-types/receipts/transfer.md) - - [TransferOut](./indexing/fuel-types/receipts/transferout.md) +- [Indexing Fuel Types](./indexing/fuel-types/index.md) + - [Blocks](./indexing/fuel-types/blocks.md) + - [Transactions](./indexing/fuel-types/transactions.md) + - [Transaction Status](./indexing/fuel-types/transaction-status.md) + - [Receipts](./indexing/fuel-types/receipts/index.md) +- [Indexing Custom Types](./indexing/custom-types/index.md) - [Authentication](./authentication/index.md) - [GraphQL](./graphql/index.md) - [Types](./graphql/types/index.md) diff --git a/docs/src/indexing/fuel-types/receipts.md b/docs/src/indexing/fuel-types/receipts.md new file mode 100644 index 000000000..ac0fa796e --- /dev/null +++ b/docs/src/indexing/fuel-types/receipts.md @@ -0,0 +1,379 @@ +# Receipts + +Every transaction in the Fuel network contains a list of receipts with information about that transaction, including what contract function was called, logged data, data returned from a function, etc. + +There are several types of receipts that can be attached to a transaction and indexed. You can learn more about each of these in the sections below. + +- [**Burn**](#burn) +- [**Call**](#call) +- [**Log**](#log) +- [**LogData**](#logdata) +- [**MessageOut**](#messageout) +- [**Mint**](#mint) +- [**Panic**](#panic) +- [**Return**](#return) +- [**ReturnData**](#returndata) +- [**Revert**](#revert) +- [**ScriptResult**](#scriptresult) +- [**Transfer**](#transfer) +- [**TransferOut**](#transferout) + +## 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://docs.fuel.network/docs/specs/abi/receipts/#burn-receipt). + +```rust, ignore +use fuel_types::{AssetId, ContractId}; +pub struct Burn { + pub sub_id: AssetId, + pub contract_id: ContractId, + pub val: u64, + pub pc: u64, + pub is: u64, +} +``` + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + 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:?}"); + } + } + } + } + } +} +``` + +## 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://docs.fuel.network/docs/specs/abi/receipts/#call-receipt). + +```rust, ignore +use fuel_types::{AssetId, ContractId}; +pub struct Call { + pub contract_id: ContractId, + pub to: ContractId, + pub amount: u64, + pub asset_id: AssetId, + pub gas: u64, + pub fn_name: String, +} +``` + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + 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:?}"); + } + } + } + } + } +} +``` + +## 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://docs.fuel.network/docs/specs/abi/receipts/#log-receipt). + +```rust, ignore +use fuel_types::ContractId; +pub struct Log { + pub contract_id: ContractId, + pub ra: u64, + pub rb: u64, +} +``` + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + 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:?}"); + } + } + } + } + } +} +``` + +## 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://docs.fuel.network/docs/specs/abi/receipts/#logdata-receipt). +> + +```rust,ignore +use fuel_types::ContractId; +pub struct LogData { + pub contract_id: ContractId, + pub data: Vec, + pub rb: u64, + pub len: u64, + pub ptr: u64, +} +``` + +> Note: the example below will run both when the type `MyEvent` is logged as well as when `MyEvent` is returned from a function. + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + fn handle_log_data(event: MyEvent) { + info!("Event {event:?} was logged in the contract"); + } +} +``` + +## 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://docs.fuel.network/docs/specs/abi/receipts/#messageout-receipt). + +```rust,ignore +use fuel_types::{MessageId, Bytes32, Address}; +pub struct MessageOut { + pub message_id: MessageId, + pub sender: Address, + pub recipient: Address, + pub amount: u64, + pub nonce: Bytes32, + pub len: u64, + pub digest: Bytes32, + pub data: Vec, +} +``` + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + fn handle_message_out(event: MyEvent) { + info!("Event {event:?} was logged in the contract"); + } +} +``` + +## 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://docs.fuel.network/docs/specs/abi/receipts/#mint-receipt). + +```rust, ignore +use fuel_types::{AssetId, ContractId}; +pub struct Mint { + pub sub_id: AssetId, + pub contract_id: ContractId, + pub val: u64, + pub pc: u64, + pub is: u64, +} +``` + +```rust, ignore +extern crate alloc; +use fuel_indexer_utils::prelude::*; + +#[indexer(manifest = "indexer.manifest.yaml")] +mod indexer_mod { + 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:?}"); + } + } + } + } + } +} +``` + +## Panic + +A `Panic` receipt is produced when a Sway smart contract call fails for a reason that doesn't produce a revert. The reason field records the reason for the panic, which is represented by a number between 0 and 255. You can find the mapping between the values and their meanings here in the FuelVM [source code](https://github.com/FuelLabs/fuel-vm/blob/master/fuel-asm/src/panic_reason.rs). [Read more about `Panic` in the Fuel Protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#mint-receipt). + +```rust, ignore +use fuel_types::ContractId; +pub struct Panic { + pub contract_id: ContractId, + pub reason: u32, +} +``` + +```rust, ignore +fn handle_panic(panic: Panic) { + // handle the emitted Panic receipt +} +```` + +## Return + +A `Return` receipt is generated when returning a non-reference type in a Sway contract, specifically `bool`, `u8`, `u16`, `u32`, and `u64`. The `val` field includes the value being returned. +- [Read more about `Return` in the Fuel Protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#return-receipt). + +```rust, ignore +use fuel_types::ContractId; +pub struct Return { + pub contract_id: ContractId, + pub val: u64, + pub pc: u64, + pub is: u64, +} +``` + + +You can handle functions that produce a `Return` receipt type by adding a parameter with the type `Return`. + +```rust, ignore +fn handle_return(data: Return) { + // handle the emitted Return receipt +} +``` + +## ReturnData + +A `ReturnData` receipt is generated when returning a reference type in a Sway contract; this includes all types _except_ non-reference types. The `data` field will include the returned value as a hexadecimal. [Read more about `ReturnData` in the Fuel protocol ABI spec](https://docs.fuel.network/docs/specs/abi/receipts/#returndata-receipt). + +```rust, ignore +use fuel_types::ContractId; +pub struct ReturnData { + id: ContractId, + data: Vec, +} +``` + +> Note: the example below will run both when the type `MyStruct` is logged as well as when `MyStruct` is returned from a function. + +```rust, ignore +fn handle_return_data(data: MyStruct) { + // handle the emitted ReturnData receipt +} +``` + +## Revert + +A `Revert` receipt is produced when a Sway smart contract function call fails. The table below lists possible reasons for the failure and their values. The `error_val` field records these values, enabling your indexer to identify the specific cause of the reversion. + +```rust, ignore +use fuel_types::ContractId; +pub struct Revert { + pub contract_id: ContractId, + pub error_val: u64, + } +``` + + +| Reason | Value | +|-----------------------|-------| +| FailedRequire | 0 | +| FailedTransferToAddress | 1 | +| FailedSendMessage | 2 | +| FailedAssertEq | 3 | +| FailedAssert | 4 | + +- [Read more about `Revert` in the Fuel Protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#revert-receipt). + + +```rust, ignore +fn handle_revert(revert: Revert) { + // handle the emitted Revert receipt +} +``` + +## ScriptResult + +A `ScriptResult` receipt is generated when a contract call resolves; that is, it's generated as a result of the `RET`, `RETD`, and `RVRT` instructions. The `result` field will contain a `0` for success, and a non-zero value otherwise. [Read more about `ScriptResult` in the Fuel Protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#scriptresult-receipt). + +```rust,ignore +pub struct ScriptResult { + pub result: u64, + pub gas_used: u64, +} +``` + +```rust, ignore +fn handle_script_result(script_result: ScriptResult) { + // handle the emitted ScriptResult receipt +} +``` + +## Transfer + +A `Transfer` receipt is generated when coins are transferred to a contract as part of a Sway contract. The `asset_id` field contains the asset ID of the transferred coins, as the FuelVM has built-in support for working with multiple assets. The `pc` and `is` fields aren't currently used for anything, but are included for completeness. [Read more about `Transfer` in the Fuel protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#transfer-receipt). + +```rust,ignore +use fuel_types::{ContractId, AssetId}; +pub struct Transfer { + pub contract_id: ContractId, + pub to: ContractId, + pub amount: u64, + pub asset_id: AssetId, + pub pc: u64, + pub is: u64, +} +``` + +```rust, ignore +fn handle_transfer(transfer: Transfer) { + // handle the emitted Transfer receipt +} +``` + +## TransferOut + +A `TransferOut` receipt is generated when coins are transferred to an address rather than a contract. Every other field of the receipt works the same way as it does in the `Transfer` receipt. [Read more about `TransferOut` in the Fuel protocol spec](https://docs.fuel.network/docs/specs/abi/receipts/#transferout-receipt). + +```rust,ignore +use fuel_types::{ContractId, AssetId, Address}; +pub struct TransferOut { + pub contract_id: ContractId, + pub to: Address, + pub amount: u64, + pub asset_id: AssetId, + pub pc: u64, + pub is: u64, +} +``` + +```rust, ignore +fn handle_transferout(transfer_out: TransferOut) { + // handle the emitted TransferOut receipt +} +``` diff --git a/docs/src/indexing/fuel-types/receipts/burn.md b/docs/src/indexing/fuel-types/receipts/burn.md deleted file mode 100644 index 268ccb674..000000000 --- a/docs/src/indexing/fuel-types/receipts/burn.md +++ /dev/null @@ -1,42 +0,0 @@ -# `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) - -## Definition - -```rust, ignore -use fuel_types::{AssetId, ContractId}; -pub struct Burn { - pub sub_id: AssetId, - pub contract_id: ContractId, - pub val: u64, - pub pc: u64, - pub is: u64, -} -``` - -## Usage - -You can handle functions that produce a `Burn` receipt type by adding a parameter with the type `Burn`. - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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 deleted file mode 100644 index c401ee123..000000000 --- a/docs/src/indexing/fuel-types/receipts/call.md +++ /dev/null @@ -1,41 +0,0 @@ -# `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}; -pub struct Call { - pub contract_id: ContractId, - pub to: ContractId, - pub amount: u64, - pub asset_id: AssetId, - pub gas: u64, - pub fn_name: String, -} -``` - -## Usage - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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/index.md b/docs/src/indexing/fuel-types/receipts/index.md deleted file mode 100644 index 7df216dcf..000000000 --- a/docs/src/indexing/fuel-types/receipts/index.md +++ /dev/null @@ -1 +0,0 @@ -# Receipts \ No newline at end of file diff --git a/docs/src/indexing/fuel-types/receipts/log.md b/docs/src/indexing/fuel-types/receipts/log.md deleted file mode 100644 index a58ffd71f..000000000 --- a/docs/src/indexing/fuel-types/receipts/log.md +++ /dev/null @@ -1,38 +0,0 @@ -# `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; -pub struct Log { - pub contract_id: ContractId, - pub ra: u64, - pub rb: u64, -} -``` - -## Usage - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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 deleted file mode 100644 index 876aa069f..000000000 --- a/docs/src/indexing/fuel-types/receipts/logdata.md +++ /dev/null @@ -1,35 +0,0 @@ - -# `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; -pub struct LogData { - pub contract_id: ContractId, - pub data: Vec, - pub rb: u64, - pub len: u64, - pub ptr: u64, -} -``` - -## Usage - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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 deleted file mode 100644 index ebb3f7048..000000000 --- a/docs/src/indexing/fuel-types/receipts/messageout.md +++ /dev/null @@ -1,35 +0,0 @@ -# `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}; -pub struct MessageOut { - pub message_id: MessageId, - pub sender: Address, - pub recipient: Address, - pub amount: u64, - pub nonce: Bytes32, - pub len: u64, - pub digest: Bytes32, - pub data: Vec, -} -``` - -## Usage - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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 deleted file mode 100644 index b9b9c2157..000000000 --- a/docs/src/indexing/fuel-types/receipts/mint.md +++ /dev/null @@ -1,40 +0,0 @@ -# `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}; -pub struct Mint { - pub sub_id: AssetId, - pub contract_id: ContractId, - pub val: u64, - pub pc: u64, - pub is: u64, -} -``` - -## Usage - -```rust, ignore -extern crate alloc; -use fuel_indexer_utils::prelude::*; - -#[indexer(manifest = "indexer.manifest.yaml")] -mod indexer_mod { - 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/receipts/panic.md b/docs/src/indexing/fuel-types/receipts/panic.md deleted file mode 100644 index 0cc0e558b..000000000 --- a/docs/src/indexing/fuel-types/receipts/panic.md +++ /dev/null @@ -1,20 +0,0 @@ -# Panic - -```rust, ignore -use fuel_types::ContractId; -pub struct Panic { - pub contract_id: ContractId, - pub reason: u32, -} -``` - -- A `Panic` receipt is produced when a Sway smart contract call fails for a reason that doesn't produce a revert. -- The reason field records the reason for the panic, which is represented by a number between 0 and 255. You can find the mapping between the values and their meanings here in the FuelVM [source code](https://github.com/FuelLabs/fuel-vm/blob/master/fuel-asm/src/panic_reason.rs). -- [Read more about `Panic` in the Fuel Protocol spec](https://specs.fuel.network/master/abi/receipts.html#panic-receipt) -- You can handle functions that could produce a `Panic` receipt by adding a parameter with the type `Panic`. - -```rust, ignore -fn handle_panic(panic: Panic) { - // handle the emitted Panic receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/receipts.md b/docs/src/indexing/fuel-types/receipts/receipts.md deleted file mode 100644 index b72a79a09..000000000 --- a/docs/src/indexing/fuel-types/receipts/receipts.md +++ /dev/null @@ -1,19 +0,0 @@ -# Receipts - -Every transaction in the Fuel network contains a list of receipts with information about that transaction, including what contract function was called, logged data, data returned from a function, etc. - -There are several types of receipts that can be attached to a transaction and indexed. You can learn more about each of these in the sections below. - -- [**Burn**](./burn.md) -- [**Call**](./call.md) -- [**Log**](./log.md) -- [**LogData**](./logdata.md) -- [**MessageOut**](./messageout.md) -- [**Mint**](./mint.md) -- [**Panic**](./panic.md) -- [**Return**](./return.md) -- [**ReturnData**](./returndata.md) -- [**Revert**](./revert.md) -- [**ScriptResult**](./scriptresult.md) -- [**Transfer**](./transfer.md) -- [**TransferOut**](./transferout.md) diff --git a/docs/src/indexing/fuel-types/receipts/return.md b/docs/src/indexing/fuel-types/receipts/return.md deleted file mode 100644 index c3b5efd26..000000000 --- a/docs/src/indexing/fuel-types/receipts/return.md +++ /dev/null @@ -1,24 +0,0 @@ -# Return - -```rust, ignore -use fuel_types::ContractId; -pub struct Return { - pub contract_id: ContractId, - pub val: u64, - pub pc: u64, - pub is: u64, -} -``` - -- A `Return` receipt is generated when returning a non-reference type in a Sway contract. - - Specifically `bool`, `u8`, `u16`, `u32`, and `u64`. -- The `val` field includes the value being returned. -- [Read more about `Log` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#return-receipt) - -You can handle functions that produce a `Return` receipt type by adding a parameter with the type `Return`. - -```rust, ignore -fn handle_return(data: Return) { - // handle the emitted Return receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/returndata.md b/docs/src/indexing/fuel-types/receipts/returndata.md deleted file mode 100644 index f4eabe64a..000000000 --- a/docs/src/indexing/fuel-types/receipts/returndata.md +++ /dev/null @@ -1,23 +0,0 @@ -# ReturnData - -```rust, ignore -use fuel_types::ContractId; -pub struct ReturnData { - id: ContractId, - data: Vec, -} -``` - -- A `ReturnData` receipt is generated when returning a reference type in a Sway contract; this includes all types _except_ non-reference types. -- The `data` field will include the returned value as a hexadecimal. -- [Read more about `ReturnData` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#returndata-receipt) - -You can handle functions that produce a `ReturnData` receipt type by using the returned 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. - -```rust, ignore -fn handle_return_data(data: MyStruct) { - // handle the emitted ReturnData receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/revert.md b/docs/src/indexing/fuel-types/receipts/revert.md deleted file mode 100644 index a7f45869e..000000000 --- a/docs/src/indexing/fuel-types/receipts/revert.md +++ /dev/null @@ -1,31 +0,0 @@ -# Revert - -```rust, ignore -use fuel_types::ContractId; -pub struct Revert { - pub contract_id: ContractId, - pub error_val: u64, - } -``` - -- A `Revert` receipt is produced when a Sway smart contract function call fails. -- The table below lists possible reasons for the failure and their values. -- The `error_val` field records these values, enabling your indexer to identify the specific cause of the reversion. - -| Reason | Value | -|-----------------------|-------| -| FailedRequire | 0 | -| FailedTransferToAddress | 1 | -| FailedSendMessage | 2 | -| FailedAssertEq | 3 | -| FailedAssert | 4 | - -- [Read more about `Revert` in the Fuel Protocol spec](https://specs.fuel.network/master/abi/receipts.html#revert-receipt) - -You can handle functions that could produce a `Revert` receipt by adding a parameter with the type `Revert`. - -```rust, ignore -fn handle_revert(revert: Revert) { - // handle the emitted Revert receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/scriptresult.md b/docs/src/indexing/fuel-types/receipts/scriptresult.md deleted file mode 100644 index a99f20754..000000000 --- a/docs/src/indexing/fuel-types/receipts/scriptresult.md +++ /dev/null @@ -1,20 +0,0 @@ -# ScriptResult - -```rust,ignore -pub struct ScriptResult { - pub result: u64, - pub gas_used: u64, -} -``` - -- A `ScriptResult` receipt is generated when a contract call resolves; that is, it's generated as a result of the `RET`, `RETD`, and `RVRT` instructions. -- The `result` field will contain a `0` for success, and a non-zero value otherwise. -- [Read more about `ScriptResult` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#scriptresult-receipt) - -You can handle functions that produce a `ScriptResult` receipt type by adding a parameter with the type `ScriptResult`. - -```rust, ignore -fn handle_script_result(script_result: ScriptResult) { - // handle the emitted ScriptResult receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/transfer.md b/docs/src/indexing/fuel-types/receipts/transfer.md deleted file mode 100644 index 534b2085c..000000000 --- a/docs/src/indexing/fuel-types/receipts/transfer.md +++ /dev/null @@ -1,26 +0,0 @@ -# Transfer - -```rust,ignore -use fuel_types::{ContractId, AssetId}; -pub struct Transfer { - pub contract_id: ContractId, - pub to: ContractId, - pub amount: u64, - pub asset_id: AssetId, - pub pc: u64, - pub is: u64, -} -``` - -- A `Transfer` receipt is generated when coins are transferred to a contract as part of a Sway contract. -- The `asset_id` field contains the asset ID of the transferred coins, as the FuelVM has built-in support for working with multiple assets. - - The `pc` and `is` fields aren't currently used for anything, but are included for completeness. -- [Read more about `Transfer` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#transfer-receipt) - -You can handle functions that produce a `Transfer` receipt type by adding a parameter with the type `Transfer`. - -```rust, ignore -fn handle_transfer(transfer: Transfer) { - // handle the emitted Transfer receipt -} -``` diff --git a/docs/src/indexing/fuel-types/receipts/transferout.md b/docs/src/indexing/fuel-types/receipts/transferout.md deleted file mode 100644 index 70a2c58e4..000000000 --- a/docs/src/indexing/fuel-types/receipts/transferout.md +++ /dev/null @@ -1,25 +0,0 @@ -# TransferOut - -```rust,ignore -use fuel_types::{ContractId, AssetId, Address}; -pub struct TransferOut { - pub contract_id: ContractId, - pub to: Address, - pub amount: u64, - pub asset_id: AssetId, - pub pc: u64, - pub is: u64, -} -``` - -- A `TransferOut` receipt is generated when coins are transferred to an address rather than a contract. -- Every other field of the receipt works the same way as it does in the `Transfer` receipt. -- [Read more about `TransferOut` in the Fuel protocol ABI spec](https://specs.fuel.network/master/abi/receipts.html#transferout-receipt) - -You can handle functions that produce a `TransferOut` receipt type by adding a parameter with the type `TransferOut`. - -```rust, ignore -fn handle_transferout(transfer_out: TransferOut) { - // handle the emitted TransferOut receipt -} -```