Skip to content

Commit

Permalink
[helpers] Support parsing DustLost event (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmendoza-cb authored Aug 10, 2023
1 parent b5d73b4 commit 6253224
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/src/helpers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const isDepositEvent = ({ event: { section, method } }: EventRecord) =>
export const isWithdrawEvent = ({ event: { section, method } }: EventRecord) =>
isBalanceEvent(section) && method.toLowerCase() === EventMethodsLC.WITHDRAW;

export const isDustLostEvent = ({ event: { section, method } }: EventRecord) =>
isBalanceEvent(section) && method.toLowerCase() === EventMethodsLC.DUST_LOST;

export const isReservedEvent = ({ event: { section, method } }: EventRecord) =>
isBalanceEvent(section) && method.toLowerCase() === EventMethodsLC.RESERVED;

Expand Down
16 changes: 16 additions & 0 deletions server/src/helpers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isBalanceEvent,
isBalanceSetEvent,
isDepositEvent,
isDustLostEvent,
isExtrinsicFailedEvent,
isExtrinsicSuccessEvent,
isReservedEvent,
Expand Down Expand Up @@ -161,6 +162,21 @@ export async function getOperations(
operations.push(depositOperation);
}

if (isDustLostEvent(event)) {
const account = data[0].toString()
const amount = data[1] as u128

const dustLostOperation = Operation.constructFromObject({
operation_identifier: new OperationIdentifier(operations.length),
type: OpType.DUST_LOST,
status: OperationStatus.SUCCESS,
account: new AccountIdentifier(account),
amount: new Amount(amount.toString(), currency),
})

operations.push(dustLostOperation);
}

if (isReservedEvent(event)) {
const account = data[0].toString()
const amount = (data[1] as u128).toBn()
Expand Down
4 changes: 3 additions & 1 deletion server/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum EventMethodsLC {
TRANSFER = 'transfer',
BALANCE_SET = 'balanceset',
TRANSACTION_FEE_PAID = 'transactionfeepaid',
DUST_LOST = 'dustlost'
}

export enum EventSectionLC {
Expand All @@ -36,7 +37,8 @@ export enum OpType {
UNRESERVED = 'Unreserved',
RESERVE_REPATRIATED = 'ReserveRepatriated',
BALANCE_SET = 'BalanceSet',
TRANSACTION_FEE_PAID = 'TransactionFeePaid'
TRANSACTION_FEE_PAID = 'TransactionFeePaid',
DUST_LOST = 'DustLost'
}

export const opTypes = Object.values(OpType);
Expand Down

0 comments on commit 6253224

Please sign in to comment.