From 9200d18cb3537ad57c34e9f5747f2e37f54cd6fd Mon Sep 17 00:00:00 2001 From: Rahul Patni Date: Fri, 22 Sep 2023 15:18:19 -0700 Subject: [PATCH] removing deprecated field usage in wallet transactions and asset utils --- .../src/commands/wallet/transactions.ts | 33 ++++++++---- ironfish-cli/src/utils/asset.ts | 54 +++++++++++++------ 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/ironfish-cli/src/commands/wallet/transactions.ts b/ironfish-cli/src/commands/wallet/transactions.ts index e58f87b4db..faf3fd3b1b 100644 --- a/ironfish-cli/src/commands/wallet/transactions.ts +++ b/ironfish-cli/src/commands/wallet/transactions.ts @@ -7,6 +7,7 @@ import { CurrencyUtils, GetAccountTransactionsResponse, PartialRecursive, + RpcClient, TransactionType, } from '@ironfish/sdk' import { CliUx, Flags } from '@oclif/core' @@ -84,8 +85,8 @@ export class TransactionsCommand extends IronfishCommand { for await (const transaction of response.contentStream()) { const transactionRows = flags.notes - ? this.getTransactionRowsByNote(transaction, format) - : this.getTransactionRows(transaction, format) + ? await this.getTransactionRowsByNote(client, transaction, format) + : await this.getTransactionRows(client, transaction, format) CliUx.ux.table(transactionRows, columns, { printLine: this.log.bind(this), @@ -102,10 +103,11 @@ export class TransactionsCommand extends IronfishCommand { } } - getTransactionRows( + async getTransactionRows( + client: RpcClient, transaction: GetAccountTransactionsResponse, format: Format, - ): PartialRecursive[] { + ): Promise[]> { const nativeAssetId = Asset.nativeId().toString('hex') const assetBalanceDeltas = transaction.assetBalanceDeltas.sort((d) => @@ -118,7 +120,11 @@ export class TransactionsCommand extends IronfishCommand { let assetCount = assetBalanceDeltas.length - for (const [index, { assetId, assetName, delta }] of assetBalanceDeltas.entries()) { + for (const [index, { assetId, delta }] of assetBalanceDeltas.entries()) { + const asset = await client.wallet.getAsset({ + id: assetId, + }) + let amount = BigInt(delta) if (assetId === Asset.nativeId().toString('hex')) { @@ -142,7 +148,7 @@ export class TransactionsCommand extends IronfishCommand { ...transaction, group, assetId, - assetName, + assetName: asset.content.name, amount, feePaid, }) @@ -150,7 +156,7 @@ export class TransactionsCommand extends IronfishCommand { transactionRows.push({ group, assetId, - assetName, + assetName: asset.content.name, amount, }) } @@ -159,10 +165,11 @@ export class TransactionsCommand extends IronfishCommand { return transactionRows } - getTransactionRowsByNote( + async getTransactionRowsByNote( + client: RpcClient, transaction: GetAccountTransactionsResponse, format: Format, - ): PartialRecursive[] { + ): Promise[]> { Assert.isNotUndefined(transaction.notes) const transactionRows = [] @@ -177,7 +184,13 @@ export class TransactionsCommand extends IronfishCommand { for (const [index, note] of notes.entries()) { const amount = BigInt(note.value) const assetId = note.assetId - const assetName = note.assetName + + const asset = await client.wallet.getAsset({ + id: assetId, + }) + + const assetName = asset.content.name + const sender = note.sender const recipient = note.owner diff --git a/ironfish-cli/src/utils/asset.ts b/ironfish-cli/src/utils/asset.ts index 01f3a0b517..9a47521766 100644 --- a/ironfish-cli/src/utils/asset.ts +++ b/ironfish-cli/src/utils/asset.ts @@ -3,8 +3,13 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { Asset } from '@ironfish/rust-nodejs' -import { BufferUtils, CurrencyUtils, RpcClient, StringUtils } from '@ironfish/sdk' -import { AssetVerification } from '@ironfish/sdk' +import { + AssetVerification, + BufferUtils, + CurrencyUtils, + RpcClient, + StringUtils, +} from '@ironfish/sdk' import chalk from 'chalk' import inquirer from 'inquirer' @@ -102,7 +107,15 @@ export async function selectAsset( account: account, }) - balances = balances.filter((b) => b.assetCreator === accountResponse.content.publicKey) + balances = await Promise.all( + balances.filter(async (b) => { + const asset = await client.wallet.getAsset({ + id: b.assetId, + }) + + return asset.content.creator === accountResponse.content.publicKey + }), + ) } if (balances.length === 0) { @@ -111,25 +124,36 @@ export async function selectAsset( if (balances.length === 1 && !options.showSingleAssetChoice) { // If there's only one available asset, showing the choices is unnecessary + + const asset = await client.wallet.getAsset({ + id: balances[0].assetId, + }) + return { id: balances[0].assetId, - name: balances[0].assetName, + name: asset.content.name, } } - const choices = balances.map((balance) => { - const assetName = BufferUtils.toHuman(Buffer.from(balance.assetName, 'hex')) - const name = `${balance.assetId} (${assetName}) (${CurrencyUtils.renderIron( - balance.available, - )})` + const choices = Promise.all( + balances.map(async (balance) => { + const asset = await client.wallet.getAsset({ + id: balance.assetId, + }) - const value = { - id: balance.assetId, - name: balance.assetName, - } + const assetName = BufferUtils.toHuman(Buffer.from(asset.content.name, 'hex')) + const name = `${balance.assetId} (${assetName}) (${CurrencyUtils.renderIron( + balance.available, + )})` - return { value, name } - }) + const value = { + id: balance.assetId, + name: asset.content.name, + } + + return { value, name } + }), + ) const response = await inquirer.prompt<{ asset: {