diff --git a/ironfish-cli/src/commands/wallet/transaction/index.ts b/ironfish-cli/src/commands/wallet/transaction/index.ts index 4c940ecb93..d9858e2967 100644 --- a/ironfish-cli/src/commands/wallet/transaction/index.ts +++ b/ironfish-cli/src/commands/wallet/transaction/index.ts @@ -59,7 +59,7 @@ export class TransactionCommand extends IronfishCommand { this.log(`Sender: ${response.content.transaction.notes[0].sender}`) if (response.content.transaction.notes.length > 0) { - this.log(`---Notes---\n`) + this.log(`\n---Notes---\n`) CliUx.ux.table(response.content.transaction.notes, { amount: { @@ -91,8 +91,26 @@ export class TransactionCommand extends IronfishCommand { }) } + if (response.content.transaction.spendsCount > 0) { + this.log(`\n---Spends---\n`) + CliUx.ux.table(response.content.transaction.spends, { + size: { + header: 'Size', + get: (spend) => spend.size, + }, + nullifier: { + header: 'Nullifier', + get: (spend) => spend.nullifier, + }, + commitmment: { + header: 'Commitment', + get: (spend) => spend.commitment, + }, + }) + } + if (response.content.transaction.assetBalanceDeltas) { - this.log(`---Asset Balance Deltas---\n`) + this.log(`\n---Asset Balance Deltas---\n`) CliUx.ux.table(response.content.transaction.assetBalanceDeltas, { assetId: { header: 'Asset ID', diff --git a/ironfish/src/rpc/routes/wallet/__fixtures__/getTransaction.test.ts.fixture b/ironfish/src/rpc/routes/wallet/__fixtures__/getTransaction.test.ts.fixture new file mode 100644 index 0000000000..e9ea860705 --- /dev/null +++ b/ironfish/src/rpc/routes/wallet/__fixtures__/getTransaction.test.ts.fixture @@ -0,0 +1,45 @@ +{ + "Route wallet/getAccountTransaction gets transaction by account": [ + { + "version": 2, + "id": "0eb11031-e0c8-47bf-b653-51f1f6f3d80a", + "name": "account", + "spendingKey": "8c43e126f7f5158bfc50e10548118e92288936bc63ef806bd94bf6264eb2985e", + "viewKey": "ad0faf2dd74086123a4e5b40982975aba6a8e8ff3a45b9bdb56d2b0b18545641f4560dcd2e9340006d21df8c6d473ec47810695ff257e41524bea9cc13a3f20a", + "incomingViewKey": "894874a01056a4df1d6dd1f89bc846cd29da5371c12b3fe4d0359f928026b003", + "outgoingViewKey": "6ecbf4a57b45d1dc550fe1dafe01dd3bcc9224f6dd7d9badca25ae977f68eee2", + "publicAddress": "9ebd7fe8d5a8511b0695900e10493289f1decc3706369427ab879754485004bd", + "createdAt": null + }, + { + "header": { + "sequence": 2, + "previousBlockHash": "88B6FA8D745A4E53BDA001318E60B04EE2E4EE06A38095688D58049CB6F15ACA", + "noteCommitment": { + "type": "Buffer", + "data": "base64:8PYL4cItain96rVyrDKBsFLW752fvGtwa43otrhbkiE=" + }, + "transactionCommitment": { + "type": "Buffer", + "data": "base64:DHdeVwmWwnLe28yAdksb40sucGQiySKZixuyJFaMAns=" + }, + "target": "883423532389192164791648750371459257913741948437809479060803100646309888", + "randomness": "0", + "timestamp": 1682372146792, + "graffiti": "0000000000000000000000000000000000000000000000000000000000000000", + "noteSize": 4, + "work": "0" + }, + "transactions": [ + { + "type": "Buffer", + "data": "base64:AQAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGzKiP////8AAAAAhbdXRoiKFdbLX0/9XeS9gUXd9qSiORcsHGlAm6rUocWFRqOT6QWCLRPPSIAeShmw6GD+AErxUDeorrycBLBraJ+lnGwBoTEF1I7csP/0e26B8Mu9tyVxzaH+SqD9G5XfC5cU6m7hVchKTGXqMfHBVFvIx1V8NIHm5tifvtntC8IF9O2pmcICZfQ82zYKkaX4Jp/tsimI5Df+ZZWfS80hshwaXP1uXPaEa5dsqEUfSzKEXb71JYqlXRpngJy8XS55VFGLR+fLLT7TuFYPNQAQf9imPYnCjon6cdQ9xDW0L8AR1ywNjM6mwafG0DTZSi6XSDZ7h0jFor3Qgwlnd68TY781bi+7vpnaxhAPMUyaN9kj2KPEYmDTSyV/rx6SUygpXIODg/YU5v3SEMMw4UFEdqcKIVkcjHpyD9ypa7tSicp6I/FL/zplVOxNeH/38N9Gjbbq/jnVwp1GsHmV492SphbD4SgBwCMqQ6tgkn9P5J2qp4Bzcgqzc8O3ZK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Pn8EKzYk0UTN40byYWprvKuM7wsxN/0rru1VhtbZQRnCi8n2p3nRJsbFjMWs/ZQyMgQQwoD5JCOxhfng6sRcBht1Ls9RabXLFs78RjpZ+yL5hiilkf0dyuZV9pCeNRNf5gyhG4t11TbOycE262QBB1JKUyFoAn+K53mnIWyPVIMCZCs+fl7MzX5A6rqYO1Fmyxup6NTANFIihwDPBWggM1loAr+XGkML8632oiMbHcfez/6dQ3sjueCw==" + } + ] +} \ No newline at end of file diff --git a/ironfish/src/rpc/routes/wallet/getTransaction.test.ts b/ironfish/src/rpc/routes/wallet/getTransaction.test.ts new file mode 100644 index 0000000000..b5e9537cf1 --- /dev/null +++ b/ironfish/src/rpc/routes/wallet/getTransaction.test.ts @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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 { Assert } from '../../../assert' +import { useAccountFixture, useTxSpendsFixture } from '../../../testUtilities' +import { createRouteTest } from '../../../testUtilities/routeTest' + +describe('Route wallet/getAccountTransaction', () => { + const routeTest = createRouteTest(true) + + it('gets transaction by account', async () => { + const node = routeTest.node + const account = await useAccountFixture(node.wallet, 'account') + + const { transaction } = await useTxSpendsFixture(node, { account }) + + const response = await routeTest.client.wallet.getAccountTransaction({ + hash: transaction.hash().toString('hex'), + account: account.name, + }) + + expect(response.status).toBe(200) + + const { transaction: responseTransaction, account: responseAccount } = response.content + + Assert.isNotNull(responseTransaction) + + expect(responseAccount).toMatch(account.name) + + expect(responseTransaction.spends).toEqual( + transaction.spends.map((spend) => ({ + nullifier: spend.nullifier.toString('hex'), + commitment: spend.commitment.toString('hex'), + size: spend.size, + })), + ) + expect(responseTransaction.notes).toHaveLength(transaction.notes.length) + }) +}) diff --git a/ironfish/src/rpc/routes/wallet/getTransaction.ts b/ironfish/src/rpc/routes/wallet/getTransaction.ts index 935ab24c72..dcd390b530 100644 --- a/ironfish/src/rpc/routes/wallet/getTransaction.ts +++ b/ironfish/src/rpc/routes/wallet/getTransaction.ts @@ -4,7 +4,7 @@ import * as yup from 'yup' import { TransactionStatus, TransactionType } from '../../../wallet' import { ApiNamespace, router } from '../router' -import { RpcAccountDecryptedNote } from './types' +import { RpcAccountDecryptedNote, RpcSpend } from './types' import { getAccount, getAccountDecryptedNotes, @@ -36,6 +36,7 @@ export type GetAccountTransactionResponse = { submittedSequence: number assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }> notes: RpcAccountDecryptedNote[] + spends: RpcSpend[] } | null } @@ -95,6 +96,17 @@ export const GetAccountTransactionResponseSchema: yup.ObjectSchema ({ + nullifier: spend.nullifier.toString('hex'), + commitment: spend.commitment.toString('hex'), + size: spend.size, + })) + const confirmations = request.data.confirmations ?? node.config.get('confirmations') const status = await node.wallet.getTransactionStatus(account, transaction, { @@ -135,6 +153,7 @@ router.register