Skip to content

Commit

Permalink
adds hash to response of wallet/postTransaction (#3764)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughy authored Apr 10, 2023
1 parent 6d89f92 commit d97fdef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ironfish/src/rpc/routes/wallet/postTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { Transaction } from '../../../primitives'
import { RawTransactionSerde } from '../../../primitives/rawTransaction'
import { useAccountFixture } from '../../../testUtilities'
import { createRawTransaction } from '../../../testUtilities/helpers/transaction'
Expand All @@ -28,6 +29,8 @@ describe('Route wallet/postTransaction', () => {
expect(addSpy).toHaveBeenCalledTimes(0)
expect(response.status).toBe(200)
expect(response.content.transaction).toBeDefined()
const transaction = new Transaction(Buffer.from(response.content.transaction, 'hex'))
expect(response.content.hash).toBe(transaction.hash().toString('hex'))
})

it('should post a raw transaction', async () => {
Expand All @@ -47,6 +50,8 @@ describe('Route wallet/postTransaction', () => {
expect(addSpy).toHaveBeenCalledTimes(1)
expect(response.status).toBe(200)
expect(response.content.transaction).toBeDefined()
const transaction = new Transaction(Buffer.from(response.content.transaction, 'hex'))
expect(response.content.hash).toBe(transaction.hash().toString('hex'))
})

it("should return an error if the transaction won't deserialize", async () => {
Expand Down
7 changes: 6 additions & 1 deletion ironfish/src/rpc/routes/wallet/postTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type PostTransactionRequest = {
}

export type PostTransactionResponse = {
hash: string
transaction: string
}

Expand All @@ -26,6 +27,7 @@ export const PostTransactionRequestSchema: yup.ObjectSchema<PostTransactionReque

export const PostTransactionResponseSchema: yup.ObjectSchema<PostTransactionResponse> = yup
.object({
hash: yup.string().defined(),
transaction: yup.string().defined(),
})
.defined()
Expand All @@ -46,6 +48,9 @@ router.register<typeof PostTransactionRequestSchema, PostTransactionResponse>(
})

const serialized = transaction.serialize()
request.end({ transaction: serialized.toString('hex') })
request.end({
hash: transaction.hash().toString('hex'),
transaction: serialized.toString('hex'),
})
},
)

0 comments on commit d97fdef

Please sign in to comment.