Transactions

TransactionData

The TransactionData struct contains important information about a transaction in the Fuel network. The id field is the transaction hash, which is a 32-byte string. The receipts field contains a list of Receipts, which are generated by a Fuel node during the execution of a Sway smart contract; you can find more information in the Receipts section.

Definition

pub struct TransactionData {
    pub transaction: Transaction,
    pub status: TransactionStatus,
    pub receipts: Vec<Receipt>,
    pub id: TxId,
}

Usage

extern crate alloc;
use fuel_indexer_utils::prelude::*;

#[indexer(manifest = "indexer.manifest.yaml")]
mod indexer_mod {
    fn handle_transaction(block_data: BlockData) {
        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()
            );
        }
    }
}

TransactionStatus

TransactionStatus refers to the status of a Transaction in the Fuel network.

Definition

pub enum TransactionStatus {
    Failure {
        block_id: String,
        time: DateTime<Utc>,
        reason: String,
    },
    SqueezedOut {
        reason: String,
    },
    Submitted {
        submitted_at: DateTime<Utc>,
    },
    Success {
        block_id: String,
        time: DateTime<Utc>,
    },
}

Usage

extern crate alloc;
use fuel_indexer_utils::prelude::*;

#[indexer(manifest = "indexer.manifest.yaml")]
mod indexer_mod {
    fn handle_transaction(block_data: BlockData) {
        let height = block_data.header.height;
        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
                        );
                    }
                },
                _ => {
                    info!("We don't care about this transaction type");
                }
            }
        }
    }
}