-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FEAT: Implement Starknet event parsers #54 #57
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: