Skip to content

Commit

Permalink
adding full transaction object to burn and mint asset response (#4311)
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir authored Sep 20, 2023
1 parent fb34f30 commit 0f08a71
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion ironfish/src/rpc/routes/wallet/burnAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '../../../testUtilities'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { CurrencyUtils } from '../../../utils'
import { serializeRpcWalletTransaction } from './utils'

describe('Route wallet/burnAsset', () => {
const routeTest = createRouteTest(true)
Expand Down Expand Up @@ -86,6 +87,9 @@ describe('Route wallet/burnAsset', () => {
value: CurrencyUtils.encode(value),
})

const walletTransaction = await account.getTransaction(burnTransaction.hash())
Assert.isNotUndefined(walletTransaction)

expect(response.content).toEqual({
asset: {
id: asset.id().toString('hex'),
Expand All @@ -100,11 +104,11 @@ describe('Route wallet/burnAsset', () => {
verification: node.assetsVerifier.verify(asset.id()),
createdTransactionHash: accountAsset.createdTransactionHash.toString('hex') ?? null,
},
transaction: await serializeRpcWalletTransaction(node, account, walletTransaction),
id: asset.id().toString('hex'),
assetId: asset.id().toString('hex'),
name: asset.name().toString('hex'),
assetName: asset.name().toString('hex'),
transactionHash: burnTransaction.hash().toString('hex'),
hash: burnTransaction.hash().toString('hex'),
value: burnTransaction.burns[0].value.toString(),
})
Expand Down
16 changes: 10 additions & 6 deletions ironfish/src/rpc/routes/wallet/burnAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Assert } from '../../../assert'
import { CurrencyUtils, YupUtils } from '../../../utils'
import { RpcAsset, RpcAssetSchema, RpcBurn, RpcBurnSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'
import { RpcWalletTransaction, RpcWalletTransactionSchema } from './types'
import { getAccount, serializeRpcWalletTransaction } from './utils'

export interface BurnAssetRequest {
account?: string
Expand All @@ -33,9 +34,9 @@ export const BurnAssetRequestSchema: yup.ObjectSchema<BurnAssetRequest> = yup

export type BurnAssetResponse = RpcBurn & {
asset: RpcAsset
transactionHash: string
transaction: RpcWalletTransaction
/**
* @deprecated Please use `transactionHash` instead
* @deprecated Please use `transaction.hash` instead
*/
hash: string
/**
Expand All @@ -48,10 +49,10 @@ export const BurnAssetResponseSchema: yup.ObjectSchema<BurnAssetResponse> =
RpcBurnSchema.concat(
yup
.object({
name: yup.string().defined(),
asset: RpcAssetSchema.defined(),
transaction: RpcWalletTransactionSchema.defined(),
name: yup.string().defined(),
hash: yup.string().defined(),
transactionHash: yup.string().defined(),
})
.defined(),
).defined()
Expand Down Expand Up @@ -89,6 +90,9 @@ routes.register<typeof BurnAssetRequestSchema, BurnAssetResponse>(
Assert.isEqual(transaction.burns.length, 1)
const burn = transaction.burns[0]

const transactionValue = await account.getTransaction(transaction.hash())
Assert.isNotUndefined(transactionValue)

request.end({
asset: {
id: asset.id.toString('hex'),
Expand All @@ -103,12 +107,12 @@ routes.register<typeof BurnAssetRequestSchema, BurnAssetResponse>(
}),
createdTransactionHash: asset.createdTransactionHash.toString('hex'),
},
transaction: await serializeRpcWalletTransaction(node, account, transactionValue),
id: burn.assetId.toString('hex'),
assetId: burn.assetId.toString('hex'),
hash: transaction.hash().toString('hex'),
name: asset.name.toString('hex'),
assetName: asset.name.toString('hex'),
transactionHash: transaction.hash().toString('hex'),
value: CurrencyUtils.encode(burn.value),
})
},
Expand Down
6 changes: 5 additions & 1 deletion ironfish/src/rpc/routes/wallet/mintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Assert } from '../../../assert'
import { useAccountFixture, useMinerBlockFixture, useTxFixture } from '../../../testUtilities'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { CurrencyUtils } from '../../../utils'
import { serializeRpcWalletTransaction } from './utils'

describe('Route wallet/mintAsset', () => {
const routeTest = createRouteTest(true)
Expand Down Expand Up @@ -93,6 +94,9 @@ describe('Route wallet/mintAsset', () => {
value: CurrencyUtils.encode(mintData.value),
})

const walletTransaction = await account.getTransaction(mintTransaction.hash())
Assert.isNotUndefined(walletTransaction)

expect(response.content).toEqual({
asset: {
id: asset.id().toString('hex'),
Expand All @@ -108,11 +112,11 @@ describe('Route wallet/mintAsset', () => {
}),
verification: node.assetsVerifier.verify(asset.id()),
},
transaction: await serializeRpcWalletTransaction(node, account, walletTransaction),
id: asset.id().toString('hex'),
creator: asset.creator().toString('hex'),
assetId: asset.id().toString('hex'),
metadata: asset.metadata().toString('hex'),
transactionHash: mintTransaction.hash().toString('hex'),
hash: mintTransaction.hash().toString('hex'),
name: asset.name().toString('hex'),
assetName: asset.name().toString('hex'),
Expand Down
14 changes: 9 additions & 5 deletions ironfish/src/rpc/routes/wallet/mintAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { CurrencyUtils, YupUtils } from '../../../utils'
import { MintAssetOptions } from '../../../wallet/interfaces/mintAssetOptions'
import { RpcAsset, RpcAssetSchema, RpcMint, RpcMintSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'
import { RpcWalletTransaction, RpcWalletTransactionSchema } from './types'
import { getAccount, serializeRpcWalletTransaction } from './utils'

export interface MintAssetRequest {
account?: string
Expand Down Expand Up @@ -39,9 +40,9 @@ export const MintAssetRequestSchema: yup.ObjectSchema<MintAssetRequest> = yup

export type MintAssetResponse = RpcMint & {
asset: RpcAsset
transactionHash: string
transaction: RpcWalletTransaction
/**
* @deprecated Please use `transactionHash` instead
* @deprecated Please use `transaction.hash` instead
*/
hash: string
}
Expand All @@ -51,8 +52,8 @@ export const MintAssetResponseSchema: yup.ObjectSchema<MintAssetResponse> =
yup
.object({
asset: RpcAssetSchema.defined(),
transaction: RpcWalletTransactionSchema.defined(),
hash: yup.string().defined(),
transactionHash: yup.string().defined(),
})
.defined(),
).defined()
Expand Down Expand Up @@ -110,6 +111,9 @@ routes.register<typeof MintAssetRequestSchema, MintAssetResponse>(
const asset = await account.getAsset(mint.asset.id())
Assert.isNotUndefined(asset)

const transactionValue = await account.getTransaction(transaction.hash())
Assert.isNotUndefined(transactionValue)

request.end({
asset: {
id: asset.id.toString('hex'),
Expand All @@ -124,9 +128,9 @@ routes.register<typeof MintAssetRequestSchema, MintAssetResponse>(
}),
createdTransactionHash: asset.createdTransactionHash.toString('hex'),
},
transaction: await serializeRpcWalletTransaction(node, account, transactionValue),
assetId: asset.id.toString('hex'),
hash: transaction.hash().toString('hex'),
transactionHash: transaction.hash().toString('hex'),
name: asset.name.toString('hex'),
value: mint.value.toString(),
id: mint.asset.id().toString('hex'),
Expand Down

0 comments on commit 0f08a71

Please sign in to comment.