Skip to content

Commit

Permalink
displays tx details before signing in 'wallet:sign' (#5691)
Browse files Browse the repository at this point in the history
changes the 'wallet:transactions:sign' command to render the details of the
unsigned transaction before signing the transaction

this gives the user a chance to see the transaction details on the CLI before
signing the transaction
  • Loading branch information
hughy authored Dec 4, 2024
1 parent 1a313d2 commit 5c05701
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ironfish-cli/src/commands/wallet/transactions/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* 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 { CurrencyUtils, RpcClient, Transaction } from '@ironfish/sdk'
import { CurrencyUtils, RpcClient, Transaction, UnsignedTransaction } from '@ironfish/sdk'
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../command'
import { RemoteFlags } from '../../../flags'
import { LedgerSingleSigner } from '../../../ledger'
import * as ui from '../../../ui'
import { renderTransactionDetails, watchTransaction } from '../../../utils/transaction'
import { renderUnsignedTransactionDetails, watchTransaction } from '../../../utils/transaction'

export class TransactionsSignCommand extends IronfishCommand {
static description = `sign an unsigned transaction`
Expand Down Expand Up @@ -45,22 +45,27 @@ export class TransactionsSignCommand extends IronfishCommand {
this.error('Cannot use --watch without --broadcast')
}

let unsignedTransaction = flags.unsignedTransaction
if (!unsignedTransaction) {
unsignedTransaction = await ui.longPrompt('Enter the unsigned transaction', {
let unsignedTransactionHex = flags.unsignedTransaction
if (!unsignedTransactionHex) {
unsignedTransactionHex = await ui.longPrompt('Enter the unsigned transaction', {
required: true,
})
}

let signedTransaction: string
let account: string

const unsignedTransaction = new UnsignedTransaction(
Buffer.from(unsignedTransactionHex, 'hex'),
)
await renderUnsignedTransactionDetails(client, unsignedTransaction, undefined, this.logger)

if (flags.ledger) {
const response = await this.signWithLedger(client, unsignedTransaction)
const response = await this.signWithLedger(client, unsignedTransactionHex)
signedTransaction = response.transaction
account = response.account
} else {
const response = await this.signWithAccount(client, unsignedTransaction)
const response = await this.signWithAccount(client, unsignedTransactionHex)
signedTransaction = response.transaction
account = response.account
}
Expand All @@ -77,8 +82,6 @@ export class TransactionsSignCommand extends IronfishCommand {
this.log(`\nHash: ${transaction.hash().toString('hex')}`)
this.log(`Fee: ${CurrencyUtils.render(transaction.fee(), true)}`)

await renderTransactionDetails(client, transaction, account, this.logger)

if (flags.broadcast && response.content.accepted === false) {
this.error(
`Transaction '${transaction.hash().toString('hex')}' was not accepted into the mempool`,
Expand Down

0 comments on commit 5c05701

Please sign in to comment.