Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ironfish): add spends to wallet/getTransaction #3835

Merged
merged 4 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions ironfish-cli/src/commands/wallet/transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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/38N9Gjbb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h5g/CC1q9HzVHDe70x4eXTHQqhpD0rrZZ9/EJQqcCZvrh39DMJ5RndPn8EKzYk0UTN40byYWprvKuM7wsxN/0rru1VhtbZQRnCi8n2p3nRJsbFjMWs/ZQyMgQQwoD5JCOxhfng6sRcBht1Ls9RabXLFs78RjpZ+yL5hiilkf0dyuZV9pCeNRNf5gyhG4t11TbOycE262QBB1JKUyFoAn+K53mnIWyPVIMCZCs+fl7MzX5A6rqYO1Fmyxup6NTANFIihwDPBWggM1loAr+XGkML8632oiMbHcfez/6dQ3sjueCw=="
}
]
}
39 changes: 39 additions & 0 deletions ironfish/src/rpc/routes/wallet/getTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
21 changes: 20 additions & 1 deletion ironfish/src/rpc/routes/wallet/getTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,6 +36,7 @@ export type GetAccountTransactionResponse = {
submittedSequence: number
assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }>
notes: RpcAccountDecryptedNote[]
spends: RpcSpend[]
} | null
}

Expand Down Expand Up @@ -94,6 +95,17 @@ export const GetAccountTransactionResponseSchema: yup.ObjectSchema<GetAccountTra
.defined(),
)
.defined(),
spends: yup
.array(
yup
.object({
nullifier: yup.string().defined(),
commitment: yup.string().defined(),
size: yup.number().defined(),
})
.defined(),
)
.defined(),
})
.defined(),
})
Expand Down Expand Up @@ -122,6 +134,12 @@ router.register<typeof GetAccountTransactionRequestSchema, GetAccountTransaction

const notes = await getAccountDecryptedNotes(node, account, transaction)

const spends = transaction.transaction.spends.map((spend) => ({
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, {
Expand All @@ -134,6 +152,7 @@ router.register<typeof GetAccountTransactionRequestSchema, GetAccountTransaction
...serializedTransaction,
assetBalanceDeltas,
notes,
spends,
status,
type,
confirmations,
Expand Down