Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
update usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashad Alston authored and Rashad Alston committed Sep 8, 2023
1 parent 7d0ae9c commit bda6d7c
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 61 deletions.
29 changes: 22 additions & 7 deletions docs/src/indexing/fuel-types/receipts/burn.md
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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:?}");
}
}
}
}
}
}
```
32 changes: 24 additions & 8 deletions docs/src/indexing/fuel-types/receipts/call.md
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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:?}");
}
}
}
}
}
}
```
33 changes: 24 additions & 9 deletions docs/src/indexing/fuel-types/receipts/log.md
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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:?}");
}
}
}
}
}
}
```
29 changes: 18 additions & 11 deletions docs/src/indexing/fuel-types/receipts/logdata.md
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
}
}
```
24 changes: 16 additions & 8 deletions docs/src/indexing/fuel-types/receipts/messageout.md
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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");
}
}
```
31 changes: 24 additions & 7 deletions docs/src/indexing/fuel-types/receipts/mint.md
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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:?}");
}
}
}
}
}
}
```
16 changes: 7 additions & 9 deletions docs/src/indexing/fuel-types/transaction-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
}
```
9 changes: 7 additions & 2 deletions docs/src/indexing/fuel-types/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
}
```

0 comments on commit bda6d7c

Please sign in to comment.