Skip to content

Commit

Permalink
Transactions WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gzigzigzeo committed Aug 7, 2018
1 parent 3daab5e commit 817d33d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"events": {
"start": "tslint -c ./tslint.json -t stylish 'src/**/*.ts'"
}
}
}
2 changes: 2 additions & 0 deletions src/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { txSchema } from "./tx.schema";
export { txResolver } from "./tx.resolver";
3 changes: 3 additions & 0 deletions src/transaction/schema/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { transactionType } from "./transaction.type";
export { transactionQuery } from "./transaction.query";
export { transactionSubscription } from "./transaction.subscription";
19 changes: 19 additions & 0 deletions src/transaction/transaction.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import stellar from "stellar-base";

export default class Transaction {
public ID: string;
public ledgerSeq: number;
public index: number;
public body: string;
public result: string;
public meta: string;

constructor(data: { data: string }) {
this.ID = data.txid;
this.ledgerSeq = data.ledgerseq;
this.index = data.txIndex;
this.body = data.txBody;
this.result = data.txResult;
this.meta = data.txMeta;
}
}
21 changes: 21 additions & 0 deletions src/transaction/transaction.repo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IDatabase } from "pg-promise";
import Transaction from "./transaction.model";

export default class LedgersRepository {
private db: IDatabase<any>;

constructor(db: any) {
this.db = db;
}

// Tries to find a transaction by id;
public findByID(id: string): Promise<Transaction> {
return this.db.oneOrNone("SELECT * FROM txhistory WHERE txid = $1", id, res => new Transaction(res));
}

public findByLedgerSeq(ledgerSeq: number): Promise<Transaction[]> {
return this.db.any("SELECT * FROM txhistory WHERE ledgerseq = $1 ORDER BY txindex", ledgerSeq, res =>
res.map(t => new Transaction(t))
);
}
}

0 comments on commit 817d33d

Please sign in to comment.