Skip to content

Commit

Permalink
Rahul/ifl 1653 update gettransaction response to use the rpc transact…
Browse files Browse the repository at this point in the history
…ion (#4300)

* adding optional serialized field and required signature field

* adding serialized to endpoint input

* updating getTransaction to use RpcTransaction

* passing test
  • Loading branch information
patnir authored Sep 20, 2023
1 parent 0a1f43b commit fb34f30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 38 deletions.
5 changes: 2 additions & 3 deletions ironfish/src/rpc/routes/chain/getTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
54 changes: 19 additions & 35 deletions ironfish/src/rpc/routes/chain/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -51,22 +37,18 @@ export const GetTransactionRequestSchema: yup.ObjectSchema<GetTransactionRequest
})
.defined()

export const GetTransactionResponseSchema: yup.ObjectSchema<GetTransactionResponse> = 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<GetTransactionResponse> =
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<typeof GetTransactionRequestSchema, GetTransactionResponse>(
`${ApiNamespace.chain}/getTransaction`,
Expand Down Expand Up @@ -112,8 +94,10 @@ routes.register<typeof GetTransactionRequestSchema, GetTransactionResponse>(
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,
Expand Down

0 comments on commit fb34f30

Please sign in to comment.