Skip to content

FEAT: Implement Starknet event parsers #54 #57

Closed as duplicate of#54
Closed as duplicate of#54
@Cevedale

Description

@Cevedale

Hey!
You may need to adapt it based on your specific needs and the details of the Starknet API:

// src/starknet/parser.ts

class Contract {
private address: string;
private abi: any; // replace 'any' with the actual type of ABI

constructor({ address, abi }: { address: string, abi: any }) {
this.address = address;
this.abi = abi;
}

eventFilter(eventName: string): any {
// Implement your logic to generate the DNA filter based on the event name
// This is just a placeholder, replace it with the actual logic
const filter = {
fromAddress: "...",
// ... other filter properties
};
return filter;
}

eventParser(eventData: any): any {
// Implement your logic to parse the event data into TypeScript objects
// This is just a placeholder, replace it with the actual logic
const parsedData = {
// ... parsed data properties
};
return parsedData;
}
}

export default Contract;

test file:
// packages/indexer/test/parser.test.ts

import Contract from '../src/starknet/parser';

describe('eventFilter', () => {
it('returns the DNA filter', () => {
const contract = new Contract({ address: 'your_contract_address', abi: {} /* your ABI here */ });
const filter = contract.eventFilter('Transfer');
expect(filter).toMatchInlineSnapshot({ fromAddress: "...", ... });
});
});

describe('eventParser', () => {
it('parses event data into TypeScript objects', () => {
const contract = new Contract({ address: 'your_contract_address', abi: {} /* your ABI here / });
const parsedData = contract.eventParser({/ your sample event data here /});
expect(parsedData).toMatchInlineSnapshot({ /
expected parsed data structure */ });
});
});

Replace 'your_contract_address', {} /* your ABI here */, and other placeholders with the actual values and data structures based on your Starknet contract and ABI.

This is a basic starting point, and you may need to adjust it based on the actual structure of Starknet events and contracts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions