Skip to content

Commit

Permalink
adds transaction timer to wallet send
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir committed Mar 21, 2024
1 parent 0ea0100 commit a1b97ea
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ironfish-cli/src/commands/wallet/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { selectAsset } from '../../utils/asset'
import { promptCurrency } from '../../utils/currency'
import { getExplorer } from '../../utils/explorer'
import { selectFee } from '../../utils/fees'
import { getSpendPostTimeInMs } from '../../utils/spendPostTime'
import { TransactionTimer } from '../../utils/timer'
import { displayTransactionSummary, watchTransaction } from '../../utils/transaction'

export class Send extends IronfishCommand {
Expand Down Expand Up @@ -103,6 +105,11 @@ export class Send extends IronfishCommand {
description: 'The note hashes to include in the transaction',
multiple: true,
}),
benchmark: Flags.boolean({
hidden: true,
default: false,
description: 'Force run the benchmark to measure the time to combine 1 note',
}),
}

async start(): Promise<void> {
Expand Down Expand Up @@ -239,14 +246,20 @@ export class Send extends IronfishCommand {

displayTransactionSummary(raw, assetId, amount, from, to, memo)

const spendPostTime = await getSpendPostTimeInMs(this.sdk, client, from, flags.benchmark)

const transactionTimer = new TransactionTimer(spendPostTime, raw)

transactionTimer.displayEstimate()

if (!flags.confirm) {
const confirmed = await CliUx.ux.confirm('Do you confirm (Y/N)?')
if (!confirmed) {
this.error('Transaction aborted.')
}
}

CliUx.ux.action.start('Sending the transaction')
transactionTimer.start()

const response = await client.wallet.postTransaction({
transaction: RawTransactionSerde.serialize(raw).toString('hex'),
Expand All @@ -256,7 +269,7 @@ export class Send extends IronfishCommand {
const bytes = Buffer.from(response.content.transaction, 'hex')
const transaction = new Transaction(bytes)

CliUx.ux.action.stop()
transactionTimer.end()

if (response.content.accepted === false) {
this.warn(
Expand All @@ -268,6 +281,7 @@ export class Send extends IronfishCommand {
this.warn(`Transaction '${transaction.hash().toString('hex')}' failed to broadcast`)
}

this.log()
this.log(`Sent ${CurrencyUtils.renderIron(amount, true, assetId)} to ${to} from ${from}`)
this.log(`Hash: ${transaction.hash().toString('hex')}`)
this.log(`Fee: ${CurrencyUtils.renderIron(transaction.fee(), true)}`)
Expand Down

0 comments on commit a1b97ea

Please sign in to comment.