Skip to content

Commit

Permalink
Merge pull request #16 from EjembiEmmanuel/main
Browse files Browse the repository at this point in the history
minor changes
  • Loading branch information
EjembiEmmanuel authored Dec 12, 2024
2 parents 3d1aeeb + fcf3b29 commit e5f1689
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 63 deletions.
3 changes: 1 addition & 2 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ export default {
},
event_names: {
CAMPAIGN_CREATED: 'CreateCampaign',
CAMPAIGN_UPDATED: 'CampaignUpdated',
DONATION_RECEIVED: 'DonationCreated',
CAMPAIGN_DELETED: 'CampaignDeleted',
DEPLOYED_TOKEN_GIVER_NFT: 'DeployedTokenGiverNFT',
},
apibara: {
maxReceiveMessageLength: 128 * 1_048_576,
Expand Down
62 changes: 1 addition & 61 deletions src/token-giver-indexer/token-giver-indexer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ export class TokenGiverIndexerService {
validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.CAMPAIGN_CREATED),
),
validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.CAMPAIGN_UPDATED),
),
validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.DONATION_RECEIVED),
),
validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.CAMPAIGN_DELETED),
),
];
}

Expand All @@ -51,21 +45,11 @@ export class TokenGiverIndexerService {
):
this.handleCampaignCreatedEvent(event);
break;
case validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.CAMPAIGN_UPDATED),
):
this.handleCampaignUpdatedEvent(event);
break;
case validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.DONATION_RECEIVED),
):
this.handleDonationReceivedEvent(event);
break;
case validateAndParseAddress(
hash.getSelectorFromName(constants.event_names.CAMPAIGN_DELETED),
):
this.handleCampaignDeletedEvent(event);
break;
default:
this.logger.warn(`Unknown event type: ${eventKey}`);
}
Expand Down Expand Up @@ -107,53 +91,9 @@ export class TokenGiverIndexerService {
});
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private async handleCampaignUpdatedEvent(event: starknet.IEvent) {
const [ownerFelt, campaignAddressFelt] = event.keys;

const [tokenIdLow, tokenIdtHigh, tokenGiverNftContractAddressFelt] =
event.data;

const owner = validateAndParseAddress(
`0x${FieldElement.toBigInt(ownerFelt).toString(16)}`,
);

const campaignAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(campaignAddressFelt).toString(16)}`,
);

const tokenId = Number(
uint256.uint256ToBN({
low: FieldElement.toBigInt(tokenIdLow),
high: FieldElement.toBigInt(tokenIdtHigh),
}),
);

const tokenGiverNftContractAddress = validateAndParseAddress(
`0x${FieldElement.toBigInt(tokenGiverNftContractAddressFelt).toString(16)}`,
);

const campaign = await this.prismaService.campaign.findFirst({
where: { token_id: tokenId },
});

if (!campaign) {
this.logger.warn(`Campaign with token Id ${tokenId} doesn't exist`);
}

await this.prismaService.campaign.update({
where: { id: campaign.id },
data: {
campaign_address: campaignAddress,
campaign_owner: owner,
token_giver_nft_contract_address: tokenGiverNftContractAddress,
},
});
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private async handleDonationReceivedEvent(event: starknet.IEvent) {}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private async handleCampaignDeletedEvent(event: starknet.IEvent) {}
private async handleDeployedTokenGiverNftEvent(event: starknet.IEvent) {}
}

0 comments on commit e5f1689

Please sign in to comment.