Skip to content

Commit

Permalink
chore: remove handling of transfer event
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 2, 2024
1 parent 1a6f8d9 commit 9fc1b43
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,84 +165,6 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<

await Promise.allSettled(recordSaves);
}

export async function handleTransferEvent(
cosmosEvent: CosmosEvent
): Promise<void> {
const { event } = cosmosEvent;

if (event.type != EVENT_TYPES.TRANSFER) {
logger.warn('Not valid transfer event.');
return;
}

logger.info('Event:TRANSFER');
logger.info(`Event Data:${JSON.stringify(cosmosEvent.event)}`);

const balancesKit = balancesEventKit();
const data = balancesKit.getData(cosmosEvent);
logger.info(`Decoded Data:${JSON.stringify(data)}`);

const recipientAddress = balancesKit.getAttributeValue(
data,
BALANCE_FIELDS.transfer_recipient
);
const senderAddress = balancesKit.getAttributeValue(
data,
BALANCE_FIELDS.transfer_sender
);
const transactionAmount = balancesKit.getAttributeValue(
data,
BALANCE_FIELDS.amount
);

if (!recipientAddress) {
logger.error('Recipient address is missing or invalid.');
return;
}

if (!senderAddress) {
logger.error('Sender address is missing or invalid.');
return;
}

const { isBLDTransaction, amount } =
balancesKit.validateBLDTransaction(transactionAmount);

if (!transactionAmount || !isBLDTransaction) {
logger.error(`Amount ${transactionAmount} invalid.`);
return;
}

const [recipientEntryExists, senderEntryExists] = await Promise.all([
balancesKit.addressExists(recipientAddress),
balancesKit.addressExists(senderAddress),
]);

if (!recipientEntryExists) {
await balancesKit.createBalancesEntry(recipientAddress);
}

if (!senderEntryExists) {
await balancesKit.createBalancesEntry(senderAddress);
}

const adjustedAmount = BigInt(Math.round(Number(amount.slice(0, -4))));

await Promise.all([
balancesKit.updateBalance(
senderAddress,
adjustedAmount,
Operation.Decrement
),
balancesKit.updateBalance(
recipientAddress,
adjustedAmount,
Operation.Increment
),
]);
}

export async function handleBalanceEvent(
cosmosEvent: CosmosEvent
): Promise<void> {
Expand Down

0 comments on commit 9fc1b43

Please sign in to comment.