Skip to content

Commit

Permalink
feat: adds long prompt method for input of lengthy text (#4716)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks authored Feb 12, 2024
1 parent ed86d43 commit df84a1c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { Flags } from '@oclif/core'
import { IronfishCommand } from '../../../command'
import { RemoteFlags } from '../../../flags'
import { largePrompt } from '../../../utils/longPrompt'

export class CreateSignatureShareCommand extends IronfishCommand {
static description = `Creates a signature share for a participant for a given transaction`
Expand All @@ -20,25 +21,35 @@ export class CreateSignatureShareCommand extends IronfishCommand {
unsignedTransaction: Flags.string({
char: 'u',
description: 'The unsigned transaction for which the signature share will be created',
required: true,
required: false,
}),
signingPackage: Flags.string({
char: 's',
description: 'The signing package for which the signature share will be created',
required: true,
required: false,
}),
}

async start(): Promise<void> {
const { flags } = await this.parse(CreateSignatureShareCommand)
let unsignedTransaction = flags.unsignedTransaction?.trim()
let signingPackage = flags.signingPackage?.trim()

if (!unsignedTransaction) {
unsignedTransaction = await largePrompt('Enter the unsigned transaction: ')
}

if (!signingPackage) {
signingPackage = await largePrompt('Enter the signing package: ')
}

const client = await this.sdk.connectRpc()
// TODO(andrea): use flags.transaction to create commiment when we incorportate deterministic nonces
// set required to true as well
const signatureShareResponse = await client.wallet.multisig.createSignatureShare({
account: flags.account,
unsignedTransaction: flags.unsignedTransaction,
signingPackage: flags.signingPackage,
unsignedTransaction,
signingPackage,
seed: 0,
})

Expand Down
19 changes: 19 additions & 0 deletions ironfish-cli/src/utils/longPrompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 readline from 'readline'

// Most effective way to take in a large textual prompt input without affecting UX
export function largePrompt(question: string): Promise<string> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})

return new Promise((resolve) => {
rl.question(question, (answer) => {
rl.close()
resolve(answer.trim())
})
})
}

0 comments on commit df84a1c

Please sign in to comment.