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

Initial Code #1

Open
wants to merge 57 commits into
base: init_commit
Choose a base branch
from
Open

Initial Code #1

wants to merge 57 commits into from

Conversation

nandubatchu
Copy link
Owner

@nandubatchu nandubatchu commented Mar 25, 2020

LedgerSystem class is the core class with methods to:

  • create accounts
  • post operations
  • get accounts/operations

Data/InMemoryData class is the database class with methods to:

  • store/retrieve data from the database
  • perform insert/insertMany(transactions)

API is exposed via Express APP and separate Routes for Operations (considering transfer as an operation) and Accounts.

There is a rest.http file to interact with the local server easily using the VSCode extension “REST Client”.

FIFOQueue class as the sub-system of LedgerSystem is used to serialise the task (posting entries corresponding to operations created).

@nandubatchu
Copy link
Owner Author

nandubatchu commented Mar 25, 2020

Other planned features:

  • database ORM to communicate with Postgres database instead of InMemoryData.
  • add Models and validations for Entries, Accounts & Operations.
  • API to list all accounts (optional).

Copy link

@quixote911 quixote911 left a comment

Choose a reason for hiding this comment

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

Have reviewed api.js mainly
and a bit of ledger.js, going through

src/api.js Outdated Show resolved Hide resolved
src/api.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated
const FIFOQueue = require("./queue");
const sleep = require('./utils').sleep;
const groupBy = require('./utils').groupBy;
const OperationTypes = {

Choose a reason for hiding this comment

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

Probably we dont need this enum because there can't be more types of operations by definition. In fact there should be no concept of 'Type Of Operation'

src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated Show resolved Hide resolved
src/ledger.js Outdated
return account;
}
getAccountBalances(id) {
const accountEntries = this.db.getAll(Entities.ENTRIES, id);

Choose a reason for hiding this comment

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

one interesting complexity we have to model -

we're saying that ledger will be decoupled from persistence (here, DB). there are some useful things DB offers that we will need to generalize:

For account balance i don't need to fetch entire ledger history. I can just do it in a single query on DB. so the persistence layer needs some more control over the getAccountBalance functionality if it supports something like this.

src/ledger.js Outdated Show resolved Hide resolved
src/api.js Outdated Show resolved Hide resolved
@quixote911
Copy link

quixote911 commented Mar 26, 2020

Other things pending on a high level wrt Prod readiness

Defining Error scenarios
Error handling in code
Proper Logging
Monitoring & Metrics
Defining currencies, precision etc

We will worry about these things next week

src/ledger.ts Outdated
}
private getOperationTask(operation: IOperation) {
return async () => {
await this.postOperationEntries(operation.id!, operation.entries)

Choose a reason for hiding this comment

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

Please don't use the word 'post'

It's confusing with 'postingQueue` and HTTP POST

src/ledger.ts Outdated
const operation: IOperation = Object.assign({status: OperationStatus.INIT}, operationRequest);
return new Promise(async (resolve, reject) => {
const operationId = (await this.dataConnector.insertOperation(operation)).id as string;
this.postingQueue.enqueueTask(async () => {

Choose a reason for hiding this comment

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

Ok so you're doing 2 things here -

inserting operation in DB
inserting it in an in-memory task queue to be processed.

The latter in fact should be the responsibility of a separate decoupled system which reads the operation from DB and inserts it in an in-memory task queue to be processed.

src/ledger.ts Outdated
export interface IBookBalances {
[assetId: string]: string,
}
export class LedgerSystem {

Choose a reason for hiding this comment

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

You need to expose this additional functionality -

'Get operations on book' -> paginated way to get latest completed operations on book.

Callers need it for several use cases.

SequelizeDataConnector and migration script for local sqlite db
implement server-client model for FIFO Queue management
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.

2 participants