Skip to content

Commit

Permalink
enable orderId logging in print-block script
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 committed Sep 30, 2024
1 parent 4270782 commit b047742
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AffiliatesController extends Controller {
const isVolumeEligible = Number(walletRow.totalVolume) >= config.VOLUME_ELIGIBILITY_THRESHOLD;
const isAffiliate = referredUserRows !== undefined ? referredUserRows.length > 0 : false;

// No need to check subaccountRows.length > 1 as subaccountNumber is unique for an address
// subaccountRows.length > 1 is not possible because subaccountNumber is unique for an address
if (subaccountRows.length === 0) {
// error logging will be performed by handleInternalServerError
throw new UnexpectedServerError(`Subaccount 0 not found for address ${address}`);
Expand All @@ -78,14 +78,22 @@ class AffiliatesController extends Controller {
},
[],
);
// No need to check usernameRows.length > 1 as subAccountId is unique (foreign key constraint)
// This error can happen if a user calls this endpoint before subaccount-username-generator
// has generated the username

let referralCode: string = '';
// usernameRows.length > 1 is not possible because subAccountId is unique (foreign key
// constraint)
if (usernameRows.length === 0) {
// This error can happen if a user calls this endpoint before subaccount-username-generator
// has generated the username
stats.increment(`${config.SERVICE_NAME}.${controllerName}.get_metadata.subaccount_username_not_found`);
logger.warning({
at: 'affiliates-controller#metadata',
message: `Could not find referral code for address: ${address}`,
});
throw new UnexpectedServerError(`Username not found for subaccount ${subaccountId}`);
} else {
referralCode = usernameRows[0].username;
}
const referralCode = usernameRows[0].username;

return {
referralCode,
Expand Down
3 changes: 3 additions & 0 deletions indexer/services/scripts/src/helpers/block-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
UpdateClobPairEventV1,
UpdatePerpetualEventV1,
} from '@dydxprotocol-indexer/v4-protos';
import { OrderTable } from '@dydxprotocol-indexer/postgres';

import { AnnotatedIndexerTendermintEvent, DydxIndexerSubtypes } from './types';

Expand Down Expand Up @@ -52,6 +53,8 @@ export function annotateIndexerTendermintEvent(
};
}
case (DydxIndexerSubtypes.STATEFUL_ORDER.toString()): {
const temp = StatefulOrderEventV1.decode(eventDataBinary);
const orderId = OrderTable.orderIdToUuid(temp.orderRemoval!.removedOrderId!);
return {
...event,
dataBytes: new Uint8Array(),
Expand Down
2 changes: 2 additions & 0 deletions indexer/services/scripts/src/print-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import yargs from 'yargs';
import config from './config';
import { annotateIndexerTendermintEvent } from './helpers/block-helpers';
import { AnnotatedIndexerTendermintBlock, AnnotatedIndexerTendermintEvent } from './helpers/types';
import { OrderTable } from '@dydxprotocol-indexer/postgres';

/**
* Creates an IndexerTendermintBlock from a KafkaMessage.
Expand Down Expand Up @@ -106,6 +107,7 @@ export async function printMessageAtHeight(
});
throw Error('Failed to parse event');
}

annotatedEvents.push(annotatedEvent);
});
const annotatedBlock: AnnotatedIndexerTendermintBlock = {
Expand Down

0 comments on commit b047742

Please sign in to comment.