From 607ec6bed8a61a8fc2c8fbf4494a883a225a1945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com> Date: Mon, 9 Apr 2018 08:46:02 +0200 Subject: [PATCH] [enh] Refactoring: type FileDAL.txsDAL --- app/lib/dal/fileDAL.ts | 4 +-- app/lib/dal/sqliteDAL/TxsDAL.ts | 7 ++++- .../bma/lib/controllers/transactions.ts | 27 +++++++++++++------ app/modules/bma/lib/dtos.ts | 14 +++++++++- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts index e544a79e2..9d707693b 100644 --- a/app/lib/dal/fileDAL.ts +++ b/app/lib/dal/fileDAL.ts @@ -23,7 +23,7 @@ import {DBPeer} from "./sqliteDAL/PeerDAL" import {TransactionDTO} from "../dto/TransactionDTO" import {CertDAL, DBCert} from "./sqliteDAL/CertDAL" import {DBWallet, WalletDAL} from "./sqliteDAL/WalletDAL" -import {DBTx} from "./sqliteDAL/TxsDAL" +import {DBTx, TxsDAL} from "./sqliteDAL/TxsDAL" import {DBBlock} from "../db/DBBlock" import {DBMembership, MembershipDAL} from "./sqliteDAL/MembershipDAL" import {MerkleDTO} from "../dto/MerkleDTO" @@ -67,7 +67,7 @@ export class FileDAL { metaDAL:MetaDAL peerDAL:any blockDAL:any - txsDAL:any + txsDAL:TxsDAL statDAL:StatDAL idtyDAL:IdentityDAL certDAL:CertDAL diff --git a/app/lib/dal/sqliteDAL/TxsDAL.ts b/app/lib/dal/sqliteDAL/TxsDAL.ts index 278220cd1..f1f1fc4bb 100644 --- a/app/lib/dal/sqliteDAL/TxsDAL.ts +++ b/app/lib/dal/sqliteDAL/TxsDAL.ts @@ -251,7 +251,12 @@ export class TxsDAL extends AbstractSQLite<DBTx> { return this.query('SELECT * FROM sandbox_txs LIMIT ' + (this.sandbox.maxSize), []) } - sandbox = new SandBox(constants.SANDBOX_SIZE_TRANSACTIONS, this.getSandboxTxs.bind(this), (compared:DBTx, reference:DBTx) => { + sandbox:SandBox<{ issuers: string[], output_base:number, output_amount:number }> = new SandBox( + constants.SANDBOX_SIZE_TRANSACTIONS, + () => this.getSandboxTxs(), + (compared:{ issuers: string[], output_base:number, output_amount:number }, + reference:{ issuers: string[], output_base:number, output_amount:number } + ) => { if (compared.output_base < reference.output_base) { return -1; } diff --git a/app/modules/bma/lib/controllers/transactions.ts b/app/modules/bma/lib/controllers/transactions.ts index 068993fc1..f9e3f36a3 100644 --- a/app/modules/bma/lib/controllers/transactions.ts +++ b/app/modules/bma/lib/controllers/transactions.ts @@ -127,14 +127,25 @@ export class TransactionBinding extends AbstractController { async getPending(): Promise<HttpTxPending> { const pending = await this.server.dal.getTransactionsPending(); - const res = { - "currency": this.conf.currency, - "pending": pending - }; - pending.map(function(tx:any, index:number) { - pending[index] = _.omit(TransactionDTO.fromJSONObject(tx).json(), 'currency', 'raw'); - }); - return res; + return { + currency: this.conf.currency, + pending: pending.map(t => { + const tx = TransactionDTO.fromJSONObject(t) + return { + version: tx.version, + issuers: tx.issuers, + inputs: tx.inputs, + unlocks: tx.unlocks, + outputs: tx.outputs, + comment: tx.comment, + locktime: tx.locktime, + blockstamp: tx.blockstamp, + blockstampTime: tx.blockstampTime, + signatures: tx.signatures, + hash: tx.hash + } + }) + } } private async getFilteredHistory(pubkey:string, filter:any): Promise<HttpTxHistory> { diff --git a/app/modules/bma/lib/dtos.ts b/app/modules/bma/lib/dtos.ts index ef752ecc2..91c431777 100644 --- a/app/modules/bma/lib/dtos.ts +++ b/app/modules/bma/lib/dtos.ts @@ -772,6 +772,18 @@ export interface HttpTransaction { hash: string } +export interface HttpTransactionPending { + version: number + issuers: string[] + inputs: string[] + unlocks: string[] + outputs: string[] + comment: string + locktime: number + signatures: string[] + hash: string +} + export const Source = { "type": String, "noffset": Number, @@ -867,7 +879,7 @@ export const TxPending = { export interface HttpTxPending { currency: string - pending: HttpTransaction[] + pending: HttpTransactionPending[] } export const UD = { -- GitLab