Skip to content
Snippets Groups Projects

fix(1442): Improve BMA '/tx/history'

Closed Benoit Lavenier requested to merge fix/1442/improve_bma_tx_history into dev
9 files
+ 404
80
Compare changes
  • Side-by-side
  • Inline
Files
9
+ 59
26
@@ -80,7 +80,7 @@ import { LevelDBMindex } from "./indexDAL/leveldb/LevelDBMindex";
import { ConfDAO } from "./indexDAL/abstract/ConfDAO";
import { ServerDAO } from "./server-dao";
import { PeerDTO } from "../dto/PeerDTO";
import { RustPendingTx } from "../../../neon/native/server";
import { RustPendingTx, RustTxsHistory } from "../../../neon/native/server";
const readline = require("readline");
const indexer = require("../indexer").Indexer;
@@ -1449,7 +1449,7 @@ export class FileDAL implements ServerDAO {
return tx;
}
async RustDbTxToDbTx(tx: RustDbTx): Promise<DBTx> {
private async rustDbTxToDbTx(tx: RustDbTx): Promise<DBTx> {
let writtenBlockNumber = tx.writtenBlockNumber;
let writtenTime = tx.writtenTime;
let tx_dto = await this.computeTxBlockstampTime(
@@ -1458,10 +1458,11 @@ export class FileDAL implements ServerDAO {
let db_tx = DBTx.fromTransactionDTO(tx_dto);
db_tx.block_number = writtenBlockNumber;
db_tx.time = writtenTime;
db_tx.written = !!writtenBlockNumber;
return db_tx;
}
async RustPendingTxToDbTx(tx: RustPendingTx): Promise<DBTx> {
private async rustPendingTxToDbTx(tx: RustPendingTx): Promise<DBTx> {
let receivedTime = tx.receivedTime;
let tx_dto = await this.computeTxBlockstampTime(
TransactionDTO.fromJSONObject(tx)
@@ -1471,32 +1472,64 @@ export class FileDAL implements ServerDAO {
return db_tx;
}
async getTransactionsHistory(pubkey: string) {
const history: {
sent: DBTx[];
received: DBTx[];
sending: DBTx[];
pending: DBTx[];
} = {
sent: [],
received: [],
sending: [],
pending: [],
private async toDbTxHistory(source: RustTxsHistory) {
return <
{
sent: DBTx[];
received: DBTx[];
sending: DBTx[];
pending: DBTx[];
}
>{
sent: await Promise.all(
source.sent.map(async (tx) => this.rustDbTxToDbTx(tx))
),
received: await Promise.all(
source.received.map(async (tx) => this.rustDbTxToDbTx(tx))
),
sending: await Promise.all(
source.sending.map(async (tx) => this.rustPendingTxToDbTx(tx))
),
pending: await Promise.all(
source.pending.map(async (tx) => this.rustPendingTxToDbTx(tx))
),
};
const res = this.rustServer.getTransactionsHistory(pubkey);
history.sent = await Promise.all(
res.sent.map(async (tx) => this.RustDbTxToDbTx(tx))
);
history.received = await Promise.all(
res.received.map(async (tx) => this.RustDbTxToDbTx(tx))
);
history.sending = await Promise.all(
res.sending.map(async (tx) => this.RustPendingTxToDbTx(tx))
}
async getTxHistoryByPubkey(pubkey: string) {
const res = this.rustServer.getTxHistoryByPubkey(pubkey);
return this.toDbTxHistory(res);
}
async getTxHistoryByPubkeyBetweenBlocks(
pubkey: string,
from: number,
to: number
) {
const res = this.rustServer.getTxHistoryByPubkeyBetweenBlocks(
pubkey,
+from,
+to
);
history.pending = await Promise.all(
res.pending.map(async (tx) => this.RustPendingTxToDbTx(tx))
return this.toDbTxHistory(res);
}
async getTxHistoryByPubkeyBetweenTimes(
pubkey: string,
from: number,
to: number
) {
const res = this.rustServer.getTxHistoryByPubkeyBetweenTimes(
pubkey,
+from,
+to
);
return history;
return this.toDbTxHistory(res);
}
async getTxHistoryMempool(pubkey: string) {
const res = this.rustServer.getTxHistoryMempool(pubkey);
return this.toDbTxHistory(res);
}
async getUDHistory(pubkey: string): Promise<{ history: HttpUD[] }> {
Loading