Skip to content

Commit

Permalink
Enter TypeORM, filter accounts by data
Browse files Browse the repository at this point in the history
  • Loading branch information
charlie-wasp authored May 20, 2019
1 parent dce3f11 commit e233d65
Show file tree
Hide file tree
Showing 35 changed files with 462 additions and 356 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"squel": "^5.12.2",
"stellar-base": "^0.11.0",
"stellar-sdk": "^0.13.0",
"typeorm": "^0.2.17",
"typescript-memoize": "^1.0.0-alpha.3",
"winston": "^3.0.0"
},
Expand Down
6 changes: 0 additions & 6 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import pgPromise = require("pg-promise");

import * as secrets from "./util/secrets";

import AccountsRepo from "./repo/accounts";
import AssetsRepo from "./repo/assets";
import DataEntriesRepo from "./repo/data_entries";
import LedgerHeadersRepo from "./repo/ledger_headers";
import OffersRepo from "./repo/offers";
import StoreStateRepo from "./repo/store_state";
Expand All @@ -18,9 +16,7 @@ import TrustLinesRepo from "./repo/trust_lines";

// Database Interface Extensions:
interface IExtensions {
accounts: AccountsRepo;
assets: AssetsRepo;
dataEntries: DataEntriesRepo;
ledgerHeaders: LedgerHeadersRepo;
offers: OffersRepo;
transactions: TransactionsRepo;
Expand All @@ -35,9 +31,7 @@ const initOptions: IOptions<IExtensions> = {
extend(obj: IExtensions) {
// Do not use 'require()' here, because this event occurs for every task
// and transaction being executed, which should be as fast as possible.
obj.accounts = new AccountsRepo(obj);
obj.assets = new AssetsRepo(obj);
obj.dataEntries = new DataEntriesRepo(obj);
obj.ledgerHeaders = new LedgerHeadersRepo(obj);
obj.offers = new OffersRepo(obj);
obj.transactions = new TransactionsRepo(obj);
Expand Down
20 changes: 17 additions & 3 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import * as Sentry from "@sentry/node";
import { createConnection } from "typeorm";
import { Account } from "./orm/entities/account";
import { AccountData } from "./orm/entities/account_data";
import "./util/asset";
import logger from "./util/logger";
import "./util/memo";
import { SENTRY_DSN } from "./util/secrets";
import * as secrets from "./util/secrets";
import { setNetwork as setStellarNetwork, updateBaseReserve } from "./util/stellar";

export default async function init(): Promise<void> {
if (SENTRY_DSN) {
if (secrets.SENTRY_DSN) {
Sentry.init({
dsn: SENTRY_DSN,
dsn: secrets.SENTRY_DSN,
integrations: [new Sentry.Integrations.RewriteFrames({ root: __dirname || process.cwd() })]
});
}
Expand All @@ -17,4 +20,15 @@ export default async function init(): Promise<void> {
logger.info(`Using ${network}`);

await updateBaseReserve();
await createConnection({
type: "postgres",
host: secrets.DBHOST,
port: secrets.DBPORT,
username: secrets.DBUSER,
password: secrets.DBPASSWORD,
database: secrets.DB,
entities: [Account, AccountData],
synchronize: false,
logging: process.env.DEBUG_SQL !== undefined
});
}
51 changes: 0 additions & 51 deletions src/model/account.ts

This file was deleted.

12 changes: 9 additions & 3 deletions src/model/account_values.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { IAccountBase } from "./account";
import { AccountThresholds } from "./account_thresholds";
import { AccountID, AccountThresholds } from "./";
import { Signer } from "./signer";

export interface IAccountValues extends IAccountBase {
export interface IAccountValues {
id: AccountID;
balance: string;
sequenceNumber: string;
numSubentries: number;
inflationDestination: AccountID;
homeDomain: string;
thresholds: AccountThresholds;
signers: Signer[];
}

Expand Down
23 changes: 0 additions & 23 deletions src/model/data_entry.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/model/data_entry_values.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { IDataEntryBase } from "./data_entry";

export type IDataEntryValues = IDataEntryBase;
export interface IDataEntryValues {
accountID: string;
name: string;
value: string;
}

export class DataEntryValues implements IDataEntryBase {
export class DataEntryValues implements IDataEntryValues {
public accountID: string;
public name: string;
public value: string;
Expand Down
44 changes: 0 additions & 44 deletions src/model/factories/account_factory.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/model/factories/account_values_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { publicKeyFromXDR } from "../../util/xdr";
export class AccountValuesFactory {
public static fromXDR(xdr: any): AccountValues {
const id = publicKeyFromXDR(xdr);
const signers = xdr.signers().map((s: any) => SignerFactory.fromXDR(s, id));
const signers = xdr.signers().map((s: any) => SignerFactory.fromXDR(s));
const thresholds = AccountThresholdsFactory.fromValue(xdr.thresholds());

signers.unshift(SignerFactory.self(id, thresholds.masterWeight));
Expand Down
3 changes: 2 additions & 1 deletion src/model/factories/balance_factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BigNumber from "bignumber.js";
import { xdr as XDR } from "stellar-base";
import { Account, Balance, IBalance } from "../";
import { Balance, IBalance } from "../";
import { Account } from "../../orm/entities";
import { MAX_INT64 } from "../../util";
import { getReservedBalance } from "../../util/base_reserve";

Expand Down
21 changes: 0 additions & 21 deletions src/model/factories/data_entry_factory.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/model/factories/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
export * from "./account_factory";
export * from "./account_flags_factory";
export * from "./account_thresholds_factory";
export * from "./account_values_factory";
export * from "./asset_factory";
export * from "./balance_factory";
export * from "./balance_values_factory";
export * from "./data_entry_factory";
export * from "./data_entry_values_factory";
export * from "./effect_factory";
export * from "./ledger_header_factory";
Expand Down
15 changes: 2 additions & 13 deletions src/model/factories/signer_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,17 @@ export interface ISignerTableRow {
}

export class SignerFactory {
public static fromXDR(xdr: any, accountID: string) {
public static fromXDR(xdr: any) {
const data: ISigner = {
accountID,
signer: SignerFactory.keyFromXDR(xdr.key()),
weight: xdr.weight()
};

return new Signer(data);
}

public static fromDb(row: ISignerTableRow): Signer {
const data: ISigner = {
accountID: row.accountid,
signer: row.publickey,
weight: row.weight
};

return new Signer(data);
}

public static self(id: string, weight: number): Signer {
return new Signer({ accountID: id, signer: id, weight });
return new Signer({ signer: id, weight });
}

public static keyFromXDR(xdr: any): string {
Expand Down
2 changes: 0 additions & 2 deletions src/model/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./account";
export * from "./account_id";
export * from "./account_thresholds";
export * from "./account_flags";
Expand All @@ -8,7 +7,6 @@ export * from "./asset";
export * from "./asset_code";
export * from "./asset_id";
export * from "./asset_input";
export * from "./data_entry";
export * from "./data_entry_subscription_payload";
export * from "./data_entry_values";
export * from "./effect";
Expand Down
3 changes: 0 additions & 3 deletions src/model/signer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface ISigner {
accountID: string;
signer: string;
weight: number;
}
Expand All @@ -17,12 +16,10 @@ export class Signer implements ISigner {
});
}

public accountID: string;
public signer: string;
public weight: number;

constructor(data: ISigner) {
this.accountID = data.accountID;
this.signer = data.signer;
this.weight = data.weight;
}
Expand Down
Loading

0 comments on commit e233d65

Please sign in to comment.