Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: transaction checker app (#2) #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mwb-al
Copy link
Collaborator

@mwb-al mwb-al commented Jan 24, 2025

Description:

Rewrite transaction checker project from .go into node version using typescript.

Related issue(s):

Fixes #2

Signed-off-by: Michał Walczak <[email protected]>
@mwb-al mwb-al self-assigned this Jan 24, 2025
networkUrl: process.env.NETWORK_URL || '127.0.0.1:50211',
networkAccount: process.env.NETWORK_ACCOUNT || '3',
operatorAccount: process.env.OPERATOR_ACCOUNT || '2',
operatorAccountKey: process.env.OPERATOR_ACCOUNT_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This default private key comes from Hedera's documentation

Comment on lines 3 to 11
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can remove commented config, we can always set something when needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: 414c48c

await sendAndLogToFile(payload, status.toString(), null);
} catch (error) {
mirrorQueue.push(payload);
console.log(`Hedera Worker ${id} failed to get receipt of transaction ${payload.transactionId}, sent to mirror queue. Error was: ${error}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets change it to console.error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: 74c890f


await sendAndLogToFile(payload, status, null);
} catch (error) {
console.log(`Mirror Worker ${id} failed to get the status of transaction ${payload.transactionId}: ${error}`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets change it to console.error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: 74c890f

} // Log to file if enabled in environment variables.

const logEntry = `${new Date().toISOString()} - ${jsonString}\n`;
const logFilePath = path.resolve(__dirname, `../../${env.logFilePath}${env.logFileName}`);
Copy link
Collaborator

@mp-arianelabs mp-arianelabs Jan 28, 2025

Choose a reason for hiding this comment

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

Suggested change
const logFilePath = path.resolve(__dirname, `../../${env.logFilePath}${env.logFileName}`);
const logFilePath = path.resolve(__dirname, `..`, `..`, env.logFilePath, env.logFileName);

This will make it a bit better as we are not going to get double slash by accident. Also, assuming:

  logFilePath = 'logs',    
  logFileName = 'app.log'
  __dirname = '/user/project/src';

The output would be: /user/logs/app.log whereas with using .join() we would get /user/project/logs/app.log.

Is the first output desired?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: a155a8b

export const env = {
port: parseInt(process.env.PORT || '8081'),
logToFile: process.env.LOG_TO_FILE || 'false',
logFilePath: process.env.LOG_FILE_PATH || 'logs/',
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets remove trailing slash

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: a155a8b

Create a ```.env``` file in the root of project and add all variables as in ```.env.example```. Api key for ```OPERATOR_PRIVATE``` should be added from the shadowing

- ``PORT``- port which app will be running on - default is 8081
- ``LOG_TO_FILE``- directory to store logs
Copy link
Collaborator

Choose a reason for hiding this comment

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

This description looks like a mishap, in the code it is used to decide whether to log or not

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed: a155a8b

console.log(`Status of transaction ${payload.transactionId} is: ${status}`);

await sendAndLogToFile(payload, status, null);
} catch (error) {
Copy link
Collaborator

@mp-arianelabs mp-arianelabs Jan 28, 2025

Choose a reason for hiding this comment

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

This will make any error repeated if something inside constantly fails, is this desired?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The current code does not lead to an infinite loop because the payload is removed from the mirrorQueue using shift() and is not reprocessed in case of an error. However, when the Mirror Node is unavailable and returns an error, we lose such a payload. Addressing this was not part of this task, but I will add a TODO comment to the code - ae80e71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite transaction checker from GO to TypeScript(node)
2 participants