diff --git a/packages/core-api/src/repositories/transactions.ts b/packages/core-api/src/repositories/transactions.ts index cdb7ec6abf..c46360f6ca 100644 --- a/packages/core-api/src/repositories/transactions.ts +++ b/packages/core-api/src/repositories/transactions.ts @@ -69,7 +69,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findAllLegacy(parameters: any = {}): Promise { const selectQuery = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query); if (parameters.senderId) { @@ -115,7 +115,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findAllByWallet(wallet, parameters: any = {}): Promise { const selectQuery = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query); const applyConditions = queries => { @@ -202,7 +202,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findById(id): Promise { const query = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query) .where(this.query.id.equals(id)); @@ -219,7 +219,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findByTypeAndId(type, id): Promise { const query = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query) .where(this.query.id.equals(id).and(this.query.type.equals(type))); @@ -235,7 +235,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findByIds(ids): Promise { const query = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query) .where(this.query.id.in(ids)); @@ -248,7 +248,7 @@ export class TransactionsRepository extends Repository implements IRepository { */ public async findWithVendorField(): Promise { const query = this.query - .select(this.query.block_id, this.query.serialized, this.query.timestamp) + .select(this.query.id, this.query.block_id, this.query.serialized, this.query.timestamp) .from(this.query) .where(this.query.vendor_field_hex.isNotNull()); diff --git a/packages/core-api/src/versions/1/transactions/transformer.ts b/packages/core-api/src/versions/1/transactions/transformer.ts index fa35e2da21..733a6cff93 100644 --- a/packages/core-api/src/versions/1/transactions/transformer.ts +++ b/packages/core-api/src/versions/1/transactions/transformer.ts @@ -1,23 +1,23 @@ import { app } from "@arkecosystem/core-container"; -import { Blockchain } from "@arkecosystem/core-interfaces"; -import { bignumify } from "@arkecosystem/core-utils"; -import { crypto, Transaction } from "@arkecosystem/crypto"; +import { Blockchain, Database } from "@arkecosystem/core-interfaces"; +import { Transaction } from "@arkecosystem/crypto"; export function transformTransactionLegacy(model) { - const config = app.getConfig(); const blockchain = app.resolvePlugin("blockchain"); + const databaseService = app.resolvePlugin("database"); - const { data } = Transaction.fromBytes(model.serialized); + const { data } = Transaction.fromBytesUnsafe(model.serialized, model.id); + const senderId = databaseService.walletManager.findByPublicKey(data.senderPublicKey).address; return { id: data.id, blockid: model.blockId, type: data.type, timestamp: model.timestamp || data.timestamp, - amount: +bignumify(data.amount).toFixed(), - fee: +bignumify(data.fee).toFixed(), + amount: +data.amount, + fee: +data.fee, recipientId: data.recipientId, - senderId: crypto.getAddress(data.senderPublicKey, config.get("network.pubKeyHash")), + senderId, senderPublicKey: data.senderPublicKey, vendorField: data.vendorField, signature: data.signature, diff --git a/packages/core-api/src/versions/2/transactions/controller.ts b/packages/core-api/src/versions/2/transactions/controller.ts index ae568862ae..45b1828d2d 100644 --- a/packages/core-api/src/versions/2/transactions/controller.ts +++ b/packages/core-api/src/versions/2/transactions/controller.ts @@ -101,7 +101,7 @@ export class TransactionsController extends Controller { return Boom.notFound("Transaction not found"); } - const data = { serialized: transaction.serialized.toString("hex") }; + const data = { id: transaction.id, serialized: transaction.serialized.toString("hex") }; return super.respondWithResource(request, data, "transaction"); } catch (error) { diff --git a/packages/core-api/src/versions/2/transactions/transformer.ts b/packages/core-api/src/versions/2/transactions/transformer.ts index 8d88b73f9c..d0b973c16a 100644 --- a/packages/core-api/src/versions/2/transactions/transformer.ts +++ b/packages/core-api/src/versions/2/transactions/transformer.ts @@ -1,13 +1,15 @@ import { app } from "@arkecosystem/core-container"; -import { Blockchain } from "@arkecosystem/core-interfaces"; -import { bignumify, formatTimestamp } from "@arkecosystem/core-utils"; -import { crypto, Transaction } from "@arkecosystem/crypto"; +import { Blockchain, Database } from "@arkecosystem/core-interfaces"; +import { formatTimestamp } from "@arkecosystem/core-utils"; +import { Transaction } from "@arkecosystem/crypto"; export function transformTransaction(model) { - const config = app.getConfig(); const blockchain = app.resolvePlugin("blockchain"); + const databaseService = app.resolvePlugin("database"); + + const { data } = Transaction.fromBytesUnsafe(model.serialized, model.id); + const sender = databaseService.walletManager.findByPublicKey(data.senderPublicKey).address; - const { data } = Transaction.fromBytes(model.serialized); const lastBlock = blockchain.getLastBlock(); return { @@ -15,9 +17,9 @@ export function transformTransaction(model) { blockId: model.blockId, version: data.version, type: data.type, - amount: +bignumify(data.amount).toFixed(), - fee: +bignumify(data.fee).toFixed(), - sender: crypto.getAddress(data.senderPublicKey, config.get("network.pubKeyHash")), + amount: +data.amount, + fee: +data.fee, + sender, recipient: data.recipientId, signature: data.signature, signSignature: data.signSignature, diff --git a/packages/core-api/src/versions/2/wallets/controller.ts b/packages/core-api/src/versions/2/wallets/controller.ts index 07855fffb6..b5ee067471 100644 --- a/packages/core-api/src/versions/2/wallets/controller.ts +++ b/packages/core-api/src/versions/2/wallets/controller.ts @@ -1,4 +1,3 @@ -import { app } from "@arkecosystem/core-container"; import Boom from "boom"; import Hapi from "hapi"; import { Controller } from "../shared/controller"; diff --git a/packages/crypto/src/transactions/types/transaction.ts b/packages/crypto/src/transactions/types/transaction.ts index d564a2092c..9d2d354101 100644 --- a/packages/crypto/src/transactions/types/transaction.ts +++ b/packages/crypto/src/transactions/types/transaction.ts @@ -33,10 +33,10 @@ export abstract class Transaction { * NOTE: Only use this internally when it is safe to assume the buffer has already been * verified. */ - public static fromBytesUnsafe(buffer: Buffer, id: string): Transaction { + public static fromBytesUnsafe(buffer: Buffer, id?: string): Transaction { try { const transaction = TransactionDeserializer.deserialize(buffer); - transaction.data.id = id; + transaction.data.id = id || crypto.getId(transaction.data); transaction.isVerified = true; return transaction;