Indexer panics at runtime

Hi team

Indexer service panics at runtime whenever it executes the wasm module . I am sure that indexer is executes wasm-snip [!native] before it reads from the wasm file because now on each deploy command indexer will run the build command first .

Version forc index 0.2.0

@kern could do you help?

2 Likes

Can you share your index code?

1 Like

Hi @kern
here is lib.rs

extern crate alloc;
use fuel_indexer_macros::indexer;
use fuel_indexer_plugin::prelude::*;
use fuels_types::param_types::ParamType;
use fuels_types::errors::Error as FuelError;
use fuels_core::try_from_bytes;

pub struct NFTListedEvent {
    pub owner: Identity,
    pub nft_contract: ContractId,
    pub token_id: u64,
    pub price: u64, 
    pub token_uri: SizedAsciiString<59usize>
}

impl Parameterize for NFTListedEvent {
    fn param_type() -> ParamType {
        let types = [
            <Identity>::param_type(),
            <ContractId>::param_type(),
            <u64>::param_type(),
            <u64>::param_type(),
            SizedAsciiString::<59usize>::param_type(),
        ].to_vec();

        ParamType::Struct {
            fields: types,
            generics: [].to_vec(),
        }
    }
}

impl Tokenizable for NFTListedEvent {
    fn into_token(self) -> Token {
        let tokens = [
            self.owner.into_token(),
            self.nft_contract.into_token(),
            self.token_id.into_token(),
            self.price.into_token(),
            self.token_uri.into_token(),
        ]
            .to_vec();
        Token::Struct(tokens)
    }
    fn from_token(token: Token) -> Result<Self, FuelError> {
        match token {
            Token::Struct(tokens) => {
                let mut tokens_iter = tokens.into_iter();
                let mut next_token = move || {
                    tokens_iter
                        .next()
                        .ok_or_else(|| {
                            FuelError::InstantiationError("Rasn out of token before construction close".into())
                        })
                };
                Ok(Self {
                    owner: <Identity>::from_token(next_token()?)?,
                    nft_contract: <ContractId>::from_token(next_token()?)?,
                    token_id: <u64>::from_token(next_token()?)?,
                    price: <u64>::from_token(next_token()?)?,
                    token_uri: <SizedAsciiString<
                        59usize,
                    >>::from_token(next_token()?)?,
                })
            }
            _ => {
                Err(
                    FuelError::InstantiationError("Expected token struct".into()),
                )
            }
        }
    }
}


#[indexer(manifest = "/home/ahimas/indexer/test-index/test_index.manifest.yaml")]
pub mod test_index_index_mod {

    fn test_index_handler(block_data: BlockData) {
        Logger::info("Processing a block. (>'.')>");
       for transaction in block_data.transactions {
            for receipts in transaction.receipts {
                if let Receipt::LogData { 
                    id, 
                    ra, 
                    rb, 
                    ptr, 
                    len, 
                    digest, 
                    data, 
                    pc, 
                    is
                }  = receipts {
                    let msg = format!("Processing a receipt logdata. (>'.')> ");
                        Logger::info(msg.as_str());
                        if rb == 14 {
                            if let Ok(list_event)  = try_from_bytes::<NFTListedEvent>(&data[..]){
                                    let nft_list = NftList{
                                        id: list_event.token_id,
                                        nft_contract : list_event.nft_contract,
                                        token_id : list_event.token_id,
                                        price : list_event.price
                                    };
                                    let message = format!(
                                        "id : {}, nft_contract: {}, token_id : {}, price: {} , token_uri : {}" , nft_list.id, nft_list.nft_contract,
                                        nft_list.token_id,nft_list.price,"foo"
                                    );
                                    Logger::info(&message);
                                    nft_list.save();
                                    Logger::info(":) Saved Successfully");
                            }
                        }
                }
                
            }    
        }
    }
}

*-manifest.yaml

namespace: fuelindexer
abi: ~
identifier: test_index
graphql_schema: /home/indexer/test-index/schema/test_index.schema.graphql
module:
  wasm: /home/indexer/test-index/target/wasm32-unknown-unknown/debug/test_index.wasm
metrics: ~
contract_id: "0xf4ee210395d1d53f25927abd7c33459a67db12b1f65f1944f63ec2ddaef3e52c"
start_block: ~
2 Likes

@Ahimasjason Could you just share your ABI and GraphQL schema, if possible?

Hi @rashad , I was getting this error Failed to build indexer due to `ContractId` not found in this scope when i add ABI path in the manifest file so i did not add the ABI path as you can clearly see on the manifest file which i posted on my earlier comment also i have just used basic graphql schema you can find it below.

schema {
    query: QueryRoot
}

type QueryRoot {
   nft: NftList
}


type NftList {
    id : ID!
    nft_contract: ContractId!
    token_id: UInt8!
    price : UInt8!
}

@Ahimasjason