From fb34f30e8964778bcacd31e6057c60d0f734fb61 Mon Sep 17 00:00:00 2001 From: Rahul Patni Date: Wed, 20 Sep 2023 14:35:42 -0700 Subject: [PATCH] Rahul/ifl 1653 update gettransaction response to use the rpc transaction (#4300) * adding optional serialized field and required signature field * adding serialized to endpoint input * updating getTransaction to use RpcTransaction * passing test --- .../rpc/routes/chain/getTransaction.test.ts | 5 +- .../src/rpc/routes/chain/getTransaction.ts | 54 +++++++------------ 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/ironfish/src/rpc/routes/chain/getTransaction.test.ts b/ironfish/src/rpc/routes/chain/getTransaction.test.ts index 1ef0bc56a6..0f1cf15e95 100644 --- a/ironfish/src/rpc/routes/chain/getTransaction.test.ts +++ b/ironfish/src/rpc/routes/chain/getTransaction.test.ts @@ -3,7 +3,6 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { useMinerBlockFixture } from '../../../testUtilities' import { createRouteTest } from '../../../testUtilities/routeTest' -import { CurrencyUtils } from '../../../utils' import { RpcRequestError } from '../../clients' import { GetTransactionResponse } from './getTransaction' import { RpcSpend } from './types' @@ -43,7 +42,7 @@ describe('Route chain/getTransaction', () => { })) expect(response.content).toMatchObject({ - fee: CurrencyUtils.encode(transaction.fee()), + fee: Number(transaction.fee()), expiration: transaction.expiration(), notesCount: 1, spendsCount: 0, @@ -89,7 +88,7 @@ describe('Route chain/getTransaction', () => { })) expect(response.content).toMatchObject({ - fee: CurrencyUtils.encode(transaction.fee()), + fee: Number(transaction.fee()), expiration: transaction.expiration(), notesCount: 1, spendsCount: 0, diff --git a/ironfish/src/rpc/routes/chain/getTransaction.ts b/ironfish/src/rpc/routes/chain/getTransaction.ts index 364714f659..cf4105e03f 100644 --- a/ironfish/src/rpc/routes/chain/getTransaction.ts +++ b/ironfish/src/rpc/routes/chain/getTransaction.ts @@ -3,27 +3,19 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import * as yup from 'yup' import { Assert } from '../../../assert' +import { getTransactionSize } from '../../../network/utils/serializers' import { FullNode } from '../../../node' import { BlockHashSerdeInstance } from '../../../serde' import { CurrencyUtils } from '../../../utils' import { NotFoundError, ValidationError } from '../../adapters' -import { - RpcBurn, - RpcBurnSchema, - RpcEncryptedNote, - RpcEncryptedNoteSchema, - RpcMint, - RpcMintSchema, -} from '../../types' import { ApiNamespace, routes } from '../router' -import { RpcSpend, RpcSpendSchema } from './types' +import { RpcTransaction, RpcTransactionSchema } from './types' export type GetTransactionRequest = { transactionHash: string; blockHash?: string } -export type GetTransactionResponse = { - fee: string - expiration: number +export type GetTransactionResponse = RpcTransaction & { noteSize: number + blockHash: string /** * @deprecated Please use `notes.length` instead */ @@ -32,12 +24,6 @@ export type GetTransactionResponse = { * @deprecated Please use `spends.length` instead */ spendsCount: number - signature: string - spends: RpcSpend[] - notes: RpcEncryptedNote[] - mints: RpcMint[] - burns: RpcBurn[] - blockHash: string /** * @deprecated Please use `notes` instead */ @@ -51,22 +37,18 @@ export const GetTransactionRequestSchema: yup.ObjectSchema = yup - .object({ - fee: yup.string().defined(), - expiration: yup.number().defined(), - noteSize: yup.number().defined(), - notesCount: yup.number().defined(), - spendsCount: yup.number().defined(), - signature: yup.string().defined(), - notesEncrypted: yup.array(yup.string().defined()).defined(), - spends: yup.array(RpcSpendSchema).defined(), - notes: yup.array(RpcEncryptedNoteSchema).defined(), - mints: yup.array(RpcMintSchema).defined(), - burns: yup.array(RpcBurnSchema).defined(), - blockHash: yup.string().defined(), - }) - .defined() +export const GetTransactionResponseSchema: yup.ObjectSchema = + RpcTransactionSchema.concat( + yup + .object({ + notesCount: yup.number().defined(), + spendsCount: yup.number().defined(), + notesEncrypted: yup.array(yup.string().defined()).defined(), + noteSize: yup.number().defined(), + blockHash: yup.string().defined(), + }) + .defined(), + ) routes.register( `${ApiNamespace.chain}/getTransaction`, @@ -112,8 +94,10 @@ routes.register( const { transaction, initialNoteIndex } = foundTransaction const rawTransaction: GetTransactionResponse = { - fee: transaction.fee().toString(), + fee: Number(transaction.fee()), expiration: transaction.expiration(), + hash: transaction.hash().toString('hex'), + size: getTransactionSize(transaction), noteSize: initialNoteIndex + transaction.notes.length, notesCount: transaction.notes.length, spendsCount: transaction.spends.length,