Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codebuild/buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ env:
testnetindia_PUSH_NOTIFICATION_ENABLED: "true"
testnetindia_PUSH_ALLOWED_PROVIDERS: "android,ios"
testnetindia_APPLICATION_NAME: "wallet-service-testnet-india"
testnetindia_SERVERLESS_DEPLOY_PREFIX: "wallet-service"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question(non-blocking): Just double-checking that we won't be using the default 'hathor-wallet-service' prefix for testnet-india, right?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it was the first one where I tested a custom prefix

mainnet_staging_DEFAULT_SERVER: "https://wallet-service.private-nodes.hathor.network/v1a/"
mainnet_staging_WS_DOMAIN: "ws.staging.wallet-service.hathor.network"
mainnet_staging_NETWORK: "mainnet"
Expand Down
13 changes: 10 additions & 3 deletions packages/common/__tests__/utils/nft.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ describe('invokeNftHandlerLambda', () => {
const mLambdaClient = new LambdaClientMock({});
(mLambdaClient.send as jest.Mocked<any>).mockImplementationOnce(async () => expectedLambdaResponse);

const result = await NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', logger);
const result = await NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', 'hathor-wallet-service', logger);

// Method should return void
expect(result).toBeUndefined();
Expand All @@ -405,7 +405,7 @@ describe('invokeNftHandlerLambda', () => {
const mLambdaClient = new LambdaClientMock({});
(mLambdaClient.send as jest.Mocked<any>).mockResolvedValueOnce(expectedLambdaResponse);

await expect(NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', logger))
await expect(NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', 'hathor-wallet-service', logger))
.rejects.toThrow('onNewNftEvent lambda invoke failed for tx: test-tx-id');

// Verify alert was added
Expand All @@ -424,7 +424,7 @@ describe('invokeNftHandlerLambda', () => {
// Disable NFT auto review
process.env.NFT_AUTO_REVIEW_ENABLED = 'false';

const result = await NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', logger);
const result = await NftUtils.invokeNftHandlerLambda('test-tx-id', 'local', 'hathor-wallet-service', logger);

// Method should return void
expect(result).toBeUndefined();
Expand Down Expand Up @@ -688,6 +688,7 @@ describe('processNftEvent', () => {
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand Down Expand Up @@ -718,6 +719,7 @@ describe('processNftEvent', () => {
expect(invokeNftLambdaSpy).toHaveBeenCalledWith(
eventData.hash,
'test-stage',
'hathor-wallet-service',
logger
);
});
Expand All @@ -732,6 +734,7 @@ describe('processNftEvent', () => {
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand All @@ -751,6 +754,7 @@ describe('processNftEvent', () => {
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand All @@ -776,6 +780,7 @@ describe('processNftEvent', () => {
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand Down Expand Up @@ -809,6 +814,7 @@ describe('processNftEvent', () => {
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand Down Expand Up @@ -887,6 +893,7 @@ it('should perform full NFT processing with real event data and no mocks', async
const result = await NftUtils.processNftEvent(
eventData,
'test-stage',
'hathor-wallet-service',
mockNetwork as unknown as hathorLib.Network,
logger
);
Expand Down
7 changes: 4 additions & 3 deletions packages/common/src/utils/nft.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class NftUtils {
* Invokes this application's own intermediary lambda `onNewNftEvent`.
* This is to improve the failure tolerance on this non-critical step of the sync loop.
*/
static async invokeNftHandlerLambda(txId: string, stage: string, logger: Logger): Promise<void> {
static async invokeNftHandlerLambda(txId: string, stage: string, deployPrefix: string, logger: Logger): Promise<void> {
// Check for required environment variables
if (!process.env.WALLET_SERVICE_LAMBDA_ENDPOINT || !process.env.AWS_REGION) {
throw new Error('Environment variables WALLET_SERVICE_LAMBDA_ENDPOINT and AWS_REGION are not set.');
Expand All @@ -163,7 +163,7 @@ export class NftUtils {
});
// invoke lambda asynchronously to metadata update
const command = new InvokeCommand({
FunctionName: `hathor-wallet-service-${stage}-onNewNftEvent`,
FunctionName: `${deployPrefix}-${stage}-onNewNftEvent`,
InvocationType: 'Event',
Payload: JSON.stringify({ nftUid: txId }),
});
Expand All @@ -190,6 +190,7 @@ export class NftUtils {
static async processNftEvent(
eventData: FullNodeTransaction,
stage: string,
deployPrefix: string,
network: Network,
logger: Logger
): Promise<boolean> {
Expand All @@ -215,7 +216,7 @@ export class NftUtils {
const txId = eventData.hash;

// Invoke the lambda function
await NftUtils.invokeNftHandlerLambda(txId, stage, logger);
await NftUtils.invokeNftHandlerLambda(txId, stage, deployPrefix, logger);
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/daemon/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const TX_CACHE_SIZE = parseInt(process.env.TX_CACHE_SIZE ?? '10000', 10);
// Number of blocks before unlocking a block utxo
export const BLOCK_REWARD_LOCK = parseInt(process.env.BLOCK_REWARD_LOCK ?? '10', 10);
export const STAGE = process.env.STAGE ?? 'local';
export const SERVERLESS_DEPLOY_PREFIX = process.env.SERVERLESS_DEPLOY_PREFIX ?? 'hathor-wallet-service';

// Fullnode information, used to make sure we're connected to the same fullnode
export const FULLNODE_PEER_ID = process.env.FULLNODE_PEER_ID;
Expand Down Expand Up @@ -114,6 +115,7 @@ export default () => ({
PUSH_NOTIFICATION_ENABLED,
WALLET_SERVICE_LAMBDA_ENDPOINT,
STAGE,
SERVERLESS_DEPLOY_PREFIX,
ACCOUNT_ID,
AWS_REGION,
ALERT_MANAGER_REGION,
Expand Down
3 changes: 2 additions & 1 deletion packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {
const {
NETWORK,
STAGE,
SERVERLESS_DEPLOY_PREFIX,
PUSH_NOTIFICATION_ENABLED,
} = getConfig();

Expand Down Expand Up @@ -444,7 +445,7 @@ export const handleVertexAccepted = async (context: Context, _event: Event) => {

// Call to process the data for NFT handling (if applicable)
// This process is not critical, so we run it in a fire-and-forget manner, not waiting for the promise.
NftUtils.processNftEvent(fullNodeData, STAGE, network, logger)
NftUtils.processNftEvent(fullNodeData, STAGE, SERVERLESS_DEPLOY_PREFIX, network, logger)
.catch((err: unknown) => logger.error('[ALERT] Error processing NFT event', err));
}

Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/src/utils/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { addAlert, Transaction } from '@wallet-service/common';
import { bigIntUtils } from '@hathor/wallet-lib';

export function buildFunctionName(functionName: string): string {
const { STAGE } = getConfig();
return `hathor-wallet-service-${STAGE}-${functionName}`;
const { STAGE, SERVERLESS_DEPLOY_PREFIX } = getConfig();
return `${SERVERLESS_DEPLOY_PREFIX}-${STAGE}-${functionName}`;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ provider:
REDIS_PASSWORD: ${env:REDIS_PASSWORD}
SERVICE_NAME: ${self:service}
STAGE: ${self:custom.stage}
SERVERLESS_DEPLOY_PREFIX: ${env:SERVERLESS_DEPLOY_PREFIX}
EXPLORER_SERVICE_STAGE: ${self:custom.explorerServiceStage}
NFT_AUTO_REVIEW_ENABLED: ${env:NFT_AUTO_REVIEW_ENABLED}
VOIDED_TX_OFFSET: ${env:VOIDED_TX_OFFSET}
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function loadEnvConfig(): EnvironmentConfig {
const config: EnvironmentConfig = {
defaultServer: process.env.DEFAULT_SERVER ?? 'https://node1.mainnet.hathor.network/v1a/',
stage: process.env.STAGE,
serverlessDeployPrefix: process.env.SERVERLESS_DEPLOY_PREFIX ?? 'hathor-wallet-service',
network: process.env.NETWORK,
serviceName: process.env.SERVICE_NAME,
maxAddressGap: Number.parseInt(process.env.MAX_ADDRESS_GAP, 10),
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const FullnodeVersionSchema = Joi.object<FullNodeApiVersionResponse>({
export const EnvironmentConfigSchema = Joi.object<EnvironmentConfig>({
defaultServer: Joi.string().required(),
stage: Joi.string().required(),
serverlessDeployPrefix: Joi.string().required(),
network: Joi.string().required(),
serviceName: Joi.string().required(),
maxAddressGap: Joi.number().required(),
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum TxProposalStatus {
export interface EnvironmentConfig {
defaultServer: string;
stage: string;
serverlessDeployPrefix: string;
network: string;
serviceName: string;
maxAddressGap: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const FirebaseConfigSchema = EnvironmentConfigSchema.fork([
], (schema) => schema.required());

export function buildFunctionName(functionName: string): string {
return `hathor-wallet-service-${config.stage}-${functionName}`;
return `${config.serverlessDeployPrefix}-${config.stage}-${functionName}`;
}

export enum FunctionName {
Expand Down