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

Remove CurrencyUtils.encode #5567

Draft
wants to merge 1 commit into
base: staging
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions ironfish-cli/src/commands/wallet/burn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ This will destroy tokens and decrease supply for a given asset.`
burns: [
{
assetId,
value: CurrencyUtils.encode(amount),
value: amount.toString(),
},
],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
fee: flags.fee ? flags.fee.toString() : null,
feeRate: flags.feeRate ? flags.feeRate.toString() : null,
expiration: flags.expiration,
confirmations: flags.confirmations,
}
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/commands/wallet/chainport/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ export class BridgeCommand extends IronfishCommand {
memo: txn.gas_fee_output.memo,
},
],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
fee: flags.fee ? flags.fee.toString() : null,
feeRate: flags.feeRate ? flags.feeRate.toString() : null,
expiration,
}

Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/src/commands/wallet/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,16 @@ This will create tokens and increase supply for a given asset.`
...(assetData != null ? { assetId } : {}),
name: name,
metadata: metadata,
value: CurrencyUtils.encode(amount),
value: amount.toString(),
transferOwnershipTo: flags.transferOwnershipTo,
}

const params: CreateTransactionRequest = {
account,
outputs: [],
mints: [mint],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
fee: flags.fee ? flags.fee.toString() : null,
feeRate: flags.feeRate ? flags.feeRate.toString() : null,
expiration: expiration,
confirmations: flags.confirmations,
}
Expand Down
10 changes: 5 additions & 5 deletions ironfish-cli/src/commands/wallet/notes/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,12 @@ export class CombineNotesCommand extends IronfishCommand {
{
publicAddress: to,
assetId,
amount: CurrencyUtils.encode(totalAmount),
amount: totalAmount.toString(),
memo,
},
],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
fee: flags.fee ? flags.fee.toString() : null,
feeRate: flags.feeRate ? flags.feeRate.toString() : null,
notes: notes.map((note) => note.noteHash),
expiration,
}
Expand All @@ -326,8 +326,8 @@ export class CombineNotesCommand extends IronfishCommand {
if (assetId === Asset.nativeId().toString('hex')) {
amount = totalAmount - raw.fee
}
params.outputs[0].amount = CurrencyUtils.encode(amount)
params.fee = CurrencyUtils.encode(raw.fee)
params.outputs[0].amount = amount.toString()
params.fee = raw.fee.toString()

const createTransactionResponse = await client.wallet.createTransaction(params)
const createTransactionBytes = Buffer.from(
Expand Down
6 changes: 3 additions & 3 deletions ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,13 @@ export class Send extends IronfishCommand {
outputs: [
{
publicAddress: to,
amount: CurrencyUtils.encode(amount),
amount: amount.toString(),
memo,
assetId,
},
],
fee: flags.fee ? CurrencyUtils.encode(flags.fee) : null,
feeRate: flags.feeRate ? CurrencyUtils.encode(flags.feeRate) : null,
fee: flags.fee ? flags.fee.toString() : null,
feeRate: flags.feeRate ? flags.feeRate.toString() : null,
expiration: expiration,
confirmations: flags.confirmations,
notes: flags.note,
Expand Down
4 changes: 2 additions & 2 deletions ironfish-cli/src/utils/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function selectFee(options: {

const custom = await options.client.wallet.createTransaction({
...options.transaction,
fee: CurrencyUtils.encode(fee),
fee: fee.toString(),
})

const bytes = Buffer.from(custom.content.transaction, 'hex')
Expand All @@ -103,7 +103,7 @@ async function getTxWithFee(
): Promise<RawTransaction | null> {
const promise = client.wallet.createTransaction({
...params,
feeRate: CurrencyUtils.encode(feeRate),
feeRate: feeRate.toString(),
})

const response = await promise.catch((e) => {
Expand Down
5 changes: 2 additions & 3 deletions ironfish-cli/src/utils/spendPostTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Asset } from '@ironfish/rust-nodejs'
import {
BenchUtils,
CreateTransactionRequest,
CurrencyUtils,
EstimateFeeRatesResponse,
IronfishSdk,
RawTransaction,
Expand Down Expand Up @@ -79,7 +78,7 @@ export async function benchmarkSpendPostTime(
outputs: [
{
publicAddress: publicKey,
amount: CurrencyUtils.encode(BigInt(notes[0].value)),
amount: BigInt(notes[0].value).toString(),
memo: '',
},
],
Expand All @@ -95,7 +94,7 @@ export async function benchmarkSpendPostTime(
outputs: [
{
publicAddress: publicKey,
amount: CurrencyUtils.encode(BigInt(notes[0].value) + BigInt(notes[1].value)),
amount: (BigInt(notes[0].value) + BigInt(notes[1].value)).toString(),
memo: '',
},
],
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/mining/poolShares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Assert } from '../assert'
import { Config } from '../fileStores/config'
import { Logger } from '../logger'
import { RpcClient } from '../rpc/clients/client'
import { CurrencyUtils, ErrorUtils } from '../utils'
import { ErrorUtils } from '../utils'
import { PoolDatabase } from './poolDatabase'
import { DatabaseBlock, DatabasePayoutTransaction } from './poolDatabase/database'
import { WebhookNotifier } from './webhooks'
Expand Down Expand Up @@ -236,7 +236,7 @@ export class MiningPoolShares {
const amount = amountPerShare * BigInt(payout.shareCount)
outputs.push({
publicAddress: payout.publicAddress,
amount: CurrencyUtils.encode(amount),
amount: amount.toString(),
memo: `${this.poolName} payout ${payoutPeriod.id}`,
assetId,
})
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/chain/estimateFeeRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as yup from 'yup'
import { Assert } from '../../../assert'
import { PRIORITY_LEVELS, PriorityLevel } from '../../../memPool/feeEstimator'
import { FullNode } from '../../../node'
import { CurrencyUtils } from '../../../utils'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

Expand Down Expand Up @@ -35,6 +34,6 @@ routes.register<typeof EstimateFeeRateRequestSchema, EstimateFeeRateResponse>(

const priority = request.data?.priority ?? 'average'
const rate = node.memPool.feeEstimator.estimateFeeRate(priority)
request.end({ rate: CurrencyUtils.encode(rate) })
request.end({ rate: rate.toString() })
},
)
7 changes: 3 additions & 4 deletions ironfish/src/rpc/routes/chain/estimateFeeRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import * as yup from 'yup'
import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { CurrencyUtils } from '../../../utils'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

Expand Down Expand Up @@ -36,9 +35,9 @@ routes.register<typeof EstimateFeeRatesRequestSchema, EstimateFeeRatesResponse>(
const rates = node.memPool.feeEstimator.estimateFeeRates()

request.end({
slow: CurrencyUtils.encode(rates.slow),
average: CurrencyUtils.encode(rates.average),
fast: CurrencyUtils.encode(rates.fast),
slow: rates.slow.toString(),
average: rates.average.toString(),
fast: rates.fast.toString(),
})
},
)
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/chain/getAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import '../../../testUtilities/matchers'
import { Asset } from '@ironfish/rust-nodejs'
import { Assert } from '../../../assert'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { CurrencyUtils } from '../../../utils'

describe('Route chain.getAsset', () => {
const routeTest = createRouteTest()
Expand All @@ -24,7 +23,7 @@ describe('Route chain.getAsset', () => {
expect(response.content.nonce).toBe(asset.nonce)
expect(response.content.creator).toBe(asset.creator.toString('hex'))
expect(response.content.owner).toBe(asset.owner.toString('hex'))
expect(response.content.supply).toBe(CurrencyUtils.encode(asset.supply))
expect(response.content.supply).toBe(asset.supply.toString())
expect(response.content.createdTransactionHash).toBe(
asset.createdTransactionHash.toString('hex'),
)
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/chain/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as yup from 'yup'
import { Assert } from '../../../assert'
import { AssetValue } from '../../../blockchain/database/assetValue'
import { FullNode } from '../../../node'
import { CurrencyUtils } from '../../../utils'
import { AssetStatus } from '../../../wallet'
import { RpcNotFoundError, RpcValidationError } from '../../adapters'
import { ApiNamespace } from '../namespaces'
Expand Down Expand Up @@ -81,7 +80,7 @@ routes.register<typeof GetAssetRequestSchema, GetAssetResponse>(
nonce: asset.nonce,
creator: asset.creator.toString('hex'),
owner: asset.owner.toString('hex'),
supply: CurrencyUtils.encode(asset.supply),
supply: asset.supply.toString(),
status: await getAssetStatus(node, asset),
verification: node.assetsVerifier.verify(asset.id),
})
Expand Down
8 changes: 4 additions & 4 deletions ironfish/src/rpc/routes/chain/getTransactionStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ChainProcessor } from '../../../chainProcessor'
import { FullNode } from '../../../node'
import { Block } from '../../../primitives/block'
import { BlockHeader } from '../../../primitives/blockheader'
import { BufferUtils, CurrencyUtils } from '../../../utils'
import { BufferUtils } from '../../../utils'
import { PromiseUtils } from '../../../utils/promise'
import { isValidIncomingViewKey, isValidOutgoingViewKey } from '../../../wallet/validator'
import { RpcValidationError } from '../../adapters/errors'
Expand Down Expand Up @@ -158,7 +158,7 @@ routes.register<typeof GetTransactionStreamRequestSchema, GetTransactionStreamRe

const assetValue = await node.chain.getAssetById(decryptedNote.assetId())
notes.push({
value: CurrencyUtils.encode(decryptedNote.value()),
value: decryptedNote.value().toString(),
memo,
assetId: decryptedNote.assetId().toString('hex'),
assetName: assetValue?.name.toString('hex') || '',
Expand All @@ -171,7 +171,7 @@ routes.register<typeof GetTransactionStreamRequestSchema, GetTransactionStreamRe
for (const burn of tx.burns) {
const assetValue = await node.chain.getAssetById(burn.assetId)
burns.push({
value: CurrencyUtils.encode(burn.value),
value: burn.value.toString(),
id: burn.assetId.toString('hex'),
assetId: burn.assetId.toString('hex'),
assetName: assetValue?.name.toString('hex') || '',
Expand All @@ -180,7 +180,7 @@ routes.register<typeof GetTransactionStreamRequestSchema, GetTransactionStreamRe

for (const mint of tx.mints) {
mints.push({
value: CurrencyUtils.encode(mint.value),
value: mint.value.toString(),
assetId: mint.asset.id().toString('hex'),
assetName: mint.asset.name().toString('hex'),
id: mint.asset.id().toString('hex'),
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/wallet/burnAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
usePostTxFixture,
} from '../../../testUtilities'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { CurrencyUtils } from '../../../utils'
import { serializeRpcWalletTransaction } from './serializers'

describe('Route wallet/burnAsset', () => {
Expand Down Expand Up @@ -84,7 +83,7 @@ describe('Route wallet/burnAsset', () => {
account: account.name,
assetId: assetId.toString('hex'),
fee: '1',
value: CurrencyUtils.encode(value),
value: value.toString(),
})

const walletTransaction = await account.getTransaction(burnTransaction.hash())
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/burnAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ routes.register<typeof BurnAssetRequestSchema, BurnAssetResponse>(
hash: transaction.hash().toString('hex'),
name: asset.name.toString('hex'),
assetName: asset.name.toString('hex'),
value: CurrencyUtils.encode(burn.value),
value: burn.value.toString(),
})
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BufferMap } from 'buffer-map'
import { Assert } from '../../../assert'
import { useAccountFixture, useBlockWithTx } from '../../../testUtilities'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { AsyncUtils, BufferUtils, CurrencyUtils } from '../../../utils'
import { AsyncUtils, BufferUtils } from '../../../utils'
import { DecryptedNoteValue } from '../../../wallet/walletdb/decryptedNoteValue'

describe('Route wallet/getAccountNotesStream', () => {
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Route wallet/getAccountNotesStream', () => {

Assert.isNotUndefined(expectedNote)

expect(note.value).toEqual(CurrencyUtils.encode(expectedNote.note.value()))
expect(note.value).toEqual(expectedNote.note.value().toString())
expect(note.assetId).toEqual(expectedNote.note.assetId().toString('hex'))
expect(note.memo).toEqual(BufferUtils.toHuman(expectedNote.note.memo()))
expect(note.sender).toEqual(expectedNote.note.sender())
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/routes/wallet/getAccountNotesStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 * as yup from 'yup'
import { BufferUtils, CurrencyUtils } from '../../../utils'
import { BufferUtils } from '../../../utils'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'
import { AssertHasRpcContext } from '../rpcContext'
Expand Down Expand Up @@ -46,7 +46,7 @@ routes.register<typeof GetAccountNotesStreamRequestSchema, GetAccountNotesStream
const asset = await account.getAsset(note.assetId())

request.stream({
value: CurrencyUtils.encode(note.value()),
value: note.value().toString(),
assetId: note.assetId().toString('hex'),
assetName: asset?.name.toString('hex') || '',
memo: BufferUtils.toHuman(note.memo()),
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/wallet/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import { ASSET_ID_LENGTH } from '@ironfish/rust-nodejs'
import * as yup from 'yup'
import { CurrencyUtils } from '../../../utils'
import { RpcNotFoundError, RpcValidationError } from '../../adapters'
import { RpcAsset, RpcAssetSchema } from '../chain/types'
import { ApiNamespace } from '../namespaces'
Expand Down Expand Up @@ -62,7 +61,7 @@ routes.register<typeof GetWalletAssetRequestSchema, GetWalletAssetResponse>(
status: await node.wallet.getAssetStatus(account, asset, {
confirmations: request.data.confirmations,
}),
supply: asset.supply ? CurrencyUtils.encode(asset.supply) : undefined,
supply: asset.supply ? asset.supply.toString() : undefined,
verification: node.assetsVerifier.verify(asset.id),
})
},
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/wallet/getAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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 * as yup from 'yup'
import { CurrencyUtils } from '../../../utils'
import { RpcAsset, RpcAssetSchema } from '../chain'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'
Expand Down Expand Up @@ -50,7 +49,7 @@ routes.register<typeof GetAssetsRequestSchema, GetAssetsResponse>(
status: await node.wallet.getAssetStatus(account, asset, {
confirmations: request.data.confirmations,
}),
supply: asset.supply !== null ? CurrencyUtils.encode(asset.supply) : undefined,
supply: asset.supply !== null ? asset.supply.toString() : undefined,
createdTransactionHash: asset.createdTransactionHash.toString('hex'),
verification: node.assetsVerifier.verify(asset.id),
})
Expand Down
9 changes: 4 additions & 5 deletions ironfish/src/rpc/routes/wallet/getBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import * as yup from 'yup'
import { AssetVerification } from '../../../assets'
import { CurrencyUtils } from '../../../utils'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'
import { AssertHasRpcContext } from '../rpcContext'
Expand Down Expand Up @@ -113,13 +112,13 @@ routes.register<typeof GetBalancesRequestSchema, GetBalancesResponse>(
assetOwner: asset?.owner.toString('hex') ?? '',
assetVerification: { status: context.assetsVerifier.verify(balance.assetId).status },
blockHash: balance.blockHash?.toString('hex') ?? null,
confirmed: CurrencyUtils.encode(balance.confirmed),
confirmed: balance.confirmed.toString(),
sequence: balance.sequence,
unconfirmed: CurrencyUtils.encode(balance.unconfirmed),
unconfirmed: balance.unconfirmed.toString(),
unconfirmedCount: balance.unconfirmedCount,
pending: CurrencyUtils.encode(balance.pending),
pending: balance.pending.toString(),
pendingCount: balance.pendingCount,
available: CurrencyUtils.encode(balance.available),
available: balance.available.toString(),
availableNoteCount: balance.availableNoteCount,
})
}
Expand Down
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/wallet/mintAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Asset } from '@ironfish/rust-nodejs'
import { Assert } from '../../../assert'
import { useAccountFixture, useMinerBlockFixture, useTxFixture } from '../../../testUtilities'
import { createRouteTest } from '../../../testUtilities/routeTest'
import { CurrencyUtils } from '../../../utils'
import { serializeRpcWalletTransaction } from './serializers'

describe('Route wallet/mintAsset', () => {
Expand Down Expand Up @@ -112,7 +111,7 @@ describe('Route wallet/mintAsset', () => {
fee: '1',
metadata: asset.metadata().toString('utf8'),
name: asset.name().toString('utf8'),
value: CurrencyUtils.encode(mintData.value),
value: mintData.value.toString(),
transferOwnershipTo: newOwner,
})

Expand Down
Loading
Loading