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

Rahul/ifl 1603 make asset response consistent across all endpoints #4272

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
84e4811
new burn asset response with asset object
patnir Sep 7, 2023
6ba92da
updating tests
patnir Sep 7, 2023
dfdf840
moving asset to a types file to be reused in mint and burn
patnir Sep 8, 2023
a9fd8f8
updating test
patnir Sep 8, 2023
d659113
adding two different construct rpc methods
patnir Sep 12, 2023
de11199
updating RcpAccountAssetBalanceDeltaSchema
patnir Sep 12, 2023
de6602e
updating get account transactions
patnir Sep 12, 2023
2ee8aff
deprecating asset variables in balance endpoints
patnir Sep 12, 2023
067e459
removing asset object when id doesn't guarantee asset object is found
patnir Sep 12, 2023
bc00c67
removing optional asset object
patnir Sep 12, 2023
d9251c6
removing unused variable
patnir Sep 12, 2023
862744a
removing construct functions
patnir Sep 12, 2023
dee7827
removing optional asset object
patnir Sep 12, 2023
416e7dd
deprecating asset name fields in note, mint, and burn
patnir Sep 13, 2023
009d009
normalizing rpc asset object for all endpointS
patnir Sep 13, 2023
3fdcbb1
fixing tests
patnir Sep 13, 2023
e06918b
using asset value object
patnir Sep 13, 2023
8153ee0
adding back GetAssetResponse
patnir Sep 13, 2023
9371644
reverting client ts changes
patnir Sep 13, 2023
804d84b
show n/a if supply is not available
patnir Sep 13, 2023
d12c57e
Merge branch 'staging' into rahul/ifl-1603-spike-field-update-method-…
patnir Sep 13, 2023
7bb9d34
chain get asset uses same asset model
patnir Sep 13, 2023
acfc85c
using Assert.isNotUndefined(accountAsset)
patnir Sep 13, 2023
425e638
deprecating the status field on the asset
patnir Sep 13, 2023
0e00ba2
adding comment
patnir Sep 13, 2023
b4bdc00
removing expect
patnir Sep 13, 2023
cc80b3f
Resetti9ng fixture
patnir Sep 13, 2023
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
11 changes: 11 additions & 0 deletions ironfish/src/rpc/routes/wallet/burnAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ describe('Route wallet/burnAsset', () => {
})
jest.spyOn(wallet, 'burn').mockResolvedValueOnce(burnTransaction)

const accountAsset = await account.getAsset(assetId)

expect(accountAsset).toBeDefined()

const response = await routeTest.client.wallet.burnAsset({
account: account.name,
assetId: assetId.toString('hex'),
Expand All @@ -82,6 +86,13 @@ describe('Route wallet/burnAsset', () => {
})

expect(response.content).toEqual({
asset: {
id: asset.id().toString('hex'),
metadata: asset.metadata().toString('hex'),
name: asset.name().toString('hex'),
creator: asset.creator().toString('hex'),
nonce: accountAsset?.nonce ?? null,
},
assetId: asset.id().toString('hex'),
name: asset.name().toString('hex'),
hash: burnTransaction.hash().toString('hex'),
Expand Down
10 changes: 10 additions & 0 deletions ironfish/src/rpc/routes/wallet/burnAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as yup from 'yup'
import { Assert } from '../../../assert'
import { CurrencyUtils, YupUtils } from '../../../utils'
import { constructRpcAsset, RpcAsset, RpcAssetSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'

Expand All @@ -18,8 +19,15 @@ export interface BurnAssetRequest {
}

export interface BurnAssetResponse {
asset: RpcAsset
/**
* @deprecated Please use `asset.id` instead
*/
assetId: string
hash: string
/**
* @deprecated Please use `asset.name` instead
*/
name: string
value: string
}
Expand All @@ -38,6 +46,7 @@ export const BurnAssetRequestSchema: yup.ObjectSchema<BurnAssetRequest> = yup

export const BurnAssetResponseSchema: yup.ObjectSchema<BurnAssetResponse> = yup
.object({
asset: RpcAssetSchema.required(),
assetId: yup.string().required(),
hash: yup.string().required(),
name: yup.string().required(),
Expand Down Expand Up @@ -71,6 +80,7 @@ routes.register<typeof BurnAssetRequestSchema, BurnAssetResponse>(
const burn = transaction.burns[0]

request.end({
asset: constructRpcAsset(asset),
assetId: burn.assetId.toString('hex'),
hash: transaction.hash().toString('hex'),
name: asset.name.toString('hex'),
Expand Down
21 changes: 8 additions & 13 deletions ironfish/src/rpc/routes/wallet/getAccountTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as yup from 'yup'
import { TransactionStatus, TransactionType } from '../../../wallet'
import { RpcSpend, RpcSpendSchema } from '../chain'
import { ApiNamespace, routes } from '../router'
import { RpcWalletNote, RpcWalletNoteSchema } from './types'
import {
RcpAccountAssetBalanceDelta,
RcpAccountAssetBalanceDeltaSchema,
RpcWalletNote,
RpcWalletNoteSchema,
} from './types'
import {
getAccount,
getAccountDecryptedNotes,
Expand Down Expand Up @@ -35,7 +40,7 @@ export type GetAccountTransactionResponse = {
burnsCount: number
timestamp: number
submittedSequence: number
assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }>
assetBalanceDeltas: RcpAccountAssetBalanceDelta[]
notes: RpcWalletNote[]
Comment on lines -38 to 44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using an already defined object

spends: RpcSpend[]
} | null
Expand Down Expand Up @@ -69,17 +74,7 @@ export const GetAccountTransactionResponseSchema: yup.ObjectSchema<GetAccountTra
burnsCount: yup.number().defined(),
timestamp: yup.number().defined(),
submittedSequence: yup.number().defined(),
assetBalanceDeltas: yup
.array(
yup
.object({
assetId: yup.string().defined(),
assetName: yup.string().defined(),
delta: yup.string().defined(),
})
.defined(),
)
.defined(),
assetBalanceDeltas: yup.array(RcpAccountAssetBalanceDeltaSchema).defined(),
notes: yup.array(RpcWalletNoteSchema).defined(),
spends: yup.array(RpcSpendSchema).defined(),
})
Expand Down
21 changes: 8 additions & 13 deletions ironfish/src/rpc/routes/wallet/getAccountTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { TransactionValue } from '../../../wallet/walletdb/transactionValue'
import { RpcRequest } from '../../request'
import { RpcSpend, RpcSpendSchema } from '../chain'
import { ApiNamespace, routes } from '../router'
import { RpcWalletNote, RpcWalletNoteSchema } from './types'
import {
RcpAccountAssetBalanceDelta,
RcpAccountAssetBalanceDeltaSchema,
RpcWalletNote,
RpcWalletNoteSchema,
} from './types'
import {
getAccount,
getAccountDecryptedNotes,
Expand Down Expand Up @@ -43,7 +48,7 @@ export type GetAccountTransactionsResponse = {
expiration: number
timestamp: number
submittedSequence: number
assetBalanceDeltas: Array<{ assetId: string; assetName: string; delta: string }>
assetBalanceDeltas: RcpAccountAssetBalanceDelta[]
Comment on lines -46 to +51
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using an already defined object

notes?: RpcWalletNote[]
spends?: RpcSpend[]
}
Expand Down Expand Up @@ -79,17 +84,7 @@ export const GetAccountTransactionsResponseSchema: yup.ObjectSchema<GetAccountTr
expiration: yup.number().defined(),
timestamp: yup.number().defined(),
submittedSequence: yup.number().defined(),
assetBalanceDeltas: yup
.array(
yup
.object({
assetId: yup.string().defined(),
assetName: yup.string().defined(),
delta: yup.string().defined(),
})
.defined(),
)
.defined(),
assetBalanceDeltas: yup.array(RcpAccountAssetBalanceDeltaSchema).defined(),
notes: yup.array(RpcWalletNoteSchema).defined(),
spends: yup.array(RpcSpendSchema).defined(),
})
Expand Down
9 changes: 9 additions & 0 deletions ironfish/src/rpc/routes/wallet/getBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Asset } from '@ironfish/rust-nodejs'
import * as yup from 'yup'
import { AssetVerification } from '../../../assets'
import { constructRpcAsset, RpcAsset, RpcAssetSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'

Expand All @@ -18,6 +19,10 @@ export type GetBalanceRequest =
export type GetBalanceResponse = {
account: string
assetId: string
asset?: RpcAsset
/**
* @deprecated Please use getAsset endpoint to get this information
* */
assetVerification: AssetVerification
confirmed: string
unconfirmed: string
Expand All @@ -42,6 +47,7 @@ export const GetBalanceResponseSchema: yup.ObjectSchema<GetBalanceResponse> = yu
.object({
account: yup.string().defined(),
assetId: yup.string().defined(),
asset: RpcAssetSchema.optional(),
assetVerification: yup
.object({ status: yup.string().oneOf(['verified', 'unverified', 'unknown']).defined() })
.defined(),
patnir marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -74,9 +80,12 @@ routes.register<typeof GetBalanceRequestSchema, GetBalanceResponse>(
confirmations,
})

const asset = await account.getAsset(assetId)

request.end({
account: account.name,
assetId: assetId.toString('hex'),
asset: asset ? constructRpcAsset(asset) : undefined,
assetVerification: node.assetsVerifier.verify(assetId),
confirmed: balance.confirmed.toString(),
unconfirmed: balance.unconfirmed.toString(),
Expand Down
16 changes: 16 additions & 0 deletions ironfish/src/rpc/routes/wallet/getBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as yup from 'yup'
import { AssetVerification } from '../../../assets'
import { CurrencyUtils } from '../../../utils'
import { constructRpcAsset, RpcAsset, RpcAssetSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'

Expand All @@ -15,10 +16,23 @@ export interface GetBalancesRequest {
export interface GetBalancesResponse {
account: string
balances: {
asset?: RpcAsset
assetId: string
/**
* @deprecated Please use `asset.name` instead
*/
assetName: string
/**
* @deprecated Please use `asset.creator` instead
*/
assetCreator: string
/**
* @deprecated Please use getAsset endpoint to get this information
* */
assetOwner: string
/**
* @deprecated Please use getAsset endpoint to get this information
* */
assetVerification: AssetVerification
confirmed: string
unconfirmed: string
Expand Down Expand Up @@ -47,6 +61,7 @@ export const GetBalancesResponseSchema: yup.ObjectSchema<GetBalancesResponse> =
yup
.object()
.shape({
asset: RpcAssetSchema.defined(),
assetId: yup.string().defined(),
assetName: yup.string().defined(),
assetCreator: yup.string().defined(),
Expand Down Expand Up @@ -86,6 +101,7 @@ routes.register<typeof GetBalancesRequestSchema, GetBalancesResponse>(
const asset = await account.getAsset(balance.assetId)

balances.push({
asset: asset ? constructRpcAsset(asset) : undefined,
assetId: balance.assetId.toString('hex'),
assetName: asset?.name.toString('hex') ?? '',
assetCreator: asset?.creator.toString('hex') ?? '',
patnir marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
7 changes: 7 additions & 0 deletions ironfish/src/rpc/routes/wallet/mintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ describe('Route wallet/mintAsset', () => {
})

expect(response.content).toEqual({
asset: {
id: asset.id().toString('hex'),
metadata: asset.metadata().toString('hex'),
name: asset.name().toString('hex'),
creator: asset.creator().toString('hex'),
nonce: asset.nonce() ?? null,
},
assetId: asset.id().toString('hex'),
hash: mintTransaction.hash().toString('hex'),
name: asset.name().toString('hex'),
Expand Down
10 changes: 10 additions & 0 deletions ironfish/src/rpc/routes/wallet/mintAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as yup from 'yup'
import { Assert } from '../../../assert'
import { CurrencyUtils, YupUtils } from '../../../utils'
import { MintAssetOptions } from '../../../wallet/interfaces/mintAssetOptions'
import { constructRpcAssetFromAsset, RpcAsset, RpcAssetSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { getAccount } from './utils'

Expand All @@ -22,8 +23,15 @@ export interface MintAssetRequest {
}

export interface MintAssetResponse {
asset: RpcAsset
/**
* @deprecated Please use `asset.id` instead
*/
assetId: string
hash: string
/**
* @deprecated Please use `asset.name` instead
*/
name: string
value: string
}
Expand All @@ -44,6 +52,7 @@ export const MintAssetRequestSchema: yup.ObjectSchema<MintAssetRequest> = yup

export const MintAssetResponseSchema: yup.ObjectSchema<MintAssetResponse> = yup
.object({
asset: RpcAssetSchema.defined(),
assetId: yup.string().required(),
hash: yup.string().required(),
name: yup.string().required(),
Expand Down Expand Up @@ -94,6 +103,7 @@ routes.register<typeof MintAssetRequestSchema, MintAssetResponse>(
const mint = transaction.mints[0]

request.end({
asset: constructRpcAssetFromAsset(mint.asset),
assetId: mint.asset.id().toString('hex'),
hash: transaction.hash().toString('hex'),
name: mint.asset.name().toString('hex'),
Expand Down
18 changes: 18 additions & 0 deletions ironfish/src/rpc/routes/wallet/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import * as yup from 'yup'
import { AccountImport } from '../../../wallet/walletdb/accountValue'
import { RpcAsset, RpcAssetSchema } from '../../types'

export type RpcAccountTransaction = {
hash: string
Expand All @@ -21,13 +22,29 @@ export type RpcAccountTransaction = {

export type RcpAccountAssetBalanceDelta = {
assetId: string
/**
* @deprecated Please use the getAsset RPC to fetch additional asset details
*/
assetName: string
delta: string
}

export const RcpAccountAssetBalanceDeltaSchema: yup.ObjectSchema<RcpAccountAssetBalanceDelta> =
yup
.object({
assetId: yup.string().defined(),
assetName: yup.string().defined(),
delta: yup.string().defined(),
})
.defined()

export type RpcWalletNote = {
value: string
assetId: string
asset?: RpcAsset
/**
* @deprecated Please use `asset.name` instead
*/
assetName: string
memo: string
sender: string
Expand All @@ -51,6 +68,7 @@ export const RpcWalletNoteSchema: yup.ObjectSchema<RpcWalletNote> = yup
.object({
value: yup.string().defined(),
assetId: yup.string().defined(),
asset: RpcAssetSchema.optional(),
assetName: yup.string().defined(),
memo: yup.string().defined(),
sender: yup.string().defined(),
Expand Down
2 changes: 2 additions & 0 deletions ironfish/src/rpc/routes/wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DecryptedNoteValue } from '../../../wallet/walletdb/decryptedNoteValue'
import { TransactionValue } from '../../../wallet/walletdb/transactionValue'
import { WorkerPool } from '../../../workerPool'
import { ValidationError } from '../../adapters'
import { constructRpcAsset } from '../../types'
import {
RcpAccountAssetBalanceDelta,
RpcAccountImport,
Expand Down Expand Up @@ -173,6 +174,7 @@ export function serializeRpcWalletNote(
return {
value: CurrencyUtils.encode(note.note.value()),
assetId: note.note.assetId().toString('hex'),
asset: asset ? constructRpcAsset(asset) : undefined,
assetName: asset?.name.toString('hex') || '',
memo: note.note.memo(),
owner: note.note.owner(),
Expand Down
Loading
Loading